update
This commit is contained in:
@@ -15,28 +15,40 @@ import {
|
||||
} from '@/commons/utils/encryptUtil.js'
|
||||
import infoBox from "@/commons/utils/infoBox.js"
|
||||
import go from '@/commons/utils/go.js';
|
||||
import { reject } from 'lodash';
|
||||
import {
|
||||
reject
|
||||
} from 'lodash';
|
||||
// 测试服
|
||||
let baseUrl = 'https://admintestpapi.sxczgkj.cn'
|
||||
|
||||
// let baseUrl = 'http://192.168.1.31'
|
||||
// let baseUrl = 'https://admintestpapi.sxczgkj.cn'
|
||||
// const proxyApiwws = 'ws://192.168.1.31:2348' // 调试地址
|
||||
//预发布
|
||||
// let baseUrl = 'https://pre-cashieradmin.sxczgkj.cn'
|
||||
|
||||
//正式
|
||||
// let baseUrl = 'https://cashieradmin.sxczgkj.cn'
|
||||
// let baseUrl = 'https://cashier.sxczgkj.com'
|
||||
|
||||
// 本地测
|
||||
let baseUrl = "http://192.168.1.31"
|
||||
// #ifdef H5
|
||||
baseUrl = '/ysk'
|
||||
// #endif
|
||||
|
||||
// 王伟本地测
|
||||
// let baseUrl = '/ww'
|
||||
// let baseUrl = 'http://192.168.1.15:8000'
|
||||
// 巩
|
||||
// let baseUrl = 'http://192.168.1.9:8000'
|
||||
// 巩
|
||||
// let baseUrl = 'http://192.168.1.9:8000'
|
||||
// 多少 ms 以内, 不提示loading
|
||||
const loadingShowTime = 200
|
||||
|
||||
|
||||
function getHeader(){
|
||||
const headerObject={}
|
||||
headerObject["Authorization"] = storageManage.token()
|
||||
function getHeader() {
|
||||
const headerObject = {}
|
||||
headerObject["token"] = uni.getStorageSync('tokenInfo').tokenValue
|
||||
headerObject["shopId"] = uni.getStorageSync("shopId"),
|
||||
// shopId:shopInfo.value.id
|
||||
headerObject["Content-Type"] = 'application/json;charset=UTF-8'
|
||||
headerObject["platformType"] ="PAD"
|
||||
return headerObject
|
||||
}
|
||||
|
||||
@@ -85,37 +97,20 @@ function commonsProcess(showLoading, httpReqCallback) {
|
||||
return Promise.reject(bodyData) // 跳转到catch函数
|
||||
}
|
||||
if (statusCode == 401) {
|
||||
// storageManage.token(null, true)
|
||||
// 提示信息
|
||||
|
||||
isShowErrorToast = true
|
||||
// infoBox.showErrorToast('请登录').then(() => {
|
||||
// go.to("PAGES_LOGIN", {}, go.GO_TYPE_RELAUNCH)
|
||||
// })
|
||||
|
||||
return Promise.reject(bodyData) // 跳转到catch函数
|
||||
}
|
||||
// http响应码不正确
|
||||
if (statusCode != 200 && statusCode != 204 && statusCode != 201) {
|
||||
isShowErrorToast = true
|
||||
data.message=data.message=='Bad credentials'?'用户名或密码错误':data.message
|
||||
data.message = data.message == 'Bad credentials' ? '用户名或密码错误' : data.message
|
||||
infoBox.showToast(data.message || '服务器异常')
|
||||
return Promise.reject(bodyData) // 跳转到catch函数
|
||||
}
|
||||
|
||||
// // 业务响应异常
|
||||
// if (bodyData.hasOwnProperty('code') && bodyData.code != 200) {
|
||||
// isShowErrorToast = true
|
||||
// infoBox.showToast(bodyData.msg)
|
||||
// if (bodyData.code == 5005) { // 密码已过期, 直接跳转到更改密码页面
|
||||
// uni.reLaunch({
|
||||
// url: '/pageUser/setting/updatePwd'
|
||||
// })
|
||||
// }
|
||||
// // if(bodyData.code == 500){ // 密码已过期, 直接跳转到更改密码页面
|
||||
// // uni.redirectTo({url: '/pages/login/index'})
|
||||
// // }
|
||||
// return bodyData
|
||||
// // return Promise.reject(bodyData)
|
||||
// }
|
||||
|
||||
|
||||
// 加密数据
|
||||
if (!bodyData.data && bodyData.encryptData) {
|
||||
@@ -130,26 +125,20 @@ function commonsProcess(showLoading, httpReqCallback) {
|
||||
return Promise.resolve(bodyData)
|
||||
|
||||
}).catch(res => {
|
||||
if(res.status==401){
|
||||
if (res.status == 401) {
|
||||
storageManage.token(null, true)
|
||||
infoBox.showErrorToast(res.message||'请登录').then(() => {
|
||||
uni.redirectTo({url: '/pages/login/index'})
|
||||
infoBox.showErrorToast(res.message || '请登录').then(() => {
|
||||
uni.redirectTo({
|
||||
url: '/pages/login/index'
|
||||
})
|
||||
reject()
|
||||
})
|
||||
}
|
||||
// if(res.status==400){
|
||||
// storageManage.token(null, true)
|
||||
// infoBox.showErrorToast('').then(() => {
|
||||
// go.to("PAGES_LOGIN", {}, go.GO_TYPE_RELAUNCH)
|
||||
// })
|
||||
// }
|
||||
if(res.status==500){
|
||||
infoBox.showErrorToast(res.message||'服务器异常').then(() => {
|
||||
})
|
||||
|
||||
if (res.status == 500) {
|
||||
infoBox.showErrorToast(res.message || '服务器异常').then(() => {})
|
||||
}
|
||||
// if(res&&res.msg){
|
||||
// infoBox.showErrorToast(res.msg)
|
||||
// }
|
||||
|
||||
reqFinishFunc(); // 请求完毕的动作
|
||||
|
||||
// 如果没有提示错误, 那么此处提示 异常。
|
||||
@@ -168,7 +157,6 @@ function commonsProcess(showLoading, httpReqCallback) {
|
||||
|
||||
// 默认 显示loading(控制 xxs 内 不提示loading )
|
||||
function req(uri, data, method = "GET", showLoading = true, extParams = {}) {
|
||||
// headerObject[appConfig.tokenKey] = storageManage.token()
|
||||
return commonsProcess(showLoading, () => {
|
||||
return uni.request(
|
||||
Object.assign({
|
||||
@@ -193,14 +181,15 @@ function request(args) {
|
||||
extParams = {}
|
||||
} = args
|
||||
let headerObject = {}
|
||||
// headerObject[appConfig.tokenKey] = storageManage.token()
|
||||
return commonsProcess(showLoading, () => {
|
||||
// console.log('baseUrl+');
|
||||
// console.log(baseUrl + url);
|
||||
return uni.request(
|
||||
Object.assign({
|
||||
url: baseUrl + url,
|
||||
data: params||data,
|
||||
data: params || data,
|
||||
method: method,
|
||||
header: getHeader()
|
||||
header: getHeader()
|
||||
}, extParams)
|
||||
)
|
||||
})
|
||||
@@ -212,7 +201,6 @@ function request(args) {
|
||||
function upload(uri, data, file, showLoading = true, extParams = {}) {
|
||||
// 放置token
|
||||
let headerObject = {}
|
||||
// headerObject[appConfig.tokenKey] = storageManage.token()
|
||||
|
||||
return commonsProcess(showLoading, () => {
|
||||
return uni.uploadFile(
|
||||
@@ -220,14 +208,14 @@ function upload(uri, data, file, showLoading = true, extParams = {}) {
|
||||
url: baseUrl + uri,
|
||||
formData: data,
|
||||
name: "file",
|
||||
filePath: file.path||file.url,
|
||||
header: getHeader()
|
||||
filePath: file.path || file.url,
|
||||
header: getHeader()
|
||||
}, extParams)
|
||||
).then((httpData) => {
|
||||
// uni.upload 返回bodyData 的是 string类型。 需要解析。
|
||||
httpData.data = JSON.parse(httpData.data)
|
||||
return Promise.resolve(httpData)
|
||||
}).catch(err=>{
|
||||
}).catch(err => {
|
||||
uni.hideLoading()
|
||||
infoBox.showErrorToast(`上传失败`)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user