leisure-core 0.5.59 → 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.
- package/le-date-picker/src/main-back.vue +119 -0
- package/le-date-picker/src/main.vue +11 -63
- package/package.json +1 -1
|
@@ -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>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<el-date-picker
|
|
3
3
|
v-model="internalValue"
|
|
4
4
|
v-bind="$attrs"
|
|
5
|
-
v-on="listeners"
|
|
5
|
+
v-on="$listeners"
|
|
6
6
|
:class="['customClass', $attrs.class]"
|
|
7
7
|
:style="$attrs.style"
|
|
8
8
|
:type="type"
|
|
@@ -14,7 +14,7 @@ export default {
|
|
|
14
14
|
name: "le-date-picker",
|
|
15
15
|
props: {
|
|
16
16
|
value: {
|
|
17
|
-
type: [Number, Date, String
|
|
17
|
+
type: [Number, Date, String], // 可以接收时间戳、Date 对象或日期字符串
|
|
18
18
|
default: null,
|
|
19
19
|
},
|
|
20
20
|
type: {
|
|
@@ -28,92 +28,40 @@ export default {
|
|
|
28
28
|
},
|
|
29
29
|
data() {
|
|
30
30
|
return {
|
|
31
|
-
internalValue:
|
|
31
|
+
internalValue: this.convertValueToInternal(this.value), // 初始化内部值
|
|
32
32
|
};
|
|
33
33
|
},
|
|
34
|
-
computed: {
|
|
35
|
-
listeners() {
|
|
36
|
-
return {
|
|
37
|
-
...this.$listeners,
|
|
38
|
-
input: this.handleInput,
|
|
39
|
-
change: this.handleChange,
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
34
|
watch: {
|
|
44
|
-
value
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
},
|
|
35
|
+
// value(newVal) {
|
|
36
|
+
// this.internalValue = this.convertValueToInternal(newVal);
|
|
37
|
+
// },
|
|
38
|
+
// internalValue(newVal) {
|
|
39
|
+
// const outputValue = this.convertValueToOutput(newVal);
|
|
40
|
+
// this.$emit("input", outputValue);
|
|
41
|
+
// },
|
|
51
42
|
},
|
|
52
43
|
methods: {
|
|
53
44
|
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
45
|
if (this.translateDate && typeof value === "number") {
|
|
68
|
-
// 假设是秒级时间戳
|
|
69
46
|
return new Date(value * 1000);
|
|
70
47
|
} else if (value instanceof Date) {
|
|
71
48
|
return value;
|
|
72
49
|
} else if (typeof value === "string" && !isNaN(Date.parse(value))) {
|
|
73
50
|
return new Date(value);
|
|
74
|
-
} else if (typeof value === "number") {
|
|
75
|
-
// 如果不是translateDate模式,但传入了数字,假设是毫秒级时间戳
|
|
76
|
-
return new Date(value);
|
|
77
51
|
} else {
|
|
78
52
|
return null;
|
|
79
53
|
}
|
|
80
54
|
},
|
|
81
|
-
|
|
82
55
|
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
56
|
if (this.translateDate && value instanceof Date) {
|
|
97
|
-
// 输出秒级时间戳
|
|
98
57
|
return Math.floor(value.getTime() / 1000);
|
|
99
58
|
} else {
|
|
100
59
|
return value;
|
|
101
60
|
}
|
|
102
61
|
},
|
|
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
62
|
},
|
|
114
63
|
mounted() {
|
|
115
|
-
//
|
|
116
|
-
this.internalValue = this.convertValueToInternal(this.value);
|
|
64
|
+
// 如果需要在组件挂载后执行某些操作,可以在这里添加代码。
|
|
117
65
|
},
|
|
118
66
|
};
|
|
119
67
|
</script>
|