chore: bump @kevisual/router to version 0.0.75, update QueryClient constructor, and enhance token handling in Query class

This commit is contained in:
2026-02-18 05:28:12 +08:00
parent 585becb6f5
commit 30245606d2
6 changed files with 56 additions and 97 deletions

View File

@@ -19,23 +19,8 @@ type QueryOpts = {
* 前端调用后端QueryRouter, 封装 beforeRequest 和 wss
*/
export class QueryClient extends Query {
tokenName: string;
storage: Storage;
token: string;
constructor(opts?: QueryOptions & { tokenName?: string; storage?: Storage; io?: boolean }) {
constructor(opts?: QueryOptions & { io?: boolean }) {
super(opts);
this.tokenName = opts?.tokenName || 'token';
this.storage = opts?.storage || globalThis.localStorage;
this.beforeRequest = async (opts) => {
const token = this.token || this.getToken();
if (token) {
opts.headers = {
...opts.headers,
Authorization: `Bearer ${token}`,
};
}
return opts;
};
if (opts?.io) {
this.createWs();
}
@@ -43,15 +28,6 @@ export class QueryClient extends Query {
createWs(opts?: QueryWsOpts) {
this.qws = new QueryWs({ url: this.url, ...opts });
}
getToken() {
return this.storage.getItem(this.tokenName);
}
saveToken(token: string) {
this.storage.setItem(this.tokenName, token);
}
removeToken() {
this.storage.removeItem(this.tokenName);
}
}
// 移除默认生成的实例
// export const client = new QueryClient();