修改登录进去时获取当前公司从缓存中取
Showing
2 changed files
with
70 additions
and
37 deletions
| ... | @@ -87,6 +87,11 @@ export const getUserTenant = () => request({ | ... | @@ -87,6 +87,11 @@ export const getUserTenant = () => request({ |
| 87 | method: 'get' | 87 | method: 'get' |
| 88 | }) | 88 | }) |
| 89 | 89 | ||
| 90 | export const getCurrentTenantCache = () => request({ | ||
| 91 | url: `${import.meta.env.VITE_APP_PERSONAL_URL}/tenant/get-current-user-tenant-from-cache`, | ||
| 92 | method: 'get' | ||
| 93 | }) | ||
| 94 | |||
| 90 | // 获取企业信息 | 95 | // 获取企业信息 |
| 91 | export const getEnterpriseData = (params) => request({ | 96 | export const getEnterpriseData = (params) => request({ |
| 92 | url: `${import.meta.env.VITE_APP_DIGITAL_CONTRACT_URL}/enterprise/detail-by-logonUser`, | 97 | url: `${import.meta.env.VITE_APP_DIGITAL_CONTRACT_URL}/enterprise/detail-by-logonUser`, | ... | ... |
| ... | @@ -6,6 +6,7 @@ import apiUser from '@/api/modules/user' | ... | @@ -6,6 +6,7 @@ import apiUser from '@/api/modules/user' |
| 6 | import { getCurrentTime } from '@/utils/common' | 6 | import { getCurrentTime } from '@/utils/common' |
| 7 | import { getSystemMenu, getUserInfo, getTokenByCode, loginOut, refreshToken, editPasswordInterface, getCurrentUserInfo, getTenantDetailInfo } from '@/api/modules/queryService' | 7 | import { getSystemMenu, getUserInfo, getTokenByCode, loginOut, refreshToken, editPasswordInterface, getCurrentUserInfo, getTenantDetailInfo } from '@/api/modules/queryService' |
| 8 | import { getConnectorStatus } from '@/api/modules/dataRequire' | 8 | import { getConnectorStatus } from '@/api/modules/dataRequire' |
| 9 | import { getCurrentTenantCache } from '@/api/modules/dataIdentify' | ||
| 9 | 10 | ||
| 10 | const useUserStore = defineStore( | 11 | const useUserStore = defineStore( |
| 11 | // 唯一ID | 12 | // 唯一ID |
| ... | @@ -55,45 +56,72 @@ const useUserStore = defineStore( | ... | @@ -55,45 +56,72 @@ const useUserStore = defineStore( |
| 55 | refreshUserToken(false); | 56 | refreshUserToken(false); |
| 56 | //获取用户信息 | 57 | //获取用户信息 |
| 57 | account.value = res.data.logonUser | 58 | account.value = res.data.logonUser |
| 58 | userId.value = res.data.userId | 59 | userId.value = res.data.userId; |
| 59 | currentTenantGuid.value = res.data.tenantInfoList && res.data.tenantInfoList.length ? res.data.tenantInfoList[0].guid : ''; | 60 | let exec = (currTenantGuid) => { |
| 60 | localStorage.setItem('currentTenantGuid', currentTenantGuid.value); | 61 | currentTenantGuid.value = currTenantGuid ? currTenantGuid : ( |
| 61 | let currentTenant = res.data.tenantInfoList?.[0]; | 62 | res.data.tenantInfoList && res.data.tenantInfoList.length |
| 62 | getTenantDetailInfo(currentTenantGuid.value).then((res: any) => { | 63 | ? res.data.tenantInfoList[0].guid |
| 63 | if (res.code == '00000') { | 64 | : ""); |
| 64 | localStorage.setItem('tenantInfo', JSON.stringify(res.data)); | 65 | localStorage.setItem( |
| 66 | "currentTenantGuid", | ||
| 67 | currentTenantGuid.value, | ||
| 68 | ); | ||
| 69 | getTenantDetailInfo(currentTenantGuid.value).then( | ||
| 70 | (res: any) => { | ||
| 71 | if (res.code == "00000") { | ||
| 72 | localStorage.setItem( | ||
| 73 | "tenantInfo", | ||
| 74 | JSON.stringify(res.data), | ||
| 75 | ); | ||
| 76 | } else { | ||
| 77 | ElMessage.error(res.msg); | ||
| 78 | } | ||
| 79 | }, | ||
| 80 | ); | ||
| 81 | getConnectorStatus().then((res: any) => { | ||
| 82 | if (res.code == "00000") { | ||
| 83 | isLogOutConnector.value = res.data?.isLogOut || "N"; | ||
| 84 | localStorage.setItem( | ||
| 85 | "isLogOutConnector", | ||
| 86 | isLogOutConnector.value, | ||
| 87 | ); | ||
| 88 | } else { | ||
| 89 | // 暂不弹错误提示 | ||
| 90 | } | ||
| 91 | }); | ||
| 92 | return getCurrentUserInfo({ | ||
| 93 | tenantGuid: currentTenantGuid.value, | ||
| 94 | }).then((res: any) => { | ||
| 95 | console.log(res, "getCurrentUserInfo"); | ||
| 96 | if (res.code == "00000") { | ||
| 97 | userName.value = res.data.staffName; | ||
| 98 | localStorage.setItem("userName", res.data?.staffName); | ||
| 99 | localStorage.setItem("userData", JSON.stringify(res.data)); | ||
| 100 | userData.value = localStorage.getItem("userData"); | ||
| 101 | isGetCurrUserInfo.value = true; | ||
| 102 | // return getSystemMenu({ tenantGuid: currentTenantGuid.value }, res.data?.isAdmin == 'Y' && (!res.data?.superTubeFlag || res.data?.superTubeFlag == 'Y')).then((info: any) => { //解决页面调用流程接口传递staffGuid,为空的问题 | ||
| 103 | // if (info.code == '00000') { | ||
| 104 | // localStorage.setItem('userInfoData', JSON.stringify(info.data)); | ||
| 105 | // userInfoData.value = info.data; | ||
| 106 | // // window.location.href = location.origin + info.data[0].menuList[0].path | ||
| 107 | // } else { | ||
| 108 | // ElMessage.error(info.msg) | ||
| 109 | // } | ||
| 110 | // }) | ||
| 111 | } else { | ||
| 112 | ElMessage.error(res.msg); | ||
| 113 | } | ||
| 114 | }); | ||
| 115 | }; | ||
| 116 | getCurrentTenantCache().then((res: any) => { | ||
| 117 | if (res?.code == '00000') { | ||
| 118 | exec(res.data || null); | ||
| 65 | } else { | 119 | } else { |
| 66 | ElMessage.error(res.msg) | 120 | exec(null); |
| 67 | } | 121 | res?.msg && ElMessage.error(res.msg); |
| 68 | }) | ||
| 69 | getConnectorStatus().then((res: any) => { | ||
| 70 | if (res.code == '00000') { | ||
| 71 | isLogOutConnector.value = res.data?.isLogOut || 'N'; | ||
| 72 | localStorage.setItem('isLogOutConnector', isLogOutConnector.value); | ||
| 73 | } else { | ||
| 74 | // 暂不弹错误提示 | ||
| 75 | } | ||
| 76 | }) | ||
| 77 | return getCurrentUserInfo({tenantGuid: currentTenantGuid.value}).then((res: any) => { | ||
| 78 | console.log(res, 'getCurrentUserInfo'); | ||
| 79 | if (res.code == '00000') { | ||
| 80 | userName.value = res.data.staffName; | ||
| 81 | localStorage.setItem('userName', res.data?.staffName); | ||
| 82 | localStorage.setItem('userData', JSON.stringify(res.data)); | ||
| 83 | userData.value = localStorage.getItem('userData'); | ||
| 84 | isGetCurrUserInfo.value = true | ||
| 85 | // return getSystemMenu({ tenantGuid: currentTenantGuid.value }, res.data?.isAdmin == 'Y' && (!res.data?.superTubeFlag || res.data?.superTubeFlag == 'Y')).then((info: any) => { //解决页面调用流程接口传递staffGuid,为空的问题 | ||
| 86 | // if (info.code == '00000') { | ||
| 87 | // localStorage.setItem('userInfoData', JSON.stringify(info.data)); | ||
| 88 | // userInfoData.value = info.data; | ||
| 89 | // // window.location.href = location.origin + info.data[0].menuList[0].path | ||
| 90 | // } else { | ||
| 91 | // ElMessage.error(info.msg) | ||
| 92 | // } | ||
| 93 | // }) | ||
| 94 | } else { | ||
| 95 | ElMessage.error(res.msg) | ||
| 96 | } | 122 | } |
| 123 | }).catch(() => { | ||
| 124 | exec(null); | ||
| 97 | }) | 125 | }) |
| 98 | } else { | 126 | } else { |
| 99 | isLogin.value = false; | 127 | isLogin.value = false; | ... | ... |
-
Please register or sign in to post a comment