diff --git a/ops-platform/src/utils/date.ts b/ops-platform/src/utils/date.ts new file mode 100644 index 0000000..f0f02ed --- /dev/null +++ b/ops-platform/src/utils/date.ts @@ -0,0 +1,7 @@ +const TZ = 'Asia/Shanghai' + +export function formatTime(value: string | number | null | undefined): string { + if (value === null || value === undefined || value === '') return '-' + const date = new Date(value as string | number) + return Number.isNaN(date.getTime()) ? '-' : date.toLocaleString('zh-CN', { timeZone: TZ }) +} diff --git a/ops-platform/src/views/apps/AppDetailView.vue b/ops-platform/src/views/apps/AppDetailView.vue index 23786a7..49eaab1 100644 --- a/ops-platform/src/views/apps/AppDetailView.vue +++ b/ops-platform/src/views/apps/AppDetailView.vue @@ -55,6 +55,7 @@ import { onMounted, ref } from 'vue' import { useRoute } from 'vue-router' import { opsApi, type AppDetail } from '@/api/ops' +import { formatTime } from '@/utils/date' const route = useRoute() const detail = ref(null) @@ -65,9 +66,7 @@ async function loadDetail() { detail.value = res.data.data } -function fmt(value: string) { - return value ? new Date(value).toLocaleString('zh-CN') : '-' -} +const fmt = formatTime function mask(value: string) { if (!value) return '-' diff --git a/ops-platform/src/views/apps/AppListView.vue b/ops-platform/src/views/apps/AppListView.vue index 55bb907..58981f8 100644 --- a/ops-platform/src/views/apps/AppListView.vue +++ b/ops-platform/src/views/apps/AppListView.vue @@ -35,7 +35,7 @@ - +