|
@@ -6,6 +6,9 @@ import { Toast } from 'tdesign-mobile-vue';
|
|
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
|
|
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
|
|
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
|
|
+// 请求数
|
|
|
|
+let LOADINGCOUNT = 0;
|
|
|
|
+let LOADING;
|
|
|
|
|
|
let config = {
|
|
let config = {
|
|
baseURL: import.meta.env.VITE_APP_API_URL,
|
|
baseURL: import.meta.env.VITE_APP_API_URL,
|
|
@@ -18,6 +21,19 @@ const _axios = axios.create(config);
|
|
_axios.interceptors.request.use(
|
|
_axios.interceptors.request.use(
|
|
function (config) {
|
|
function (config) {
|
|
// Do something before request is sent
|
|
// Do something before request is sent
|
|
|
|
+
|
|
|
|
+ // 设置loading
|
|
|
|
+ if (LOADINGCOUNT === 0) {
|
|
|
|
+ LOADING = Toast({
|
|
|
|
+ message: "loading...",
|
|
|
|
+ duration: 0,
|
|
|
|
+ theme:'loading',
|
|
|
|
+ preventScrollThrough:true
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ LOADINGCOUNT++;
|
|
|
|
+
|
|
|
|
+
|
|
let auth = localStorage.getItem('token')
|
|
let auth = localStorage.getItem('token')
|
|
if(auth) {
|
|
if(auth) {
|
|
config.headers.Authorization = auth;
|
|
config.headers.Authorization = auth;
|
|
@@ -35,6 +51,12 @@ _axios.interceptors.request.use(
|
|
_axios.interceptors.response.use(
|
|
_axios.interceptors.response.use(
|
|
function (response) {
|
|
function (response) {
|
|
// Do something with response data
|
|
// Do something with response data
|
|
|
|
+ //关闭loading
|
|
|
|
+ LOADINGCOUNT--;
|
|
|
|
+ if (LOADINGCOUNT === 0) {
|
|
|
|
+ LOADING.clear();
|
|
|
|
+ }
|
|
|
|
+
|
|
let data
|
|
let data
|
|
if(import.meta.env.MODE==='production'){
|
|
if(import.meta.env.MODE==='production'){
|
|
data=JSON.parse(CryptoJS.Des3Decrypt(response.data,import.meta.env.VITE_APP_RESPONSE_DES_KEY));//解密
|
|
data=JSON.parse(CryptoJS.Des3Decrypt(response.data,import.meta.env.VITE_APP_RESPONSE_DES_KEY));//解密
|