k94314517
2024-10-16 17efddc6a667670dca682bf36b51a43e99615e6d
h5/utils/service.js
@@ -2,7 +2,7 @@
export const http = function (options) {
   {
      return new Promise((resolve, reject) => {
         let token = uni.getStorageSync('token')
         let token = uni.getStorageSync('token') || ''
         // 在登录的时候需要储存 token uni.setStorageSync("authorization","这里是登录获取的token值")
         // uni.showLoading({
@@ -18,7 +18,7 @@
            method: options.method || 'GET',
            header: options.header || {
               // 根据实际接口设计 key 取 token 或者 authorization
               token: token,
               dm_user_token: token,
               "content-type": 'application/json'
            },
            success: (res) => {
@@ -26,17 +26,21 @@
               // 控制台显示数据信息
               uni.hideLoading()
               // 登录过期
               if (data.code === 401) {
                  uni.navigateTo({
                     url: '/packageA/loginAgain/loginAgain'
                  })
               }
               if (data.code !== 200) {
                  uni.showToast({
                     title: response.data.message,
                     icon: "none",
                     duration: 2000
                  setTimeout(() => {
                     uni.showToast({
                        title: data.message,
                        icon: "none",
                        duration: 2000
                     })
                  })
                  if (data.code === 500) {
                     uni.clearStorageSync()
                     return uni.navigateTo({
                        url: '/pages/login/login'
                     })
                  }
                  return
               }
               resolve(data)
               // return response.data
@@ -46,6 +50,7 @@
               uni.showToast({
                  title: '请求接口失败'
               })
               // 返回错误消息
               reject(err)
               uni.hideLoading()