LOCKING盒子版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

86 lines
2.3 KiB

  1. import { history } from 'umi';
  2. import { fetchApi } from '@/utils/request';
  3. import storage from '@/utils/storage';
  4. import { errorReponse, isReqSuccess } from '@/utils/tool';
  5. import system from './system';
  6. import { DATA } from './API';
  7. import { fileMng } from '@/utils/hooks';
  8. export async function queryCurrent() {
  9. const accountId = storage.get('accountId');
  10. if (!accountId) {
  11. return errorReponse('');
  12. }
  13. const res = await fetchApi<DATA.User>('user/queryUserByUserId', {
  14. id: accountId,
  15. });
  16. return res;
  17. }
  18. export async function login(account: string, password: string) {
  19. const res = await fetchApi<DATA.User>(
  20. 'authentication/login',
  21. { UserName: account, Password: password },
  22. { silent: true },
  23. );
  24. if (!isReqSuccess(res)) {
  25. // dispatch(logout());
  26. return res;
  27. }
  28. const userData = res.data;
  29. const isSuperAdmin = userData.backgroundPermission === 3;
  30. if (isSuperAdmin) {
  31. return errorReponse('该账号没有访问权限');
  32. }
  33. const companyInfoRes = await fetchApi(
  34. 'company/queryFrontDeskCompanyById',
  35. { id: userData.companyId },
  36. { silent: true },
  37. );
  38. if (!isReqSuccess(companyInfoRes)) {
  39. return companyInfoRes;
  40. }
  41. const systemLoginRes = await system.login(
  42. res.data.id,
  43. res.data.phone,
  44. companyInfoRes.data?.company?.IpfsApi || '',
  45. );
  46. if (!isReqSuccess(systemLoginRes)) {
  47. return errorReponse('本地网管通讯失败');
  48. }
  49. // const { data: { company: { SoftwareVersion } = {} } = {} } = companyInfoRes;
  50. // 角色判断
  51. // const { app: appStore } = getState();
  52. // if (appStore.appType && userData.userType !== appStore.appType) { // 登录角色权限不符合,退出登录
  53. // hint('账号权限不足');
  54. // dispatch(logout());
  55. // return false;
  56. // }
  57. // const payload = {
  58. // accountId: userData.id,
  59. // accountName: userData.cnName,
  60. // customerId: userData.companyId,
  61. // avatorUrl: userData.headImgUrl,
  62. // isMini: SoftwareVersion === 'Mini',
  63. // };
  64. storage.set('accountId', userData.id);
  65. storage.set('companyId', userData.companyId);
  66. // storage.set('isMini', payload.isMini);
  67. return res;
  68. }
  69. export function logout(clearStorage = true) {
  70. if (clearStorage) {
  71. storage.clear();
  72. }
  73. fileMng.clear();
  74. system.logout();
  75. // window.location.href = '/login';
  76. history.replace('/login');
  77. // window.location.reload();
  78. }