linwe
2024-08-08 3c738f4fe2762bba8087e5a22fc0dc06560eab0e
http/api.js
@@ -19,12 +19,20 @@
      config.header['Authorization'] = 'Basic ' + Base64.encode(clientId + ':' + clientSecret);
   }
   if (config.custom.Authorization == true) {
      console.log(config.custom,"==========")
      config.header['Authorization']="Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJBRE1JTiIsIlVzZXJJZCI6IjEiLCJzY29wZSI6WyJhbGwiXSwiVXNlclJlYWxOYW1lIjoi6LaF57qn566h55CG5ZGYIiwiVXNlclh6cWhkbSI6IjQyMDUiLCJleHAiOjI1MTk3NzIwMTAsImp0aSI6ImExNTcxYzk1LTBkNjMtNDkyYi1iOWEyLTE2ZTIzNTQ5ZTY1ZiIsImNsaWVudF9pZCI6InVzZXItc2VydmljZSJ9.ebNVZrw9LbhKaj2w6RR8b2wccQiDkhvBeq79SxxCK-yWiOlIFqBkotTN4TNJg8umcpyYvLILwvqXWRJhffEtgi25sX2y6MqLIWM4kMZ9d8ptdnSmTpBPhltSiQOM0KFa1kl5nSDCBwYOLn-pESJglam76cjpgZNoC88x3iNHacdiXDItY0rtY85HrQ26uyJu9UovKtmYmZRHsIbGMpDta5Q1p4vfaCIr-YUayDrCweZJiQDEEcOSpWJ7O7RMk3pRkX_4UmPHFzrOI2lMp1jQIhxnSTE7EVAz_4z8h8r46muSkpF54Ic4XSawHKqdSLHx8T05LB0MpvOzWMPS6c1uHA"
      console.log(config.custom, "==========")
      config.header['Authorization'] =
         "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJBRE1JTiIsIlVzZXJJZCI6IjEiLCJzY29wZSI6WyJhbGwiXSwiVXNlclJlYWxOYW1lIjoi6LaF57qn566h55CG5ZGYIiwiVXNlclh6cWhkbSI6IjQyMDUiLCJleHAiOjI1MTk3NzIwMTAsImp0aSI6ImExNTcxYzk1LTBkNjMtNDkyYi1iOWEyLTE2ZTIzNTQ5ZTY1ZiIsImNsaWVudF9pZCI6InVzZXItc2VydmljZSJ9.ebNVZrw9LbhKaj2w6RR8b2wccQiDkhvBeq79SxxCK-yWiOlIFqBkotTN4TNJg8umcpyYvLILwvqXWRJhffEtgi25sX2y6MqLIWM4kMZ9d8ptdnSmTpBPhltSiQOM0KFa1kl5nSDCBwYOLn-pESJglam76cjpgZNoC88x3iNHacdiXDItY0rtY85HrQ26uyJu9UovKtmYmZRHsIbGMpDta5Q1p4vfaCIr-YUayDrCweZJiQDEEcOSpWJ7O7RMk3pRkX_4UmPHFzrOI2lMp1jQIhxnSTE7EVAz_4z8h8r46muSkpF54Ic4XSawHKqdSLHx8T05LB0MpvOzWMPS6c1uHA"
      config.header["Content-Type"] = "application/json";
   }
   if (accessToken) {
      config.header['Blade-Auth'] = 'bearer ' + accessToken;
      config.header['roleName'] = uni.getStorageSync("activeRole").roleAlias || "";
      let activeRole = uni.getStorageSync("activeRole")
      if (activeRole.roleAlias === 'inhabitant') {
         config.header['communityCode'] = uni.getStorageSync("siteInfo").neiCode || ""
      } else {
         config.header['communityCode'] = uni.getStorageSync("siteInfo").id || ""
      }
   }
   if (config.params.tenantId) {
      config.header['Tenant-Id'] = config.params.tenantId;
@@ -66,44 +74,28 @@
}, config => { // 可使用async await 做异步操作
   return Promise.reject(config)
})
// uni.showLoading({
//    title:"加载中..."
// })
http.interceptors.response.use((response) => {
   // 若有数据返回则通过
   if (response.data.access_token || response.data.key) {
      return response.data
   }
   //对该区域做处理
   if (response.data.resultList && response.data.resultList.length > 0) {
      response.data.resultList = response.data.resultList.map(item => {
         if (item.city_nm && item.city_nm == '恩施土家族苗族自治州') {
            item.city_nm = '恩施州'
         }
         if (item.ad_nm && item.ad_nm == '恩施土家族苗族自治州') {
            item.ad_nm = '恩施州'
         }
         if (item.ad_name && item.ad_name == '恩施土家族苗族自治州') {
            item.ad_name = '恩施州'
         }
         return item
      })
   }
   //对该区域做处理
   if (response.data.data && (response.data.data instanceof Array) && response.data.data.length > 0) {
      response.data.data = response.data.data.map(item => {
         if (item.c_name && item.c_name == '恩施土家族苗族自治州') {
            item.c_name = '恩施州'
         }
         return item
      })
   }
   // 服务端返回的状态码不等于200,则reject()
   if (response.data.code) {
      if (response.data.code !== 200) {
         uni.showToast({
            title: response.data.msg,
            icon: 'none'
         });
         return Promise.reject(response);
      }
   } else {
      if (response.data.error_code !== 200) {
         uni.showToast({
            title: response.data.msg,
            icon: 'none'
@@ -114,7 +106,8 @@
   //数据中台返回的数据结果
   if (response.statusCode) {
      if (response.statusCode !== 200) {
      // uni.hideLoading()
      if (response.statusCode >= 300) {
         console.log(response.data.msg)
         uni.showToast({
            title: '系统繁忙,请稍后再试',
@@ -135,24 +128,30 @@
      const currentPage = pages[pages.length - 1]
      uni.setStorageSync("responIndex", 0)
      uni.clearStorageSync()
      // uni.redirectTo({
      //    url: `/pages/login/login-account?redirect=/${currentPage.route}`
      // })
      uni.showModal({
         title: "提示",
         content: "请登录",
         showCancel: false,
         // showCancel: false,
         success: res => {
            if (res.confirm) {
               uni.redirectTo({
                  url: `/pages/login/index?redirect=/${currentPage.route}`
                  url: `/pages/login/login-account?redirect=/${currentPage.route}`
               })
            } else if (res.cancel) {
               console.log('用户点击取消');
            }
         }
      })
   } else {
      uni.showToast({
         title: '系统繁忙,请稍后再试',
         icon: 'none'
      });
   }
   return Promise.reject(response)
})