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.
- package/dist/best-unit.cjs +8 -8
- package/dist/best-unit.js +537 -531
- package/dist/types/global.d.ts +1 -1
- package/package.json +1 -1
- package/src/api/axiosInstance.ts +18 -3
- package/src/api/index.ts +16 -12
- package/src/components/business/recharge-sdk/index.tsx +1 -1
- package/src/main.ts +1 -1
- package/src/types/global.d.ts +1 -1
- package/src/utils/business/index.ts +5 -0
package/dist/types/global.d.ts
CHANGED
package/package.json
CHANGED
package/src/api/axiosInstance.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
99
|
-
|
|
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
|
})
|
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 = ["
|
|
9
|
+
export const components = ["BestRecharge", "best-statistical-balance"];
|
|
10
10
|
export { npmTest, printCurrentTime, initFundUnit, viteProxy };
|
package/src/types/global.d.ts
CHANGED
|
@@ -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,
|