fix: remove dist for query
This commit is contained in:
20
src/index.ts
20
src/index.ts
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user