更新请求头设置

This commit is contained in:
2024-09-10 16:33:55 +08:00
parent 4a6de0a22b
commit 50b7e6bf15

View File

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