refactor: formatDuration & filterLostRecordList

This commit is contained in:
yangsy
2025-09-16 15:39:48 +08:00
parent df8c7ee8b3
commit b28e59049f
4 changed files with 86 additions and 135 deletions

View File

@@ -1,32 +1,7 @@
<script lang="ts">
const formatDuration = (time: number) => {
if (time < 1) {
return '';
}
const d = Math.floor(time / 86400);
const h = Math.floor((time % 86400) / 3600);
const m = Math.floor((time % 3600) / 60);
const s = Math.floor(time % 60);
let result = '';
if (d > 0) {
result += `${d}`;
}
if (h > 0) {
result += `${h}小时`;
}
if (m > 0) {
result += `${m}分钟`;
}
if (s > 0) {
result += `${s}`;
}
return result;
};
</script>
<script setup lang="ts">
import type { NdmDeviceResultVO, NdmIcmpLogResultVO, NdmIcmpLogVO, PageParams, PageResult } from '@/apis/models';
import { postIcmpLogPage } from '@/apis/requests';
import { formatDuration } from '@/utils/format-duration';
import { useMutation } from '@tanstack/vue-query';
import dayjs from 'dayjs';
import { NCard, NPagination, NScrollbar, NTimeline, NTimelineItem, type DatePickerProps, type PaginationProps, type TimelineItemProps } from 'naive-ui';
@@ -113,8 +88,7 @@ const timelineItems = computed<TimelineItemProps[]>(() => {
const { deviceStatus, createdTime } = icmpLog;
const type: TimelineItemProps['type'] = deviceStatus === '10' ? 'success' : deviceStatus === '20' ? 'error' : 'warning';
const title = deviceStatus === '10' ? '在线' : deviceStatus === '20' ? '离线' : '未知';
const duration = prevIcmpLog ? dayjs(prevIcmpLog.createdTime).diff(dayjs(createdTime), 'second') : undefined;
const content = `持续时长:${duration ? formatDuration(duration) : '至今'}`;
const content = `持续时长:${prevIcmpLog ? formatDuration(createdTime, prevIcmpLog.createdTime) : '至今'}`;
const time = createdTime;
items.push({
type,