fix: bug#11004

This commit is contained in:
jackhoo_98 2023-03-27 20:33:27 +08:00
parent 5f5b3e5b41
commit 4a561741c8
2 changed files with 17 additions and 20 deletions

View File

@ -21,7 +21,7 @@
:allowClear="false" :allowClear="false"
:show-time="{ format: 'HH:mm:ss' }" :show-time="{ format: 'HH:mm:ss' }"
format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"
v-model="data.time" v-model:value="data.time.time"
@change="pickerTimeChange" @change="pickerTimeChange"
> >
<template #suffixIcon <template #suffixIcon
@ -39,24 +39,18 @@
import { dashboard } from '@/api/data-collect/dashboard'; import { dashboard } from '@/api/data-collect/dashboard';
import { getTimeByType, pointParams, pointOptionsSeries } from '../tool.ts'; import { getTimeByType, pointParams, pointOptionsSeries } from '../tool.ts';
import * as echarts from 'echarts'; import * as echarts from 'echarts';
import { Dayjs } from 'dayjs'; import dayjs from 'dayjs';
const chartRef = ref<Record<string, any>>({}); const chartRef = ref<Record<string, any>>({});
const loading = ref(false); const loading = ref(false);
const data = ref({ const data: any = ref({
time: { time: {
type: 'hour', type: 'hour',
end: 0, time: [null, null],
start: 0,
}, },
}); });
const pickerTimeChange = ( const pickerTimeChange = () => {
value: [Dayjs, Dayjs],
dateString: [string, string],
) => {
data.value.time.start = Date.parse(dateString[0]);
data.value.time.end = Date.parse(dateString[1]);
data.value.time.type = undefined; data.value.time.type = undefined;
}; };
@ -114,8 +108,8 @@ const handleOptions = (x = [], y = []) => {
watch( watch(
() => data.value.time.type, () => data.value.time.type,
(value) => { (value) => {
data.value.time.end = Date.parse(Date()); const date = getTimeByType(value);
data.value.time.start = Date.parse(getTimeByType(value)); data.value.time.time = [dayjs(date), dayjs(new Date())];
}, },
{ immediate: true, deep: true }, { immediate: true, deep: true },
); );
@ -123,7 +117,7 @@ watch(
() => data.value, () => data.value,
(value) => { (value) => {
const { time } = value; const { time } = value;
if (time.type || (time.end && time.start)) { if (time.type || (time.time[0] && time.time[1])) {
getEcharts(value); getEcharts(value);
} }
}, },

View File

@ -1,4 +1,5 @@
import moment from 'moment'; import dayjs from 'dayjs';
import dayjs from 'dayjs';
const getParams = (dt: any) => { const getParams = (dt: any) => {
switch (dt.type) { switch (dt.type) {
@ -21,6 +22,8 @@ const getParams = (dt: any) => {
format: 'HH:mm', format: 'HH:mm',
}; };
default: default:
console.log(22, dt, dayjs(dt.time[0]));
const time = dt.end - dt.start; const time = dt.end - dt.start;
const hour = 60 * 60 * 1000; const hour = 60 * 60 * 1000;
const days = hour * 24; const days = hour * 24;
@ -56,15 +59,15 @@ const getParams = (dt: any) => {
export const getTimeByType = (type: string) => { export const getTimeByType = (type: string) => {
switch (type) { switch (type) {
case 'hour': case 'hour':
return moment().subtract(1, 'hours'); return dayjs().subtract(1, 'hours');
case 'week': case 'week':
return moment().subtract(6, 'days'); return dayjs().subtract(6, 'days');
case 'month': case 'month':
return moment().subtract(29, 'days'); return dayjs().subtract(29, 'days');
case 'year': case 'year':
return moment().subtract(365, 'days'); return dayjs().subtract(365, 'days');
default: default:
return moment().startOf('day'); return dayjs().startOf('day');
} }
}; };