Browse Source

fix 修复 无法获取token问题 将 globalHeaders 改为函数

疯狂的狮子Li 1 year ago
parent
commit
50891e99ac

+ 1 - 1
src/components/Editor/index.vue

@@ -50,7 +50,7 @@ const props = defineProps({
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
 
 const upload = reactive<UploadOption>({
-  headers: globalHeaders,
+  headers: globalHeaders(),
   url: import.meta.env.VITE_APP_BASE_API + '/resource/oss/upload'
 })
 const myQuillEditor = ref();

+ 1 - 1
src/components/FileUpload/index.vue

@@ -66,7 +66,7 @@ const uploadList = ref<any[]>([]);
 
 const baseUrl = import.meta.env.VITE_APP_BASE_API;
 const uploadFileUrl = ref(baseUrl + "/resource/oss/upload"); // 上传文件服务器地址
-const headers = ref(globalHeaders);
+const headers = ref(globalHeaders());
 
 const fileList = ref<any[]>([]);
 const showTip = computed(

+ 1 - 1
src/components/ImageUpload/index.vue

@@ -70,7 +70,7 @@ const dialogVisible = ref(false);
 
 const baseUrl = import.meta.env.VITE_APP_BASE_API;
 const uploadImgUrl = ref(baseUrl + "/resource/oss/upload"); // 上传的图片服务器地址
-const headers = ref(globalHeaders);
+const headers = ref(globalHeaders());
 
 const fileList = ref<any[]>([]);
 const showTip = computed(

+ 2 - 2
src/plugins/download.ts

@@ -16,7 +16,7 @@ export default {
         method: 'get',
         url: url,
         responseType: 'blob',
-        headers: globalHeaders,
+        headers: globalHeaders(),
       });
       const isBlob = blobValidate(res.data);
       if (isBlob) {
@@ -40,7 +40,7 @@ export default {
         method: 'get',
         url: url,
         responseType: 'blob',
-        headers: globalHeaders,
+        headers: globalHeaders(),
       });
       const isBlob = blobValidate(res.data);
       if (isBlob) {

+ 5 - 3
src/utils/request.ts

@@ -14,9 +14,11 @@ import { encrypt } from '@/utils/jsencrypt';
 let downloadLoadingInstance: LoadingInstance;
 // 是否显示重新登录
 export const isRelogin = { show: false };
-export const globalHeaders = {
-  Authorization: "Bearer " + getToken(),
-  clientid: import.meta.env.VITE_APP_CLIENT_ID
+export const globalHeaders = () => {
+  return {
+    Authorization: "Bearer " + getToken(),
+    clientid: import.meta.env.VITE_APP_CLIENT_ID
+  }
 }
 
 axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';

+ 1 - 1
src/views/system/user/index.vue

@@ -335,7 +335,7 @@ const upload = reactive<ImportOption>({
   // 是否更新已经存在的用户数据
   updateSupport: 0,
   // 设置上传的请求头部
-  headers: globalHeaders,
+  headers: globalHeaders(),
   // 上传的地址
   url: import.meta.env.VITE_APP_BASE_API + "/system/user/importData"
 })