增加根据env请求不用的地址
This commit is contained in:
31
api/http.js
31
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类型。 需要解析。
|
||||
|
||||
Reference in New Issue
Block a user