From 1136cfbb22bf7d68827af7e21c65340fa4b423bc Mon Sep 17 00:00:00 2001 From: HJ <2365331988@qq.com> Date: Wed, 8 Mar 2023 15:44:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E5=85=AC?= =?UTF-8?q?=E5=85=B1=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/request.js | 132 +++++++++--------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/src/main/resources/static/linfeng-community-uniapp-ky/utils/request.js b/src/main/resources/static/linfeng-community-uniapp-ky/utils/request.js index 4ff9062..e0e8c30 100644 --- a/src/main/resources/static/linfeng-community-uniapp-ky/utils/request.js +++ b/src/main/resources/static/linfeng-community-uniapp-ky/utils/request.js @@ -1,67 +1,67 @@ -import config from './config.js'; -export default { - request(options = {}) { - return new Promise((resolve, reject) => { - let url = options.url; - if (url.indexOf("http://") == -1 && url.indexOf("https://") == -1) { - options.url = config.domain + url; - } - options.header.token = uni.getStorageSync("token"); - options.complete = (response) => { - if (response.statusCode == 200 || response.statusCode == 0) { - if (response.data.code == 401 || response.data.code == 420) { - // #ifdef MP-WEIXIN - uni.navigateTo({ - url: "/pages/login/weixin" - }) - // #endif - - // #ifdef H5 - uni.navigateTo({ - url: "/pages/login/login" - }) - // #endif - } - - if (response.data.code == 500) { - uni.showToast({ - title: response.data.msg, - icon: "none", - duration: 2000 - }); - } - resolve(response.data) - } else { - uni.showToast({ - title: '请求异常!', - icon: "none" - }); - } - } - - uni.request(options) - }) - }, - - post(url, data = {}, header = {}) { - - let options = { - url: url, - data: data, - header: header, - method: "POST" - } - - return this.request(options); - }, - - get(url, data = {}, header = {}) { - let options = { - url: url, - data: data, - header: header - } - - return this.request(options); - } +import config from './config.js'; +export default { + request(options = {}) { + return new Promise((resolve, reject) => { + let url = options.url; + if (url.indexOf("http://") == -1 && url.indexOf("https://") == -1) { + options.url = config.domain + url; + } + options.header.token = uni.getStorageSync("token"); + options.complete = (response) => { + if (response.statusCode == 200 || response.statusCode == 0) { + if (response.data.code == 401 || response.data.code == 420) { + // #ifdef MP-WEIXIN + uni.navigateTo({ + url: "/pages/login/weixin" + }) + // #endif + + // #ifdef H5 + uni.navigateTo({ + url: "/pages/login/login" + }) + // #endif + } + + if (response.data.code == 500) { + uni.showToast({ + title: response.data.msg, + icon: "none", + duration: 2000 + }); + } + resolve(response.data) + } else { + uni.showToast({ + title: '请求异常!', + icon: "none" + }); + } + } + + uni.request(options) + }) + }, + + post(url, data = {}, header = {}) { + + let options = { + url: url, + data: data, + header: header, + method: "POST" + } + + return this.request(options); + }, + + get(url, data = {}, header = {}) { + let options = { + url: url, + data: data, + header: header + } + + return this.request(options); + } };