fix(api): 时间区间查询参数错误

closed #I6PWSR
pull/3/head
xingyuv 2023-03-25 22:13:38 +08:00
parent a69aefc566
commit cd2c8ca054
1 changed files with 18 additions and 0 deletions

View File

@ -125,6 +125,24 @@ const transform: AxiosTransform = {
if (!isString(params)) {
// 给 get 请求加上时间戳参数,避免从缓存中拿数据。
config.params = Object.assign(params || {}, joinTimestamp(joinTime, false))
let url = config.url + '?'
for (const propName of Object.keys(config.params)) {
const value = config.params[propName]
if (value !== void 0 && value !== null && typeof value !== 'undefined') {
if (typeof value === 'object') {
for (const val of Object.keys(value)) {
const paramss = propName + '[' + val + ']'
const subPart = encodeURIComponent(paramss) + '='
url += subPart + encodeURIComponent(value[val]) + '&'
}
} else {
url += `${propName}=${encodeURIComponent(value)}&`
}
}
}
url = url.slice(0, -1)
config.params = {}
config.url = url
} else {
// 兼容restful风格
config.url = config.url + params + `${joinTimestamp(joinTime, true)}`