leisure-core 0.5.57 → 0.5.59

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.
@@ -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], // 可以接收时间戳、Date 对象或日期字符串
17
+ type: [Number, Date, String, Array], // 添加Array类型支持日期范围
18
18
  default: null,
19
19
  },
20
20
  type: {
@@ -28,40 +28,92 @@ export default {
28
28
  },
29
29
  data() {
30
30
  return {
31
- internalValue: this.convertValueToInternal(this.value), // 初始化内部值
31
+ internalValue: null,
32
32
  };
33
33
  },
34
+ computed: {
35
+ listeners() {
36
+ return {
37
+ ...this.$listeners,
38
+ input: this.handleInput,
39
+ change: this.handleChange,
40
+ };
41
+ },
42
+ },
34
43
  watch: {
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
- // },
44
+ value: {
45
+ handler(newVal) {
46
+ this.internalValue = this.convertValueToInternal(newVal);
47
+ },
48
+ immediate: true,
49
+ deep: true,
50
+ },
42
51
  },
43
52
  methods: {
44
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) {
45
67
  if (this.translateDate && typeof value === "number") {
68
+ // 假设是秒级时间戳
46
69
  return new Date(value * 1000);
47
70
  } else if (value instanceof Date) {
48
71
  return value;
49
72
  } else if (typeof value === "string" && !isNaN(Date.parse(value))) {
50
73
  return new Date(value);
74
+ } else if (typeof value === "number") {
75
+ // 如果不是translateDate模式,但传入了数字,假设是毫秒级时间戳
76
+ return new Date(value);
51
77
  } else {
52
78
  return null;
53
79
  }
54
80
  },
81
+
55
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) {
56
96
  if (this.translateDate && value instanceof Date) {
97
+ // 输出秒级时间戳
57
98
  return Math.floor(value.getTime() / 1000);
58
99
  } else {
59
100
  return value;
60
101
  }
61
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
+ },
62
113
  },
63
114
  mounted() {
64
- // 如果需要在组件挂载后执行某些操作,可以在这里添加代码。
115
+ // 初始化internalValue
116
+ this.internalValue = this.convertValueToInternal(this.value);
65
117
  },
66
118
  };
67
119
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leisure-core",
3
- "version": "0.5.57",
3
+ "version": "0.5.59",
4
4
  "description": "leisure-core是京心数据基于vue2.x开发的一套后台管理系统桌面端组件库,封装了大量实用的UI控件模板,非常方便开发者快速搭建前端应用",
5
5
  "private": false,
6
6
  "author": "北方乐逍遥(zcx7878)",