best-unit 0.0.53 → 0.0.55
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 +9 -9
- package/dist/best-unit.js +491 -464
- package/dist/types/global.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/business/recharge-sdk/components/OfflineTransferForm.tsx +3 -1
- package/src/components/business/recharge-sdk/components/OnlineRechargeForm.tsx +52 -2
- package/src/types/global.d.ts +2 -0
- package/src/utils/business/index.ts +1 -1
- package/src/utils/common/index.ts +0 -27
package/dist/types/global.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare function initFundUnit(params: {
|
|
|
7
7
|
merchant_id?: string;
|
|
8
8
|
biz_type?: string;
|
|
9
9
|
fund_balance_id?: string;
|
|
10
|
+
user_id: string;
|
|
10
11
|
theme?: Theme;
|
|
11
12
|
locale?: Locale;
|
|
12
13
|
}): {
|
|
@@ -38,6 +39,7 @@ declare global {
|
|
|
38
39
|
user_id: string;
|
|
39
40
|
fund_balance_id?: string;
|
|
40
41
|
locale?: "zh" | "en";
|
|
42
|
+
theme?: Theme;
|
|
41
43
|
}) => void;
|
|
42
44
|
};
|
|
43
45
|
}
|
package/package.json
CHANGED
|
@@ -311,8 +311,10 @@ export const OfflineTransferForm: FunctionalComponent<
|
|
|
311
311
|
type="text"
|
|
312
312
|
placeholder={t("请输入转账交易ID")}
|
|
313
313
|
value={formState.transactionId}
|
|
314
|
+
maxLength={200}
|
|
314
315
|
onInput={(e) => {
|
|
315
|
-
|
|
316
|
+
let value = (e.target as HTMLInputElement).value;
|
|
317
|
+
if (value.length > 200) value = value.slice(0, 200);
|
|
316
318
|
setFormState((state: any) => ({
|
|
317
319
|
...state,
|
|
318
320
|
transactionId: value,
|
|
@@ -21,6 +21,27 @@ interface OnlineRechargeFormProps {
|
|
|
21
21
|
loading: boolean;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
// 辅助函数:只允许输入数字和小数点,且最多两位小数
|
|
25
|
+
function formatAmountInput(value: string) {
|
|
26
|
+
// 只保留数字和小数点
|
|
27
|
+
value = value.replace(/[^\d.]/g, "");
|
|
28
|
+
// 只保留第一个小数点
|
|
29
|
+
value = value.replace(/\.(?=.*\.)/g, "");
|
|
30
|
+
// 保证最多两位小数
|
|
31
|
+
value = value.replace(/^(\d+)(\.\d{0,2})?.*$/, "$1$2");
|
|
32
|
+
// 去除前导0(保留0.和0.xx)
|
|
33
|
+
value = value.replace(/^0+(\d)/, "$1");
|
|
34
|
+
if (value.startsWith(".")) value = "0" + value;
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
// 辅助函数:格式化为两位小数
|
|
38
|
+
function formatToTwoDecimal(value: string) {
|
|
39
|
+
if (!value) return "";
|
|
40
|
+
const num = parseFloat(value);
|
|
41
|
+
if (isNaN(num)) return "";
|
|
42
|
+
return num.toFixed(2);
|
|
43
|
+
}
|
|
44
|
+
|
|
24
45
|
export const OnlineRechargeForm: FunctionalComponent<
|
|
25
46
|
OnlineRechargeFormProps
|
|
26
47
|
> = ({ formState, setFormState, onClose, loading }) => {
|
|
@@ -263,11 +284,40 @@ export const OnlineRechargeForm: FunctionalComponent<
|
|
|
263
284
|
placeholder={t("请输入充值金额")}
|
|
264
285
|
value={formState.amount}
|
|
265
286
|
onInput={(e) => {
|
|
266
|
-
|
|
287
|
+
let value = (e.target as HTMLInputElement).value;
|
|
288
|
+
value = formatAmountInput(value);
|
|
289
|
+
let amountError = "";
|
|
290
|
+
// 只有输入为合法数字且不以小数点结尾时才做区间修正
|
|
291
|
+
if (value && !value.endsWith(".")) {
|
|
292
|
+
let num = parseFloat(value);
|
|
293
|
+
if (!isNaN(num)) {
|
|
294
|
+
if (num < 1) num = 1;
|
|
295
|
+
if (num > 999999.99) num = 999999.99;
|
|
296
|
+
value = num.toString();
|
|
297
|
+
// 如果原始输入有小数点且小数点后有内容,保留小数部分
|
|
298
|
+
if (/\./.test((e.target as HTMLInputElement).value)) {
|
|
299
|
+
const decimalPart = (
|
|
300
|
+
e.target as HTMLInputElement
|
|
301
|
+
).value.split(".")[1];
|
|
302
|
+
if (decimalPart !== undefined && decimalPart.length > 0) {
|
|
303
|
+
value = num.toFixed(Math.min(decimalPart.length, 2));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
setFormState((state: any) => ({
|
|
309
|
+
...state,
|
|
310
|
+
amount: value,
|
|
311
|
+
amountError,
|
|
312
|
+
}));
|
|
313
|
+
}}
|
|
314
|
+
onBlur={(e) => {
|
|
315
|
+
let value = (e.target as HTMLInputElement).value;
|
|
316
|
+
value = formatToTwoDecimal(value);
|
|
267
317
|
setFormState((state: any) => ({
|
|
268
318
|
...state,
|
|
269
319
|
amount: value,
|
|
270
|
-
amountError:
|
|
320
|
+
amountError: "",
|
|
271
321
|
}));
|
|
272
322
|
}}
|
|
273
323
|
style={{
|
package/src/types/global.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare function initFundUnit(params: {
|
|
|
7
7
|
merchant_id?: string;
|
|
8
8
|
biz_type?: string;
|
|
9
9
|
fund_balance_id?: string;
|
|
10
|
+
user_id: string;
|
|
10
11
|
theme?: Theme;
|
|
11
12
|
locale?: Locale;
|
|
12
13
|
}): {
|
|
@@ -38,6 +39,7 @@ declare global {
|
|
|
38
39
|
user_id: string;
|
|
39
40
|
fund_balance_id?: string;
|
|
40
41
|
locale?: "zh" | "en";
|
|
42
|
+
theme?: Theme;
|
|
41
43
|
}) => void;
|
|
42
44
|
};
|
|
43
45
|
}
|
|
@@ -6,30 +6,3 @@ export function printCurrentTime() {
|
|
|
6
6
|
const now = new Date();
|
|
7
7
|
console.log("Current time:", now.toISOString());
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 过滤对象中的空值(null 和 undefined)
|
|
12
|
-
* @param obj 要过滤的对象
|
|
13
|
-
* @returns 过滤后的新对象
|
|
14
|
-
*/
|
|
15
|
-
export function filterEmptyValues(
|
|
16
|
-
obj: Record<string, any>
|
|
17
|
-
): Record<string, any> {
|
|
18
|
-
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
19
|
-
// 如果值是对象且不是数组,递归处理
|
|
20
|
-
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
21
|
-
const filtered = filterEmptyValues(value);
|
|
22
|
-
// 只有当过滤后的对象有属性时才添加
|
|
23
|
-
if (Object.keys(filtered).length > 0) {
|
|
24
|
-
acc[key] = filtered;
|
|
25
|
-
}
|
|
26
|
-
return acc;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// 如果值不为 null 或 undefined,则保留
|
|
30
|
-
if (value !== null && value !== undefined && !isNaN(value)) {
|
|
31
|
-
acc[key] = value;
|
|
32
|
-
}
|
|
33
|
-
return acc;
|
|
34
|
-
}, {} as Record<string, any>);
|
|
35
|
-
}
|