Commit 2316e68a1ab6d75c6350b9c5c85d436d0da6f1a9
Merge branch 'ww' into 'main'
fix(token): 修复token过期未调用刷新token接口获取新token See merge request yunteng/thingskit-view!14
Showing
5 changed files
with
8 additions
and
13 deletions
... | ... | @@ -12,7 +12,7 @@ const toIotPlatformLogin = ({ to, from, next }: { to: RouteLocationNormalized, f |
12 | 12 | const { origin, port } = window.location |
13 | 13 | if (Number(port) === Number(import.meta.env.VITE_DEV_PORT)) { |
14 | 14 | if (whitePathList.includes(to.path)) { |
15 | - next() | |
15 | + next() | |
16 | 16 | return |
17 | 17 | } else { |
18 | 18 | next(PageEnum.BASE_LOGIN) |
... | ... | @@ -23,7 +23,7 @@ const toIotPlatformLogin = ({ to, from, next }: { to: RouteLocationNormalized, f |
23 | 23 | } |
24 | 24 | |
25 | 25 | export function createPermissionGuard(router: Router) { |
26 | - const userStore = useUserStoreWithOut() | |
26 | + const userStore = useUserStoreWithOut() | |
27 | 27 | |
28 | 28 | router.beforeEach((to, from, next) => { |
29 | 29 | if (from.path === '/' && |
... | ... | @@ -50,7 +50,6 @@ export function createPermissionGuard(router: Router) { |
50 | 50 | } |
51 | 51 | else { |
52 | 52 | if (!isAloneMode) { |
53 | - console.log({ to, from }) | |
54 | 53 | toIotPlatformLogin({ to, from, next }) |
55 | 54 | return |
56 | 55 | } |
... | ... | @@ -65,7 +64,6 @@ export function createPermissionGuard(router: Router) { |
65 | 64 | redirect: true |
66 | 65 | } as RouteLocationRaw |
67 | 66 | if (!isAloneMode) { |
68 | - console.log({ to, from }) | |
69 | 67 | toIotPlatformLogin({ to, from, next }) |
70 | 68 | return |
71 | 69 | } | ... | ... |
... | ... | @@ -4,7 +4,7 @@ import { defineStore } from 'pinia'; |
4 | 4 | import { pinia as store } from '@/store'; |
5 | 5 | import { RoleEnum } from '@/enums/external/roleEnum'; |
6 | 6 | import { JWT_TOKEN_KEY, REFRESH_TOKEN_KEY, ROLES_KEY, USER_INFO_KEY } from '@/enums/external/cacheEnum'; |
7 | -import { getAuthCache, setAuthCache } from '@/utils/external/auth'; | |
7 | +import { getAuthCache, getJwtToken, getRefreshToken, setAuthCache } from '@/utils/external/auth'; | |
8 | 8 | import { |
9 | 9 | LoginParams, |
10 | 10 | LoginResultModel, |
... | ... | @@ -44,9 +44,9 @@ export const useUserStore = defineStore({ |
44 | 44 | userInfo: null, |
45 | 45 | userUpdateInfo: null, |
46 | 46 | // token |
47 | - jwtToken: undefined, | |
47 | + jwtToken: getJwtToken() as string || undefined, | |
48 | 48 | //refresh Token |
49 | - refreshToken: undefined, | |
49 | + refreshToken: getRefreshToken() as string || undefined, | |
50 | 50 | // roleList |
51 | 51 | roleList: [], |
52 | 52 | // Whether the login expired |
... | ... | @@ -148,7 +148,6 @@ export const useUserStore = defineStore({ |
148 | 148 | if (sessionTimeout) { |
149 | 149 | this.setSessionTimeout(false); |
150 | 150 | } else if (goHome) { |
151 | - | |
152 | 151 | await router.replace(userInfo.homePath || PageEnum.BASE_HOME); |
153 | 152 | } |
154 | 153 | return userInfo; | ... | ... |
... | ... | @@ -118,8 +118,7 @@ export class VAxios { |
118 | 118 | if (userStore && userStore.jwtToken) { |
119 | 119 | try { |
120 | 120 | const res = jwt_decode(userStore.jwtToken) as JwtModel; |
121 | - console.log(res) | |
122 | - const currentTime = (new Date().getTime() - (config.timeout || 0)) / 1000; | |
121 | + const currentTime = (new Date().getTime() + (config.timeout || 0)) / 1000; | |
123 | 122 | if (currentTime >= res.exp && this.isNeedTokenURL(config.url!)) { |
124 | 123 | await this.refreshTokenBeforeReq(userStore.doRefresh); |
125 | 124 | } | ... | ... |
... | ... | @@ -143,8 +143,7 @@ const transform: AxiosTransform = { |
143 | 143 | } |
144 | 144 | } catch (error: any) { |
145 | 145 | throw new Error(error); |
146 | - } | |
147 | - console.log([error]) | |
146 | + } | |
148 | 147 | checkStatus(error?.response?.status, msg, errorMessageMode); |
149 | 148 | return Promise.reject(response?.data); |
150 | 149 | }, | ... | ... |
... | ... | @@ -31,7 +31,7 @@ const handleUpdateValue = (value: string, _option: SelectOption) => { |
31 | 31 | <template> |
32 | 32 | <NSpace> |
33 | 33 | <NText>背景选择</NText> |
34 | - <NSelect size="small" placeholder="请选择您要使用的背景" style="width: 250px" :value="canvasConfig.backgroundImage" | |
34 | + <NSelect size="small" placeholder="请选择您要使用的背景" clearable style="width: 250px" :value="canvasConfig.backgroundImage" | |
35 | 35 | :options="getSelectBgOptions" :render-label="renderOption" @update-value="handleUpdateValue" /> |
36 | 36 | </NSpace> |
37 | 37 | </template> | ... | ... |