Просмотр исходного кода

fix:下载场景code信息查询表接口当没有targetTenantId时,不要传这个header

louhangfei 1 год назад
Родитель
Сommit
0495b2ce08
2 измененных файлов с 22 добавлено и 12 удалено
  1. 18 1
      src/utils/http/axios/index.ts
  2. 4 11
      src/views/cameras/overview/components/BatchImportCamera.vue

+ 18 - 1
src/utils/http/axios/index.ts

@@ -16,7 +16,7 @@ import { setObjToUrlParams } from '@/utils/urlUtils';
 
 
 import { RequestOptions, Result, CreateAxiosOptions } from './types';
 import { RequestOptions, Result, CreateAxiosOptions } from './types';
 
 
-import { useUserStoreWidthOut } from '@/store/modules/user';
+import { useUserStore, useUserStoreWidthOut } from '@/store/modules/user';
 import urlJoin from 'url-join';
 import urlJoin from 'url-join';
 
 
 const globSetting = useGlobSetting();
 const globSetting = useGlobSetting();
@@ -321,3 +321,20 @@ export const http = createAxios();
 //     urlPrefix: 'api',
 //     urlPrefix: 'api',
 //   },
 //   },
 // });
 // });
+
+/** 生成所需要的headers */
+export const getHeaders = () => {
+  const userStore = useUserStore();
+  const localTId = localStorage.getItem('targetTenantId');
+  const baseHeaders = {
+    Satoken: userStore.getToken,
+    Tenantid: userStore.getTenantId,
+  };
+  if (localTId) {
+    return {
+      ...baseHeaders,
+      targetTenantId: localStorage.getItem('targetTenantId') || '',
+    };
+  }
+  return baseHeaders;
+};

+ 4 - 11
src/views/cameras/overview/components/BatchImportCamera.vue

@@ -22,7 +22,7 @@
         <el-upload
         <el-upload
           ref="upload"
           ref="upload"
           style="width: 384px; height: 192px; border-radius: 8px"
           style="width: 384px; height: 192px; border-radius: 8px"
-          :headers="headers"
+          :headers="getHeaders()"
           :multiple="false"
           :multiple="false"
           :limit="1"
           :limit="1"
           drag
           drag
@@ -103,22 +103,15 @@
 <script setup lang="ts">
 <script setup lang="ts">
   import { computed, ref } from 'vue';
   import { computed, ref } from 'vue';
   import axios, { AxiosRequestConfig } from 'axios';
   import axios, { AxiosRequestConfig } from 'axios';
-  import { useUserStore } from '@/store/modules/user';
   import { genFileId, ElMessage } from 'element-plus';
   import { genFileId, ElMessage } from 'element-plus';
   import type { UploadInstance, UploadProps, UploadRawFile } from 'element-plus';
   import type { UploadInstance, UploadProps, UploadRawFile } from 'element-plus';
   import { Close, Document, WarnTriangleFilled, Download } from '@element-plus/icons-vue';
   import { Close, Document, WarnTriangleFilled, Download } from '@element-plus/icons-vue';
   import { useGlobSetting } from '@/hooks/setting';
   import { useGlobSetting } from '@/hooks/setting';
   import urlJoin from 'url-join';
   import urlJoin from 'url-join';
+  import { getHeaders } from '@/utils/http/axios';
 
 
   const emits = defineEmits(['close', 'update']);
   const emits = defineEmits(['close', 'update']);
 
 
-  const userStore = useUserStore();
-  const headers = {
-    Satoken: userStore.getToken,
-    Tenantid: userStore.getTenantId,
-    targetTenantId: localStorage.getItem('targetTenantId') || '',
-  };
-
   const upload = ref<UploadInstance>();
   const upload = ref<UploadInstance>();
   const cardVisible = ref<boolean>(true);
   const cardVisible = ref<boolean>(true);
   const isImportEnable = ref<boolean>(true);
   const isImportEnable = ref<boolean>(true);
@@ -137,7 +130,7 @@
   const handleDownloadSceneCode = async () => {
   const handleDownloadSceneCode = async () => {
     try {
     try {
       const config: AxiosRequestConfig = {
       const config: AxiosRequestConfig = {
-        headers,
+        headers: getHeaders(),
         responseType: 'blob',
         responseType: 'blob',
       };
       };
       const response = await axios.get(
       const response = await axios.get(
@@ -165,7 +158,7 @@
   const handleDownloadTemplate = async () => {
   const handleDownloadTemplate = async () => {
     try {
     try {
       const config: AxiosRequestConfig = {
       const config: AxiosRequestConfig = {
-        headers,
+        headers: getHeaders(),
         responseType: 'blob',
         responseType: 'blob',
       };
       };
       const response = await axios.get(
       const response = await axios.get(