feat: 优化query,添加别名queryFetch

This commit is contained in:
2025-03-02 09:11:59 +08:00
parent 0b575d44c0
commit 3a8396279b
3 changed files with 30 additions and 2 deletions

View File

@@ -4,7 +4,14 @@ type AdapterOpts = {
body?: Record<string, any>;
timeout?: number;
};
export const adapter = async (opts: AdapterOpts) => {
/**
*
* @param opts
* @param overloadOpts 覆盖fetch的默认配置
* @returns
*/
export const adapter = async (opts: AdapterOpts, overloadOpts?: RequestInit) => {
const controller = new AbortController();
const signal = controller.signal;
const timeout = opts.timeout || 60000 * 3; // 默认超时时间为 60s * 3
@@ -20,6 +27,7 @@ export const adapter = async (opts: AdapterOpts) => {
},
body: JSON.stringify(opts.body),
signal,
...overloadOpts,
})
.then((response) => {
// 获取 Content-Type 头部信息
@@ -44,3 +52,7 @@ export const adapter = async (opts: AdapterOpts) => {
clearTimeout(timer);
});
};
/**
* adapter
*/
export const queryFetch = adapter;