Browse Source

支持对接口进行loading配置

刘洋 1 year ago
parent
commit
af462341c9
2 changed files with 8 additions and 0 deletions
  1. 1 0
      src/api/user.js
  2. 7 0
      src/utils/request.js

+ 1 - 0
src/api/user.js

@@ -5,6 +5,7 @@ export const login = (data) =>
     url: '/api/login',
     method: 'post',
     data,
+    loading: true,
   });
 export const logout = (data) =>
   request({

+ 7 - 0
src/utils/request.js

@@ -4,6 +4,7 @@ import { local, download } from '@/utils/tool';
 import { get, isEmpty } from 'lodash';
 import qs from 'qs';
 import { h } from 'vue';
+import { LoadingPlugin } from 'tdesign-vue-next';
 function createService() {
   // 创建一个 axios 实例
   const service = axios.create();
@@ -11,6 +12,9 @@ function createService() {
   // HTTP request 拦截器
   service.interceptors.request.use(
     (config) => {
+      if (config.loading) {
+        LoadingPlugin(true);
+      }
       if (config.download) {
         config.responseType ??= 'blob';
       }
@@ -25,6 +29,9 @@ function createService() {
   // HTTP response 拦截器
   service.interceptors.response.use(
     (response) => {
+      if (response.config.loading) {
+        LoadingPlugin(false);
+      }
       // 以下代码看后端是否有统一在接口里增加外层code的规范
       // if (response.data.code && response.data.code !== 200) {
       //   Message.error({