ysy 2 lat temu
rodzic
commit
ad0fe68813
4 zmienionych plików z 96 dodań i 82 usunięć
  1. 6 1
      src/App.vue
  2. 5 0
      src/components/upload/fileUpload.vue
  3. 2 3
      src/utils/file.js
  4. 83 78
      src/utils/request.js

+ 6 - 1
src/App.vue

@@ -16,7 +16,12 @@
       );
       // 恢复主题
       this.$store.dispatch('theme/recoverTheme');
-      getPageList({ status: [1], size: 10, pageNum: 1 });
+      if (!sessionStorage.filePath) {
+        // getPathAddress().then((res) => {
+        //   console.log(res);
+        //   sessionStorage.filePath = res;
+        // });
+      }
     },
     methods: {
       /* 路由切换更新浏览器标题 */

+ 5 - 0
src/components/upload/fileUpload.vue

@@ -11,6 +11,7 @@
       :before-upload="beforeUpload"
       :file-list="fileList"
       :show-file-list="!showLib"
+      :disabled="disabled"
     >
       <slot>
         <el-button type="primary" icon="el-icon-plus">点击上传</el-button>
@@ -101,6 +102,10 @@
       size: {
         type: Number,
         default: 10
+      },
+      disabled:{
+        default:false,
+        type:Boolean
       }
     },
     data () {

+ 2 - 3
src/utils/file.js

@@ -2,7 +2,7 @@ import { getToken } from './token-util';
 import { TOKEN_HEADER_NAME } from '@/config/setting';
 
 // 获取图片反显url
-export function getImageUrl(path) {
+export function getImageUrl (path) {
   return `${sessionStorage.filePath}${path}`;
   // if (process.env.NODE_ENV === 'development') {
   //   return `http://192.168.3.51:18086/main/file/getFile?${TOKEN_HEADER_NAME}=${getToken()}&objectName=${path}`;
@@ -13,7 +13,7 @@ export function getImageUrl(path) {
   // }
 }
 // 从反显url上获取接口需要path
-export function getImagePath(url) {
+export function getImagePath (url) {
   if (!url) {
     return '';
   }
@@ -24,7 +24,6 @@ export function getImagePath(url) {
 }
 
 // 下载方法
-
 export function download (data, name) {
   const a = document.createElement('a');
   const url = window.URL.createObjectURL(data);

+ 83 - 78
src/utils/request.js

@@ -1,81 +1,86 @@
 /**
  * axios 实例
  */
-import axios from 'axios';
-import router from '@/router';
-import { MessageBox, Message } from 'element-ui';
-import { API_BASE_URL, TOKEN_HEADER_NAME, LAYOUT_PATH } from '@/config/setting';
-import { getToken, setToken } from './token-util';
-import { logout } from './page-tab-util';
-import JSONBIG from 'json-bigint';
-
-const service = axios.create({
-  baseURL: API_BASE_URL,
-  transformResponse: [
-    function (data) {
-      const json = JSONBIG({
-        storeAsString: true
-      });
-      const res = json.parse(data);
-      return res;
-    }
-  ]
-});
-/**
- * 添加请求拦截器
- */
-service.interceptors.request.use(
-  (config) => {
-    // 添加 token 到 header
-    const token = getToken();
-    if (token && config.headers) {
-      config.headers.common[TOKEN_HEADER_NAME] = token;
-    }
-    return config;
-  },
-  (error) => {
-    return Promise.reject(error);
-  }
-);
-
-/**
- * 添加响应拦截器
- */
-service.interceptors.response.use(
-  (res) => {
-    // token 自动续期
-    if (res.data.code == '-1' && res.config?.showErrorToast !== false) {
-      Message.error(res.data.message);
-    }
-    const token = res.headers[TOKEN_HEADER_NAME.toLowerCase()];
-    if (token) {
-      setToken(token);
-    }
-    return res;
-  },
-  (error) => {
-    // 登录过期处理
-    if (error?.response?.status === 401) {
-      const currentPath = router.currentRoute.path;
-      if (currentPath === LAYOUT_PATH) {
-        logout(true);
-      } else {
-        MessageBox.alert('登录状态已过期, 请退出重新登录!', '系统提示', {
-          confirmButtonText: '重新登录',
-          callback: (action) => {
-            if (action === 'confirm') {
-              logout(false, currentPath);
-            }
-          },
-          beforeClose: () => {
-            MessageBox.close();
-          }
-        });
-      }
-      return Promise.reject(new Error(error.response.data?.message));
-    }
-    return Promise.reject(error);
-  }
-);
-
-export default service;
+ import axios from 'axios';
+ import router from '@/router';
+ import store from '@/store';
+ import { MessageBox, Message } from 'element-ui';
+ import { API_BASE_URL, TOKEN_HEADER_NAME, LAYOUT_PATH } from '@/config/setting';
+ import { getToken, setToken } from './token-util';
+ import { logout } from './page-tab-util';
+ import JSONBIG from 'json-bigint';
+ const service = axios.create({
+   baseURL: API_BASE_URL,
+   transformResponse: [
+     function (data) {
+       if (data instanceof Blob) {
+         return data;
+       }
+       const json = JSONBIG({
+         storeAsString: true
+       });
+       const res = json.parse(data);
+       return res;
+     }
+   ]
+ });
+ /**
+  * 添加请求拦截器
+  */
+ service.interceptors.request.use(
+   (config) => {
+     // 添加 token 到 header
+     const token = getToken();
+     if (token && config.headers) {
+       config.headers.common[TOKEN_HEADER_NAME] = token;
+     }
+ 
+     return config;
+   },
+   (error) => {
+     return Promise.reject(error);
+   }
+ );
+ 
+ /**
+  * 添加响应拦截器
+  */
+ service.interceptors.response.use(
+   (res) => {
+     // token 自动续期
+     if (res.data.code == '-1' && res.config?.showErrorToast !== false&&res.data.message) {
+       Message.error(res.data.message);
+     }
+     const token = res.headers[TOKEN_HEADER_NAME.toLowerCase()];
+     if (token) {
+       setToken(token);
+     }
+     return res;
+   },
+   (error) => {
+     // 登录过期处理
+     if (error?.response?.status === 401) {
+       const currentPath = router.currentRoute.path;
+       if (currentPath === LAYOUT_PATH) {
+         logout(true);
+       } else {
+         MessageBox.alert('登录状态已过期, 请退出重新登录!', '系统提示', {
+           confirmButtonText: '重新登录',
+           callback: (action) => {
+             if (action === 'confirm') {
+               logout(false, currentPath);
+             }
+           },
+           beforeClose: () => {
+             MessageBox.close();
+           }
+         });
+       }
+       return Promise.reject(new Error(error.response.data?.message));
+     }
+     return Promise.reject(error);
+   }
+ );
+ 
+ export default service;
+