![](https://i-blog.csdnimg.cn/blog_migrate/e07dd128a024397bf0d6430f12b5d6f5.png)
<div style="display: flex; justify-content: space-between">
<a-radio-group default-value="today" @change="timeChange">
<a-radio-button value="today">今日</a-radio-button>
<a-radio-button value="week">近一周 </a-radio-button>
<a-radio-button value="month">近一月 </a-radio-button>
</a-radio-group>
<a-range-picker
:show-time="{ format: 'HH:mm' }"
format="YYYY-MM-DD HH:mm"
v-model="time"
/>
</div>
// 时间切换
timeChange(e) {
const timer = e?.nativeEvent?.target?._value || e;
let getNowDate = new Date();
let time1;
switch (timer) {
case "today":
time1 = new Date();
time1.setHours(0);
time1.setMinutes(0);
time1.setSeconds(0);
this.time = [timeFormat(time1), timeFormat(getNowDate)];
return;
case "week":
time1 = new Date(getNowDate - 7 * 24 * 3600 * 1000);
this.time = [timeFormat(time1), timeFormat(getNowDate)];
return;
case "month":
time1 = new Date(Date.parse(getNowDate));
time1.setMonth(time1.getMonth() - 1);
var thirtyYear = time1.getFullYear();
var thirtyMonth = time1.getMonth() + 1;
var thirtyDay = time1.getDate();
if (thirtyMonth >= 1 && thirtyMonth <= 9) {
thirtyMonth = "0" + thirtyMonth;
}
if (thirtyDay >= 1 && thirtyDay <= 9) {
thirtyDay = "0" + thirtyDay;
}
this.time = [
timeFormat(thirtyYear + "-" + thirtyMonth + "-" + thirtyDay),
timeFormat(getNowDate),
];
return;
}
},