You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.1 KiB
98 lines
2.1 KiB
import {showLoading,hideLoading} from "./plugIn/globalLoading";
|
|
const request = (url, data, method = 'GET') => {
|
|
return new Promise((resolve, reject) => {
|
|
let header = {
|
|
"Content-Type": "application/json"
|
|
}
|
|
const res = uni.getStorageSync('storage_key');
|
|
const token = res.token
|
|
if (token) {
|
|
header['Authorization'] = token
|
|
}
|
|
|
|
var fullUrl = window.location.search;
|
|
if (fullUrl.indexOf("?") != -1) {
|
|
fullUrl = fullUrl.substring(1);
|
|
var paramStrs = fullUrl.split("&");
|
|
for(let i=0;i<paramStrs.length;i++){
|
|
const newStrs = paramStrs[i].split("=");
|
|
if(newStrs[0] === 'project'){
|
|
header['project'] = newStrs[1]
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if(header['project'] == undefined || header['project']== ''){
|
|
header['project'] = '0'
|
|
}
|
|
var locale = uni.getLocale() || 'zh'
|
|
if(locale == 'zh-Hans'){
|
|
locale = 'zh'
|
|
}
|
|
header['language'] = locale
|
|
showLoading()
|
|
uni.request({
|
|
url: url,
|
|
data: data,
|
|
method: method,
|
|
header: header,
|
|
success: res => {
|
|
hideLoading()
|
|
if (res.statusCode == 200) {
|
|
if (res.data.code === "200" || res.data.code === "") {
|
|
resolve(res.data)
|
|
} else if (res.data.code === "20004" || res.data.code === "20005") {
|
|
uni.removeStorageSync("storage_key")
|
|
uni.navigateTo({
|
|
url: '/pages_category_page2/userModule/login'
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
title: res.data.message,
|
|
icon: "none"
|
|
})
|
|
}
|
|
} else {
|
|
reject(res)
|
|
}
|
|
},
|
|
fail: res => {
|
|
hideLoading()
|
|
reject(res)
|
|
},
|
|
})
|
|
});
|
|
}
|
|
//不带token接口请求,首页
|
|
const request1 = (url, data, method = 'GET') => {
|
|
return new Promise((resolve, reject) => {
|
|
let header = {
|
|
'Content-Type': 'application/json',
|
|
'tenant': 'MDAwMA==',
|
|
}
|
|
showLoading()
|
|
uni.request({
|
|
url: url,
|
|
data: data,
|
|
method: method,
|
|
header: header,
|
|
success: res => {
|
|
hideLoading()
|
|
if (res.data.code === "200" || data.code === "") {
|
|
resolve(res.data)
|
|
} else {
|
|
reject(res)
|
|
}
|
|
},
|
|
fail: res => {
|
|
hideLoading()
|
|
reject(res)
|
|
}
|
|
})
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
request: request,
|
|
request1: request1
|
|
}
|