main
vue 50 lines 1.22 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 { SocNote } from "@/types/soc/note.d"
16 import { NTimeline, NTimelineItem } from "naive-ui"
17 import { onBeforeMount, ref } from "vue"
18 import { useSettingsStore } from "@/stores/settings"
19 import dayjs from "@/utils/dayjs"
20
21 const { note } = defineProps<{ note: SocNote }>()
22
23 const dFormats = useSettingsStore().dateFormat
24
25 const history = ref<
26 {
27 timeString: string
28 label: string
29 }[]
30 >([])
31
32 function formatDate(timestamp: string | number | Date, utc: boolean = true): string {
33 return dayjs(timestamp).utc(utc).format(dFormats.datetimesec)
34 }
35
36 onBeforeMount(() => {
37 if (note.note_details.note_creationdate) {
38 history.value.push({
39 timeString: formatDate(note.note_details.note_creationdate, false),
40 label: "Created"
41 })
42 }
43 if (note.note_details.note_lastupdate) {
44 history.value.push({
45 timeString: formatDate(note.note_details.note_lastupdate, false),
46 label: "Updated"
47 })
48 }
49 })
50 </script>