LOCKING盒子版
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

78 righe
2.3 KiB

  1. import { history } from 'umi';
  2. import { fetchApi } from '@/utils/request';
  3. import storage from '@/utils/storage';
  4. import { errorReponse, firstCharToLowerCase, isReqSuccess } from '@/utils/tool';
  5. import { propertyOf } from 'lodash';
  6. import system, { isClient } from './system';
  7. import { DATA } from './API';
  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 systemLoginRes = await system.login(res.data.id, res.data.phone);
  34. if (!isReqSuccess(systemLoginRes)) {
  35. return errorReponse('本地网管通讯失败');
  36. }
  37. // const companyInfoRes = await fetchApi('company/queryFrontDeskCompanyById', { id: userData.companyId }, { silent: true });
  38. // if (!isReqSuccess(companyInfoRes)) {
  39. // return companyInfoRes;
  40. // }
  41. // const { data: { company: { SoftwareVersion } = {} } = {} } = companyInfoRes;
  42. // 角色判断
  43. // const { app: appStore } = getState();
  44. // if (appStore.appType && userData.userType !== appStore.appType) { // 登录角色权限不符合,退出登录
  45. // hint('账号权限不足');
  46. // dispatch(logout());
  47. // return false;
  48. // }
  49. // const payload = {
  50. // accountId: userData.id,
  51. // accountName: userData.cnName,
  52. // customerId: userData.companyId,
  53. // avatorUrl: userData.headImgUrl,
  54. // isMini: SoftwareVersion === 'Mini',
  55. // };
  56. storage.set('accountId', userData.id);
  57. storage.set('companyId', userData.companyId);
  58. // storage.set('isMini', payload.isMini);
  59. return res;
  60. }
  61. export function logout(clearStorage = true) {
  62. if (clearStorage) {
  63. storage.clear();
  64. }
  65. system.logout();
  66. // window.location.href = '/login';
  67. history.replace('/login');
  68. // window.location.reload();
  69. }