Browse Source

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

closed #I6PWSR
main
xingyuv 2 years ago
parent
commit
cd2c8ca054
  1. 18
      src/utils/http/axios/index.ts

18
src/utils/http/axios/index.ts

@ -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)}`