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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "best-unit",
3
3
  "private": false,
4
- "version": "2.1.9",
4
+ "version": "2.1.13",
5
5
  "type": "module",
6
6
  "main": "dist/best-unit.cjs",
7
7
  "module": "dist/best-unit.js",
@@ -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
- ...prev,
91
- [bizType]: value,
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="number"
204
- min="0"
205
- max="100"
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
- onChange={(e) => {
246
+ onInput={(e) => {
210
247
  onPercentageChange(
211
248
  item.bizType,
212
- (e.target as HTMLInputElement).value,
249
+ formatPercentageInput(
250
+ (e.target as HTMLInputElement).value,
251
+ ),
213
252
  );
214
253
  }}
215
254
  style={{
package/src/demo/App.tsx CHANGED
@@ -46,7 +46,8 @@ export default function DemoApp() {
46
46
  env: env ?? currentEnv,
47
47
  size: Size.SMALL,
48
48
  biz_type: "ad",
49
- merchant_id: "1128",
49
+ merchant_id: "13226",
50
+ // merchant_id: "1128",
50
51
  // theme_config: {
51
52
  // white: {
52
53
  // color: "red",
package/src/local/en.ts CHANGED
@@ -131,6 +131,7 @@ export const en: Record<string, string> = {
131
131
  提交审核: "Submit for Review",
132
132
  请选择转账时间: "Please select transfer time",
133
133
  请输入转账金额: "Please enter transfer amount",
134
+ 请输入: "Please enter",
134
135
  是否使用资金分配: "Use fund allocation",
135
136
  是: "Yes",
136
137
  否: "No",
package/src/local/zh.ts CHANGED
@@ -94,6 +94,7 @@ export const zh: Record<string, string> = {
94
94
  提交审核: "提交审核",
95
95
  请选择转账时间: "请选择转账时间",
96
96
  请输入转账金额: "请输入转账金额",
97
+ 请输入: "请输入",
97
98
  是否使用资金分配: "是否使用资金分配",
98
99
  是: "是",
99
100
  否: "否",