best-unit 1.0.4 → 1.0.6

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.
@@ -49,7 +49,7 @@ declare global {
49
49
 
50
50
  namespace JSX {
51
51
  interface IntrinsicElements {
52
- "best-recharge": {
52
+ BestRecharge: {
53
53
  theme?: any;
54
54
  merchant_id?: string;
55
55
  biz_type?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "best-unit",
3
3
  "private": false,
4
- "version": "1.0.4",
4
+ "version": "1.0.6",
5
5
  "type": "module",
6
6
  "main": "dist/best-unit.cjs",
7
7
  "module": "dist/best-unit.js",
@@ -18,8 +18,8 @@ export function createAxiosInstance(options: CreateAxiosOptions = {}) {
18
18
  const fundUnitParams = JSON.parse(
19
19
  sessionStorage.getItem("fund_unit_params") || "{}"
20
20
  );
21
- console.log("fundUnitParams", fundUnitParams);
22
21
 
22
+ console.log("fundUnitParams", fundUnitParams);
23
23
  const { env } = fundUnitParams;
24
24
 
25
25
  let apiUrl: string;
@@ -91,6 +91,21 @@ export function createAxiosInstance(options: CreateAxiosOptions = {}) {
91
91
  return instance;
92
92
  }
93
93
 
94
- // 默认实例
95
- const http = createAxiosInstance();
94
+ // 缓存 axios 实例
95
+ let httpInstance: AxiosInstance | null = null;
96
+
97
+ // 获取 axios 实例的函数
98
+ export function http(): AxiosInstance {
99
+ if (!httpInstance) {
100
+ httpInstance = createAxiosInstance();
101
+ }
102
+ return httpInstance;
103
+ }
104
+
105
+ // 重置 axios 实例(当 fund_unit_params 更新时调用)
106
+ export function resetHttpInstance(): void {
107
+ httpInstance = null;
108
+ }
109
+
110
+ // 默认导出获取实例的函数
96
111
  export default http;
package/src/api/index.ts CHANGED
@@ -1,11 +1,11 @@
1
- import http from "./axiosInstance";
1
+ import { http } from "./axiosInstance";
2
2
  import type { AxiosProgressEvent } from "axios";
3
3
  // 获取余额
4
4
  export function getBalance() {
5
5
  const fundUnitParams = JSON.parse(
6
6
  sessionStorage.getItem("fund_unit_params") || "{}"
7
7
  );
8
- return http
8
+ return http()
9
9
  .get("/balance", {
10
10
  params: {
11
11
  merchant_id: fundUnitParams.merchantId,
@@ -25,10 +25,12 @@ export function getBalance() {
25
25
 
26
26
  // 获取所有字典
27
27
  export const getAllDicts = async () => {
28
- return http.get("/all-dicts", {}).then((res) => {
29
- sessionStorage.setItem("all_dicts", JSON.stringify(res.data));
30
- return res.data || {};
31
- });
28
+ return http()
29
+ .get("/all-dicts", {})
30
+ .then((res) => {
31
+ sessionStorage.setItem("all_dicts", JSON.stringify(res.data));
32
+ return res.data || {};
33
+ });
32
34
  };
33
35
 
34
36
  // 上传文件
@@ -36,7 +38,7 @@ export const uploadFile = async (
36
38
  file: any,
37
39
  onProgress?: (percent: number) => void
38
40
  ) => {
39
- return http
41
+ return http()
40
42
  .post("/oss/upload", file, {
41
43
  headers: {
42
44
  "Content-Type": "multipart/form-data",
@@ -72,7 +74,7 @@ export const createOfflineRecharge = async (data: any) => {
72
74
  transfer_channel: data.transferChannel,
73
75
  voucher_urls: data.voucherUrls,
74
76
  };
75
- return http.post("/offline/recharge/create", params, {});
77
+ return http().post("/offline/recharge/create", params, {});
76
78
  };
77
79
 
78
80
  // 创建在线充值
@@ -95,9 +97,11 @@ export const createOnlineRecharge = async (data: any) => {
95
97
  recharge_channel: data.rechargeChannel,
96
98
  return_url: window.location.href,
97
99
  };
98
- return http.post("/online/recharge/create", params, {}).then((res) => {
99
- return res.data.redirect_url;
100
- });
100
+ return http()
101
+ .post("/online/recharge/create", params, {})
102
+ .then((res) => {
103
+ return res.data.redirect_url;
104
+ });
101
105
  };
102
106
 
103
107
  interface CalcPaymentAmountParams {
@@ -108,7 +112,7 @@ interface CalcPaymentAmountParams {
108
112
 
109
113
  // 计算支付金额
110
114
  export const calcPaymentAmount = async (data: CalcPaymentAmountParams) => {
111
- return http
115
+ return http()
112
116
  .get("/calc-payment-amount", {
113
117
  params: data,
114
118
  })
@@ -34,6 +34,6 @@ export function BestUnit() {
34
34
  );
35
35
  }
36
36
 
37
- register(BestUnit, "best-recharge", ["theme"], { shadow: false });
37
+ register(BestUnit, "BestRecharge", ["theme"], { shadow: false });
38
38
 
39
39
  export default BestUnit;
package/src/main.ts CHANGED
@@ -6,5 +6,5 @@ import "./components/business/recharge-sdk";
6
6
  import "./components/business/statistical-balance";
7
7
 
8
8
  // 可选:导出组件列表或版本信息
9
- export const components = ["best-recharge", "best-statistical-balance"];
9
+ export const components = ["BestRecharge", "best-statistical-balance"];
10
10
  export { npmTest, printCurrentTime, initFundUnit, viteProxy };
@@ -49,7 +49,7 @@ declare global {
49
49
 
50
50
  namespace JSX {
51
51
  interface IntrinsicElements {
52
- "best-recharge": {
52
+ BestRecharge: {
53
53
  theme?: any;
54
54
  merchant_id?: string;
55
55
  biz_type?: string;
@@ -1,4 +1,5 @@
1
1
  import { getAllDicts } from "../../api";
2
+ import { resetHttpInstance } from "../../api/axiosInstance";
2
3
  import { Locale, Theme, type Env } from "../../types";
3
4
 
4
5
  export function initFundUnit(params: {
@@ -34,6 +35,10 @@ export function initFundUnit(params: {
34
35
  env,
35
36
  })
36
37
  );
38
+
39
+ // 重置 axios 实例,确保使用新的配置
40
+ resetHttpInstance();
41
+
37
42
  getAllDicts();
38
43
  return {
39
44
  token,