This commit is contained in:
duan 2024-09-10 16:52:10 +08:00
commit 200ecaea29
1 changed files with 14 additions and 10 deletions

View File

@ -19,6 +19,17 @@ let baseUrl = 'https://admintestpapi.sxczgkj.cn'
// 多少 ms 以内, 不提示loading
const loadingShowTime = 200
function getHeader(){
const headerObject={}
headerObject["Authorization"] = storageManage.token()
headerObject["Content-Type"] = 'application/json'
headerObject["loginname"] = 'admin'
headerObject["token"] = 'eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyVHlwZSI6Ik1HIiwiZXhwIjoxNjkwMTgwNzE2LCJ1c2VySWQiOiIyNDQiLCJpYXQiOjE2ODg3MDk0ODcsImxvZ2luTmFtZSI6ImFkbWluIn0.lqxxvv2-FcecQngMBorz4MpkB3mIJQDG-IUULQyV-KQ'
headerObject["userId"] = '244'
return headerObject
}
// 通用处理逻辑
function commonsProcess(showLoading, httpReqCallback) {
@ -141,18 +152,14 @@ function commonsProcess(showLoading, httpReqCallback) {
// 默认 显示loading(控制 xxs 内 不提示loading )
function req(uri, data, method = "GET", showLoading = true, extParams = {}) {
let headerObject = {}
// headerObject[appConfig.tokenKey] = storageManage.token()
headerObject["authorization"] = storageManage.token()
headerObject["content-type"] = 'application/json'
return commonsProcess(showLoading, () => {
return uni.request(
Object.assign({
url: baseUrl + uri,
data: data,
method: method,
header: headerObject
header: getHeader()
}, extParams)
)
})
@ -171,8 +178,6 @@ function request(args) {
} = args
let headerObject = {}
// headerObject[appConfig.tokenKey] = storageManage.token()
headerObject["satoken"] = storageManage.token()
headerObject["content-type"] = 'application/json'
return commonsProcess(showLoading, () => {
return uni.request(
@ -180,7 +185,7 @@ function request(args) {
url: baseUrl + url,
data: params||data,
method: method,
header: headerObject
header: getHeader()
}, extParams)
)
})
@ -193,7 +198,6 @@ function upload(uri, data, file, showLoading = true, extParams = {}) {
// 放置token
let headerObject = {}
// headerObject[appConfig.tokenKey] = storageManage.token()
headerObject["satoken"] = storageManage.token()
return commonsProcess(showLoading, () => {
return uni.uploadFile(
@ -202,7 +206,7 @@ function upload(uri, data, file, showLoading = true, extParams = {}) {
formData: data,
name: "file",
filePath: file.path,
header: headerObject
header: getHeader()
}, extParams)
).then((httpData) => {
// uni.upload 返回bodyData 的是 string类型。 需要解析。