c4d5a5f7 by lihua

尝试解决登录成功后又报token过期重新登录的问题

1 parent 423e0317
......@@ -56,14 +56,22 @@ onMounted(() => {
hotkeys('alt+i', () => {
eventBus.emit('global-system-info-toggle')
})
//判断token的过期时间。
if (!route.fullPath?.includes('?code=')) {
if (!window.location?.href?.includes('?code=')) {
userStore.refreshUserToken();
} else {
localStorage.setItem('token', '');
localStorage.setItem('code', '');
localStorage.setItem('state', '');
localStorage.setItem('refresh_token', "");
localStorage.setItem('expiresIn', '');
}
})
import.meta.env.VITE_APP_DEBUG_TOOL === 'eruda' && eruda.init()
onUnmounted(() => {
window.onresize = null
})
</script>
<template>
......
......@@ -82,9 +82,9 @@ const useUserStore = defineStore(
});
}
function refreshUserToken(isExec = true) {
async function refreshUserToken(isExec = true) {
let expiresIn = localStorage.getItem('expiresIn');
if (!expiresIn) {
if (!expiresIn || (parseInt(expiresIn) - Date.now()) < 0) {
return;
}
const process = async () => {
......@@ -98,7 +98,9 @@ const useUserStore = defineStore(
}
}
}
isExec && process();
if (isExec) {
await process();
}
/** 轮询是否需要刷新token。如果是同步多个调用,则不处理错误的信息。 */
setInterval(async () => {
process();
......
......@@ -119,7 +119,8 @@ const searchItemList = ref([
{ label: '审批中', value: 'A' },
{ label: '已通过', value: 'Y' },
{ label: '已驳回', value: 'R' },
{ label: '已撤销', value: 'C' }
{ label: '已撤销', value: 'C' },
{ label: '--', value: 'null' }
],
clearable: true
},
......@@ -144,7 +145,8 @@ const getTableData = () => {
pageSize: page.value.limit,
pageIndex: page.value.curr,
daName: page.value.daName,
approveState: page.value.approveState,
isApprove: page.value.approveState == 'null' ? 'N' : '',
approveState: page.value.approveState == 'null' ? null : page.value.approveState,
currentStaffGuid: userData.staffGuid
}).then((res: any) => {
tableInfo.value.loading = false
......
......@@ -109,6 +109,7 @@ const searchItemList = ref([
{ label: '已通过', value: 'Y' },
{ label: '已驳回', value: 'R' },
{ label: '已撤销', value: 'C' },
{ label: '--', value: 'null' }
],
clearable: true
},
......@@ -133,7 +134,8 @@ const getTableData = () => {
pageSize: page.value.limit,
pageIndex: page.value.curr,
daName: page.value.daName,
approveState: page.value.approveState,
isApprove: page.value.approveState == 'null' ? 'N' : '',
approveState: page.value.approveState == 'null' ? null : page.value.approveState,
currentStaffGuid: userData.staffGuid
}).then((res: any) => {
tableInfo.value.loading = false;
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!