best-unit 0.0.48 → 0.0.49
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 +27 -27
- package/dist/best-unit.js +1864 -1863
- package/package.json +1 -1
- package/src/api/axiosInstance.ts +12 -18
- package/src/utils/business/index.ts +24 -42
package/package.json
CHANGED
package/src/api/axiosInstance.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type {
|
|
|
6
6
|
} from "axios";
|
|
7
7
|
import { message } from "../components/common/Message";
|
|
8
8
|
import { Locale } from "../types";
|
|
9
|
-
import { waitForInitialization } from "../utils/business";
|
|
10
9
|
|
|
11
10
|
export interface CreateAxiosOptions {
|
|
12
11
|
baseURL?: string;
|
|
@@ -20,24 +19,19 @@ export function createAxiosInstance(options: CreateAxiosOptions = {}) {
|
|
|
20
19
|
const instance: AxiosInstance = axios.create({ baseURL, timeout });
|
|
21
20
|
|
|
22
21
|
// 请求拦截:加 token、国际化
|
|
23
|
-
instance.interceptors.request.use(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
instance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
|
|
23
|
+
const fundUnitParams = JSON.parse(
|
|
24
|
+
sessionStorage.getItem("fund_unit_params") || "{}"
|
|
25
|
+
);
|
|
26
|
+
const { token, locale } = fundUnitParams;
|
|
27
|
+
config.headers = {
|
|
28
|
+
...config.headers,
|
|
29
|
+
Authorization: token,
|
|
30
|
+
"x-locale": locale === Locale.ZH ? "zh-CN" : "en-US",
|
|
31
|
+
} as any;
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
);
|
|
31
|
-
const { token, locale } = fundUnitParams;
|
|
32
|
-
config.headers = {
|
|
33
|
-
...config.headers,
|
|
34
|
-
Authorization: token,
|
|
35
|
-
"x-locale": locale === Locale.ZH ? "zh-CN" : "en-US",
|
|
36
|
-
} as any;
|
|
37
|
-
|
|
38
|
-
return config;
|
|
39
|
-
}
|
|
40
|
-
);
|
|
33
|
+
return config;
|
|
34
|
+
});
|
|
41
35
|
|
|
42
36
|
// 响应拦截:code=0判定成功,其他走 onError
|
|
43
37
|
instance.interceptors.response.use(
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import { getAllDicts } from "../../api";
|
|
1
2
|
import { Locale, Theme } from "../../types";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
let initPromise: Promise<any> | null = null;
|
|
5
|
-
|
|
6
|
-
export async function initFundUnit(params: {
|
|
4
|
+
export function initFundUnit(params: {
|
|
7
5
|
token: string;
|
|
8
6
|
merchant_id?: string;
|
|
9
7
|
biz_type?: string;
|
|
@@ -11,48 +9,32 @@ export async function initFundUnit(params: {
|
|
|
11
9
|
theme?: Theme;
|
|
12
10
|
locale?: Locale;
|
|
13
11
|
}) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} = params;
|
|
26
|
-
const token = "Bearer " + params.token;
|
|
27
|
-
|
|
28
|
-
const fundUnitParams = {
|
|
12
|
+
const {
|
|
13
|
+
merchant_id,
|
|
14
|
+
biz_type,
|
|
15
|
+
fund_balance_id,
|
|
16
|
+
theme = Theme.WHITE,
|
|
17
|
+
locale = Locale.ZH,
|
|
18
|
+
} = params;
|
|
19
|
+
const token = "Bearer " + params.token;
|
|
20
|
+
sessionStorage.setItem(
|
|
21
|
+
"fund_unit_params",
|
|
22
|
+
JSON.stringify({
|
|
29
23
|
merchantId: merchant_id,
|
|
30
24
|
bizType: biz_type,
|
|
31
25
|
fundBalanceId: fund_balance_id,
|
|
32
26
|
token,
|
|
33
27
|
theme,
|
|
34
28
|
locale,
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// 检查是否已初始化
|
|
48
|
-
export function isFundUnitInitialized(): boolean {
|
|
49
|
-
return isInitialized;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 等待初始化完成
|
|
53
|
-
export function waitForInitialization(): Promise<any> {
|
|
54
|
-
if (isInitialized) {
|
|
55
|
-
return Promise.resolve();
|
|
56
|
-
}
|
|
57
|
-
return initPromise || Promise.resolve();
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
getAllDicts();
|
|
32
|
+
return {
|
|
33
|
+
token,
|
|
34
|
+
merchantId: merchant_id,
|
|
35
|
+
bizType: biz_type,
|
|
36
|
+
fundBalanceId: fund_balance_id,
|
|
37
|
+
theme,
|
|
38
|
+
locale,
|
|
39
|
+
};
|
|
58
40
|
}
|