leisure-core 0.5.72 → 0.5.74
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/le-input-validate/src/main.vue +93 -0
- package/le-list/src/main.vue +28 -12
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
@input="handleInput"
|
|
10
10
|
@blur="handleBlur"
|
|
11
11
|
@clear="handleClear"
|
|
12
|
+
@focus="handleFocus"
|
|
12
13
|
>
|
|
13
14
|
<template v-if="showCount" #suffix>
|
|
14
15
|
<span class="input-count" :class="{ 'is-error': isOverMaxLength }">
|
|
@@ -44,6 +45,11 @@ export default {
|
|
|
44
45
|
type: Boolean,
|
|
45
46
|
default: false,
|
|
46
47
|
},
|
|
48
|
+
// 金额类型
|
|
49
|
+
amount: {
|
|
50
|
+
type: Boolean,
|
|
51
|
+
default: false,
|
|
52
|
+
},
|
|
47
53
|
// 最大长度
|
|
48
54
|
maxlength: {
|
|
49
55
|
type: [Number, String],
|
|
@@ -64,6 +70,16 @@ export default {
|
|
|
64
70
|
type: [String, Number],
|
|
65
71
|
default: "",
|
|
66
72
|
},
|
|
73
|
+
// 是否允许小数
|
|
74
|
+
allowDecimal: {
|
|
75
|
+
type: Boolean,
|
|
76
|
+
default: true,
|
|
77
|
+
},
|
|
78
|
+
// 小数位数限制
|
|
79
|
+
decimalLimit: {
|
|
80
|
+
type: Number,
|
|
81
|
+
default: 2,
|
|
82
|
+
},
|
|
67
83
|
},
|
|
68
84
|
|
|
69
85
|
data() {
|
|
@@ -72,6 +88,7 @@ export default {
|
|
|
72
88
|
errorMessage: "",
|
|
73
89
|
internalValue: this.value,
|
|
74
90
|
isTouched: false,
|
|
91
|
+
isFocused: false,
|
|
75
92
|
};
|
|
76
93
|
},
|
|
77
94
|
|
|
@@ -87,10 +104,13 @@ export default {
|
|
|
87
104
|
delete attrs.number;
|
|
88
105
|
delete attrs.mobile;
|
|
89
106
|
delete attrs.email;
|
|
107
|
+
delete attrs.amount;
|
|
90
108
|
delete attrs.maxlength;
|
|
91
109
|
delete attrs.showCount;
|
|
92
110
|
delete attrs.validator;
|
|
93
111
|
delete attrs.value;
|
|
112
|
+
delete attrs.allowDecimal;
|
|
113
|
+
delete attrs.decimalLimit;
|
|
94
114
|
|
|
95
115
|
// 合并值,确保我们的 value 逻辑优先
|
|
96
116
|
return {
|
|
@@ -122,6 +142,10 @@ export default {
|
|
|
122
142
|
},
|
|
123
143
|
|
|
124
144
|
displayValue() {
|
|
145
|
+
// 金额类型在非聚焦状态下显示格式化后的值
|
|
146
|
+
if (this.amount && !this.isFocused && this.internalValue) {
|
|
147
|
+
return this.formatAmount(this.internalValue);
|
|
148
|
+
}
|
|
125
149
|
return this.internalValue;
|
|
126
150
|
},
|
|
127
151
|
},
|
|
@@ -152,6 +176,11 @@ export default {
|
|
|
152
176
|
processedValue = this.formatMobile(value);
|
|
153
177
|
}
|
|
154
178
|
|
|
179
|
+
// 金额类型处理
|
|
180
|
+
if (this.amount) {
|
|
181
|
+
processedValue = this.formatAmountInput(value);
|
|
182
|
+
}
|
|
183
|
+
|
|
155
184
|
// 长度限制
|
|
156
185
|
if (
|
|
157
186
|
this.computedMaxlength &&
|
|
@@ -169,6 +198,7 @@ export default {
|
|
|
169
198
|
|
|
170
199
|
handleBlur(event) {
|
|
171
200
|
this.isTouched = true;
|
|
201
|
+
this.isFocused = false;
|
|
172
202
|
this.validateInput(this.internalValue, true);
|
|
173
203
|
this.$emit("blur", event);
|
|
174
204
|
|
|
@@ -176,6 +206,14 @@ export default {
|
|
|
176
206
|
this.$listeners.blur && this.$listeners.blur(event);
|
|
177
207
|
},
|
|
178
208
|
|
|
209
|
+
handleFocus(event) {
|
|
210
|
+
this.isFocused = true;
|
|
211
|
+
this.$emit("focus", event);
|
|
212
|
+
|
|
213
|
+
// 触发外部监听的事件
|
|
214
|
+
this.$listeners.focus && this.$listeners.focus(event);
|
|
215
|
+
},
|
|
216
|
+
|
|
179
217
|
handleClear() {
|
|
180
218
|
this.hasError = false;
|
|
181
219
|
this.errorMessage = "";
|
|
@@ -195,6 +233,47 @@ export default {
|
|
|
195
233
|
return value.replace(/\D/g, "");
|
|
196
234
|
},
|
|
197
235
|
|
|
236
|
+
formatAmountInput(value) {
|
|
237
|
+
// 金额输入过滤:只允许数字和小数点
|
|
238
|
+
let filteredValue = value.replace(/[^\d.]/g, "");
|
|
239
|
+
|
|
240
|
+
// 处理多个小数点的情况
|
|
241
|
+
const parts = filteredValue.split(".");
|
|
242
|
+
if (parts.length > 2) {
|
|
243
|
+
filteredValue = parts[0] + "." + parts.slice(1).join("");
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// 限制小数位数
|
|
247
|
+
if (parts.length === 2 && parts[1].length > this.decimalLimit) {
|
|
248
|
+
filteredValue =
|
|
249
|
+
parts[0] + "." + parts[1].substring(0, this.decimalLimit);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return filteredValue;
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
formatAmount(value) {
|
|
256
|
+
if (!value) return "";
|
|
257
|
+
|
|
258
|
+
// 将值转换为字符串
|
|
259
|
+
const strValue = String(value);
|
|
260
|
+
|
|
261
|
+
// 分割整数和小数部分
|
|
262
|
+
const parts = strValue.split(".");
|
|
263
|
+
let integerPart = parts[0];
|
|
264
|
+
let decimalPart = parts.length > 1 ? parts[1] : "";
|
|
265
|
+
|
|
266
|
+
// 对整数部分添加千分位分隔符
|
|
267
|
+
integerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
268
|
+
|
|
269
|
+
// 组合整数和小数部分
|
|
270
|
+
if (decimalPart && this.allowDecimal) {
|
|
271
|
+
return `${integerPart}.${decimalPart}`;
|
|
272
|
+
} else {
|
|
273
|
+
return integerPart;
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
|
|
198
277
|
validateInput(value, showError = false) {
|
|
199
278
|
if (!this.isTouched && !showError) return true;
|
|
200
279
|
|
|
@@ -227,6 +306,20 @@ export default {
|
|
|
227
306
|
}
|
|
228
307
|
}
|
|
229
308
|
|
|
309
|
+
// 金额验证
|
|
310
|
+
if (this.amount && strValue) {
|
|
311
|
+
const amountRegex = this.allowDecimal
|
|
312
|
+
? new RegExp(`^\\d+(\\.\\d{0,${this.decimalLimit}})?$`)
|
|
313
|
+
: /^\d+$/;
|
|
314
|
+
|
|
315
|
+
if (!amountRegex.test(strValue.replace(/,/g, ""))) {
|
|
316
|
+
isValid = false;
|
|
317
|
+
message = this.allowDecimal
|
|
318
|
+
? `请输入有效的金额(最多${this.decimalLimit}位小数)`
|
|
319
|
+
: "请输入有效的金额(整数)";
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
230
323
|
// 最大长度验证
|
|
231
324
|
if (this.computedMaxlength && strValue.length > this.computedMaxlength) {
|
|
232
325
|
isValid = false;
|
package/le-list/src/main.vue
CHANGED
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
<template v-else>
|
|
59
59
|
<div class="rowBtns">
|
|
60
60
|
<le-button @click="editItem(scope.row)" v-if="disBtn === 'edit'">
|
|
61
|
-
|
|
61
|
+
{{ editBtnText }}</le-button
|
|
62
62
|
>
|
|
63
63
|
<le-button @click="detail(scope.row)" v-if="disBtn === 'detail'">
|
|
64
64
|
详情</le-button
|
|
@@ -153,6 +153,10 @@ export default {
|
|
|
153
153
|
type: String,
|
|
154
154
|
default: "id",
|
|
155
155
|
},
|
|
156
|
+
editBtnText: {
|
|
157
|
+
type: String,
|
|
158
|
+
default: "编辑",
|
|
159
|
+
},
|
|
156
160
|
},
|
|
157
161
|
watch: {
|
|
158
162
|
searchParam: {
|
|
@@ -286,17 +290,29 @@ export default {
|
|
|
286
290
|
this.rowItems = val;
|
|
287
291
|
},
|
|
288
292
|
format(type, value, spec) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
293
|
+
// 参数验证
|
|
294
|
+
if (type === undefined || value === undefined) return value;
|
|
295
|
+
|
|
296
|
+
switch (type) {
|
|
297
|
+
case "bool":
|
|
298
|
+
return value === 1 || value === "1" || value === true ? "是" : "否";
|
|
299
|
+
|
|
300
|
+
case "date":
|
|
301
|
+
if (!value) return "";
|
|
302
|
+
try {
|
|
303
|
+
return spec ? this.parseTime(value, spec) : this.parseTime(value);
|
|
304
|
+
} catch {
|
|
305
|
+
return value;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
case "currency":
|
|
309
|
+
if (value == null || value === "") return "";
|
|
310
|
+
const num = parseFloat(value);
|
|
311
|
+
return isNaN(num) ? value : `$${num.toFixed(2)}`;
|
|
312
|
+
|
|
313
|
+
default:
|
|
314
|
+
return value;
|
|
315
|
+
}
|
|
300
316
|
},
|
|
301
317
|
},
|
|
302
318
|
};
|