best-unit 1.2.10 → 1.2.11
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/best-unit.cjs +9 -9
- package/dist/best-unit.js +578 -568
- package/package.json +1 -1
- package/src/api/axiosInstance.ts +29 -15
package/package.json
CHANGED
package/src/api/axiosInstance.ts
CHANGED
|
@@ -42,21 +42,35 @@ export function createAxiosInstance(options: CreateAxiosOptions = {}) {
|
|
|
42
42
|
|
|
43
43
|
const instance: AxiosInstance = axios.create({ baseURL, timeout });
|
|
44
44
|
|
|
45
|
-
//
|
|
46
|
-
instance.interceptors.request.use(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
45
|
+
// 请求拦截:等待参数就绪、加 token、国际化
|
|
46
|
+
instance.interceptors.request.use(
|
|
47
|
+
async (config: InternalAxiosRequestConfig) => {
|
|
48
|
+
// 若参数未就绪,则等待至就绪
|
|
49
|
+
try {
|
|
50
|
+
const obj = JSON.parse(
|
|
51
|
+
sessionStorage.getItem("fund_unit_params") || "{}"
|
|
52
|
+
);
|
|
53
|
+
if (!obj || Object.keys(obj).length === 0) {
|
|
54
|
+
await waitUntilParamsReady();
|
|
55
|
+
}
|
|
56
|
+
} catch (_) {
|
|
57
|
+
await waitUntilParamsReady();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 每次请求读取最新的 fund_unit_params,避免闭包老数据
|
|
61
|
+
const latestParams = JSON.parse(
|
|
62
|
+
sessionStorage.getItem("fund_unit_params") || "{}"
|
|
63
|
+
);
|
|
64
|
+
const { token, locale } = latestParams || {};
|
|
65
|
+
config.headers = {
|
|
66
|
+
...config.headers,
|
|
67
|
+
Authorization: token,
|
|
68
|
+
"x-locale": locale === Locale.ZH ? "zh-CN" : "en-US",
|
|
69
|
+
} as any;
|
|
70
|
+
|
|
71
|
+
return config;
|
|
72
|
+
}
|
|
73
|
+
);
|
|
60
74
|
|
|
61
75
|
// 响应拦截:code=0判定成功,其他走 onError
|
|
62
76
|
instance.interceptors.response.use(
|