best-unit 0.0.37 → 0.0.39
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 +7 -7
- package/dist/best-unit.js +2977 -2898
- package/dist/types/global.d.ts +4 -4
- package/dist/types/index.ts +9 -0
- package/package.json +1 -1
- package/src/components/business/recharge-sdk/components/OfflineTransferForm.tsx +6 -3
- package/src/components/business/recharge-sdk/components/OnlineRechargeForm.tsx +6 -2
- package/src/components/business/recharge-sdk/components/Recharge.tsx +8 -10
- package/src/components/business/recharge-sdk/index.tsx +2 -19
- package/src/components/business/statistical-balance/index.tsx +113 -61
- package/src/components/common/HoverPopover.tsx +43 -8
- package/src/components/common/Upload.tsx +90 -37
- package/src/demo/App.tsx +188 -35
- package/src/local/index.ts +4 -10
- package/src/types/global.d.ts +4 -4
- package/src/types/index.ts +9 -0
- package/src/utils/business/index.ts +8 -4
package/src/demo/App.tsx
CHANGED
|
@@ -4,52 +4,92 @@ import { BestUnit } from "../components/business/recharge-sdk";
|
|
|
4
4
|
import { initFundUnit } from "../main";
|
|
5
5
|
import StatisticalBalance from "../components/business/statistical-balance";
|
|
6
6
|
import { t } from "../local";
|
|
7
|
+
import { Locale, Theme } from "../types";
|
|
7
8
|
|
|
8
9
|
export default function DemoApp() {
|
|
9
|
-
const [currentLocale, setCurrentLocale] = useState<
|
|
10
|
+
const [currentLocale, setCurrentLocale] = useState<Locale>(Locale.ZH);
|
|
11
|
+
const [currentTheme, setCurrentTheme] = useState<Theme>(Theme.WHITE);
|
|
10
12
|
|
|
11
|
-
const initApp = (locale:
|
|
13
|
+
const initApp = ({ locale, theme }: { locale?: Locale; theme?: Theme }) => {
|
|
12
14
|
initFundUnit({
|
|
13
15
|
token:
|
|
14
16
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NTM0MTM1MjksIm1lcmNoYW50X2lkIjoxMTI4LCJ0aW1lc3RhbXAiOjE3NTMxNTQzMjl9.UAvzq0P4HCnbJR1Ga3CgF6q3vk2RHiZRvnAFohBTHpw",
|
|
15
17
|
merchant_id: "1128",
|
|
16
18
|
biz_type: "ad",
|
|
17
|
-
locale: locale,
|
|
19
|
+
locale: locale as Locale,
|
|
20
|
+
theme: theme ?? Theme.WHITE,
|
|
18
21
|
});
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
// 初始化应用
|
|
22
|
-
initApp(currentLocale);
|
|
25
|
+
initApp({ locale: currentLocale, theme: currentTheme });
|
|
23
26
|
|
|
24
|
-
const handleLocaleChange = (locale:
|
|
27
|
+
const handleLocaleChange = (locale: Locale) => {
|
|
25
28
|
setCurrentLocale(locale);
|
|
26
29
|
// 重新初始化以更新语言设置
|
|
27
|
-
initApp(locale);
|
|
30
|
+
initApp({ locale, theme: currentTheme });
|
|
28
31
|
};
|
|
29
32
|
|
|
33
|
+
const handleThemeChange = (theme: Theme) => {
|
|
34
|
+
setCurrentTheme(theme);
|
|
35
|
+
initApp({ locale: currentLocale, theme });
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const isDark = currentTheme === Theme.DARK;
|
|
39
|
+
|
|
30
40
|
return (
|
|
31
|
-
<div
|
|
32
|
-
|
|
41
|
+
<div
|
|
42
|
+
style={{
|
|
43
|
+
background: isDark ? "#181A20" : "#fff",
|
|
44
|
+
minHeight: "100vh",
|
|
45
|
+
transition: "background 0.3s",
|
|
46
|
+
color: isDark ? "#F5F6FA" : "#111827",
|
|
47
|
+
}}
|
|
48
|
+
>
|
|
49
|
+
<h2
|
|
50
|
+
style={{
|
|
51
|
+
color: isDark ? "#F5F6FA" : undefined,
|
|
52
|
+
background: isDark ? "#23262F" : undefined,
|
|
53
|
+
padding: isDark ? 8 : undefined,
|
|
54
|
+
borderRadius: isDark ? 8 : undefined,
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
组件库可视化测试
|
|
58
|
+
</h2>
|
|
33
59
|
|
|
34
60
|
{/* 国际化切换区域 */}
|
|
35
61
|
<div
|
|
36
62
|
style={{
|
|
37
63
|
marginBottom: 20,
|
|
38
64
|
padding: 16,
|
|
39
|
-
border: "1px solid #e5e7eb",
|
|
65
|
+
border: isDark ? "1px solid #23262F" : "1px solid #e5e7eb",
|
|
40
66
|
borderRadius: 8,
|
|
41
|
-
backgroundColor: "#f9fafb",
|
|
67
|
+
backgroundColor: isDark ? "#23262F" : "#f9fafb",
|
|
42
68
|
}}
|
|
43
69
|
>
|
|
44
|
-
<h3
|
|
70
|
+
<h3
|
|
71
|
+
style={{
|
|
72
|
+
marginTop: 0,
|
|
73
|
+
marginBottom: 12,
|
|
74
|
+
color: isDark ? "#F5F6FA" : undefined,
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
国际化测试:
|
|
78
|
+
</h3>
|
|
45
79
|
<div style={{ display: "flex", gap: 12, alignItems: "center" }}>
|
|
46
80
|
<span>当前语言:</span>
|
|
47
81
|
<button
|
|
48
|
-
onClick={() => handleLocaleChange("zh")}
|
|
82
|
+
onClick={() => handleLocaleChange("zh" as Locale)}
|
|
49
83
|
style={{
|
|
50
84
|
padding: "8px 16px",
|
|
51
|
-
backgroundColor:
|
|
52
|
-
|
|
85
|
+
backgroundColor:
|
|
86
|
+
currentLocale === "zh"
|
|
87
|
+
? "#155EEF"
|
|
88
|
+
: isDark
|
|
89
|
+
? "#23262F"
|
|
90
|
+
: "#fff",
|
|
91
|
+
color:
|
|
92
|
+
currentLocale === "zh" ? "#fff" : isDark ? "#F5F6FA" : "#333",
|
|
53
93
|
border: "1px solid #155EEF",
|
|
54
94
|
borderRadius: 6,
|
|
55
95
|
cursor: "pointer",
|
|
@@ -59,11 +99,17 @@ export default function DemoApp() {
|
|
|
59
99
|
中文
|
|
60
100
|
</button>
|
|
61
101
|
<button
|
|
62
|
-
onClick={() => handleLocaleChange("en")}
|
|
102
|
+
onClick={() => handleLocaleChange("en" as Locale)}
|
|
63
103
|
style={{
|
|
64
104
|
padding: "8px 16px",
|
|
65
|
-
backgroundColor:
|
|
66
|
-
|
|
105
|
+
backgroundColor:
|
|
106
|
+
currentLocale === "en"
|
|
107
|
+
? "#155EEF"
|
|
108
|
+
: isDark
|
|
109
|
+
? "#23262F"
|
|
110
|
+
: "#fff",
|
|
111
|
+
color:
|
|
112
|
+
currentLocale === "en" ? "#fff" : isDark ? "#F5F6FA" : "#333",
|
|
67
113
|
border: "1px solid #155EEF",
|
|
68
114
|
borderRadius: 6,
|
|
69
115
|
cursor: "pointer",
|
|
@@ -72,7 +118,13 @@ export default function DemoApp() {
|
|
|
72
118
|
>
|
|
73
119
|
English
|
|
74
120
|
</button>
|
|
75
|
-
<span
|
|
121
|
+
<span
|
|
122
|
+
style={{
|
|
123
|
+
marginLeft: 12,
|
|
124
|
+
fontSize: 14,
|
|
125
|
+
color: isDark ? "#B5B8BE" : "#666",
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
76
128
|
{currentLocale === "zh"
|
|
77
129
|
? "当前显示中文"
|
|
78
130
|
: "Currently showing English"}
|
|
@@ -81,23 +133,95 @@ export default function DemoApp() {
|
|
|
81
133
|
</div>
|
|
82
134
|
|
|
83
135
|
<div>
|
|
84
|
-
<h3
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
136
|
+
<h3 style={{ color: isDark ? "#F5F6FA" : undefined }}>
|
|
137
|
+
BestUnit 主题切换:
|
|
138
|
+
</h3>
|
|
139
|
+
<button
|
|
140
|
+
onClick={() => handleThemeChange(Theme.WHITE)}
|
|
141
|
+
style={{
|
|
142
|
+
padding: "8px 16px",
|
|
143
|
+
backgroundColor:
|
|
144
|
+
currentTheme === Theme.WHITE
|
|
145
|
+
? "#155EEF"
|
|
146
|
+
: isDark
|
|
147
|
+
? "#23262F"
|
|
148
|
+
: "#fff",
|
|
149
|
+
color:
|
|
150
|
+
currentTheme === Theme.WHITE
|
|
151
|
+
? "#fff"
|
|
152
|
+
: isDark
|
|
153
|
+
? "#F5F6FA"
|
|
154
|
+
: "#333",
|
|
155
|
+
border: "1px solid #155EEF",
|
|
156
|
+
borderRadius: 6,
|
|
157
|
+
cursor: "pointer",
|
|
158
|
+
fontWeight: currentTheme === Theme.WHITE ? "bold" : "normal",
|
|
159
|
+
marginRight: 8,
|
|
160
|
+
}}
|
|
161
|
+
>
|
|
162
|
+
白色主题
|
|
163
|
+
</button>
|
|
164
|
+
<button
|
|
165
|
+
onClick={() => handleThemeChange(Theme.DARK)}
|
|
166
|
+
style={{
|
|
167
|
+
padding: "8px 16px",
|
|
168
|
+
backgroundColor:
|
|
169
|
+
currentTheme === Theme.DARK
|
|
170
|
+
? "#155EEF"
|
|
171
|
+
: isDark
|
|
172
|
+
? "#23262F"
|
|
173
|
+
: "#fff",
|
|
174
|
+
color:
|
|
175
|
+
currentTheme === Theme.DARK
|
|
176
|
+
? "#fff"
|
|
177
|
+
: isDark
|
|
178
|
+
? "#F5F6FA"
|
|
179
|
+
: "#333",
|
|
180
|
+
border: "1px solid #155EEF",
|
|
181
|
+
borderRadius: 6,
|
|
182
|
+
cursor: "pointer",
|
|
183
|
+
fontWeight: currentTheme === Theme.DARK ? "bold" : "normal",
|
|
184
|
+
}}
|
|
185
|
+
>
|
|
186
|
+
暗黑主题
|
|
187
|
+
</button>
|
|
91
188
|
</div>
|
|
189
|
+
|
|
92
190
|
<div>
|
|
93
|
-
<h3
|
|
94
|
-
|
|
191
|
+
<h3 style={{ color: isDark ? "#F5F6FA" : undefined }}>
|
|
192
|
+
BestUnit 组件演示:
|
|
193
|
+
</h3>
|
|
194
|
+
<BestUnit />
|
|
195
|
+
</div>
|
|
196
|
+
|
|
197
|
+
<div>
|
|
198
|
+
<h3 style={{ color: isDark ? "#F5F6FA" : undefined }}>方法演示:</h3>
|
|
199
|
+
<button
|
|
200
|
+
onClick={npmTest}
|
|
201
|
+
style={{
|
|
202
|
+
marginRight: 10,
|
|
203
|
+
background: isDark ? "#23262F" : undefined,
|
|
204
|
+
color: isDark ? "#F5F6FA" : undefined,
|
|
205
|
+
border: isDark ? "1px solid #444C5C" : undefined,
|
|
206
|
+
}}
|
|
207
|
+
>
|
|
95
208
|
调用 npmTest()
|
|
96
209
|
</button>
|
|
97
|
-
<button
|
|
210
|
+
<button
|
|
211
|
+
onClick={printCurrentTime}
|
|
212
|
+
style={{
|
|
213
|
+
background: isDark ? "#23262F" : undefined,
|
|
214
|
+
color: isDark ? "#F5F6FA" : undefined,
|
|
215
|
+
border: isDark ? "1px solid #444C5C" : undefined,
|
|
216
|
+
}}
|
|
217
|
+
>
|
|
218
|
+
调用 printCurrentTime()
|
|
219
|
+
</button>
|
|
98
220
|
</div>
|
|
99
221
|
<div style={{ textAlign: "center" }}>
|
|
100
|
-
<h3
|
|
222
|
+
<h3 style={{ color: isDark ? "#F5F6FA" : undefined }}>
|
|
223
|
+
余额卡片组件演示:
|
|
224
|
+
</h3>
|
|
101
225
|
<StatisticalBalance />
|
|
102
226
|
</div>
|
|
103
227
|
|
|
@@ -106,12 +230,20 @@ export default function DemoApp() {
|
|
|
106
230
|
style={{
|
|
107
231
|
marginTop: 20,
|
|
108
232
|
padding: 16,
|
|
109
|
-
border: "1px solid #e5e7eb",
|
|
233
|
+
border: isDark ? "1px solid #23262F" : "1px solid #e5e7eb",
|
|
110
234
|
borderRadius: 8,
|
|
111
|
-
backgroundColor: "#f9fafb",
|
|
235
|
+
backgroundColor: isDark ? "#23262F" : "#f9fafb",
|
|
112
236
|
}}
|
|
113
237
|
>
|
|
114
|
-
<h3
|
|
238
|
+
<h3
|
|
239
|
+
style={{
|
|
240
|
+
marginTop: 0,
|
|
241
|
+
marginBottom: 12,
|
|
242
|
+
color: isDark ? "#F5F6FA" : undefined,
|
|
243
|
+
}}
|
|
244
|
+
>
|
|
245
|
+
国际化文本测试:
|
|
246
|
+
</h3>
|
|
115
247
|
<div
|
|
116
248
|
style={{
|
|
117
249
|
display: "grid",
|
|
@@ -119,7 +251,14 @@ export default function DemoApp() {
|
|
|
119
251
|
gap: 12,
|
|
120
252
|
}}
|
|
121
253
|
>
|
|
122
|
-
<div
|
|
254
|
+
<div
|
|
255
|
+
style={{
|
|
256
|
+
padding: 8,
|
|
257
|
+
backgroundColor: isDark ? "#181A20" : "#fff",
|
|
258
|
+
borderRadius: 4,
|
|
259
|
+
color: isDark ? "#F5F6FA" : undefined,
|
|
260
|
+
}}
|
|
261
|
+
>
|
|
123
262
|
<strong>余额相关:</strong>
|
|
124
263
|
<br />
|
|
125
264
|
{t("余额详情")}
|
|
@@ -130,7 +269,14 @@ export default function DemoApp() {
|
|
|
130
269
|
<br />
|
|
131
270
|
{t("总可用")}
|
|
132
271
|
</div>
|
|
133
|
-
<div
|
|
272
|
+
<div
|
|
273
|
+
style={{
|
|
274
|
+
padding: 8,
|
|
275
|
+
backgroundColor: isDark ? "#181A20" : "#fff",
|
|
276
|
+
borderRadius: 4,
|
|
277
|
+
color: isDark ? "#F5F6FA" : undefined,
|
|
278
|
+
}}
|
|
279
|
+
>
|
|
134
280
|
<strong>充值相关:</strong>
|
|
135
281
|
<br />
|
|
136
282
|
{t("充值 / 转账")}
|
|
@@ -141,7 +287,14 @@ export default function DemoApp() {
|
|
|
141
287
|
<br />
|
|
142
288
|
{t("去支付")}
|
|
143
289
|
</div>
|
|
144
|
-
<div
|
|
290
|
+
<div
|
|
291
|
+
style={{
|
|
292
|
+
padding: 8,
|
|
293
|
+
backgroundColor: isDark ? "#181A20" : "#fff",
|
|
294
|
+
borderRadius: 4,
|
|
295
|
+
color: isDark ? "#F5F6FA" : undefined,
|
|
296
|
+
}}
|
|
297
|
+
>
|
|
145
298
|
<strong>按钮文本:</strong>
|
|
146
299
|
<br />
|
|
147
300
|
{t("充值/转账")}
|
package/src/local/index.ts
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
import { getZhText, zh } from "./zh";
|
|
2
2
|
import { getEnText, en } from "./en";
|
|
3
|
-
|
|
4
|
-
export type Locale = "zh" | "en";
|
|
5
|
-
|
|
6
|
-
const locales = {
|
|
7
|
-
zh,
|
|
8
|
-
en,
|
|
9
|
-
};
|
|
3
|
+
import { Locale } from "../types";
|
|
10
4
|
|
|
11
5
|
// 获取当前语言
|
|
12
6
|
export function getCurrentLocale(): Locale {
|
|
13
7
|
const fundUnitParams = JSON.parse(
|
|
14
8
|
sessionStorage.getItem("fund_unit_params") || "{}"
|
|
15
9
|
);
|
|
16
|
-
return fundUnitParams.locale ||
|
|
10
|
+
return fundUnitParams.locale || Locale.ZH;
|
|
17
11
|
}
|
|
18
12
|
|
|
19
13
|
// 获取国际化文本
|
|
20
14
|
export function getLocaleText() {
|
|
21
15
|
const locale = getCurrentLocale();
|
|
22
|
-
return
|
|
16
|
+
return locale === Locale.ZH ? zh : en;
|
|
23
17
|
}
|
|
24
18
|
|
|
25
19
|
// 获取指定语言的文本
|
|
26
20
|
export function getLocaleTextByLang(locale: Locale) {
|
|
27
|
-
return
|
|
21
|
+
return locale === Locale.ZH ? zh : en;
|
|
28
22
|
}
|
|
29
23
|
|
|
30
24
|
// 使用中文key的t函数
|
package/src/types/global.d.ts
CHANGED
|
@@ -7,15 +7,15 @@ export declare function initFundUnit(params: {
|
|
|
7
7
|
merchant_id?: string;
|
|
8
8
|
biz_type?: string;
|
|
9
9
|
fund_balance_id?: string;
|
|
10
|
-
theme?:
|
|
11
|
-
locale?:
|
|
10
|
+
theme?: Theme;
|
|
11
|
+
locale?: Locale;
|
|
12
12
|
}): {
|
|
13
13
|
token: string;
|
|
14
14
|
merchantId?: string;
|
|
15
15
|
bizType?: string;
|
|
16
16
|
fundBalanceId?: string;
|
|
17
|
-
theme?:
|
|
18
|
-
locale:
|
|
17
|
+
theme?: Theme;
|
|
18
|
+
locale: Locale;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
// Vite 代理配置类型
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
+
import { getAllDicts } from "../../api";
|
|
2
|
+
import { Locale, Theme } from "../../types";
|
|
3
|
+
|
|
1
4
|
export function initFundUnit(params: {
|
|
2
5
|
token: string;
|
|
3
6
|
merchant_id?: string;
|
|
4
7
|
biz_type?: string;
|
|
5
8
|
fund_balance_id?: string;
|
|
6
|
-
theme?:
|
|
7
|
-
locale?:
|
|
9
|
+
theme?: Theme;
|
|
10
|
+
locale?: Locale;
|
|
8
11
|
}) {
|
|
12
|
+
getAllDicts();
|
|
9
13
|
const {
|
|
10
14
|
merchant_id,
|
|
11
15
|
biz_type,
|
|
12
16
|
fund_balance_id,
|
|
13
|
-
theme,
|
|
14
|
-
locale =
|
|
17
|
+
theme = Theme.WHITE,
|
|
18
|
+
locale = Locale.ZH,
|
|
15
19
|
} = params;
|
|
16
20
|
const token = "Bearer " + params.token;
|
|
17
21
|
sessionStorage.setItem(
|