tang-ui-x 1.2.7 → 1.2.9
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.
|
@@ -30,10 +30,13 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
30
30
|
})
|
|
31
31
|
|
|
32
32
|
// 使用 defineModel 管理显示状态 (v-model)
|
|
33
|
-
const visible = defineModel
|
|
33
|
+
const visible = defineModel({ default: false })
|
|
34
34
|
|
|
35
35
|
// 使用 defineModel 管理选中的值(时间戳)
|
|
36
|
-
const selectedValue = defineModel
|
|
36
|
+
const selectedValue = defineModel('value', { default: 0 })
|
|
37
|
+
|
|
38
|
+
// 使用 defineModel 管理范围选中的值(时间戳对象或数组)
|
|
39
|
+
const selectedRangeValue = defineModel('rangeValue', { default: null })
|
|
37
40
|
|
|
38
41
|
// 内部渲染状态,用于控制 DOM 显示
|
|
39
42
|
const rendered = ref(false)
|
|
@@ -152,8 +155,7 @@ const dateToTimestamp = (year: number, month: number, day: number): number => {
|
|
|
152
155
|
// 检查日期是否为范围开始
|
|
153
156
|
const isRangeStartDate = (year: number, month: number, day: number): boolean => {
|
|
154
157
|
if (!props.range || rangeStart.value === null) return false
|
|
155
|
-
const
|
|
156
|
-
const startDate = new Date(rangeStart.value)
|
|
158
|
+
const startDate = new Date(rangeStart.value as number)
|
|
157
159
|
return startDate.getFullYear() === year &&
|
|
158
160
|
startDate.getMonth() + 1 === month &&
|
|
159
161
|
startDate.getDate() === day
|
|
@@ -162,8 +164,7 @@ const isRangeStartDate = (year: number, month: number, day: number): boolean =>
|
|
|
162
164
|
// 检查日期是否为范围结束
|
|
163
165
|
const isRangeEndDate = (year: number, month: number, day: number): boolean => {
|
|
164
166
|
if (!props.range || rangeEnd.value === null) return false
|
|
165
|
-
const
|
|
166
|
-
const endDate = new Date(rangeEnd.value)
|
|
167
|
+
const endDate = new Date(rangeEnd.value as number)
|
|
167
168
|
return endDate.getFullYear() === year &&
|
|
168
169
|
endDate.getMonth() + 1 === month &&
|
|
169
170
|
endDate.getDate() === day
|
|
@@ -173,7 +174,15 @@ const isRangeEndDate = (year: number, month: number, day: number): boolean => {
|
|
|
173
174
|
const isInRangeDate = (year: number, month: number, day: number): boolean => {
|
|
174
175
|
if (!props.range || rangeStart.value === null || rangeEnd.value === null) return false
|
|
175
176
|
const timestamp = dateToTimestamp(year, month, day)
|
|
176
|
-
|
|
177
|
+
|
|
178
|
+
// 忽略时分秒进行比较
|
|
179
|
+
const startTemp = new Date(rangeStart.value as number)
|
|
180
|
+
const startTimestamp = new Date(startTemp.getFullYear(), startTemp.getMonth(), startTemp.getDate()).getTime()
|
|
181
|
+
|
|
182
|
+
const endTemp = new Date(rangeEnd.value as number)
|
|
183
|
+
const endTimestamp = new Date(endTemp.getFullYear(), endTemp.getMonth(), endTemp.getDate()).getTime()
|
|
184
|
+
|
|
185
|
+
return timestamp > startTimestamp && timestamp < endTimestamp
|
|
177
186
|
}
|
|
178
187
|
|
|
179
188
|
// 获取日期单元格样式
|
|
@@ -441,7 +450,10 @@ const handleDaySelect = (item: DayItem): void => {
|
|
|
441
450
|
selectingRange.value = 'end'
|
|
442
451
|
} else {
|
|
443
452
|
// 选择结束日期
|
|
444
|
-
|
|
453
|
+
const currentStartObj = new Date(rangeStart.value as number)
|
|
454
|
+
const currentStartTimestamp = new Date(currentStartObj.getFullYear(), currentStartObj.getMonth(), currentStartObj.getDate()).getTime()
|
|
455
|
+
|
|
456
|
+
if (rangeStart.value !== null && timestamp < currentStartTimestamp) {
|
|
445
457
|
// 如果结束日期小于开始日期,交换
|
|
446
458
|
rangeEnd.value = rangeStart.value
|
|
447
459
|
rangeStart.value = timestamp
|
|
@@ -593,12 +605,43 @@ watch(visible, (newVal: boolean) => {
|
|
|
593
605
|
// 初始状态为隐藏
|
|
594
606
|
showOverlay.value = false
|
|
595
607
|
|
|
596
|
-
//
|
|
608
|
+
// 重置范围选择状态或进行数据回显
|
|
597
609
|
if (props.range) {
|
|
598
|
-
|
|
610
|
+
let startValue: number = 0
|
|
611
|
+
let endValue: number = 0
|
|
612
|
+
const rVal = selectedRangeValue.value
|
|
613
|
+
|
|
614
|
+
if (rVal != null) {
|
|
615
|
+
if (Array.isArray(rVal) && (rVal as Array<any>).length >= 2) {
|
|
616
|
+
const arr = rVal as Array<any>
|
|
617
|
+
const s = arr[0]
|
|
618
|
+
const e = arr[1]
|
|
619
|
+
startValue = typeof s === 'string' ? new Date(s as string).getTime() : (typeof s === 'number' ? (s as number) : 0)
|
|
620
|
+
endValue = typeof e === 'string' ? new Date(e as string).getTime() : (typeof e === 'number' ? (e as number) : 0)
|
|
621
|
+
} else if (typeof rVal === 'object') {
|
|
622
|
+
const obj = rVal as any
|
|
623
|
+
const s = obj['start']
|
|
624
|
+
const e = obj['end']
|
|
625
|
+
startValue = typeof s === 'string' ? new Date(s as string).getTime() : (typeof s === 'number' ? (s as number) : 0)
|
|
626
|
+
endValue = typeof e === 'string' ? new Date(e as string).getTime() : (typeof e === 'number' ? (e as number) : 0)
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
if (startValue > 0 && endValue > 0) {
|
|
631
|
+
rangeStart.value = startValue
|
|
632
|
+
rangeEnd.value = endValue
|
|
633
|
+
selectingRange.value = 'start' // 回显后默认下一步选择开始时间
|
|
634
|
+
// 设置年月视图到开始时间
|
|
635
|
+
const startDate = new Date(rangeStart.value as number)
|
|
636
|
+
viewYear.value = startDate.getFullYear()
|
|
637
|
+
viewMonth.value = startDate.getMonth() + 1
|
|
638
|
+
} else {
|
|
639
|
+
resetRange()
|
|
640
|
+
setValueByTimestamp(Date.now())
|
|
641
|
+
}
|
|
642
|
+
} else {
|
|
643
|
+
setValueByTimestamp(selectedValue.value || Date.now())
|
|
599
644
|
}
|
|
600
|
-
|
|
601
|
-
setValueByTimestamp(selectedValue.value || Date.now())
|
|
602
645
|
// 根据模式设置初始面板
|
|
603
646
|
if (props.mode === 'month') {
|
|
604
647
|
panelMode.value = 'month'
|
|
@@ -655,22 +698,31 @@ const handleConfirm = (): void => {
|
|
|
655
698
|
if (props.range) {
|
|
656
699
|
// 范围模式
|
|
657
700
|
if (rangeStart.value !== null && rangeEnd.value !== null) {
|
|
658
|
-
const rangeValue: TDateTimePickerRangeValue = {
|
|
659
|
-
start: rangeStart.value,
|
|
660
|
-
end: rangeEnd.value
|
|
661
|
-
}
|
|
662
701
|
const formatted = [
|
|
663
|
-
formatTimestamp(rangeStart.value),
|
|
664
|
-
formatTimestamp(rangeEnd.value)
|
|
702
|
+
formatTimestamp(rangeStart.value as number),
|
|
703
|
+
formatTimestamp(rangeEnd.value as number)
|
|
665
704
|
]
|
|
666
705
|
|
|
706
|
+
let emitValue: any = null
|
|
707
|
+
if (Array.isArray(selectedRangeValue.value)) {
|
|
708
|
+
emitValue = formatted
|
|
709
|
+
selectedRangeValue.value = formatted // 回显字符串数组
|
|
710
|
+
} else {
|
|
711
|
+
const rangeValue = {
|
|
712
|
+
start: rangeStart.value,
|
|
713
|
+
end: rangeEnd.value
|
|
714
|
+
}
|
|
715
|
+
emitValue = rangeValue
|
|
716
|
+
selectedRangeValue.value = rangeValue
|
|
717
|
+
}
|
|
718
|
+
|
|
667
719
|
// 触发关闭动画
|
|
668
720
|
showOverlay.value = false
|
|
669
721
|
// 等待动画完成后更新状态
|
|
670
722
|
setTimeout(() => {
|
|
671
723
|
rendered.value = false
|
|
672
724
|
visible.value = false
|
|
673
|
-
emit('confirmRange',
|
|
725
|
+
emit('confirmRange', emitValue, formatted)
|
|
674
726
|
}, 350)
|
|
675
727
|
}
|
|
676
728
|
} else {
|
|
@@ -32,12 +32,7 @@ export type TDateTimePickerDayItem = {
|
|
|
32
32
|
/**
|
|
33
33
|
* 日期范围值类型
|
|
34
34
|
*/
|
|
35
|
-
export type TDateTimePickerRangeValue =
|
|
36
|
-
/** 开始时间戳 */
|
|
37
|
-
start: number
|
|
38
|
-
/** 结束时间戳 */
|
|
39
|
-
end: number
|
|
40
|
-
}
|
|
35
|
+
export type TDateTimePickerRangeValue = any
|
|
41
36
|
|
|
42
37
|
/**
|
|
43
38
|
* TDateTimePicker 时间选择器组件属性类型定义
|
package/package.json
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
// 字体粗细
|
|
13
13
|
$font-weights: (
|
|
14
|
-
thin: 100, extralight: 200, light: 300, normal: 400,
|
|
15
|
-
medium: 500, semibold: 600, bold: 700, extrabold: 800, black: 900
|
|
14
|
+
"thin": 100, "extralight": 200, "light": 300, "normal": 400,
|
|
15
|
+
"medium": 500, "semibold": 600, "bold": 700, "extrabold": 800, "black": 900
|
|
16
16
|
);
|
|
17
17
|
@each $key, $val in $font-weights {
|
|
18
18
|
.font-#{$key} { font-weight: $val; }
|