快捷选择日期
This commit is contained in:
parent
6abc588e4d
commit
bd1246782d
@ -81,10 +81,19 @@ const adminInfo = useAdminInfo()
|
||||
|
||||
const timeRange = ref([])
|
||||
const shortcuts = [
|
||||
{
|
||||
text: '今天',
|
||||
value: () => {
|
||||
const end = new Date()
|
||||
const start = new Date()
|
||||
return [start, end]
|
||||
},
|
||||
},
|
||||
{
|
||||
text: '昨天',
|
||||
value: () => {
|
||||
const end = new Date()
|
||||
end.setDate(end.getDate() - 1)
|
||||
const start = new Date()
|
||||
start.setDate(start.getDate() - 1)
|
||||
return [start, end]
|
||||
@ -95,26 +104,20 @@ const shortcuts = [
|
||||
value: () => {
|
||||
const end = new Date()
|
||||
const start = new Date()
|
||||
start.setDate(start.getDate() - 3)
|
||||
start.setDate(start.getDate() - 2)
|
||||
return [start, end]
|
||||
},
|
||||
},
|
||||
{
|
||||
text: '上周',
|
||||
text: '本周',
|
||||
value: () => {
|
||||
const end = new Date()
|
||||
const start = new Date()
|
||||
start.setDate(start.getDate() - 7)
|
||||
return [start, end]
|
||||
return getDateRange('week')
|
||||
},
|
||||
},
|
||||
{
|
||||
text: '上个月',
|
||||
text: '本月',
|
||||
value: () => {
|
||||
const end = new Date()
|
||||
const start = new Date()
|
||||
start.setMonth(start.getMonth() - 1)
|
||||
return [start, end]
|
||||
return getDateRange('month')
|
||||
},
|
||||
},
|
||||
]
|
||||
@ -201,25 +204,28 @@ const okSubmit = (val) => {
|
||||
console.log(val)
|
||||
getalarmsList()
|
||||
}
|
||||
const getTodayAndYesterday = () => {
|
||||
const getDateRange = (type: 'week' | 'month') => {
|
||||
const today = new Date()
|
||||
const yesterday = new Date()
|
||||
yesterday.setDate(today.getDate() - 1)
|
||||
const formatDate = (date) => {
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
if (type === 'week') {
|
||||
const dayOfWeek = today.getDay()
|
||||
const startOfWeek = new Date(today)
|
||||
startOfWeek.setDate(today.getDate() - dayOfWeek + (dayOfWeek === 0 ? -6 : 1))
|
||||
startOfWeek.setHours(0, 0, 0, 0)
|
||||
const endOfWeek = new Date(startOfWeek)
|
||||
endOfWeek.setDate(startOfWeek.getDate() + 6)
|
||||
endOfWeek.setHours(23, 59, 59, 999)
|
||||
return [startOfWeek, endOfWeek]
|
||||
}
|
||||
|
||||
return {
|
||||
today: formatDate(today),
|
||||
yesterday: formatDate(yesterday),
|
||||
if (type === 'month') {
|
||||
const startOfMonth = new Date(today.getFullYear(), today.getMonth(), 1)
|
||||
startOfMonth.setHours(0, 0, 0, 0)
|
||||
const endOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0)
|
||||
endOfMonth.setHours(23, 59, 59, 999)
|
||||
return [startOfMonth, endOfMonth]
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// timeRange[0] = getTodayAndYesterday().yesterday
|
||||
// timeRange[1] = getTodayAndYesterday().today
|
||||
equipList({
|
||||
// orgId: adminInfo.orgid,
|
||||
objectType: 10002,
|
||||
|
Loading…
Reference in New Issue
Block a user