#
zhou zhou
7 天以前 bccdb8f81c07c8a9cdcd6838173dfd1c73c98d90
config/request.js
@@ -9,7 +9,7 @@
         settings = {
            ip: '127.0.0.1',
            port: '8080',
            project: 'jshdasrs'
            project: 'wms'
         };
         // uni.setStorageSync('app_settings', settings);
      }
@@ -34,13 +34,9 @@
         });
      }
      // 根据custom参数中配置的是否需要token,添加对应的请求头
      // 默认或显式 auth 为 true 时添加 token
      if (config?.custom?.auth !== false) {
         const token = uni.getStorageSync('token');
         if (token) {
            config.header.token = token;
         }
      }
      return config
   }, config => { // 可使用async await 做异步操作
@@ -60,9 +56,16 @@
      const custom = response.config?.custom || {}
      if (data.code !== 200) {
         if (data.code === 401 || data.code === 403) {
            vm.$showToast({ type: 'error', message: data.msg || data.message || '请重新登录' })
            setTimeout(() => {
               uni.reLaunch({ url: '/pages/login/login' })
            }, 1000)
         } else {
         // 如果没有显式定义custom的toast参数为false的话,默认对报错进行toast弹出提示
         if (custom.toast !== false) {
            uni.$u.toast(data.msg || data.message || '请求失败')
               vm.$showToast({ type: 'error', message: data.msg || data.message || '请求失败' })
            }
         }
         // 如果需要catch返回,则进行reject
@@ -81,6 +84,17 @@
      if (hideLoading === false || hideLoading === undefined) {
         uni.hideLoading();
      }
      if (response.statusCode === 401 || response.statusCode === 403) {
         vm.$showToast({ type: 'error', message: '请重新登录' })
         setTimeout(() => {
            uni.reLaunch({ url: '/pages/login/login' })
         }, 1000)
      } else {
         const errMsg = response.data?.msg || response.data?.message || '请求失败';
         vm.$showToast({ type: 'error', message: errMsg })
      }
      return Promise.reject(response)
   })
}