优化:查询页面平滑切换与默认月份高亮
This commit is contained in:
@@ -3,6 +3,18 @@ export function previousCompleteMonth(reference = new Date()): { year: number; m
|
||||
return { year: previous.getFullYear(), month: previous.getMonth() + 1 };
|
||||
}
|
||||
|
||||
export function defaultQueryMonth(options?: { periods?: string[]; latestDataPeriod?: { year?: number; month?: number } } | null, reference = new Date()): { year: number; month: number } {
|
||||
const previous = previousCompleteMonth(reference);
|
||||
const key = `${previous.year}-${String(previous.month).padStart(2, '0')}`;
|
||||
const latest = options?.latestDataPeriod;
|
||||
const latestKey = latest?.year && latest.month && latest.month >= 1 && latest.month <= 12
|
||||
? `${latest.year}-${String(latest.month).padStart(2, '0')}` : undefined;
|
||||
const previousMissing = Array.isArray(options?.periods)
|
||||
? !options.periods.includes(key) : latestKey != null && latestKey < key;
|
||||
// 只按已发布月份判断;筛选结果为空不会改动用户选定的月份。
|
||||
return previousMissing ? previousCompleteMonth(new Date(previous.year, previous.month - 1, 1)) : previous;
|
||||
}
|
||||
|
||||
export function previousCompleteQuarter(reference = new Date()): { year: number; quarter: number } {
|
||||
const firstMonthOfCurrentQuarter = Math.floor(reference.getMonth() / 3) * 3;
|
||||
const previousQuarterEnd = new Date(reference.getFullYear(), firstMonthOfCurrentQuarter, 0);
|
||||
|
||||
Reference in New Issue
Block a user