fix: dayjs替换moment

This commit is contained in:
leiqiaochu 2023-03-21 16:14:16 +08:00
parent cc879c1731
commit 4c58bf1c31
9 changed files with 47 additions and 50 deletions

View File

@ -28,7 +28,7 @@
</template>
<script setup lang="ts">
import moment from 'moment';
import dayjs from 'dayjs';
import { PropType } from 'vue';
interface BtnOptions {
@ -70,8 +70,8 @@ const rangeVal = ref<[string, string]>();
const rangeChange = (val: any) => {
radioValue.value = undefined;
emit('change', {
start: moment(val[0]).valueOf(),
end: moment(val[1]).valueOf(),
start: dayjs(val[0]).valueOf(),
end: dayjs(val[1]).valueOf(),
type: undefined,
});
};
@ -79,29 +79,29 @@ const rangeChange = (val: any) => {
const getTimeByType = (type: string) => {
switch (type) {
case 'hour':
return moment().subtract(1, 'hours').valueOf();
return dayjs().subtract(1, 'hours').valueOf();
case 'week':
return moment().subtract(6, 'days').valueOf();
return dayjs().subtract(6, 'days').valueOf();
case 'month':
return moment().subtract(29, 'days').valueOf();
return dayjs().subtract(29, 'days').valueOf();
case 'year':
return moment().subtract(365, 'days').valueOf();
return dayjs().subtract(365, 'days').valueOf();
default:
return moment().startOf('day').valueOf();
return dayjs().startOf('day').valueOf();
}
};
const handleBtnChange = (val: string) => {
radioValue.value = val;
let endTime = moment(new Date()).valueOf();
let endTime = dayjs(new Date()).valueOf();
let startTime = getTimeByType(val);
if (val === 'yesterday') {
startTime = moment().subtract(1, 'days').startOf('day').valueOf();
endTime = moment().subtract(1, 'days').endOf('day').valueOf();
startTime = dayjs().subtract(1, 'days').startOf('day').valueOf();
endTime = dayjs().subtract(1, 'days').endOf('day').valueOf();
}
rangeVal.value = [
moment(startTime).format('YYYY-MM-DD HH:mm:ss'),
moment(endTime).format('YYYY-MM-DD HH:mm:ss'),
dayjs(startTime).format('YYYY-MM-DD HH:mm:ss'),
dayjs(endTime).format('YYYY-MM-DD HH:mm:ss'),
];
emit('change', {
start: startTime,
@ -110,8 +110,5 @@ const handleBtnChange = (val: string) => {
});
};
handleBtnChange(radioValue.value);
watch(
() => radioValue.value,
{ deep: true, immediate: true },
);
watch(() => radioValue.value, { deep: true, immediate: true });
</script>

View File

@ -29,12 +29,12 @@
}}</j-button>
</j-descriptions-item>
<j-descriptions-item label="创建时间">{{
moment(productStore.current.createTime).format(
dayjs(productStore.current.createTime).format(
'YYYY-MM-DD HH:mm:ss',
)
}}</j-descriptions-item>
<j-descriptions-item label="更新时间">{{
moment(productStore.current.modifyTime).format(
dayjs(productStore.current.modifyTime).format(
'YYYY-MM-DD HH:mm:ss',
)
}}</j-descriptions-item>
@ -51,7 +51,7 @@
<script lang="ts" setup>
import { useProductStore } from '@/store/product';
import Save from '../../Save/index.vue';
import moment from 'moment';
import dayjs from 'dayjs';
import { useRoute } from 'vue-router';
const productStore = useProductStore();
const route = useRoute();

View File

@ -16,7 +16,7 @@
}"
>
<template #alarmTime="slotProps">{{
moment(slotProps.alarmTime).format('YYYY-MM-DD HH:mm:ss')
dayjs(slotProps.alarmTime).format('YYYY-MM-DD HH:mm:ss')
}}</template>
<template #action="slotProps">
<j-space
@ -47,7 +47,7 @@
<script lang="ts" setup>
import { detail, queryHistoryList } from '@/api/rule-engine/log';
import { useRoute } from 'vue-router';
import moment from 'moment';
import dayjs from 'dayjs';
import type { ActionsType } from '@/components/Table/index.vue';
import { message } from 'jetlinks-ui-components';
import { useAlarmStore } from '@/store/alarm';

View File

@ -7,7 +7,7 @@
props.data?.alarmConfigName
}}</j-descriptions-item>
<j-descriptions-item label="告警时间" :span="1">{{
moment(data?.alarmTime).format('YYYY-MM-DD HH:mm:ss')
dayjs(data?.alarmTime).format('YYYY-MM-DD HH:mm:ss')
}}</j-descriptions-item>
<j-descriptions-item label="告警级别" :span="1">
<j-tooltip
@ -44,7 +44,7 @@
</template>
<script lang="ts" setup>
import moment from 'moment';
import dayjs from 'dayjs';
import { Store } from 'jetlinks-store';
import JsonViewer from 'vue-json-viewer';
const props = defineProps({

View File

@ -29,7 +29,7 @@
<template #handleTime="slotsProps">
<span>
{{
moment(slotsProps.handleTime).format(
dayjs(slotsProps.handleTime).format(
'YYYY-MM-DD HH:mm:ss'
)
}}
@ -41,7 +41,7 @@
<template #alarmTime="slotProps">
<span>
{{
moment(slotProps.alarmTime).format(
dayjs(slotProps.alarmTime).format(
'YYYY-MM-DD HH:mm:ss',
)
}}
@ -53,7 +53,7 @@
<script lang="ts" setup>
import { queryHandleHistory } from '@/api/rule-engine/log';
import moment from 'moment';
import dayjs from 'dayjs';
const props = defineProps({
data: {
type: Object,

View File

@ -79,7 +79,7 @@
<Ellipsis
><div>
{{
moment(slotProps?.alarmTime).format(
dayjs(slotProps?.alarmTime).format(
'YYYY-MM-DD HH:mm:ss',
)
}}
@ -157,7 +157,7 @@ import Search from '@/components/Search';
import { useAlarmStore } from '@/store/alarm';
import { storeToRefs } from 'pinia';
import { Store } from 'jetlinks-store';
import moment from 'moment';
import dayjs from 'dayjs';
import type { ActionsType } from '@/components/Table';
import SolveComponent from '../SolveComponent/index.vue';
import SolveLog from '../SolveLog/index.vue';

View File

@ -10,7 +10,7 @@
:src="getImage('/alarm/bashboard.png')"
alt=""
/>{{
moment(item.alarmTime).format(
dayjs(item.alarmTime).format(
'YYYY-MM-DD HH:mm:ss',
)
}}
@ -64,7 +64,7 @@
import { Empty } from 'jetlinks-ui-components';
import { getImage } from '@/utils/comm';
import { useMenuStore } from '@/store/menu';
import moment from 'moment';
import dayjs from 'dayjs';
const props = defineProps({
alarmList: {
type: Array,

View File

@ -28,7 +28,7 @@
</template>
<script setup lang="ts">
import moment from 'moment';
import dayjs from 'dayjs';
import { PropType } from 'vue';
interface BtnOptions {
@ -70,8 +70,8 @@ const rangeVal = ref<[string, string]>();
const rangeChange = (val: any) => {
radioValue.value = undefined;
emit('change', {
start: moment(val[0]).valueOf(),
end: moment(val[1]).valueOf(),
start: dayjs(val[0]).valueOf(),
end: dayjs(val[1]).valueOf(),
type: undefined,
});
};
@ -79,29 +79,29 @@ const rangeChange = (val: any) => {
const getTimeByType = (type: string) => {
switch (type) {
case 'hour':
return moment().subtract(1, 'hours').valueOf();
return dayjs().subtract(1, 'hours').valueOf();
case 'week':
return moment().subtract(6, 'days').valueOf();
return dayjs().subtract(6, 'days').valueOf();
case 'month':
return moment().subtract(29, 'days').valueOf();
return dayjs().subtract(29, 'days').valueOf();
case 'year':
return moment().subtract(365, 'days').valueOf();
return dayjs().subtract(365, 'days').valueOf();
default:
return moment().startOf('day').valueOf();
return dayjs().startOf('day').valueOf();
}
};
const handleBtnChange = (val: string) => {
radioValue.value = val;
let endTime = moment(new Date()).valueOf();
let endTime = dayjs(new Date()).valueOf();
let startTime = getTimeByType(val);
if (val === 'yesterday') {
startTime = moment().subtract(1, 'days').startOf('day').valueOf();
endTime = moment().subtract(1, 'days').endOf('day').valueOf();
startTime = dayjs().subtract(1, 'days').startOf('day').valueOf();
endTime = dayjs().subtract(1, 'days').endOf('day').valueOf();
}
rangeVal.value = [
moment(startTime).format('YYYY-MM-DD HH:mm:ss'),
moment(endTime).format('YYYY-MM-DD HH:mm:ss'),
dayjs(startTime).format('YYYY-MM-DD HH:mm:ss'),
dayjs(endTime).format('YYYY-MM-DD HH:mm:ss'),
];
emit('change', {
start: startTime,

View File

@ -92,7 +92,7 @@ import {
getAlarmConfigCount,
getAlarmLevel,
} from '@/api/rule-engine/dashboard';
import moment from 'moment';
import dayjs from 'dayjs';
let currentMonAlarm = ref<Footer[]>([
{
title: '当月告警',
@ -169,7 +169,7 @@ const today = {
time: '1d',
// targetType: 'device',
format: 'HH:mm:ss',
from: moment(new Date(new Date().setHours(0, 0, 0, 0))).format(
from: dayjs(new Date(new Date().setHours(0, 0, 0, 0))).format(
'YYYY-MM-DD HH:mm:ss',
),
to: 'now',
@ -353,8 +353,8 @@ const selectChange = () => {
// to: 'now',
limit: limit, // 12
// time: params.time.type === 'today' ? '1h' : '1d',
from: moment(queryCodition.startTime).format('YYYY-MM-DD HH:mm:ss'),
to: moment(queryCodition.endTime).format('YYYY-MM-DD HH:mm:ss'),
from: dayjs(queryCodition.startTime).format('YYYY-MM-DD HH:mm:ss'),
to: dayjs(queryCodition.endTime).format('YYYY-MM-DD HH:mm:ss'),
// limit: 30,
},
};
@ -370,8 +370,8 @@ const selectChange = () => {
// time: '1h',
time: time,
targetType: queryCodition.targetType,
from: moment(queryCodition.startTime).format('YYYY-MM-DD HH:mm:ss'),
to: moment(queryCodition.endTime).format('YYYY-MM-DD HH:mm:ss'),
from: dayjs(queryCodition.startTime).format('YYYY-MM-DD HH:mm:ss'),
to: dayjs(queryCodition.endTime).format('YYYY-MM-DD HH:mm:ss'),
limit: 9,
},
};