From 9ee9d2af52480fb090dcbceb8280deefa50874f0 Mon Sep 17 00:00:00 2001 From: THK3121 Date: Thu, 28 Sep 2023 15:41:02 +0800 Subject: [PATCH] bug --- pages/nongKe/cloud_entrepot/indexa.vue | 18 ++-- utils/http.js | 137 +++++++++++++------------ 2 files changed, 80 insertions(+), 75 deletions(-) diff --git a/pages/nongKe/cloud_entrepot/indexa.vue b/pages/nongKe/cloud_entrepot/indexa.vue index 9592892..778e746 100644 --- a/pages/nongKe/cloud_entrepot/indexa.vue +++ b/pages/nongKe/cloud_entrepot/indexa.vue @@ -26,11 +26,11 @@ width="50.82rpx" height="50.82rpx" @click='goBack'> --> - - - + + + @@ -114,11 +114,11 @@ - - - + + 供销综合云市场 diff --git a/utils/http.js b/utils/http.js index 71b29da..da904bb 100644 --- a/utils/http.js +++ b/utils/http.js @@ -1,89 +1,94 @@ import { - HTTP_REQUEST_URL, - HTTP_REQUEST_URL_TWO, - HTTP_REQUEST_URL_THREE, - HEADER, - TOKENNAME, + HTTP_REQUEST_URL, + HTTP_REQUEST_URL_TWO, + HTTP_REQUEST_URL_THREE, + HEADER, + TOKENNAME, } from '@/config/app'; import { - checkLogin + checkLogin } from '../libs/login'; -import { Toast } from '../libs/uniApi'; +import { + Toast +} from '../libs/uniApi'; import store from '../store'; function toLogin() { - store.commit("LOGOUT"); - uni.showToast({ - title: '请登录', - icon: 'none', - duration: 1000 - }); + store.commit("LOGOUT"); + uni.showToast({ + title: '请登录', + icon: 'none', + duration: 1000 + }); } function baseRequestTwo(url, method, data, { - noAuth = false, - noVerify = false + noAuth = false, + noVerify = false }) { - let Url = HTTP_REQUEST_URL_TWO, - header = HEADER; + let Url = HTTP_REQUEST_URL_TWO, + header = HEADER; - if (!noAuth) { - //登录过期自动登录 - if (!store.state.app.token && !checkLogin()) { - toLogin(); - return Promise.reject({ - msg: '未登录' - }); - } - } + if (!noAuth) { + //登录过期自动登录 + if (!store.state.app.token && !checkLogin()) { + toLogin(); + return Promise.reject({ + msg: '未登录' + }); + } + } - if (store.state.app.token) header[TOKENNAME] = 'Bearer ' + store.state.app.token; + if (store.state.app.token) header[TOKENNAME] = 'Bearer ' + store.state.app.token; - return new Promise((reslove, reject) => { - uni.request({ - url: Url + '/api' + url, - method: method || 'GET', - header: header, - data: data || {}, - success: (res) => { - // #ifdef APP-PLUS - // console.log('app', Url + '/api/' + url, res.data); - // #endif - if (noVerify) - // reslove(res.data, res); - reslove(res.data); - else if (res.data.status == 200) - reslove(res.data, res); - else if (res.data.code == 1) { - reslove(res.data); - } else if (res.data.code == 0) { - reslove(res.data, res); - } else if ([410000, 410001, 410002, 40000].indexOf(res.data.status) !== -1) { - toLogin(); - reject(res.data); - } else if (res.data.status == 501) { - uni.reLaunch({ - url: '/pages/error/index' - }) - reject(res.data); - } else if (res.statusCode === 500) - Toast("请检查网络") - else - reject(res.data.message || '请检查网络'); + return new Promise((reslove, reject) => { + uni.request({ + url: Url + '/api' + url, + method: method || 'GET', + header: header, + data: data || {}, + success: (res) => { + // #ifdef APP-PLUS + // console.log('app', Url + '/api/' + url, res.data); + // #endif + if (noVerify) + // reslove(res.data, res); + reslove(res.data); + else if (res.data.status == 200) + reslove(res.data, res); + else if (res.data.code == 1) { + reslove(res.data); + } else if (res.data.code == 0) { + reslove(res.data, res); + } else if ([410000, 410001, 410002, 40000].indexOf(res.data.status) !== -1) { + toLogin(); + reject(res.data); + } else if (res.data.status == 501) { + uni.reLaunch({ + url: '/pages/error/index' + }) + reject(res.data); + } else if (res.statusCode === 500) + Toast("请检查网络") + else + reject(res.data.message || '请检查网络'); - }, - fail: (message) => { - // console.log('message', message); - reject('请求失败'); - } - }) - }); + }, + fail: (message) => { + // console.log('message', message); + reject('请求失败'); + } + }) + + + + }); } const http = {}; ['options', 'get', 'post', 'put', 'head', 'delete', 'trace', 'connect'].forEach((method) => { - http[method] = (api, data, opt) => baseRequestTwo(api, method, data, opt || {}) + http[method] = (api, data, opt) => baseRequestTwo(api, method, data, opt || {}) }); export default http; \ No newline at end of file