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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "best-unit",
3
3
  "private": false,
4
- "version": "0.0.48",
4
+ "version": "0.0.49",
5
5
  "type": "module",
6
6
  "main": "dist/best-unit.cjs",
7
7
  "module": "dist/best-unit.js",
@@ -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
- async (config: InternalAxiosRequestConfig) => {
25
- // 等待初始化完成
26
- await waitForInitialization();
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
- const fundUnitParams = JSON.parse(
29
- sessionStorage.getItem("fund_unit_params") || "{}"
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
- let isInitialized = false;
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
- isInitialized = false;
16
- initPromise = null;
17
-
18
- initPromise = new Promise(async (resolve) => {
19
- const {
20
- merchant_id,
21
- biz_type,
22
- fund_balance_id,
23
- theme = Theme.WHITE,
24
- locale = Locale.ZH,
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
- sessionStorage.setItem("fund_unit_params", JSON.stringify(fundUnitParams));
38
- isInitialized = true;
39
-
40
- console.log("initFundUnit 更新完成:", fundUnitParams);
41
- resolve(fundUnitParams);
42
- });
43
-
44
- return initPromise;
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
  }