This commit is contained in:
aihe 2024-06-21 12:59:09 +08:00
parent 58ec6c369f
commit ed8d66fae6

View File

@ -4,6 +4,11 @@ import { host } from "./api"
import { getSessionXToken } from "@/session"
const coreRequestBase = (url, reqParams, options = {}, methodType = "POST", coreParams = {}) => {
// get请求 需要转成query参
if(methodType.toLocaleLowerCase() == 'get') {
url = url + (url.indexOf('?') == -1 ? '?': '') + tansGetParamsToQuery(reqParams)
reqParams = {}
}
return new Promise((resolve, reject) => {
uni.request({
url,
@ -23,6 +28,32 @@ const coreRequestBase = (url, reqParams, options = {}, methodType = "POST", core
const baseParam = {}
/**
* 参数处理
* @param {*} params 参数
*/
export function tansGetParamsToQuery(params) {
let result = ''
for (const propName of Object.keys(params)) {
const value = params[propName];
var part = encodeURIComponent(propName) + "=";
if (value !== null && typeof (value) !== "undefined") {
if (typeof value === 'object') {
for (const key of Object.keys(value)) {
if (value[key] !== null && typeof (value[key]) !== 'undefined') {
let params = propName + '[' + key + ']';
var subPart = encodeURIComponent(params) + "=";
result += subPart + encodeURIComponent(value[key]) + "&";
}
}
} else {
result += part + encodeURIComponent(value) + "&";
}
}
}
return result
}
// 请求处理
let coreRequest = function(url, params = {}, options = {}, methodType, coreParams = {}) {
let comReqData = getCommonReqData()