uu
This commit is contained in:
parent
58ec6c369f
commit
ed8d66fae6
@ -4,6 +4,11 @@ import { host } from "./api"
|
|||||||
import { getSessionXToken } from "@/session"
|
import { getSessionXToken } from "@/session"
|
||||||
|
|
||||||
const coreRequestBase = (url, reqParams, options = {}, methodType = "POST", coreParams = {}) => {
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
uni.request({
|
uni.request({
|
||||||
url,
|
url,
|
||||||
@ -23,6 +28,32 @@ const coreRequestBase = (url, reqParams, options = {}, methodType = "POST", core
|
|||||||
|
|
||||||
const baseParam = {}
|
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 coreRequest = function(url, params = {}, options = {}, methodType, coreParams = {}) {
|
||||||
let comReqData = getCommonReqData()
|
let comReqData = getCommonReqData()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user