leisure-core 0.5.69 → 0.5.70
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/index.js +6 -0
- package/le-date-picker-auto/index.js +6 -0
- package/le-date-picker-auto/src/main.vue +131 -0
- package/le-input-validate/index.js +6 -0
- package/le-input-validate/src/main.vue +301 -0
- package/le-list-form/src/main.vue +11 -0
- package/package.json +1 -1
- package/le-date-picker/src/main-back.vue +0 -119
package/index.js
CHANGED
|
@@ -44,6 +44,8 @@ import LeUrl from "./le-url/index.js";
|
|
|
44
44
|
import LeSpan from "./le-span/index.js";
|
|
45
45
|
import LeInputAdvanced from "./le-input-advanced/index.js";
|
|
46
46
|
import LeButtonAudit from "./le-button-audit/index.js";
|
|
47
|
+
import LeInputValidate from "./le-input-validate/index.js";
|
|
48
|
+
import LeDatePickerAuto from "./le-date-picker-auto/index.js";
|
|
47
49
|
|
|
48
50
|
const components = [
|
|
49
51
|
LeArea,
|
|
@@ -86,6 +88,8 @@ const components = [
|
|
|
86
88
|
LeUrl,
|
|
87
89
|
LeInputAdvanced,
|
|
88
90
|
LeButtonAudit,
|
|
91
|
+
LeInputValidate,
|
|
92
|
+
LeDatePickerAuto,
|
|
89
93
|
];
|
|
90
94
|
|
|
91
95
|
const install = function (Vue) {
|
|
@@ -197,4 +201,6 @@ export default {
|
|
|
197
201
|
LeInputAdvanced,
|
|
198
202
|
LeButtonAudit,
|
|
199
203
|
leMixins,
|
|
204
|
+
LeInputValidate,
|
|
205
|
+
LeDatePickerAuto,
|
|
200
206
|
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-date-picker
|
|
3
|
+
v-model="internalValue"
|
|
4
|
+
v-bind="$attrs"
|
|
5
|
+
v-on="$listeners"
|
|
6
|
+
:class="['customClass', $attrs.class]"
|
|
7
|
+
:style="$attrs.style"
|
|
8
|
+
:type="type"
|
|
9
|
+
></el-date-picker>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script>
|
|
13
|
+
export default {
|
|
14
|
+
name: "le-date-picker-auto",
|
|
15
|
+
props: {
|
|
16
|
+
value: {
|
|
17
|
+
type: [Number, Date, String],
|
|
18
|
+
default: null,
|
|
19
|
+
},
|
|
20
|
+
type: {
|
|
21
|
+
type: String,
|
|
22
|
+
default: "date",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
data() {
|
|
26
|
+
return {
|
|
27
|
+
internalValue: this.convertValueToInternal(this.value),
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
watch: {
|
|
31
|
+
value(newVal) {
|
|
32
|
+
this.internalValue = this.convertValueToInternal(newVal);
|
|
33
|
+
},
|
|
34
|
+
internalValue(newVal) {
|
|
35
|
+
const outputValue = this.convertValueToOutput(newVal);
|
|
36
|
+
this.$emit("input", outputValue);
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
methods: {
|
|
40
|
+
isTimestampInSeconds(value) {
|
|
41
|
+
if (typeof value !== "number") return false;
|
|
42
|
+
|
|
43
|
+
// 秒级时间戳通常是10位数字(当前时间戳约16-17亿)
|
|
44
|
+
// 但为了更准确,我们检查时间戳是否在合理范围内
|
|
45
|
+
const currentSeconds = Math.floor(Date.now() / 1000);
|
|
46
|
+
const minReasonable = 0; // 1970-01-01
|
|
47
|
+
const maxReasonable = currentSeconds + 100 * 365 * 24 * 60 * 60; // 当前时间 + 100年
|
|
48
|
+
|
|
49
|
+
return value >= minReasonable && value <= maxReasonable;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
isTimestampInMilliseconds(value) {
|
|
53
|
+
if (typeof value !== "number") return false;
|
|
54
|
+
|
|
55
|
+
// 毫秒级时间戳通常是13位数字
|
|
56
|
+
// 检查是否在合理的时间范围内
|
|
57
|
+
const currentMs = Date.now();
|
|
58
|
+
const minReasonable = 0; // 1970-01-01
|
|
59
|
+
const maxReasonable = currentMs + 100 * 365 * 24 * 60 * 60 * 1000; // 当前时间 + 100年
|
|
60
|
+
|
|
61
|
+
return value >= minReasonable && value <= maxReasonable;
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
convertValueToInternal(value) {
|
|
65
|
+
if (value === null || value === undefined || value === "") {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 如果是数字时间戳
|
|
70
|
+
if (typeof value === "number") {
|
|
71
|
+
if (this.isTimestampInSeconds(value)) {
|
|
72
|
+
// 确认是秒级时间戳,转换为毫秒
|
|
73
|
+
return new Date(value * 1000);
|
|
74
|
+
} else if (this.isTimestampInMilliseconds(value)) {
|
|
75
|
+
// 如果是毫秒级时间戳,也转换为秒再处理,确保一致性
|
|
76
|
+
const seconds = Math.floor(value / 1000);
|
|
77
|
+
return new Date(seconds * 1000);
|
|
78
|
+
} else {
|
|
79
|
+
// 无法识别的数字,尝试直接作为毫秒处理
|
|
80
|
+
console.warn("无法识别的时间戳格式,将尝试作为毫秒处理:", value);
|
|
81
|
+
return new Date(value);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// 如果是 Date 对象
|
|
85
|
+
else if (value instanceof Date) {
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
// 如果是字符串日期
|
|
89
|
+
else if (typeof value === "string") {
|
|
90
|
+
const parsedDate = new Date(value);
|
|
91
|
+
return isNaN(parsedDate.getTime()) ? null : parsedDate;
|
|
92
|
+
}
|
|
93
|
+
// 其他情况返回 null
|
|
94
|
+
else {
|
|
95
|
+
console.warn("无法处理的值类型:", typeof value, value);
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
convertValueToOutput(value) {
|
|
101
|
+
if (value === null || value === undefined || value === "") {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 如果是 Date 对象,转换为时间戳(秒)
|
|
106
|
+
if (value instanceof Date) {
|
|
107
|
+
return Math.floor(value.getTime() / 1000);
|
|
108
|
+
}
|
|
109
|
+
// 如果是数字,根据位数判断是否需要转换
|
|
110
|
+
else if (typeof value === "number") {
|
|
111
|
+
if (this.isTimestampInSeconds(value)) {
|
|
112
|
+
return value; // 已经是秒,直接返回
|
|
113
|
+
} else if (this.isTimestampInMilliseconds(value)) {
|
|
114
|
+
return Math.floor(value / 1000); // 毫秒转秒
|
|
115
|
+
} else {
|
|
116
|
+
console.warn("无法识别的时间戳格式,将尝试作为秒处理:", value);
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// 其他情况返回 null
|
|
121
|
+
else {
|
|
122
|
+
console.warn("无法输出的值类型:", typeof value, value);
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
mounted() {
|
|
128
|
+
// 如果需要在组件挂载后执行某些操作,可以在这里添加代码。
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
</script>
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="le-input-wrapper">
|
|
3
|
+
<el-input
|
|
4
|
+
ref="inputRef"
|
|
5
|
+
v-bind="mergedAttrs"
|
|
6
|
+
:class="['le-input', $attrs.class, { 'is-error': hasError }]"
|
|
7
|
+
:style="$attrs.style"
|
|
8
|
+
clearable
|
|
9
|
+
@input="handleInput"
|
|
10
|
+
@blur="handleBlur"
|
|
11
|
+
@clear="handleClear"
|
|
12
|
+
>
|
|
13
|
+
<template v-if="showCount" #suffix>
|
|
14
|
+
<span class="input-count" :class="{ 'is-error': isOverMaxLength }">
|
|
15
|
+
{{ valueLength }}/{{ computedMaxlength }}
|
|
16
|
+
</span>
|
|
17
|
+
</template>
|
|
18
|
+
</el-input>
|
|
19
|
+
|
|
20
|
+
<div v-if="hasError && errorMessage" class="error-message">
|
|
21
|
+
{{ errorMessage }}
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
25
|
+
|
|
26
|
+
<script>
|
|
27
|
+
export default {
|
|
28
|
+
name: "le-input-validate",
|
|
29
|
+
inheritAttrs: false,
|
|
30
|
+
|
|
31
|
+
props: {
|
|
32
|
+
// 数值类型
|
|
33
|
+
number: {
|
|
34
|
+
type: Boolean,
|
|
35
|
+
default: false,
|
|
36
|
+
},
|
|
37
|
+
// 手机号类型
|
|
38
|
+
mobile: {
|
|
39
|
+
type: Boolean,
|
|
40
|
+
default: false,
|
|
41
|
+
},
|
|
42
|
+
// 邮箱类型
|
|
43
|
+
email: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
default: false,
|
|
46
|
+
},
|
|
47
|
+
// 最大长度
|
|
48
|
+
maxlength: {
|
|
49
|
+
type: [Number, String],
|
|
50
|
+
default: null,
|
|
51
|
+
},
|
|
52
|
+
// 是否显示字数统计
|
|
53
|
+
showCount: {
|
|
54
|
+
type: Boolean,
|
|
55
|
+
default: false,
|
|
56
|
+
},
|
|
57
|
+
// 自定义验证函数
|
|
58
|
+
validator: {
|
|
59
|
+
type: Function,
|
|
60
|
+
default: null,
|
|
61
|
+
},
|
|
62
|
+
// 值
|
|
63
|
+
value: {
|
|
64
|
+
type: [String, Number],
|
|
65
|
+
default: "",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
data() {
|
|
70
|
+
return {
|
|
71
|
+
hasError: false,
|
|
72
|
+
errorMessage: "",
|
|
73
|
+
internalValue: this.value,
|
|
74
|
+
isTouched: false,
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
computed: {
|
|
79
|
+
mergedAttrs() {
|
|
80
|
+
const attrs = { ...this.$attrs };
|
|
81
|
+
|
|
82
|
+
// 移除已单独处理的属性
|
|
83
|
+
delete attrs.class;
|
|
84
|
+
delete attrs.style;
|
|
85
|
+
|
|
86
|
+
// 移除props中定义的属性,避免重复
|
|
87
|
+
delete attrs.number;
|
|
88
|
+
delete attrs.mobile;
|
|
89
|
+
delete attrs.email;
|
|
90
|
+
delete attrs.maxlength;
|
|
91
|
+
delete attrs.showCount;
|
|
92
|
+
delete attrs.validator;
|
|
93
|
+
delete attrs.value;
|
|
94
|
+
|
|
95
|
+
// 合并值,确保我们的 value 逻辑优先
|
|
96
|
+
return {
|
|
97
|
+
...attrs,
|
|
98
|
+
value: this.displayValue,
|
|
99
|
+
maxlength: this.computedMaxlength,
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
computedMaxlength() {
|
|
104
|
+
if (this.maxlength) {
|
|
105
|
+
return Number(this.maxlength);
|
|
106
|
+
}
|
|
107
|
+
// 手机号默认11位
|
|
108
|
+
if (this.mobile) {
|
|
109
|
+
return 11;
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
valueLength() {
|
|
115
|
+
return String(this.internalValue || "").length;
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
isOverMaxLength() {
|
|
119
|
+
return (
|
|
120
|
+
this.computedMaxlength && this.valueLength > this.computedMaxlength
|
|
121
|
+
);
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
displayValue() {
|
|
125
|
+
return this.internalValue;
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
watch: {
|
|
130
|
+
value(newVal) {
|
|
131
|
+
this.internalValue = newVal;
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
internalValue(newVal) {
|
|
135
|
+
this.validateInput(newVal);
|
|
136
|
+
// 触发外部监听的事件
|
|
137
|
+
this.$listeners.change && this.$listeners.change(newVal);
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
methods: {
|
|
142
|
+
handleInput(value) {
|
|
143
|
+
let processedValue = value;
|
|
144
|
+
|
|
145
|
+
// 数值类型处理
|
|
146
|
+
if (this.number) {
|
|
147
|
+
processedValue = this.formatNumber(value);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 手机号类型处理
|
|
151
|
+
if (this.mobile) {
|
|
152
|
+
processedValue = this.formatMobile(value);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 长度限制
|
|
156
|
+
if (
|
|
157
|
+
this.computedMaxlength &&
|
|
158
|
+
processedValue.length > this.computedMaxlength
|
|
159
|
+
) {
|
|
160
|
+
processedValue = processedValue.slice(0, this.computedMaxlength);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this.internalValue = processedValue;
|
|
164
|
+
this.$emit("input", processedValue);
|
|
165
|
+
|
|
166
|
+
// 触发外部监听的事件
|
|
167
|
+
this.$listeners.input && this.$listeners.input(processedValue);
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
handleBlur(event) {
|
|
171
|
+
this.isTouched = true;
|
|
172
|
+
this.validateInput(this.internalValue, true);
|
|
173
|
+
this.$emit("blur", event);
|
|
174
|
+
|
|
175
|
+
// 触发外部监听的事件
|
|
176
|
+
this.$listeners.blur && this.$listeners.blur(event);
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
handleClear() {
|
|
180
|
+
this.hasError = false;
|
|
181
|
+
this.errorMessage = "";
|
|
182
|
+
this.$emit("clear");
|
|
183
|
+
|
|
184
|
+
// 触发外部监听的事件
|
|
185
|
+
this.$listeners.clear && this.$listeners.clear();
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
formatNumber(value) {
|
|
189
|
+
// 只允许数字、小数点、负号
|
|
190
|
+
return value.replace(/[^\d.-]/g, "").replace(/(\..*)\./g, "$1");
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
formatMobile(value) {
|
|
194
|
+
// 只允许数字
|
|
195
|
+
return value.replace(/\D/g, "");
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
validateInput(value, showError = false) {
|
|
199
|
+
if (!this.isTouched && !showError) return true;
|
|
200
|
+
|
|
201
|
+
let isValid = true;
|
|
202
|
+
let message = "";
|
|
203
|
+
|
|
204
|
+
const strValue = String(value || "");
|
|
205
|
+
|
|
206
|
+
// 数值验证
|
|
207
|
+
if (this.number && strValue) {
|
|
208
|
+
if (!/^-?\d*\.?\d*$/.test(strValue)) {
|
|
209
|
+
isValid = false;
|
|
210
|
+
message = "请输入有效的数值";
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// 手机号验证
|
|
215
|
+
if (this.mobile && strValue) {
|
|
216
|
+
if (!/^1[3-9]\d{9}$/.test(strValue)) {
|
|
217
|
+
isValid = false;
|
|
218
|
+
message = "请输入有效的手机号码";
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// 邮箱验证
|
|
223
|
+
if (this.email && strValue) {
|
|
224
|
+
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(strValue)) {
|
|
225
|
+
isValid = false;
|
|
226
|
+
message = "请输入有效的邮箱地址";
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// 最大长度验证
|
|
231
|
+
if (this.computedMaxlength && strValue.length > this.computedMaxlength) {
|
|
232
|
+
isValid = false;
|
|
233
|
+
message = `输入内容不能超过${this.computedMaxlength}个字符`;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// 自定义验证
|
|
237
|
+
if (this.validator && typeof this.validator === "function") {
|
|
238
|
+
const customResult = this.validator(value);
|
|
239
|
+
if (customResult !== true) {
|
|
240
|
+
isValid = false;
|
|
241
|
+
message = customResult || "输入内容不符合要求";
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
this.hasError = !isValid && (this.isTouched || showError);
|
|
246
|
+
this.errorMessage = message;
|
|
247
|
+
|
|
248
|
+
return isValid;
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
// 公开方法:手动验证
|
|
252
|
+
validate() {
|
|
253
|
+
this.isTouched = true;
|
|
254
|
+
return this.validateInput(this.internalValue, true);
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
// 公开方法:清除验证状态
|
|
258
|
+
clearValidate() {
|
|
259
|
+
this.hasError = false;
|
|
260
|
+
this.errorMessage = "";
|
|
261
|
+
this.isTouched = false;
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
// 公开方法:聚焦输入框
|
|
265
|
+
focus() {
|
|
266
|
+
this.$refs.inputRef?.focus();
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
// 公开方法:失焦输入框
|
|
270
|
+
blur() {
|
|
271
|
+
this.$refs.inputRef?.blur();
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
</script>
|
|
276
|
+
|
|
277
|
+
<style scoped>
|
|
278
|
+
.le-input-wrapper {
|
|
279
|
+
position: relative;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.le-input.is-error ::v-deep .el-input__inner {
|
|
283
|
+
border-color: #f56c6c;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.input-count {
|
|
287
|
+
font-size: 12px;
|
|
288
|
+
color: #909399;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
.input-count.is-error {
|
|
292
|
+
color: #f56c6c;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
.error-message {
|
|
296
|
+
color: #f56c6c;
|
|
297
|
+
font-size: 12px;
|
|
298
|
+
line-height: 1;
|
|
299
|
+
padding-top: 4px;
|
|
300
|
+
}
|
|
301
|
+
</style>
|
|
@@ -173,6 +173,10 @@ export default {
|
|
|
173
173
|
component: "le-input",
|
|
174
174
|
props: { placeholder: "请输入" },
|
|
175
175
|
},
|
|
176
|
+
inputValidate: {
|
|
177
|
+
component: "le-input-validate",
|
|
178
|
+
props: { placeholder: "请输入" },
|
|
179
|
+
},
|
|
176
180
|
number: {
|
|
177
181
|
component: "le-input-number",
|
|
178
182
|
props: {},
|
|
@@ -190,6 +194,13 @@ export default {
|
|
|
190
194
|
translateDate: true,
|
|
191
195
|
},
|
|
192
196
|
},
|
|
197
|
+
dateAuto: {
|
|
198
|
+
component: "le-date-picker",
|
|
199
|
+
props: {
|
|
200
|
+
format: "yyyy-MM-dd",
|
|
201
|
+
"value-format": "timestamp",
|
|
202
|
+
},
|
|
203
|
+
},
|
|
193
204
|
select: { component: "le-select", props: {} },
|
|
194
205
|
smulti: { component: "le-select-multi", props: {} },
|
|
195
206
|
image: { component: "le-image-container", props: {} },
|
package/package.json
CHANGED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<el-date-picker
|
|
3
|
-
v-model="internalValue"
|
|
4
|
-
v-bind="$attrs"
|
|
5
|
-
v-on="listeners"
|
|
6
|
-
:class="['customClass', $attrs.class]"
|
|
7
|
-
:style="$attrs.style"
|
|
8
|
-
:type="type"
|
|
9
|
-
></el-date-picker>
|
|
10
|
-
</template>
|
|
11
|
-
|
|
12
|
-
<script>
|
|
13
|
-
export default {
|
|
14
|
-
name: "le-date-picker-back",
|
|
15
|
-
props: {
|
|
16
|
-
value: {
|
|
17
|
-
type: [Number, Date, String, Array], // 添加Array类型支持日期范围
|
|
18
|
-
default: null,
|
|
19
|
-
},
|
|
20
|
-
type: {
|
|
21
|
-
type: String,
|
|
22
|
-
default: "date",
|
|
23
|
-
},
|
|
24
|
-
translateDate: {
|
|
25
|
-
type: Boolean,
|
|
26
|
-
default: false,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
data() {
|
|
30
|
-
return {
|
|
31
|
-
internalValue: null,
|
|
32
|
-
};
|
|
33
|
-
},
|
|
34
|
-
computed: {
|
|
35
|
-
listeners() {
|
|
36
|
-
return {
|
|
37
|
-
...this.$listeners,
|
|
38
|
-
input: this.handleInput,
|
|
39
|
-
change: this.handleChange,
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
watch: {
|
|
44
|
-
value: {
|
|
45
|
-
handler(newVal) {
|
|
46
|
-
this.internalValue = this.convertValueToInternal(newVal);
|
|
47
|
-
},
|
|
48
|
-
immediate: true,
|
|
49
|
-
deep: true,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
methods: {
|
|
53
|
-
convertValueToInternal(value) {
|
|
54
|
-
if (value === null || value === undefined || value === "") {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// 处理日期范围数组
|
|
59
|
-
if (Array.isArray(value)) {
|
|
60
|
-
return value.map((item) => this.convertSingleValueToInternal(item));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return this.convertSingleValueToInternal(value);
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
convertSingleValueToInternal(value) {
|
|
67
|
-
if (this.translateDate && typeof value === "number") {
|
|
68
|
-
// 假设是秒级时间戳
|
|
69
|
-
return new Date(value * 1000);
|
|
70
|
-
} else if (value instanceof Date) {
|
|
71
|
-
return value;
|
|
72
|
-
} else if (typeof value === "string" && !isNaN(Date.parse(value))) {
|
|
73
|
-
return new Date(value);
|
|
74
|
-
} else if (typeof value === "number") {
|
|
75
|
-
// 如果不是translateDate模式,但传入了数字,假设是毫秒级时间戳
|
|
76
|
-
return new Date(value);
|
|
77
|
-
} else {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
convertValueToOutput(value) {
|
|
83
|
-
if (value === null || value === undefined) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 处理日期范围数组
|
|
88
|
-
if (Array.isArray(value)) {
|
|
89
|
-
return value.map((item) => this.convertSingleValueToOutput(item));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return this.convertSingleValueToOutput(value);
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
convertSingleValueToOutput(value) {
|
|
96
|
-
if (this.translateDate && value instanceof Date) {
|
|
97
|
-
// 输出秒级时间戳
|
|
98
|
-
return Math.floor(value.getTime() / 1000);
|
|
99
|
-
} else {
|
|
100
|
-
return value;
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
handleInput(value) {
|
|
105
|
-
const outputValue = this.convertValueToOutput(value);
|
|
106
|
-
this.$emit("input", outputValue);
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
handleChange(value) {
|
|
110
|
-
const outputValue = this.convertValueToOutput(value);
|
|
111
|
-
this.$emit("change", outputValue);
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
mounted() {
|
|
115
|
-
// 初始化internalValue
|
|
116
|
-
this.internalValue = this.convertValueToInternal(this.value);
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
</script>
|