main
vue 48 lines 1.25 KB
Raw
1 <template>
2 <n-timeline>
3 <n-timeline-item
4 v-for="(item, $index) of history"
5 :key="item.label"
6 :type="$index === 0 ? 'success' : undefined"
7 :title="item.label"
8 :time="item.timeString"
9 :line-type="$index === history.length - 2 ? 'dashed' : undefined"
10 />
11 </n-timeline>
12 </template>
13
14 <script setup lang="ts">
15 import type { SocCaseExt } from "@/types/soc/case.d"
16 import _toNumber from "lodash/toSafeInteger"
17 import { NTimeline, NTimelineItem } from "naive-ui"
18 import { onBeforeMount, ref } from "vue"
19 import { useSettingsStore } from "@/stores/settings"
20 import dayjs from "@/utils/dayjs"
21
22 const { caseData } = defineProps<{ caseData: SocCaseExt }>()
23
24 const dFormats = useSettingsStore().dateFormat
25
26 const history = ref<
27 {
28 timeString: string
29 label: string
30 }[]
31 >([])
32
33 function formatDate(timestamp: string | number, utc: boolean = true): string {
34 return dayjs(timestamp).utc(utc).format(dFormats.datetimesec)
35 }
36
37 onBeforeMount(() => {
38 if (Object.keys(caseData.modification_history).length) {
39 for (const key in caseData.modification_history) {
40 const item = caseData.modification_history[key]
41 history.value.push({
42 timeString: formatDate(_toNumber(key) * 1000, false),
43 label: `${item?.action ?? ""} [${item?.user ?? ""}]`
44 })
45 }
46 }
47 })
48 </script>