sadais-piui 1.2.7-beta177 → 1.2.7-beta179
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/components/pi-date-picker/index.vue +39 -8
- package/context7.json +4 -0
- package/package.json +1 -1
|
@@ -249,13 +249,16 @@ export default {
|
|
|
249
249
|
}
|
|
250
250
|
return {
|
|
251
251
|
date,
|
|
252
|
-
|
|
252
|
+
scrollingCount: 0 // picker滚动中的列数,用计数器替代boolean,支持多列并发滚动
|
|
253
253
|
}
|
|
254
254
|
},
|
|
255
255
|
computed: {
|
|
256
256
|
getPopupSelect() {
|
|
257
257
|
return this.$pi.lang.mergeDeep(datePicker.popupSelect, this.popupSelect)
|
|
258
258
|
},
|
|
259
|
+
scrolling() {
|
|
260
|
+
return this.scrollingCount > 0
|
|
261
|
+
},
|
|
259
262
|
getConfirmBtn() {
|
|
260
263
|
const datePickerConfirmBtn = this.$pi.lang.mergeDeep(
|
|
261
264
|
datePicker.confirmBtn,
|
|
@@ -522,7 +525,8 @@ export default {
|
|
|
522
525
|
} else {
|
|
523
526
|
const intValue = parseInt(value, 10)
|
|
524
527
|
const val = col.items.findIndex(m => m === intValue)
|
|
525
|
-
|
|
528
|
+
// findIndex 返回 -1 说明当前值不在选项中(如月份变更后日期越界),回退到最后一个有效值
|
|
529
|
+
pickerValue.push(val === -1 ? col.items.length - 1 : val)
|
|
526
530
|
}
|
|
527
531
|
}
|
|
528
532
|
})
|
|
@@ -556,11 +560,11 @@ export default {
|
|
|
556
560
|
})
|
|
557
561
|
},
|
|
558
562
|
handlePickstart() {
|
|
559
|
-
this.
|
|
563
|
+
this.scrollingCount++
|
|
560
564
|
},
|
|
561
565
|
// 标识滑动结束
|
|
562
566
|
handlePickend() {
|
|
563
|
-
this.
|
|
567
|
+
this.scrollingCount = Math.max(0, this.scrollingCount - 1)
|
|
564
568
|
},
|
|
565
569
|
handlePopupClose() {
|
|
566
570
|
this.val = false
|
|
@@ -570,14 +574,41 @@ export default {
|
|
|
570
574
|
},
|
|
571
575
|
handleDateChange(e) {
|
|
572
576
|
const values = e.detail.value // values 返回的数组固定是picker的数量,只返回有变化的索引值
|
|
573
|
-
|
|
577
|
+
// 克隆 Date 对象,避免直接修改原引用导致 parsedMaxDate/parsedMinDate 被污染
|
|
578
|
+
const time = new Date(this.date.time.getTime())
|
|
579
|
+
|
|
580
|
+
// 仅当年/月变化时才需要防溢出处理:预扫描收集意图年月
|
|
581
|
+
let intendedYear = time.getFullYear()
|
|
582
|
+
let intendedMonth = time.getMonth()
|
|
583
|
+
let yearMonthChanged = false
|
|
584
|
+
values.forEach((value, index) => {
|
|
585
|
+
if (value !== null && value !== -1) {
|
|
586
|
+
const col = this.columns[index]
|
|
587
|
+
if (col.field === 'year') { intendedYear = col.items[value]; yearMonthChanged = true }
|
|
588
|
+
if (col.field === 'month') { intendedMonth = col.items[value] - 1; yearMonthChanged = true }
|
|
589
|
+
}
|
|
590
|
+
})
|
|
591
|
+
|
|
592
|
+
// 预先将 day 限制在目标月份最大天数内,防止 setMonth 时 JS Date 自动溢出
|
|
593
|
+
let daysInIntendedMonth
|
|
594
|
+
if (yearMonthChanged) {
|
|
595
|
+
daysInIntendedMonth = new Date(intendedYear, intendedMonth + 1, 0).getDate()
|
|
596
|
+
if (time.getDate() > daysInIntendedMonth) {
|
|
597
|
+
time.setDate(daysInIntendedMonth)
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
574
601
|
values.forEach((value, index) => {
|
|
575
602
|
if (value !== null && value !== -1) {
|
|
576
603
|
// value为picker列的索引值
|
|
577
604
|
const col = this.columns[index]
|
|
578
|
-
|
|
605
|
+
if (!col || !col.items || col.items.length === 0) return
|
|
606
|
+
// 并发滚动时,月份变更会导致日期列选项重渲染,事件中的 index 可能越界
|
|
607
|
+
const safeIndex = Math.max(0, Math.min(value, col.items.length - 1))
|
|
608
|
+
let val = col.items[safeIndex] // 取出对应picker值
|
|
579
609
|
if (col.field === 'month') val--
|
|
580
610
|
if (col.field === 'halfday') val = value === 0 ? 0 : 12
|
|
611
|
+
if (col.field === 'day' && yearMonthChanged) val = Math.min(val, daysInIntendedMonth)
|
|
581
612
|
time[col.setMethod](val) // 调用原生date方法赋值
|
|
582
613
|
}
|
|
583
614
|
})
|
|
@@ -596,12 +627,12 @@ export default {
|
|
|
596
627
|
let needUpdate = false
|
|
597
628
|
// 校正最小日期
|
|
598
629
|
if (this.parsedMinDate && time < this.parsedMinDate.time) {
|
|
599
|
-
this.date = this.$pi.date.parseDate(this.parsedMinDate.time)
|
|
630
|
+
this.date = this.$pi.date.parseDate(new Date(this.parsedMinDate.time.getTime()))
|
|
600
631
|
needUpdate = true
|
|
601
632
|
}
|
|
602
633
|
// 校正最大日期
|
|
603
634
|
if (this.parsedMaxDate && time > this.parsedMaxDate.time) {
|
|
604
|
-
this.date = this.$pi.date.parseDate(this.parsedMaxDate.time)
|
|
635
|
+
this.date = this.$pi.date.parseDate(new Date(this.parsedMaxDate.time.getTime()))
|
|
605
636
|
needUpdate = true
|
|
606
637
|
}
|
|
607
638
|
return needUpdate
|
package/context7.json
ADDED