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

View File

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