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,7 +12,7 @@ const toIotPlatformLogin = ({ to, from, next }: { to: RouteLocationNormalized, f | ||
12 | const { origin, port } = window.location | 12 | const { origin, port } = window.location |
13 | if (Number(port) === Number(import.meta.env.VITE_DEV_PORT)) { | 13 | if (Number(port) === Number(import.meta.env.VITE_DEV_PORT)) { |
14 | if (whitePathList.includes(to.path)) { | 14 | if (whitePathList.includes(to.path)) { |
15 | - next() | 15 | + next() |
16 | return | 16 | return |
17 | } else { | 17 | } else { |
18 | next(PageEnum.BASE_LOGIN) | 18 | next(PageEnum.BASE_LOGIN) |
@@ -23,7 +23,7 @@ const toIotPlatformLogin = ({ to, from, next }: { to: RouteLocationNormalized, f | @@ -23,7 +23,7 @@ const toIotPlatformLogin = ({ to, from, next }: { to: RouteLocationNormalized, f | ||
23 | } | 23 | } |
24 | 24 | ||
25 | export function createPermissionGuard(router: Router) { | 25 | export function createPermissionGuard(router: Router) { |
26 | - const userStore = useUserStoreWithOut() | 26 | + const userStore = useUserStoreWithOut() |
27 | 27 | ||
28 | router.beforeEach((to, from, next) => { | 28 | router.beforeEach((to, from, next) => { |
29 | if (from.path === '/' && | 29 | if (from.path === '/' && |
@@ -50,7 +50,6 @@ export function createPermissionGuard(router: Router) { | @@ -50,7 +50,6 @@ export function createPermissionGuard(router: Router) { | ||
50 | } | 50 | } |
51 | else { | 51 | else { |
52 | if (!isAloneMode) { | 52 | if (!isAloneMode) { |
53 | - console.log({ to, from }) | ||
54 | toIotPlatformLogin({ to, from, next }) | 53 | toIotPlatformLogin({ to, from, next }) |
55 | return | 54 | return |
56 | } | 55 | } |
@@ -65,7 +64,6 @@ export function createPermissionGuard(router: Router) { | @@ -65,7 +64,6 @@ export function createPermissionGuard(router: Router) { | ||
65 | redirect: true | 64 | redirect: true |
66 | } as RouteLocationRaw | 65 | } as RouteLocationRaw |
67 | if (!isAloneMode) { | 66 | if (!isAloneMode) { |
68 | - console.log({ to, from }) | ||
69 | toIotPlatformLogin({ to, from, next }) | 67 | toIotPlatformLogin({ to, from, next }) |
70 | return | 68 | return |
71 | } | 69 | } |
@@ -4,7 +4,7 @@ import { defineStore } from 'pinia'; | @@ -4,7 +4,7 @@ import { defineStore } from 'pinia'; | ||
4 | import { pinia as store } from '@/store'; | 4 | import { pinia as store } from '@/store'; |
5 | import { RoleEnum } from '@/enums/external/roleEnum'; | 5 | import { RoleEnum } from '@/enums/external/roleEnum'; |
6 | import { JWT_TOKEN_KEY, REFRESH_TOKEN_KEY, ROLES_KEY, USER_INFO_KEY } from '@/enums/external/cacheEnum'; | 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 | import { | 8 | import { |
9 | LoginParams, | 9 | LoginParams, |
10 | LoginResultModel, | 10 | LoginResultModel, |
@@ -44,9 +44,9 @@ export const useUserStore = defineStore({ | @@ -44,9 +44,9 @@ export const useUserStore = defineStore({ | ||
44 | userInfo: null, | 44 | userInfo: null, |
45 | userUpdateInfo: null, | 45 | userUpdateInfo: null, |
46 | // token | 46 | // token |
47 | - jwtToken: undefined, | 47 | + jwtToken: getJwtToken() as string || undefined, |
48 | //refresh Token | 48 | //refresh Token |
49 | - refreshToken: undefined, | 49 | + refreshToken: getRefreshToken() as string || undefined, |
50 | // roleList | 50 | // roleList |
51 | roleList: [], | 51 | roleList: [], |
52 | // Whether the login expired | 52 | // Whether the login expired |
@@ -148,7 +148,6 @@ export const useUserStore = defineStore({ | @@ -148,7 +148,6 @@ export const useUserStore = defineStore({ | ||
148 | if (sessionTimeout) { | 148 | if (sessionTimeout) { |
149 | this.setSessionTimeout(false); | 149 | this.setSessionTimeout(false); |
150 | } else if (goHome) { | 150 | } else if (goHome) { |
151 | - | ||
152 | await router.replace(userInfo.homePath || PageEnum.BASE_HOME); | 151 | await router.replace(userInfo.homePath || PageEnum.BASE_HOME); |
153 | } | 152 | } |
154 | return userInfo; | 153 | return userInfo; |
@@ -118,8 +118,7 @@ export class VAxios { | @@ -118,8 +118,7 @@ export class VAxios { | ||
118 | if (userStore && userStore.jwtToken) { | 118 | if (userStore && userStore.jwtToken) { |
119 | try { | 119 | try { |
120 | const res = jwt_decode(userStore.jwtToken) as JwtModel; | 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 | if (currentTime >= res.exp && this.isNeedTokenURL(config.url!)) { | 122 | if (currentTime >= res.exp && this.isNeedTokenURL(config.url!)) { |
124 | await this.refreshTokenBeforeReq(userStore.doRefresh); | 123 | await this.refreshTokenBeforeReq(userStore.doRefresh); |
125 | } | 124 | } |
@@ -143,8 +143,7 @@ const transform: AxiosTransform = { | @@ -143,8 +143,7 @@ const transform: AxiosTransform = { | ||
143 | } | 143 | } |
144 | } catch (error: any) { | 144 | } catch (error: any) { |
145 | throw new Error(error); | 145 | throw new Error(error); |
146 | - } | ||
147 | - console.log([error]) | 146 | + } |
148 | checkStatus(error?.response?.status, msg, errorMessageMode); | 147 | checkStatus(error?.response?.status, msg, errorMessageMode); |
149 | return Promise.reject(response?.data); | 148 | return Promise.reject(response?.data); |
150 | }, | 149 | }, |
@@ -31,7 +31,7 @@ const handleUpdateValue = (value: string, _option: SelectOption) => { | @@ -31,7 +31,7 @@ const handleUpdateValue = (value: string, _option: SelectOption) => { | ||
31 | <template> | 31 | <template> |
32 | <NSpace> | 32 | <NSpace> |
33 | <NText>背景选择</NText> | 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 | :options="getSelectBgOptions" :render-label="renderOption" @update-value="handleUpdateValue" /> | 35 | :options="getSelectBgOptions" :render-label="renderOption" @update-value="handleUpdateValue" /> |
36 | </NSpace> | 36 | </NSpace> |
37 | </template> | 37 | </template> |