best-unit 1.1.1 → 1.2.2

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": "1.1.1",
4
+ "version": "1.2.2",
5
5
  "type": "module",
6
6
  "main": "dist/best-unit.cjs",
7
7
  "module": "dist/best-unit.js",
package/src/api/index.ts CHANGED
@@ -21,8 +21,11 @@ export function getBalance() {
21
21
  bizType: data.biz_type,
22
22
  currency: data.currency,
23
23
  totalAmount: data.total_amount,
24
- availableAmount: data.available_amount,
25
24
  frozenAmount: data.frozen_amount,
25
+ creditLimit: data.credit_config?.credit_limit,
26
+ creditUsed: data.credit_used,
27
+ isCredit: data.credit_config ? true : false,
28
+ availableAmount: data.available_amount,
26
29
  pendingAmount: data.pending_amount,
27
30
  status: data.status,
28
31
  createdAt: data.created_at,
@@ -14,47 +14,73 @@ function formatNumber(num: number) {
14
14
  });
15
15
  }
16
16
 
17
+ interface DetailItem {
18
+ label: string;
19
+ value: number;
20
+ color: string;
21
+ dot: string;
22
+ }
23
+
17
24
  function StatisticalBalance(props: { popoverPosition?: PopoverPosition }) {
18
- const [balanceData, setBalanceData] = useState({
25
+ const [balanceData, setBalanceData] = useState<{
26
+ available: number;
27
+ currency: string;
28
+ symbol: string;
29
+ details: DetailItem[];
30
+ }>({
19
31
  available: 0,
20
32
  currency: "USD",
21
33
  symbol: "$",
22
- details: [
23
- { label: t("真实金额"), value: 0, color: "#15b36b", dot: "#15b36b" },
24
- { label: t("冻结金额"), value: 0, color: "#f59e0b", dot: "#f59e0b" },
25
- { label: t("总可用"), value: 0, color: "#1890ff", dot: "#15b36b" },
26
- ],
34
+ details: [],
27
35
  });
28
36
 
29
37
  const fetchBalance = async () => {
30
38
  try {
31
39
  const balance = await getBalance();
32
40
 
33
- // 根据 API 返回的数据构建 balanceData
41
+ // 根据 API 返回的数据构建 balanceData,只保存数值数据
42
+ const details: DetailItem[] = [
43
+ {
44
+ label: "", // 翻译在渲染时处理
45
+ value: balance.availableAmount,
46
+ color: "#15b36b",
47
+ dot: "#15b36b",
48
+ },
49
+ {
50
+ label: "",
51
+ value: balance.frozenAmount,
52
+ color: "#f59e0b",
53
+ dot: "#f59e0b",
54
+ },
55
+ ...(balance.isCredit
56
+ ? [
57
+ {
58
+ label: "",
59
+ value: balance.creditLimit,
60
+ color: "#1890ff",
61
+ dot: "#1890ff",
62
+ },
63
+ {
64
+ label: "",
65
+ value: balance.creditUsed,
66
+ color: "#ff0000",
67
+ dot: "#ff0000",
68
+ },
69
+ ]
70
+ : []),
71
+ {
72
+ label: "",
73
+ value: balance.totalAmount,
74
+ color: "#1890ff",
75
+ dot: "#15b36b",
76
+ },
77
+ ];
78
+
34
79
  const newBalanceData = {
35
80
  available: balance.availableAmount,
36
- currency: "USD", // 可以根据实际 API 返回调整
81
+ currency: "USD",
37
82
  symbol: "$",
38
- details: [
39
- {
40
- label: t("真实金额"),
41
- value: balance.availableAmount,
42
- color: "#15b36b",
43
- dot: "#15b36b",
44
- },
45
- {
46
- label: t("冻结金额"),
47
- value: balance.frozenAmount,
48
- color: "#f59e0b",
49
- dot: "#f59e0b",
50
- },
51
- {
52
- label: t("总可用"),
53
- value: balance.totalAmount,
54
- color: "#1890ff",
55
- dot: "#15b36b",
56
- },
57
- ],
83
+ details,
58
84
  };
59
85
 
60
86
  setBalanceData(newBalanceData);
@@ -91,12 +117,50 @@ function StatisticalBalance(props: { popoverPosition?: PopoverPosition }) {
91
117
 
92
118
  const theme = getStatisticalBalanceTheme();
93
119
 
120
+ // 在渲染时动态生成翻译后的详情数据
121
+ const translatedDetails = [
122
+ {
123
+ label: t("真实金额"),
124
+ value: balanceData.details[0]?.value || 0,
125
+ color: "#15b36b",
126
+ dot: "#15b36b",
127
+ },
128
+ {
129
+ label: t("冻结金额"),
130
+ value: balanceData.details[1]?.value || 0,
131
+ color: "#f59e0b",
132
+ dot: "#f59e0b",
133
+ },
134
+ ...(balanceData.details.length > 4
135
+ ? [
136
+ {
137
+ label: t("信用额度"),
138
+ value: balanceData.details[2]?.value || 0,
139
+ color: "#1890ff",
140
+ dot: "#1890ff",
141
+ },
142
+ {
143
+ label: t("已用额度"),
144
+ value: balanceData.details[3]?.value || 0,
145
+ color: "#ff0000",
146
+ dot: "#ff0000",
147
+ },
148
+ ]
149
+ : []),
150
+ {
151
+ label: t("可用余额"),
152
+ value: balanceData.details[balanceData.details.length - 1]?.value || 0,
153
+ color: "#1890ff",
154
+ dot: "#15b36b",
155
+ },
156
+ ];
157
+
94
158
  return (
95
159
  <HoverPopover
96
160
  popover={
97
161
  <>
98
162
  <div style={theme.popoverTitle}>{t("余额详情")}</div>
99
- {balanceData.details.map((item) => (
163
+ {translatedDetails.map((item) => (
100
164
  <div key={item.label} style={theme.detailRow}>
101
165
  <span style={theme.detailLabel}>
102
166
  <span style={theme.detailDot(item.dot)} />
@@ -63,7 +63,7 @@ export const statisticalBalanceThemes = {
63
63
  justifyContent: "space-between",
64
64
  alignItems: "center",
65
65
  padding: "8px 0",
66
- borderBottom: "1px solid #23262F",
66
+ borderBottom: "1px solid #374151",
67
67
  fontSize: 15,
68
68
  },
69
69
  detailLabel: {
package/src/local/en.ts CHANGED
@@ -2,9 +2,11 @@
2
2
  export const en: Record<string, string> = {
3
3
  // 余额相关
4
4
  余额详情: "Balance Details",
5
- 真实金额: "Real Amount",
5
+ 真实金额: "Real Balance",
6
6
  冻结金额: "Frozen Amount",
7
- 总可用: "Total Available",
7
+ 信用额度: "Credit Limit",
8
+ 已用额度: "Credit Used",
9
+ 可用余额: "Available Balance",
8
10
  暂无数据: "No Data",
9
11
  "金额需在1到999999.99之间": "Amount must be between 1 and 999999.99",
10
12
 
package/src/local/zh.ts CHANGED
@@ -4,7 +4,9 @@ export const zh: Record<string, string> = {
4
4
  余额详情: "余额详情",
5
5
  真实金额: "真实金额",
6
6
  冻结金额: "冻结金额",
7
- 总可用: "总可用",
7
+ 信用额度: "信用额度",
8
+ 已用额度: "已用额度",
9
+ 可用余额: "可用余额",
8
10
  暂无数据: "暂无数据",
9
11
  "金额需在1到999999.99之间": "金额需在1到999999.99之间",
10
12