-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(DatePicker): add utils (#2950)
* fix(Menu): fix submenu classname * fix(Tab): fix tab className effect tab item * chore(datepicker): add utils
- Loading branch information
Showing
3 changed files
with
64 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 用于头部日期切换修正 | ||
export function dateCorrection(partialIndex: number, preYear: Array<number>, preMonth: Array<number>, onlyYearSelect) { | ||
let nextYear = preYear; | ||
const nextMonth = preMonth; | ||
if (partialIndex === 0) { | ||
if (nextYear[1] <= nextYear[0]) { | ||
if (onlyYearSelect) nextYear[1] = nextYear[0] + 1; | ||
else { | ||
// eslint-disable-next-line prefer-destructuring | ||
nextYear[1] = nextYear[0]; | ||
if (nextMonth[1] <= nextMonth[0]) { | ||
nextMonth[1] = nextMonth[0] + 1; | ||
if (nextMonth[1] === 12) { | ||
// 处理跨年的边界场景 | ||
nextMonth[1] = 0; | ||
nextYear = [nextYear[0], nextYear[1] + 1]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// 保证左侧时间不大于右侧 | ||
if (partialIndex === 1) { | ||
if (nextYear[0] >= nextYear[1]) { | ||
// 年/季度/月份场景下,头部只有年选择器,直接 - 1 | ||
if (onlyYearSelect) nextYear[0] = nextYear[1] - 1; | ||
else { | ||
// eslint-disable-next-line prefer-destructuring | ||
nextYear[0] = nextYear[1]; | ||
if (nextMonth[0] >= nextMonth[1]) { | ||
nextMonth[0] = nextMonth[1] - 1; | ||
if (nextMonth[0] === -1) { | ||
// 处理跨年的边界场景 | ||
nextMonth[0] = 11; | ||
nextYear = [nextYear[0] - 1, nextYear[1]]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return { nextYear, nextMonth }; | ||
} |