From 6f441a7afff9be575619de52312cc92e14befbc0 Mon Sep 17 00:00:00 2001 From: "1261008090@qq.com" Date: Sun, 20 Apr 2025 16:46:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=99=BB=E5=BD=95=E5=A4=B1?= =?UTF-8?q?=E6=95=88=E8=BF=94=E5=9B=9E=E7=99=BB=E5=BD=95=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/request.js | 69 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/utils/request.js b/utils/request.js index 0b6e470..38bb291 100644 --- a/utils/request.js +++ b/utils/request.js @@ -1,12 +1,33 @@ - -// export var requestPath = 'https://skqhdg.porthebei.com:9005/qa-regulatory-gwj/'; // 后台请求地址 - -export var requestPath = 'http://192.168.0.101:8060/new_template'; - -let videoApiPath = 'https://arqsp.qhdsafety.com:10010'; // 视频平台后台请求地址 import store from '../store/index' import dayjs from "dayjs"; import { setRefreshToken } from "@/api"; +// export var requestPath = 'https://skqhdg.porthebei.com:9005/qa-regulatory-gwj/'; // 后台请求地址 + +export var requestPath = 'http://192.168.192.201:8992/regulatory_gwj_2.0/'; + +let videoApiPath = 'https://arqsp.qhdsafety.com:10010'; // 视频平台后台请求地址 + +function logOut(reject,data) { + uni.showToast({ + title: '登录失效,请重新登录', + icon: 'none', + duration: 2000 + }); + reject(data) + setTimeout(()=>{ + let userInfo = {} + for (const userInfoKey in store.state.userInfo) { + if (store.state.userInfo.hasOwnProperty(userInfoKey)) { + userInfo[userInfoKey] = '' + } + } + store.dispatch('setUserInfo', userInfo) + uni.redirectTo({ + url: '/pages/login/login' + }) + },1000) +} + function post(url, data) { return new Promise((resolve, reject) => { if (data && data.loading !== false) { @@ -41,9 +62,13 @@ function post(url, data) { }); reject(res.data) }else{ + if(res.data.code === 401){ + logOut(reject,res.data) + return + } uni.showToast({ title: res.data.msg || '系统开小差了', - icon: 'error', + icon: 'none', duration: 2000 }); reject(res.data) @@ -83,15 +108,20 @@ function upload(url, data) { }, success: (res) => { uni.hideLoading(); - if (JSON.parse(res.data).result === 'success') { - resolve(JSON.parse(res.data)) + const data = JSON.parse(res.data) + if (data.result === 'success') { + resolve(data) } else { + if(data.code === 401){ + logOut(reject,data) + return + } uni.showToast({ - title: JSON.parse(res.data).msg || '系统开小差了', - icon: 'error', + title: data.msg || '系统开小差了', + icon: 'none', duration: 2000 }); - reject(JSON.parse(res.data)) + reject(data) } }, fail: (err) => { @@ -123,15 +153,20 @@ function uploads(url, data) { }, success: (res) => { uni.hideLoading(); - if (JSON.parse(res.data).result === 'success') { - resolve(JSON.parse(res.data)) + const data = JSON.parse(res.data) + if (data.result === 'success') { + resolve(data) } else { + if(data.code === 401){ + logOut(reject,data) + return + } uni.showToast({ - title: JSON.parse(res.data).msg || '系统开小差了', - icon: 'error', + title: data.msg || '系统开小差了', + icon: 'none', duration: 2000 }); - reject(JSON.parse(res.data)) + reject(data) } }, fail: (err) => {