best-unit 2.1.9 → 2.1.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 +14 -14
- package/dist/best-unit.js +854 -834
- package/package.json +1 -1
- package/src/components/business/payment-sdk/offline-payment/fund-allocation.tsx +50 -11
- package/src/demo/App.tsx +2 -1
- package/src/local/en.ts +1 -0
- package/src/local/zh.ts +1 -0
package/package.json
CHANGED
|
@@ -20,6 +20,29 @@ function getBizTypeLabel(bizType: string) {
|
|
|
20
20
|
return bizType;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
function getBizTypePlaceholder(bizType: string) {
|
|
24
|
+
const prefix = t("请输入");
|
|
25
|
+
const label = getBizTypeLabel(bizType);
|
|
26
|
+
return /[A-Za-z]$/.test(prefix) ? `${prefix} ${label}` : `${prefix}${label}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function formatPercentageInput(value: string) {
|
|
30
|
+
let nextValue = value.replace(/[^\d.]/g, "");
|
|
31
|
+
nextValue = nextValue.replace(/\.(?=.*\.)/g, "");
|
|
32
|
+
nextValue = nextValue.replace(/^(\d+)(\.\d{0,2})?.*$/, "$1$2");
|
|
33
|
+
nextValue = nextValue.replace(/^0+(\d)/, "$1");
|
|
34
|
+
|
|
35
|
+
if (nextValue.startsWith(".")) {
|
|
36
|
+
nextValue = `0${nextValue}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return nextValue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function formatAutoFilledPercentage(value: number) {
|
|
43
|
+
return value.toFixed(2).replace(/\.?0+$/, "");
|
|
44
|
+
}
|
|
45
|
+
|
|
23
46
|
export function useFundAllocation() {
|
|
24
47
|
const [subBusinesses, setSubBusinesses] = useState<MerchantBalanceItem[]>([]);
|
|
25
48
|
const [useFundAllocation, setUseFundAllocation] = useState(false);
|
|
@@ -86,10 +109,26 @@ export function useFundAllocation() {
|
|
|
86
109
|
};
|
|
87
110
|
|
|
88
111
|
const handlePercentageChange = (bizType: string, value: string) => {
|
|
89
|
-
setSubBizPercentages((prev) =>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
112
|
+
setSubBizPercentages((prev) => {
|
|
113
|
+
const nextPercentages = {
|
|
114
|
+
...prev,
|
|
115
|
+
[bizType]: value,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
if (subBusinesses.length === 2) {
|
|
119
|
+
const pairedBiz = subBusinesses.find((item) => item.bizType !== bizType);
|
|
120
|
+
const currentValue = Number(value);
|
|
121
|
+
|
|
122
|
+
if (pairedBiz) {
|
|
123
|
+
nextPercentages[pairedBiz.bizType] =
|
|
124
|
+
value.trim() && !Number.isNaN(currentValue) && currentValue >= 0 && currentValue <= 100
|
|
125
|
+
? formatAutoFilledPercentage(100 - currentValue)
|
|
126
|
+
: "";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return nextPercentages;
|
|
131
|
+
});
|
|
93
132
|
setSubBizError("");
|
|
94
133
|
};
|
|
95
134
|
|
|
@@ -200,16 +239,16 @@ export function FundAllocationSection({
|
|
|
200
239
|
{" (%)"}
|
|
201
240
|
</label>
|
|
202
241
|
<input
|
|
203
|
-
type="
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
step="0.01"
|
|
207
|
-
placeholder="0"
|
|
242
|
+
type="text"
|
|
243
|
+
inputMode="decimal"
|
|
244
|
+
placeholder={getBizTypePlaceholder(item.bizType)}
|
|
208
245
|
value={subBizPercentages[item.bizType] || ""}
|
|
209
|
-
|
|
246
|
+
onInput={(e) => {
|
|
210
247
|
onPercentageChange(
|
|
211
248
|
item.bizType,
|
|
212
|
-
(
|
|
249
|
+
formatPercentageInput(
|
|
250
|
+
(e.target as HTMLInputElement).value,
|
|
251
|
+
),
|
|
213
252
|
);
|
|
214
253
|
}}
|
|
215
254
|
style={{
|
package/src/demo/App.tsx
CHANGED
package/src/local/en.ts
CHANGED