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