From 28cde0020f9a5566fc6a92e3023e5687459bd48f Mon Sep 17 00:00:00 2001
From: liukangdong <898885815@qq.com>
Date: 星期二, 16 七月 2024 17:32:27 +0800
Subject: [PATCH] wxmini

---
 wechat_staff/utils/request.js |   36 ++++++++++++++++++++++++++++--------
 1 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/wechat_staff/utils/request.js b/wechat_staff/utils/request.js
index 374f9cc..7d34329 100644
--- a/wechat_staff/utils/request.js
+++ b/wechat_staff/utils/request.js
@@ -1,26 +1,46 @@
 import { baseUrl } from "./config"
 
 export function request(options){
+  let loading = options.loading || '1' // 榛樿鍊�1鏄剧ず锛屽惁鍒欎笉鏄剧ず
+  if(loading == '1'){
+    wx.showLoading()
+  }
   return new Promise(resolve => {
     wx.request({
       url: baseUrl + options.url,
-      data: options.options || {},
+      data: options.data || {},
       method: options.method || "GET",
       header: {
-        'content-type': 'application/x-www-form-urlencoded',
+        'content-type': 'application/json;charset=utf-8',
+        'token': wx.getStorageSync('token') || ''
       },
       timeout: 12000,
       success: (res) => {
-        if (res.code === 0) {
-          // res.msg && toast(res.msg)
+        if (res.data.code === 200) {
           resolve(res.data || true)
         } else {
-          res.msg && toast(res.msg || '鍙戠敓閿欒', 'none')
-          resolve(res.data || false)
+          if(res.data.code && res.data.code == 5112){
+            wx.navigateTo({
+              url: '/pages/auth/auth',
+            })
+          }
+          res.data.message && wx.showToast({
+            title: res.data.message || '鍙戠敓閿欒',
+            icon: 'none'
+          })
         }
       },
-      fail() {
-        wxToast('缃戠粶閿欒', 'none')
+      fail(err) {
+        console.log('err', err);
+        err.message && wx.showToast({
+          title: err.message || '鍙戠敓閿欒',
+          icon: 'none'
+        })
+      },
+      complete() {
+        if(loading == '1'){
+          wx.hideLoading()
+        }
       }
     })
   } )

--
Gitblit v1.9.3