leisure-core 0.5.58 → 0.5.60
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.
|
@@ -0,0 +1,119 @@
|
|
|
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>
|
|
@@ -32,14 +32,9 @@ export default {
|
|
|
32
32
|
};
|
|
33
33
|
},
|
|
34
34
|
watch: {
|
|
35
|
-
value
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.internalValue = this.convertValueToInternal(newVal);
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
immediate: true,
|
|
42
|
-
},
|
|
35
|
+
// value(newVal) {
|
|
36
|
+
// this.internalValue = this.convertValueToInternal(newVal);
|
|
37
|
+
// },
|
|
43
38
|
// internalValue(newVal) {
|
|
44
39
|
// const outputValue = this.convertValueToOutput(newVal);
|
|
45
40
|
// this.$emit("input", outputValue);
|