公共时间修改

This commit is contained in:
stt
2025-12-03 16:30:42 +08:00
parent 5db43cd4b1
commit 0518127792
3 changed files with 60 additions and 35 deletions

View File

@@ -361,21 +361,32 @@ export function getTimeOfTheMonth(key: any): [string, string] {
throw new Error('Invalid key')
}
}
/**
* 获取当月时间
* @param timeKey 组件外部时间 1 年 2 季 3 月 4 周 5 日
* @param timeList 组件勾选时间 []
* @param fullScreen 是否全屏 true 是 false 否
* @param interval 组件外部时间 1 年 2 季 3 月 4 周 5 日
* @param timeList 组件勾选时间 []
* @param externalTime //外部传入时间
*/
export function getTime(timeKey: number, timeList: any[], fullScreen: boolean, externalTime: any[]) {
export function getTime(interval: number, timeList: any, externalTime: any) {
// 1、先匹配时间
// if(匹配上){
// 是全屏 返回缓存值
// 不是全屏返回外部传入时间 externalTime
// }else{
// 返回 getTimeOfTheMonth(timeList.at(-1))
// }
}
// 检查 interval 是否在 timeList 中
if (timeList && timeList.includes(interval.toString())) {
// 匹配上了,返回外部传入时间 externalTime
if (externalTime && externalTime.length >= 2) {
return [externalTime[0], externalTime[1]]
} else {
// 如果 externalTime 无效,回退到默认逻辑
return getTimeOfTheMonth(interval.toString())
}
} else {
// 没有匹配上,返回 timeList 中最后一项的时间范围
if (timeList && timeList.length > 0) {
const lastItem = timeList[timeList.length - 1]
return getTimeOfTheMonth(lastItem)
} else {
// 如果 timeList 为空,使用 interval 参数
return getTimeOfTheMonth(interval.toString())
}
}
}