sadais-piui 1.2.7-beta177 → 1.2.7-beta178
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 +23 -0
- package/context7.json +4 -0
- package/package.json +1 -1
|
@@ -571,6 +571,28 @@ export default {
|
|
|
571
571
|
handleDateChange(e) {
|
|
572
572
|
const values = e.detail.value // values 返回的数组固定是picker的数量,只返回有变化的索引值
|
|
573
573
|
const time = this.date.time // 取出当前date的实际时间
|
|
574
|
+
|
|
575
|
+
// 仅当年/月变化时才需要防溢出处理:预扫描收集意图年月
|
|
576
|
+
let intendedYear = time.getFullYear()
|
|
577
|
+
let intendedMonth = time.getMonth()
|
|
578
|
+
let yearMonthChanged = false
|
|
579
|
+
values.forEach((value, index) => {
|
|
580
|
+
if (value !== null && value !== -1) {
|
|
581
|
+
const col = this.columns[index]
|
|
582
|
+
if (col.field === 'year') { intendedYear = col.items[value]; yearMonthChanged = true }
|
|
583
|
+
if (col.field === 'month') { intendedMonth = col.items[value] - 1; yearMonthChanged = true }
|
|
584
|
+
}
|
|
585
|
+
})
|
|
586
|
+
|
|
587
|
+
// 预先将 day 限制在目标月份最大天数内,防止 setMonth 时 JS Date 自动溢出
|
|
588
|
+
let daysInIntendedMonth
|
|
589
|
+
if (yearMonthChanged) {
|
|
590
|
+
daysInIntendedMonth = new Date(intendedYear, intendedMonth + 1, 0).getDate()
|
|
591
|
+
if (time.getDate() > daysInIntendedMonth) {
|
|
592
|
+
time.setDate(daysInIntendedMonth)
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
574
596
|
values.forEach((value, index) => {
|
|
575
597
|
if (value !== null && value !== -1) {
|
|
576
598
|
// value为picker列的索引值
|
|
@@ -578,6 +600,7 @@ export default {
|
|
|
578
600
|
let val = col.items[value] // 取出对应picker值
|
|
579
601
|
if (col.field === 'month') val--
|
|
580
602
|
if (col.field === 'halfday') val = value === 0 ? 0 : 12
|
|
603
|
+
if (col.field === 'day' && yearMonthChanged) val = Math.min(val, daysInIntendedMonth)
|
|
581
604
|
time[col.setMethod](val) // 调用原生date方法赋值
|
|
582
605
|
}
|
|
583
606
|
})
|
package/context7.json
ADDED