/// 用户能力权限模型 class CapabilityMap { final Map _capabilities; CapabilityMap(this._capabilities); factory CapabilityMap.fromJson(Map json) { final map = {}; json.forEach((key, value) { if (value is bool) { map[key] = value; } }); return CapabilityMap(map); } /// 默认全部开启 factory CapabilityMap.defaultAll() { return CapabilityMap({ 'LOGIN': true, 'TRADING': true, 'C2C': true, 'TRANSFER_IN': true, 'TRANSFER_OUT': true, 'P2P_SEND': true, 'P2P_RECEIVE': true, 'MINING_CLAIM': true, 'KYC': true, 'PROFILE_EDIT': true, 'VIEW_ASSET': true, 'VIEW_TEAM': true, 'VIEW_RECORDS': true, }); } bool isEnabled(String capability) => _capabilities[capability] ?? true; bool get loginEnabled => isEnabled('LOGIN'); bool get tradingEnabled => isEnabled('TRADING'); bool get c2cEnabled => isEnabled('C2C'); bool get transferInEnabled => isEnabled('TRANSFER_IN'); bool get transferOutEnabled => isEnabled('TRANSFER_OUT'); bool get p2pSendEnabled => isEnabled('P2P_SEND'); bool get p2pReceiveEnabled => isEnabled('P2P_RECEIVE'); bool get miningClaimEnabled => isEnabled('MINING_CLAIM'); bool get kycEnabled => isEnabled('KYC'); bool get profileEditEnabled => isEnabled('PROFILE_EDIT'); bool get viewAssetEnabled => isEnabled('VIEW_ASSET'); bool get viewTeamEnabled => isEnabled('VIEW_TEAM'); bool get viewRecordsEnabled => isEnabled('VIEW_RECORDS'); Map toJson() => Map.from(_capabilities); }