c4d5a5f7 by lihua

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

1 parent 423e0317
...@@ -56,14 +56,22 @@ onMounted(() => { ...@@ -56,14 +56,22 @@ onMounted(() => {
56 hotkeys('alt+i', () => { 56 hotkeys('alt+i', () => {
57 eventBus.emit('global-system-info-toggle') 57 eventBus.emit('global-system-info-toggle')
58 }) 58 })
59 59 if (!window.location?.href?.includes('?code=')) {
60 //判断token的过期时间。
61 if (!route.fullPath?.includes('?code=')) {
62 userStore.refreshUserToken(); 60 userStore.refreshUserToken();
61 } else {
62 localStorage.setItem('token', '');
63 localStorage.setItem('code', '');
64 localStorage.setItem('state', '');
65 localStorage.setItem('refresh_token', "");
66 localStorage.setItem('expiresIn', '');
63 } 67 }
64 }) 68 })
65 69
66 import.meta.env.VITE_APP_DEBUG_TOOL === 'eruda' && eruda.init() 70 import.meta.env.VITE_APP_DEBUG_TOOL === 'eruda' && eruda.init()
71
72 onUnmounted(() => {
73 window.onresize = null
74 })
67 </script> 75 </script>
68 76
69 <template> 77 <template>
......
...@@ -82,9 +82,9 @@ const useUserStore = defineStore( ...@@ -82,9 +82,9 @@ const useUserStore = defineStore(
82 }); 82 });
83 } 83 }
84 84
85 function refreshUserToken(isExec = true) { 85 async function refreshUserToken(isExec = true) {
86 let expiresIn = localStorage.getItem('expiresIn'); 86 let expiresIn = localStorage.getItem('expiresIn');
87 if (!expiresIn) { 87 if (!expiresIn || (parseInt(expiresIn) - Date.now()) < 0) {
88 return; 88 return;
89 } 89 }
90 const process = async () => { 90 const process = async () => {
...@@ -98,7 +98,9 @@ const useUserStore = defineStore( ...@@ -98,7 +98,9 @@ const useUserStore = defineStore(
98 } 98 }
99 } 99 }
100 } 100 }
101 isExec && process(); 101 if (isExec) {
102 await process();
103 }
102 /** 轮询是否需要刷新token。如果是同步多个调用,则不处理错误的信息。 */ 104 /** 轮询是否需要刷新token。如果是同步多个调用,则不处理错误的信息。 */
103 setInterval(async () => { 105 setInterval(async () => {
104 process(); 106 process();
......
...@@ -119,7 +119,8 @@ const searchItemList = ref([ ...@@ -119,7 +119,8 @@ const searchItemList = ref([
119 { label: '审批中', value: 'A' }, 119 { label: '审批中', value: 'A' },
120 { label: '已通过', value: 'Y' }, 120 { label: '已通过', value: 'Y' },
121 { label: '已驳回', value: 'R' }, 121 { label: '已驳回', value: 'R' },
122 { label: '已撤销', value: 'C' } 122 { label: '已撤销', value: 'C' },
123 { label: '--', value: 'null' }
123 ], 124 ],
124 clearable: true 125 clearable: true
125 }, 126 },
...@@ -144,7 +145,8 @@ const getTableData = () => { ...@@ -144,7 +145,8 @@ const getTableData = () => {
144 pageSize: page.value.limit, 145 pageSize: page.value.limit,
145 pageIndex: page.value.curr, 146 pageIndex: page.value.curr,
146 daName: page.value.daName, 147 daName: page.value.daName,
147 approveState: page.value.approveState, 148 isApprove: page.value.approveState == 'null' ? 'N' : '',
149 approveState: page.value.approveState == 'null' ? null : page.value.approveState,
148 currentStaffGuid: userData.staffGuid 150 currentStaffGuid: userData.staffGuid
149 }).then((res: any) => { 151 }).then((res: any) => {
150 tableInfo.value.loading = false 152 tableInfo.value.loading = false
......
...@@ -109,6 +109,7 @@ const searchItemList = ref([ ...@@ -109,6 +109,7 @@ const searchItemList = ref([
109 { label: '已通过', value: 'Y' }, 109 { label: '已通过', value: 'Y' },
110 { label: '已驳回', value: 'R' }, 110 { label: '已驳回', value: 'R' },
111 { label: '已撤销', value: 'C' }, 111 { label: '已撤销', value: 'C' },
112 { label: '--', value: 'null' }
112 ], 113 ],
113 clearable: true 114 clearable: true
114 }, 115 },
...@@ -133,7 +134,8 @@ const getTableData = () => { ...@@ -133,7 +134,8 @@ const getTableData = () => {
133 pageSize: page.value.limit, 134 pageSize: page.value.limit,
134 pageIndex: page.value.curr, 135 pageIndex: page.value.curr,
135 daName: page.value.daName, 136 daName: page.value.daName,
136 approveState: page.value.approveState, 137 isApprove: page.value.approveState == 'null' ? 'N' : '',
138 approveState: page.value.approveState == 'null' ? null : page.value.approveState,
137 currentStaffGuid: userData.staffGuid 139 currentStaffGuid: userData.staffGuid
138 }).then((res: any) => { 140 }).then((res: any) => {
139 tableInfo.value.loading = false; 141 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!