@kevisual/query 0.0.34 → 0.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/query-browser.d.ts +1 -0
- package/dist/query-browser.js +16 -1
- package/dist/query.d.ts +1 -0
- package/dist/query.js +15 -0
- package/package.json +1 -1
- package/src/query-browser.ts +1 -1
- package/src/query.ts +15 -0
package/dist/query-browser.d.ts
CHANGED
package/dist/query-browser.js
CHANGED
|
@@ -367,6 +367,21 @@ class Query {
|
|
|
367
367
|
'Content-Type': 'application/json',
|
|
368
368
|
};
|
|
369
369
|
this.timeout = opts?.timeout || 60000 * 3; // 默认超时时间为 60s * 3
|
|
370
|
+
if (opts.beforeRequest) {
|
|
371
|
+
this.beforeRequest = opts.beforeRequest;
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
this.beforeRequest = async (opts) => {
|
|
375
|
+
const token = globalThis?.localStorage?.getItem('token');
|
|
376
|
+
if (token) {
|
|
377
|
+
opts.headers = {
|
|
378
|
+
...opts.headers,
|
|
379
|
+
Authorization: `Bearer ${token}`,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
return opts;
|
|
383
|
+
};
|
|
384
|
+
}
|
|
370
385
|
}
|
|
371
386
|
setQueryWs(qws) {
|
|
372
387
|
this.qws = qws;
|
|
@@ -549,7 +564,7 @@ class QueryClient extends Query {
|
|
|
549
564
|
constructor(opts) {
|
|
550
565
|
super(opts);
|
|
551
566
|
this.tokenName = opts?.tokenName || 'token';
|
|
552
|
-
this.storage = opts?.storage || localStorage;
|
|
567
|
+
this.storage = opts?.storage || globalThis.localStorage;
|
|
553
568
|
this.beforeRequest = async (opts) => {
|
|
554
569
|
const token = this.token || this.getToken();
|
|
555
570
|
if (token) {
|
package/dist/query.d.ts
CHANGED
package/dist/query.js
CHANGED
|
@@ -170,6 +170,21 @@ class Query {
|
|
|
170
170
|
'Content-Type': 'application/json',
|
|
171
171
|
};
|
|
172
172
|
this.timeout = opts?.timeout || 60000 * 3; // 默认超时时间为 60s * 3
|
|
173
|
+
if (opts.beforeRequest) {
|
|
174
|
+
this.beforeRequest = opts.beforeRequest;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
this.beforeRequest = async (opts) => {
|
|
178
|
+
const token = globalThis?.localStorage?.getItem('token');
|
|
179
|
+
if (token) {
|
|
180
|
+
opts.headers = {
|
|
181
|
+
...opts.headers,
|
|
182
|
+
Authorization: `Bearer ${token}`,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return opts;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
173
188
|
}
|
|
174
189
|
setQueryWs(qws) {
|
|
175
190
|
this.qws = qws;
|
package/package.json
CHANGED
package/src/query-browser.ts
CHANGED
|
@@ -25,7 +25,7 @@ export class QueryClient extends Query {
|
|
|
25
25
|
constructor(opts?: QueryOptions & { tokenName?: string; storage?: Storage; io?: boolean }) {
|
|
26
26
|
super(opts);
|
|
27
27
|
this.tokenName = opts?.tokenName || 'token';
|
|
28
|
-
this.storage = opts?.storage || localStorage;
|
|
28
|
+
this.storage = opts?.storage || globalThis.localStorage;
|
|
29
29
|
this.beforeRequest = async (opts) => {
|
|
30
30
|
const token = this.token || this.getToken();
|
|
31
31
|
if (token) {
|
package/src/query.ts
CHANGED
|
@@ -24,6 +24,7 @@ export type QueryOptions = {
|
|
|
24
24
|
headers?: Record<string, string>;
|
|
25
25
|
timeout?: number;
|
|
26
26
|
isClient?: boolean;
|
|
27
|
+
beforeRequest?: Fn;
|
|
27
28
|
}
|
|
28
29
|
export type Data = {
|
|
29
30
|
path?: string;
|
|
@@ -113,6 +114,20 @@ export class Query {
|
|
|
113
114
|
'Content-Type': 'application/json',
|
|
114
115
|
};
|
|
115
116
|
this.timeout = opts?.timeout || 60000 * 3; // 默认超时时间为 60s * 3
|
|
117
|
+
if (opts.beforeRequest) {
|
|
118
|
+
this.beforeRequest = opts.beforeRequest;
|
|
119
|
+
} else {
|
|
120
|
+
this.beforeRequest = async (opts) => {
|
|
121
|
+
const token = globalThis?.localStorage?.getItem('token');
|
|
122
|
+
if (token) {
|
|
123
|
+
opts.headers = {
|
|
124
|
+
...opts.headers,
|
|
125
|
+
Authorization: `Bearer ${token}`,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return opts;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
116
131
|
}
|
|
117
132
|
setQueryWs(qws: QueryWs) {
|
|
118
133
|
this.qws = qws;
|