This commit is contained in:
‘937886381’
2025-12-17 16:26:21 +08:00
parent 484ba6ca53
commit c86d94ac92
16 changed files with 9326 additions and 8961 deletions

View File

@@ -150,7 +150,8 @@ export default {
startPlaceholder: '开始时间',
endPlaceholder: '结束时间',
param: 'timeVal',
width: 350
width: 350,
defaultSelect: [],
},
{
type: 'button',
@@ -226,11 +227,56 @@ export default {
// deep: true
// },
// },
created() {
mounted() {
const { startTimestamp, endTimestamp } = this.getThreeDaysAgoThisTimeToNowTimeStamps();
// 找到时间范围的配置项并赋值对应你代码中的timeVal参数
this.searchBarFormConfig[2].defaultSelect = [startTimestamp, endTimestamp]; // 赋值给日期选择器
this.queryParams.startTime = startTimestamp;
this.queryParams.endTime = endTimestamp;
this.getList();
this.getDict()
},
methods: {
getThreeDaysAgoThisTimeToNowTimeStamps() {
const now = new Date();
// 1. 计算三天前的当前时刻使用setDate直接修改日期保留时分秒等信息
const threeDaysAgoThisTime = new Date(now); // 复制当前日期对象,避免修改原对象
threeDaysAgoThisTime.setDate(threeDaysAgoThisTime.getDate() - 3); // 日期减3天时分秒保持和当前一致
// 2. 获取时间戳(毫秒级和秒级)
// 开始时间戳:三天前的当前时刻
const startTimestamp = threeDaysAgoThisTime.getTime(); // 毫秒级
const startTimestampSec = Math.floor(startTimestamp / 1000); // 秒级
// 结束时间戳:当前时刻
const endTimestamp = now.getTime(); // 毫秒级
const endTimestampSec = Math.floor(endTimestamp / 1000); // 秒级
// 封装日期格式化函数转换为yyyy-MM-dd HH:mm:ss格式
const formatDateTime = (date) => {
const y = date.getFullYear();
// 月份是从0开始的所以要+1补零确保是两位
const m = String(date.getMonth() + 1).padStart(2, '0');
const d = String(date.getDate()).padStart(2, '0');
const h = String(date.getHours()).padStart(2, '0');
const min = String(date.getMinutes()).padStart(2, '0');
const s = String(date.getSeconds()).padStart(2, '0');
return `${y}-${m}-${d} ${h}:${min}:${s}`;
};
// 格式化后的字符串:三天前的当前时刻 和 当前时刻
const startDateTimeStr = formatDateTime(threeDaysAgoThisTime);
const endDateTimeStr = formatDateTime(now);
return {
startTimestamp, // 三天前当前时刻的毫秒级时间戳
endTimestamp, // 当前时刻的毫秒级时间戳
startTimestampSec, // 三天前当前时刻的秒级时间戳
endTimestampSec, // 当前时刻的秒级时间戳
startDateTimeStr, // yyyy-MM-dd HH:mm:ss格式的开始时间字符串
endDateTimeStr // yyyy-MM-dd HH:mm:ss格式的结束时间字符串
};
},
getDict() {
getPdList().then(res => {
this.searchBarFormConfig[1].selectOptions = res.data || [];