wanshenmean
2025-04-08 517fb253f39bf8120f9bed693d35349727ae650c
´úÂë¹ÜÀí/NEWCode/WIDESEAWCS_PDA/common/http.interceptor.js
@@ -1,7 +1,6 @@
//let baseUrl ='http://192.168.1.54:8098' //'http://192.168.11.58:8098'
 // let baseUrl = 'http://192.168.12.240:8098'
let baseUrl = 'http://127.0.0.1:9291'
const install = (Vue, vm) => {
   // æ­¤ä¸ºè‡ªå®šä¹‰é…ç½®å‚数,具体参数见上方说明
   Vue.prototype.$u.http.setConfig({
      baseUrl: baseUrl,
@@ -13,22 +12,13 @@
   // è¯·æ±‚拦截,配置Token等参数
   Vue.prototype.$u.http.interceptor.request = (config) => {
      // å¼•用token
      // æ–¹å¼ä¸€ï¼Œå­˜æ”¾åœ¨vuex的token,假设使用了uView封装的vuex方式
      // è§ï¼šhttps://uviewui.com/components/globalVariable.html
      // config.header.token = vm.token;
      // åˆ¤æ–­æ˜¯å¦ä¸ºå®Œæ•´ URL,如果是则不使用 baseUrl
      if (config.url.includes('http://') || config.url.includes('https://')) {
         config.baseURL = '';
      } else {
         config.baseURL = baseUrl;
      }
      // æ–¹å¼äºŒï¼Œå¦‚果没有使用uView封装的vuex方法,那么需要使用$store.state获取
      // config.header.token = vm.$store.state.token;
      // æ–¹å¼ä¸‰ï¼Œå¦‚æžœtoken放在了globalData,通过getApp().globalData获取
      // config.header.token = getApp().globalData.username;
      // æ–¹å¼å››ï¼Œå¦‚æžœtoken放在了Storage本地存储中,拦截是每次请求都执行的
      // æ‰€ä»¥å“ªæ€•您重新登录修改了Storage,下一次的请求将会是最新值
      // const token = uni.getStorageSync('token');
      // config.header.token = token;
      console.log(2)
      config.header.Token = 'xxxxxx';
      config.header.Authorization = "Bearer " + uni.getStorageSync('jo_id_token');
      // å¯ä»¥å¯¹æŸä¸ªurl进行特别处理,此url参数为this.$u.get(url)中的url值 
@@ -41,9 +31,7 @@
   // å“åº”拦截,判断状态码是否通过
   Vue.prototype.$u.http.interceptor.response = (res) => {
      console.log(1)
      if (res.statusCode == 200) {
         console.log(0)
         // res为服务端返回值,可能有code,result等字段
         // è¿™é‡Œå¯¹res.result进行返回,将会在this.$u.post(url).then(res => {})的then回调中的res的到
         // å¦‚果配置了originalData为true,请留意这里的返回值
@@ -79,38 +67,7 @@
               url: '/pages/login/login'
            });
         })
         // uni.request({
         //    url: "http://192.168.12.245:8099/api/User/replaceToken",
         //    param: {},
         //    method: 'POST',
         //    responseType: "text",
         //    header: {
         //       Authorization: "Bearer " + vm.vuex_token
         //    },
         //    async: false,
         //    success: function(x) {
         //       if (x.data.status) {
         //          vm.$u.vuex('vuex_token',x.data.data)
         //          vm.$u.route({
         //             type: "navigateBack",
         //             delta: -1
         //          })
         //       } else {
         //          console.log(x.data.message);
         //          vm.$u.toast('验证过期,请重新登录');
         //          setTimeout(() => {
         //             // æ­¤ä¸ºuView的方法,详见路由相关文档
         //             vm.$u.route('/pages/user/login')
         //          }, 1500)
         //       }
         //    },
         //    errror: function(ex) {
         //       console.log(ex);
         //       uni.reLaunch({
         //          url: '/pages/user/login'
         //       });
         //    },
         // });
         // return false; // return false后不再进入then回调,但会进入catch回调
         return false;
      }
   }