best-unit 1.0.11 → 1.0.13
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 +25 -11
- package/dist/best-unit.js +1033 -886
- package/dist/types/global.d.ts +7 -0
- package/package.json +1 -1
- package/src/api/axiosInstance.ts +6 -6
- package/src/api/index.ts +13 -6
- package/src/components/business/refresh-button/index.tsx +94 -0
- package/src/components/business/refresh-button/theme.tsx +58 -0
- package/src/components/business/statistical-balance/index.tsx +57 -36
- package/src/demo/App.tsx +248 -1
- package/src/demo/testBalanceData.tsx +79 -0
- package/src/main.ts +19 -3
- package/src/types/global.d.ts +7 -0
- package/src/utils/business/index.ts +33 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useState } from "preact/hooks";
|
|
2
|
+
import { getBalanceData } from "@/utils/business";
|
|
3
|
+
|
|
4
|
+
interface TestBalanceDataProps {
|
|
5
|
+
isDark: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function TestBalanceData({ isDark }: TestBalanceDataProps) {
|
|
9
|
+
const [balanceData, setBalanceData] = useState<any>(null);
|
|
10
|
+
const [balanceLoading, setBalanceLoading] = useState(false);
|
|
11
|
+
|
|
12
|
+
// 测试 getBalanceData 函数
|
|
13
|
+
const testGetBalanceData = () => {
|
|
14
|
+
setBalanceLoading(true);
|
|
15
|
+
try {
|
|
16
|
+
const result = getBalanceData();
|
|
17
|
+
setBalanceData(result);
|
|
18
|
+
console.log("getBalanceData 测试结果:", result);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error("getBalanceData 测试失败:", error);
|
|
21
|
+
setBalanceData({ error: "获取失败" });
|
|
22
|
+
} finally {
|
|
23
|
+
setBalanceLoading(false);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<div
|
|
29
|
+
style={{
|
|
30
|
+
marginBottom: 20,
|
|
31
|
+
padding: 16,
|
|
32
|
+
border: "2px solid #52c41a",
|
|
33
|
+
borderRadius: 8,
|
|
34
|
+
backgroundColor: "#f6ffed",
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
<h3 style={{ marginTop: 0, marginBottom: 12, color: "#52c41a" }}>
|
|
38
|
+
🧪 getBalanceData 函数测试:
|
|
39
|
+
</h3>
|
|
40
|
+
<button
|
|
41
|
+
onClick={testGetBalanceData}
|
|
42
|
+
disabled={balanceLoading}
|
|
43
|
+
style={{
|
|
44
|
+
padding: "8px 16px",
|
|
45
|
+
backgroundColor: balanceLoading ? "#d9d9d9" : "#52c41a",
|
|
46
|
+
color: "#fff",
|
|
47
|
+
border: "none",
|
|
48
|
+
borderRadius: 6,
|
|
49
|
+
cursor: balanceLoading ? "not-allowed" : "pointer",
|
|
50
|
+
marginBottom: 12,
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
{balanceLoading ? "测试中..." : "测试 getBalanceData 函数"}
|
|
54
|
+
</button>
|
|
55
|
+
|
|
56
|
+
{balanceData && (
|
|
57
|
+
<div
|
|
58
|
+
style={{
|
|
59
|
+
marginTop: 12,
|
|
60
|
+
padding: 12,
|
|
61
|
+
backgroundColor: isDark ? "#23262F" : "#fff",
|
|
62
|
+
border: "1px solid #d9d9d9",
|
|
63
|
+
borderRadius: 6,
|
|
64
|
+
fontSize: "12px",
|
|
65
|
+
fontFamily: "monospace",
|
|
66
|
+
whiteSpace: "pre-wrap",
|
|
67
|
+
maxHeight: "200px",
|
|
68
|
+
overflow: "auto",
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
<strong>测试结果:</strong>
|
|
72
|
+
{JSON.stringify(balanceData, null, 2)}
|
|
73
|
+
</div>
|
|
74
|
+
)}
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default TestBalanceData;
|
package/src/main.ts
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import { npmTest, printCurrentTime } from "@/utils/common/index";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
initFundUnit,
|
|
4
|
+
getBalanceData,
|
|
5
|
+
refreshBalance,
|
|
6
|
+
} from "@/utils/business/index";
|
|
3
7
|
import { viteProxy } from "@/api/proxy";
|
|
4
8
|
|
|
5
9
|
import "@/components/business/recharge-sdk";
|
|
6
10
|
import "@/components/business/statistical-balance";
|
|
11
|
+
import "@/components/business/refresh-button";
|
|
7
12
|
|
|
8
13
|
// 可选:导出组件列表或版本信息
|
|
9
|
-
export const components = [
|
|
10
|
-
|
|
14
|
+
export const components = [
|
|
15
|
+
"best-recharge",
|
|
16
|
+
"best-statistical-balance",
|
|
17
|
+
"best-refresh-button",
|
|
18
|
+
];
|
|
19
|
+
export {
|
|
20
|
+
npmTest,
|
|
21
|
+
printCurrentTime,
|
|
22
|
+
initFundUnit,
|
|
23
|
+
getBalanceData,
|
|
24
|
+
refreshBalance,
|
|
25
|
+
viteProxy,
|
|
26
|
+
};
|
package/src/types/global.d.ts
CHANGED
|
@@ -21,6 +21,10 @@ export declare function initFundUnit(params: {
|
|
|
21
21
|
env: Env;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
export declare function getBalanceData(): any;
|
|
25
|
+
|
|
26
|
+
export declare function refreshBalance(): void;
|
|
27
|
+
|
|
24
28
|
// Vite 代理配置类型
|
|
25
29
|
export declare const viteProxy: {
|
|
26
30
|
"/api": {
|
|
@@ -44,6 +48,8 @@ declare global {
|
|
|
44
48
|
theme?: Theme;
|
|
45
49
|
env: Env;
|
|
46
50
|
}) => void;
|
|
51
|
+
getBalanceData: () => any;
|
|
52
|
+
refreshBalance: () => void;
|
|
47
53
|
};
|
|
48
54
|
}
|
|
49
55
|
|
|
@@ -57,6 +63,7 @@ declare global {
|
|
|
57
63
|
[key: string]: any;
|
|
58
64
|
};
|
|
59
65
|
"best-statistical-balance": any;
|
|
66
|
+
"best-refresh-button": any;
|
|
60
67
|
}
|
|
61
68
|
}
|
|
62
69
|
}
|
|
@@ -2,6 +2,20 @@ import { getAllDicts } from "@/api";
|
|
|
2
2
|
import { resetHttpInstance } from "@/api/axiosInstance";
|
|
3
3
|
import { Locale, Theme, type Env } from "@/types";
|
|
4
4
|
|
|
5
|
+
// 余额数据结构接口
|
|
6
|
+
export interface BalanceData {
|
|
7
|
+
fundBalanceId: string; // 余额账户id
|
|
8
|
+
merchantId: number; // 商户id
|
|
9
|
+
bizType: string; // 业务类型
|
|
10
|
+
currency: string; // 币种
|
|
11
|
+
totalAmount: string; // 真实金额
|
|
12
|
+
availableAmount: string; // 可用余额
|
|
13
|
+
frozenAmount: string; // 冻结金额
|
|
14
|
+
pendingAmount: string; // 待处理金额
|
|
15
|
+
status: string; // 状态
|
|
16
|
+
createdAt: string; // 创建时间
|
|
17
|
+
}
|
|
18
|
+
|
|
5
19
|
export interface InitParams {
|
|
6
20
|
token: string;
|
|
7
21
|
merchant_id?: string;
|
|
@@ -13,6 +27,11 @@ export interface InitParams {
|
|
|
13
27
|
env: Env;
|
|
14
28
|
}
|
|
15
29
|
|
|
30
|
+
// 获取余额数据并暴露给外部系统
|
|
31
|
+
export function getBalanceData() {
|
|
32
|
+
return JSON.parse(sessionStorage.getItem("balanceData") || "{}");
|
|
33
|
+
}
|
|
34
|
+
|
|
16
35
|
export function initFundUnit(params: InitParams) {
|
|
17
36
|
const {
|
|
18
37
|
merchant_id,
|
|
@@ -37,7 +56,6 @@ export function initFundUnit(params: InitParams) {
|
|
|
37
56
|
env,
|
|
38
57
|
})
|
|
39
58
|
);
|
|
40
|
-
|
|
41
59
|
// 重置 axios 实例,确保使用新的配置
|
|
42
60
|
resetHttpInstance();
|
|
43
61
|
|
|
@@ -73,3 +91,17 @@ export function getInitParams<T = InitParams>(key?: string | string[]): T {
|
|
|
73
91
|
|
|
74
92
|
return fundUnitParams[key] as T;
|
|
75
93
|
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 触发余额刷新事件
|
|
97
|
+
*/
|
|
98
|
+
export function refreshBalance() {
|
|
99
|
+
const refreshEvent = new CustomEvent("refresh-balance", {
|
|
100
|
+
detail: {},
|
|
101
|
+
bubbles: true,
|
|
102
|
+
composed: true,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// 从document开始分发事件
|
|
106
|
+
document.dispatchEvent(refreshEvent);
|
|
107
|
+
}
|