Bläddra i källkod

优化上传token

木星 2 veckor sedan
förälder
incheckning
6bf597d560

+ 10 - 3
src/components/Editor/src/Editor.vue

@@ -10,10 +10,17 @@ import { useLocaleStore } from '@/store/modules/locale'
10 10
 
11 11
 const userStore = useUserStore()
12 12
 const token = userStore.getToken
13
-const Authorization = `Bearer ${token}`
14
-
15 13
 const localeStore = useLocaleStore()
16
-const headers = ref({ Authorization: Authorization })
14
+
15
+const Authorization = ref(`Bearer ${userStore.getToken}`)
16
+const headers = ref({ Authorization: Authorization.value })
17
+
18
+setInterval(() => {
19
+  Authorization.value = `Bearer ${userStore.getToken}`
20
+  console.log('Authorization', Authorization.value)
21
+  headers.value = { Authorization: Authorization.value }
22
+}, 6000) //
23
+
17 24
 const currentLocale = computed(() => localeStore.getCurrentLocale)
18 25
 
19 26
 i18nChangeLanguage(unref(currentLocale).lang)

+ 8 - 3
src/views/Material/MaterialMange.vue

@@ -135,9 +135,14 @@ const deletetab = async (data: TableSlotDefault) => {
135 135
 const dialogVisible = ref(false)
136 136
 const dialogVisible2 = ref(false)
137 137
 
138
-const token = userStore.getToken
139
-const Authorization = `Bearer ${token}`
140
-const headers = ref({ Authorization: Authorization })
138
+const Authorization = ref(`Bearer ${userStore.getToken}`)
139
+const headers = ref({ Authorization: Authorization.value })
140
+
141
+setInterval(() => {
142
+  Authorization.value = `Bearer ${userStore.getToken}`
143
+  console.log('Authorization', Authorization.value)
144
+  headers.value = { Authorization: Authorization.value }
145
+}, 6000) //
141 146
 
142 147
 const { formRegister, formMethods } = useForm()
143 148
 const { getElFormExpose, getFormData } = formMethods

+ 8 - 3
src/views/Resource/ResourceManage.vue

@@ -127,9 +127,14 @@ const deletetab = async (data: TableSlotDefault) => {
127 127
 
128 128
 const dialogVisible = ref(false)
129 129
 
130
-const token = userStore.getToken
131
-const Authorization = `Bearer ${token}`
132
-const headers = ref({ Authorization: Authorization })
130
+const Authorization = ref(`Bearer ${userStore.getToken}`)
131
+const headers = ref({ Authorization: Authorization.value })
132
+
133
+setInterval(() => {
134
+  Authorization.value = `Bearer ${userStore.getToken}`
135
+  console.log('Authorization', Authorization.value)
136
+  headers.value = { Authorization: Authorization.value }
137
+}, 6000) // 每60秒更新一次token
133 138
 
134 139
 const { formRegister, formMethods } = useForm()
135 140
 const { getElFormExpose, getFormData } = formMethods

+ 10 - 2
src/views/System/SystemSetting.vue

@@ -33,9 +33,17 @@ import { any } from 'vue-types'
33 33
 import { useTable } from '@/hooks/web/useTable'
34 34
 const userStore = useUserStore()
35 35
 const token = userStore.getToken
36
-const Authorization = `Bearer ${token}`
36
+
37 37
 import type { UploadProps } from 'element-plus'
38
-const headers = ref({ Authorization: Authorization })
38
+
39
+const Authorization = ref(`Bearer ${userStore.getToken}`)
40
+const headers = ref({ Authorization: Authorization.value })
41
+
42
+setInterval(() => {
43
+  Authorization.value = `Bearer ${userStore.getToken}`
44
+  console.log('Authorization', Authorization.value)
45
+  headers.value = { Authorization: Authorization.value }
46
+}, 6000) //
39 47
 const PATH_URL = window.VITE_API_BASE_PATH + '/config/manage/uploadImg'
40 48
 const IMG_URL = window.VITE_API_BASE_PATH
41 49
 const { required, lengthRange } = useValidator()

+ 8 - 3
src/views/Template/TemplateManage.vue

@@ -115,9 +115,14 @@ const deletetab = async (data: TableSlotDefault) => {
115 115
 
116 116
 const dialogVisible = ref(false)
117 117
 
118
-const token = userStore.getToken
119
-const Authorization = `Bearer ${token}`
120
-const headers = ref({ Authorization: Authorization })
118
+const Authorization = ref(`Bearer ${userStore.getToken}`)
119
+const headers = ref({ Authorization: Authorization.value })
120
+
121
+setInterval(() => {
122
+  Authorization.value = `Bearer ${userStore.getToken}`
123
+  console.log('Authorization', Authorization.value)
124
+  headers.value = { Authorization: Authorization.value }
125
+}, 6000) //
121 126
 
122 127
 const { formRegister, formMethods } = useForm()
123 128
 const { getElFormExpose, getFormData } = formMethods