微调时间控件
This commit is contained in:
@@ -140,16 +140,38 @@ const updateDateRange = () => {
|
||||
endDate.value = getEndOfWeek(today.value)
|
||||
console.log(endDate.value.toLocaleDateString())
|
||||
} else if (timeUnit.value === '月') {
|
||||
startDate.value = new Date(today.value.getFullYear(), today.value.getMonth(), 1)
|
||||
endDate.value = new Date(today.value.getFullYear(), today.value.getMonth() + 1, 0)
|
||||
} else if (timeUnit.value === '季度') {
|
||||
const quarter = Math.floor(today.value.getMonth() / 3)
|
||||
startDate.value = new Date(today.value.getFullYear(), quarter * 3, 1)
|
||||
endDate.value = new Date(today.value.getFullYear(), quarter * 3 + 3, 0)
|
||||
} else if (timeUnit.value === '年') {
|
||||
startDate.value = new Date(today.value.getFullYear(), 0, 1)
|
||||
endDate.value = new Date(today.value.getFullYear(), 11, 31)
|
||||
// 获取本月的开始和结束日期
|
||||
startDate.value = new Date(today.value.getFullYear(), today.value.getMonth(), 1);
|
||||
endDate.value = new Date(today.value.getFullYear(), today.value.getMonth() + 1, 0);
|
||||
|
||||
// 确保结束日期不超过今天
|
||||
if (endDate.value > today.value) {
|
||||
endDate.value = new Date(today.value);
|
||||
endDate.value.setHours(23, 59, 59, 999); // 设置结束时间为今天的23:59:59.999
|
||||
}
|
||||
|
||||
} else if (timeUnit.value === '季度') {
|
||||
const quarter = Math.floor(today.value.getMonth() / 3);
|
||||
startDate.value = new Date(today.value.getFullYear(), quarter * 3, 1);
|
||||
endDate.value = new Date(today.value.getFullYear(), quarter * 3 + 3, 0);
|
||||
|
||||
// 确保结束日期不超过今天
|
||||
if (endDate.value > today.value) {
|
||||
endDate.value = new Date(today.value);
|
||||
endDate.value.setHours(23, 59, 59, 999); // 设置结束时间为今天的23:59:59.999
|
||||
}
|
||||
|
||||
} else if (timeUnit.value === '年') {
|
||||
startDate.value = new Date(today.value.getFullYear(), 0, 1);
|
||||
endDate.value = new Date(today.value.getFullYear(), 11, 31);
|
||||
|
||||
// 确保结束日期不超过今天
|
||||
if (endDate.value > today.value) {
|
||||
endDate.value = new Date(today.value);
|
||||
endDate.value.setHours(23, 59, 59, 999); // 设置结束时间为今天的23:59:59.999
|
||||
}
|
||||
}
|
||||
|
||||
updateNextButtonStatus()
|
||||
}
|
||||
const getStartOfWeek = (date: Date) => {
|
||||
@@ -164,7 +186,14 @@ const getEndOfWeek = (date: Date) => {
|
||||
const day = endOfWeek.getDay()
|
||||
const diff = day === 0 ? 0 : 7 - day // 星期天的情况
|
||||
endOfWeek.setDate(endOfWeek.getDate() + diff)
|
||||
return endOfWeek
|
||||
|
||||
// 获取今天的日期
|
||||
const today = new Date();
|
||||
today.setHours(23, 59, 59, 999); // 设置今天的结束时间(23:59:59.999)
|
||||
|
||||
// 返回不超过今天的结束时间
|
||||
return endOfWeek > today ? today : endOfWeek;
|
||||
//return endOfWeek
|
||||
}
|
||||
const prevPeriod = () => {
|
||||
const prevStartDate = new Date(startDate.value)
|
||||
|
||||
@@ -106,7 +106,7 @@ const columns = reactive<ColumnProps<Device.ResPqDev>[]>([
|
||||
return (
|
||||
<div class='flx-flex-start'>
|
||||
<TimeControl
|
||||
include={['日', '周', '月', '自定义']}
|
||||
include={['日', '周', '月', '季度','年','自定义']}
|
||||
default={'月'}
|
||||
onUpdate-dates={handleDateChange}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user