Commit c174e0ab0acdd7dec13f435501d02eba18685da8
Merge branch 'fix/dashboard-socket' into 'main_dev'
fix: 修复使用超级管理员快捷进入时首页消息量统计异常 See merge request yunteng/thingskit-front!638
Showing
4 changed files
with
71 additions
and
60 deletions
... | ... | @@ -124,3 +124,20 @@ export class TenantPageRequest extends BaseQueryRequest { |
124 | 124 | this.tenantName = tenantName; |
125 | 125 | } |
126 | 126 | } |
127 | + | |
128 | +export interface TenantListItemRecord { | |
129 | + id: string; | |
130 | + createTime: string; | |
131 | + updateTime: string; | |
132 | + username: string; | |
133 | + realName: string; | |
134 | + activateToken: string; | |
135 | + phoneNumber: string; | |
136 | + tbUser: string; | |
137 | + enabled: boolean; | |
138 | + hasPassword: boolean; | |
139 | + tenantId: string; | |
140 | + tenantName: string; | |
141 | + userStatusEnum: string; | |
142 | + level: number; | |
143 | +} | ... | ... |
src/hooks/business/useFastEnter.ts
0 → 100644
1 | +import { RouteRecordRaw } from 'vue-router'; | |
2 | +import { getEntitiesId } from '/@/api/dashboard'; | |
3 | +import { getMyInfo, getPermCode, getUserToken } from '/@/api/sys/user'; | |
4 | +import { RoleEnum } from '/@/enums/roleEnum'; | |
5 | +import { usePermissionStore } from '/@/store/modules/permission'; | |
6 | +import { useUserStore } from '/@/store/modules/user'; | |
7 | +import { router } from '/@/router'; | |
8 | +import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic'; | |
9 | +import { PageEnum } from '/@/enums/pageEnum'; | |
10 | +import { TenantListItemRecord } from '/@/api/tenant/tenantInfo'; | |
11 | + | |
12 | +export const useFastEnter = async (record: TenantListItemRecord, go: Fn) => { | |
13 | + const userStore = useUserStore(); | |
14 | + const permissionStore = usePermissionStore(); | |
15 | + | |
16 | + const { token, refreshToken } = await getUserToken(record.id); | |
17 | + userStore.storeToken(token, refreshToken); | |
18 | + const userInfo = await getMyInfo(); | |
19 | + const permissionList = await getPermCode(); | |
20 | + if ( | |
21 | + ![RoleEnum.SYS_ADMIN, RoleEnum.PLATFORM_ADMIN].some( | |
22 | + (item) => item === userInfo?.roles?.[0] || '' | |
23 | + ) | |
24 | + ) { | |
25 | + const res = await getEntitiesId(); | |
26 | + const entityId = res.data[0]?.entityId; | |
27 | + window.localStorage.setItem('entityId', JSON.stringify(entityId)); | |
28 | + window.sessionStorage.setItem('entityId', JSON.stringify(entityId)); | |
29 | + } | |
30 | + permissionStore.setPermCodeList(permissionList); | |
31 | + userStore.setUserInfo(userInfo); | |
32 | + userStore.setRoleList(userInfo.roles as RoleEnum[]); | |
33 | + const routes = await permissionStore.buildRoutesAction(); | |
34 | + routes.forEach((route) => { | |
35 | + router.addRoute(route as unknown as RouteRecordRaw); | |
36 | + }); | |
37 | + router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw); | |
38 | + permissionStore.setDynamicAddedRoute(true); | |
39 | + if (record?.hasPassword) go(PageEnum.BASE_HOME); | |
40 | + else go(PageEnum.SYSTEM_PASSWORD); | |
41 | +}; | ... | ... |
... | ... | @@ -103,17 +103,11 @@ |
103 | 103 | import { useGo } from '/@/hooks/web/usePage'; |
104 | 104 | import { useBatchDelete } from '/@/hooks/web/useBatchDelete'; |
105 | 105 | import { Authority } from '/@/components/Authority'; |
106 | - import { getMyInfo, getPermCode, getUserToken } from '/@/api/sys/user'; | |
107 | - import { useUserStore } from '/@/store/modules/user'; | |
108 | - import { usePermissionStore } from '/@/store/modules/permission'; | |
109 | - import { router } from '/@/router'; | |
110 | - import { RoleEnum } from '/@/enums/roleEnum'; | |
111 | - import { RouteRecordRaw } from 'vue-router'; | |
112 | - import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic'; | |
113 | - import { PageEnum } from '/@/enums/pageEnum'; | |
114 | 106 | import { getAuthCache } from '/@/utils/auth'; |
115 | 107 | import { USER_INFO_KEY } from '/@/enums/cacheEnum'; |
116 | 108 | import { isAdmin } from '/@/enums/roleEnum'; |
109 | + import { TenantListItemRecord } from '/@/api/tenant/tenantInfo'; | |
110 | + import { useFastEnter } from '/@/hooks/business/useFastEnter'; | |
117 | 111 | |
118 | 112 | export default defineComponent({ |
119 | 113 | name: 'AccountManagement', |
... | ... | @@ -190,29 +184,10 @@ |
190 | 184 | function handleView(record: Recordable) { |
191 | 185 | go('/system/account_detail/' + record.id); |
192 | 186 | } |
193 | - const userStore = useUserStore(); | |
194 | 187 | |
195 | - const permissionStore = usePermissionStore(); | |
196 | - async function handleLoginCustomAdmin(record: { | |
197 | - tbUser: string; | |
198 | - id: string; | |
199 | - hasPassword: boolean; | |
200 | - }) { | |
188 | + async function handleLoginCustomAdmin(record: TenantListItemRecord) { | |
201 | 189 | try { |
202 | - const { token, refreshToken } = await getUserToken(record.id); | |
203 | - userStore.storeToken(token, refreshToken); | |
204 | - const userInfo = await getMyInfo(); | |
205 | - const permissionList = await getPermCode(); | |
206 | - permissionStore.setPermCodeList(permissionList); | |
207 | - userStore.setUserInfo(userInfo); | |
208 | - userStore.setRoleList(userInfo.roles as RoleEnum[]); | |
209 | - const routes = await permissionStore.buildRoutesAction(); | |
210 | - routes.forEach((route) => { | |
211 | - router.addRoute(route as unknown as RouteRecordRaw); | |
212 | - }); | |
213 | - router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw); | |
214 | - permissionStore.setDynamicAddedRoute(true); | |
215 | - record.hasPassword ? go(PageEnum.BASE_HOME) : go(PageEnum.SYSTEM_PASSWORD); | |
190 | + useFastEnter(record, go); | |
216 | 191 | } catch (error) { |
217 | 192 | } finally { |
218 | 193 | } | ... | ... |
... | ... | @@ -99,18 +99,15 @@ |
99 | 99 | } from '/@/api/tenant/tenantApi'; |
100 | 100 | import { Tag } from 'ant-design-vue'; |
101 | 101 | import TenantAdminFormDrawer from './TenantAdminFormDrawer.vue'; |
102 | - import { MessageTypeEnum, SendResetPasswordEmailMsg } from '/@/api/tenant/tenantInfo'; | |
102 | + import { | |
103 | + MessageTypeEnum, | |
104 | + SendResetPasswordEmailMsg, | |
105 | + TenantListItemRecord, | |
106 | + } from '/@/api/tenant/tenantInfo'; | |
103 | 107 | import { useMessage } from '/@/hooks/web/useMessage'; |
104 | 108 | import { Authority } from '/@/components/Authority'; |
105 | - import { getMyInfo, getPermCode, getUserToken } from '/@/api/sys/user'; | |
106 | - import { useUserStore } from '/@/store/modules/user'; | |
107 | - import { usePermissionStore } from '/@/store/modules/permission'; | |
108 | - import { RoleEnum } from '/@/enums/roleEnum'; | |
109 | + import { useFastEnter } from '/@/hooks/business/useFastEnter'; | |
109 | 110 | import { useGo } from '/@/hooks/web/usePage'; |
110 | - import { PageEnum } from '/@/enums/pageEnum'; | |
111 | - import { router } from '/@/router'; | |
112 | - import { RouteRecordRaw } from 'vue-router'; | |
113 | - import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic'; | |
114 | 111 | |
115 | 112 | export default defineComponent({ |
116 | 113 | name: 'TenantAdminDrawer', |
... | ... | @@ -235,31 +232,12 @@ |
235 | 232 | reload(); |
236 | 233 | } |
237 | 234 | |
238 | - const userStore = useUserStore(); | |
239 | - const permissionStore = usePermissionStore(); | |
240 | 235 | const go = useGo(); |
241 | - async function handleLoginTenantAdmin(record: { | |
242 | - tbUser: string; | |
243 | - id: string; | |
244 | - hasPassword: boolean; | |
245 | - }) { | |
236 | + async function handleLoginTenantAdmin(record: TenantListItemRecord) { | |
246 | 237 | try { |
247 | - const { token, refreshToken } = await getUserToken(record.id); | |
248 | - userStore.storeToken(token, refreshToken); | |
249 | - const userInfo = await getMyInfo(); | |
250 | - const permissionList = await getPermCode(); | |
251 | - permissionStore.setPermCodeList(permissionList); | |
252 | - userStore.setUserInfo(userInfo); | |
253 | - userStore.setRoleList(userInfo.roles as RoleEnum[]); | |
254 | - const routes = await permissionStore.buildRoutesAction(); | |
255 | - routes.forEach((route) => { | |
256 | - router.addRoute(route as unknown as RouteRecordRaw); | |
257 | - }); | |
258 | - router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw); | |
259 | - permissionStore.setDynamicAddedRoute(true); | |
260 | - if (record?.hasPassword) go(PageEnum.BASE_HOME); | |
261 | - else go(PageEnum.SYSTEM_PASSWORD); | |
238 | + useFastEnter(record, go); | |
262 | 239 | } catch (error) { |
240 | + throw error; | |
263 | 241 | } finally { |
264 | 242 | } |
265 | 243 | } | ... | ... |