123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:flutter/foundation.dart';
- import 'package:vitalapp/architecture/utils/common_util.dart';
- import 'package:vitalapp/rpc.dart';
- import 'package:vitalapp/store/store.dart';
- import 'package:fis_common/helpers/encrypt.dart';
- import 'package:fis_common/logger/logger.dart';
- import 'interfaces/account.dart';
- class AccountManager implements IAccountManager {
- @override
- Future<int> login(String account, String password, bool isAutoLogin) async {
- int code = 0;
- try {
- final symmetryEncryptPassword =
- password.isEmpty ? '' : FEncryptHelper.symmetryEncrypt(password);
- final result = await rpc.vitalLogin.commonLoginAsync(
- CommonLoginRequest2(
- anyAccount: account,
- password: symmetryEncryptPassword,
- loginSource: LoginSource.Pad,
- ),
- );
- await Store.user
- .handleLogin(account, result.token!, password, isAutoLogin);
- } catch (e) {
- // TODO 待提取封装公用函数
- code = -1;
- if (e is JsonRpcException) {
- if (e is JsonRpcNetworkException) {
- code = -1001; // 网络异常
- if (e.message?.toLowerCase().contains("timeout") == true) {
- code = -1002; // 超时
- }
- } else if (e.data?.code != null) {
- code = e.data.code!;
- } else if (e.code != null) {
- code = e.code!;
- }
- }
- }
- return code;
- }
- @override
- Future<bool> logout() async {
- await Store.user.handleLogOut();
- try {
- await rpc.login.loginOutAsync(
- TokenRequest(token: Store.user.token),
- );
- } catch (e) {
- logger.e("AccountManager call logout error", e);
- }
- if (!kIsWeb) {
- CommonUtil.idCardRecognition.release();
- }
- return true;
- }
- @override
- Future<UserDTO2?> getUserDetailAsync() async {
- try {
- return await rpc.vitalUser.getUserDetailAsync(
- GetUserRequest(
- token: Store.user.token,
- code: Store.user.userCode,
- ),
- );
- } catch (e) {
- return null;
- }
- }
- @override
- Future<bool> updateUserAsync(UserDTO2 dto) async {
- try {
- var request = UpdateUserRequest(
- token: Store.user.token,
- code: dto.code,
- realName: dto.realName,
- phone: dto.phone,
- headImageToken: dto.headImageToken,
- );
- var result = await rpc.vitalUser.updateUserAsync(request);
- if (result) {
- await Store.user.updateUserInfo(dto);
- }
- return result;
- } catch (e) {}
- return false;
- }
- @override
- Future<String> getUserPasswordDetailAsync() async {
- try {
- var result = await rpc.vitalUserPassword.getUserPasswordDetailAsync(
- GetUserPasswordRequest(
- token: Store.user.token, code: Store.user.userCode));
- return result.secretPassword ?? '';
- } catch (e) {}
- return '';
- }
- @override
- Future<bool> updateUserPasswordAsync(String secretPassword) async {
- try {
- var result = await rpc.vitalUserPassword.updateUserPasswordAsync(
- UpdateUserPasswordRequest(
- token: Store.user.token,
- code: Store.user.userCode,
- secretPassword: secretPassword));
- return result;
- } catch (e) {}
- return false;
- }
- @override
- Future<List<UserFeatureDTO>?> getMenuPermission() async {
- try {
- var result = await rpc.vitalUser.getMenuPermissionAsync(
- GetMenuPermissionRequest(
- token: Store.user.token,
- appType: ApplicationTypeEnum.App,
- ),
- );
- for (var element in result) {
- print(element.toJson());
- }
- return result;
- } catch (e) {
- logger.e("AccountManager call getMenuPermission error", e);
- }
- return null;
- }
- @override
- Future<List<UserFeatureDTO>?> getOperationPermission() async {
- try {
- var request = GetOperationPermissionRequest(
- token: Store.user.token,
- appType: ApplicationTypeEnum.App,
- );
- var result = await rpc.vitalUser.getOperationPermissionAsync(request);
- // var json = jsonEncode(request);
- // print(jsonEncode(request.toJson()));
- for (var element in result) {
- print(element.toJson());
- logger.i('新增权限${element.toJson()}');
- }
- return result;
- } catch (e) {
- logger.e("AccountManager call getMenuPermission error", e);
- }
- return null;
- }
- }
|