doum
14 小时以前 22881a4d6409c7d17867e1d40bf81a13578208df
h5/utils/service.js
@@ -1,8 +1,8 @@
import { baseUrl } from "./config.js"
import { baseUrl, app_url } from "./config.js"
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,24 @@
               // 控制台显示数据信息
               uni.hideLoading()
               // 登录过期
               if (data.code === 401) {
                  uni.navigateTo({
                     url: '/packageA/loginAgain/loginAgain'
                  })
               }
               if (data.code !== 200) {
                  uni.showToast({
                     title: data.message,
                     icon: "none",
                     duration: 2000
                  })
                  setTimeout(() => {
                     uni.showToast({
                        title: data.message,
                        icon: "none",
                        duration: 2000
                     })
                  },500)
                  if (data.code === 500) {
                     uni.showToast({
                        'title': '服务器异常',icon:'none'
                     })
                  }
                  // if (data.code === 5112) {
                  //    uni.clearStorageSync()
                  //    window.location.href = app_url
                  // }
                  return resolve(data)
               }
               resolve(data)
               // return response.data
@@ -44,8 +51,10 @@
            fail: (err) => {
               // 页面中弹框显示失败
               uni.showToast({
                  title: '请求接口失败'
                  title: '请求接口失败',
                  icon:"none"
               })
               // 返回错误消息
               reject(err)
               uni.hideLoading()