refactor(http): 重构HTTP模块结构,将相关文件迁移至src/http目录

将原本分散在src/utils和src/interceptors下的HTTP相关代码统一迁移至src/http目录,包括请求工具、拦截器、类型定义等
移除不再使用的src/interceptors目录
调整相关文件的引用路径
新增统一的HTTP模块入口文件
This commit is contained in:
feige996
2025-07-08 16:59:32 +08:00
parent c0118df836
commit dc5fdda452
21 changed files with 14 additions and 181 deletions

29
src/http/queryString.ts Normal file
View File

@@ -0,0 +1,29 @@
/**
* 将对象序列化为URL查询字符串用于替代第三方的 qs 库,节省宝贵的体积
* 支持基本类型值和数组,不支持嵌套对象
* @param obj 要序列化的对象
* @returns 序列化后的查询字符串
*/
export function stringifyQuery(obj: Record<string, any>): string {
if (!obj || typeof obj !== 'object' || Array.isArray(obj))
return ''
return Object.entries(obj)
.filter(([_, value]) => value !== undefined && value !== null)
.map(([key, value]) => {
// 对键进行编码
const encodedKey = encodeURIComponent(key)
// 处理数组类型
if (Array.isArray(value)) {
return value
.filter(item => item !== undefined && item !== null)
.map(item => `${encodedKey}=${encodeURIComponent(item)}`)
.join('&')
}
// 处理基本类型
return `${encodedKey}=${encodeURIComponent(value)}`
})
.join('&')
}