fix: remove dist for query

This commit is contained in:
2024-09-28 16:50:59 +08:00
parent 28558d92f0
commit 632d164087
6 changed files with 10 additions and 224 deletions

View File

@@ -20,16 +20,16 @@ type Data = {
payload?: Record<string, any>;
[key: string]: any;
};
type Result<S=any> = {
type Result<S = any> = {
code: number;
data?: S;
message?: string;
success: boolean;
}
};
// 额外功能
type DataOpts = Partial<QueryOpts> & {
beforeRequest?: Fn;
afterResponse?: (result: Result)=>Promise<any>;
afterResponse?: (result: Result) => Promise<any>;
};
/**
* const query = new Query();
@@ -42,16 +42,16 @@ export class Query {
adapter: typeof adapter;
url: string;
beforeRequest?: Fn;
afterResponse?: (result: Result)=>Promise<any>;
afterResponse?: (result: Result) => Promise<any>;
headers?: Record<string, string>;
timeout?: number;
constructor(opts: QueryOpts) {
this.adapter = opts.adapter || adapter;
this.url = opts.url || '/api/router';
this.headers = opts.headers || {
constructor(opts?: QueryOpts) {
this.adapter = opts?.adapter || adapter;
this.url = opts?.url || '/api/router';
this.headers = opts?.headers || {
'Content-Type': 'application/json',
};
this.timeout = opts.timeout || 60000; // 默认超时时间为 60s
this.timeout = opts?.timeout || 60000; // 默认超时时间为 60s
}
async get<T, S>(params: Record<string, any> & Data & T, options?: DataOpts): Promise<Result<S>> {
return this.post(params, options);
@@ -82,7 +82,7 @@ export class Query {
before(fn: Fn) {
this.beforeRequest = fn;
}
after(fn: (result: Result)=>Promise<any>) {
after(fn: (result: Result) => Promise<any>) {
this.afterResponse = fn;
}
}