diff --git a/api/http.js b/api/http.js index 401c7c8..87ea8d3 100644 --- a/api/http.js +++ b/api/http.js @@ -15,15 +15,20 @@ import { } from '@/commons/utils/encryptUtil.js' import infoBox from "@/commons/utils/infoBox.js" // let baseUrl = '' -// let baseUrl = 'https://cashier.sxczgkj.com' -let baseUrl = 'https://frp.sxczgkj.com' +let baseUrl_pro = 'https://cashier.sxczgkj.com' +let baseUrl_test = 'https://frp.sxczgkj.com' +let baseUrl = { + prod: 'https://cashier.sxczgkj.com', + test: 'https://frp.sxczgkj.com', + dev: 'https://frp.sxczgkj.com' +} // let baseUrl = '/api' // 多少 ms 以内, 不提示loading const loadingShowTime = 200 -function getHeader(){ - const headerObject={} +function getHeader() { + const headerObject = {} // headerObject["Authorization"] = storageManage.token() headerObject["Content-Type"] = 'application/json' // headerObject["loginname"] = 'admin' @@ -93,15 +98,15 @@ function commonsProcess(showLoading, httpReqCallback) { return Promise.reject(bodyData) // 跳转到catch函数 } - + // 构造请求成功的响应数据 return Promise.resolve(bodyData) }).catch(res => { - if(res.status==401){ + if (res.status == 401) { infoBox.showToast(`登录失效`) } - if(res.status==500){ + if (res.status == 500) { infoBox.showToast(`网络异常`) } // if(res&&res.msg){ @@ -126,10 +131,11 @@ function commonsProcess(showLoading, httpReqCallback) { // 默认 显示loading(控制 xxs 内 不提示loading ) function req(uri, data, method = "GET", showLoading = true, extParams = {}) { // headerObject[appConfig.tokenKey] = storageManage.token() + const env = localStorage.getItem('env') || 'prod' return commonsProcess(showLoading, () => { return uni.request( Object.assign({ - url: baseUrl + uri, + url: baseUrl[env] + uri, data: data, method: method, header: getHeader() @@ -141,6 +147,7 @@ function req(uri, data, method = "GET", showLoading = true, extParams = {}) { // 默认 显示loading(控制 xxs 内 不提示loading ) function request(args) { + const env = localStorage.getItem('env') || 'prod' const { url, data, @@ -155,10 +162,10 @@ function request(args) { return commonsProcess(showLoading, () => { return uni.request( Object.assign({ - url: baseUrl + url, - data: params||data, + url: baseUrl[env] + url, + data: params || data, method: method, - header: getHeader() + header: getHeader() }, extParams) ) }) @@ -179,7 +186,7 @@ function upload(uri, data, file, showLoading = true, extParams = {}) { formData: data, name: "file", filePath: file.path, - header: getHeader() + header: getHeader() }, extParams) ).then((httpData) => { // uni.upload 返回bodyData 的是 string类型。 需要解析。 diff --git a/pages/index/index.vue b/pages/index/index.vue index 1028798..1bab792 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -35,6 +35,8 @@ export default { onShow() { this.shopId = this.getUrlParam('shopId'); this.orderId = this.getUrlParam('orderId'); + localStorage.setItem('env', this.getUrlParam('env') || 'prod'); + if (this.getUrlParam('payAmount')) { this.payAmount = this.getUrlParam('payAmount'); this.disabled = true; @@ -125,7 +127,7 @@ export default { // payType: this.payType, //微信 WECHAT; 支付宝 ALIPAY; // appId: appId, //微信 WECHAT; 支付宝 ALIPAY; source: this.payType == 'WECHAT' ? 'wechat' : 'alipay', - shopId: this.getUrlParam('shopId') //微信 WECHAT; 支付宝 ALIPAY; + shopId: this.getUrlParam('shopId') //微信 WECHAT; 支付宝 ALIPAY }; getOpenId(params).then((res) => { console.log('获取微信/支付宝openid', res);