From 50b7e6bf15a2241adec6fa7ef8bb646831b09023 Mon Sep 17 00:00:00 2001 From: YeMingfei666 <1619116647@qq.com> Date: Tue, 10 Sep 2024 16:33:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=B7=E6=B1=82=E5=A4=B4?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http/yskApi/http.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/http/yskApi/http.js b/http/yskApi/http.js index 7ae4cfb..2aca0ef 100644 --- a/http/yskApi/http.js +++ b/http/yskApi/http.js @@ -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类型。 需要解析。