diff --git a/frontend/src/utils/time.ts b/frontend/src/utils/time.ts new file mode 100644 index 0000000..cf1b804 --- /dev/null +++ b/frontend/src/utils/time.ts @@ -0,0 +1,23 @@ +type DateInput = string | number | Date | null | undefined + +export function formatDateTime(value: DateInput, fallback = '-') { + if (!value) return fallback + const date = value instanceof Date ? value : new Date(value) + if (Number.isNaN(date.getTime())) { + return typeof value === 'string' && value.trim() ? value.replace('T', ' ') : fallback + } + return [ + date.getFullYear(), + pad(date.getMonth() + 1), + pad(date.getDate()), + ].join('-') + ` ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}` +} + +export function formatDateMinute(value: DateInput, fallback = '-') { + const formatted = formatDateTime(value, fallback) + return formatted === fallback ? fallback : formatted.slice(0, 16) +} + +function pad(value: number) { + return String(value).padStart(2, '0') +} diff --git a/frontend/src/views/account/NotificationsView.vue b/frontend/src/views/account/NotificationsView.vue index 068c0b5..1890ebe 100644 --- a/frontend/src/views/account/NotificationsView.vue +++ b/frontend/src/views/account/NotificationsView.vue @@ -3,6 +3,7 @@ import { ElMessage } from 'element-plus' import { onMounted, ref } from 'vue' import { fetchNotifications, markNotificationRead, type NotificationItem } from '@/api/notifications' +import { formatDateTime } from '@/utils/time' const loading = ref(false) const notifications = ref([]) @@ -40,7 +41,7 @@ async function markRead(id: number) { {{ item.type }}

{{ item.title }}

{{ item.content }}

- {{ item.created_at }} + {{ formatDateTime(item.created_at) }}
diff --git a/frontend/src/views/account/OrderDetailView.vue b/frontend/src/views/account/OrderDetailView.vue index 89f1dde..7045ad0 100644 --- a/frontend/src/views/account/OrderDetailView.vue +++ b/frontend/src/views/account/OrderDetailView.vue @@ -17,6 +17,7 @@ import { type Order, } from '@/api/orders' import { useSessionStore } from '@/stores/session' +import { formatDateTime } from '@/utils/time' const route = useRoute() const router = useRouter() @@ -207,8 +208,8 @@ function readError(error: unknown, fallback: string) {

租期:{{ order.rent_hours }} 小时

-

开始:{{ order.rent_start_at || '未开始' }}

-

结束:{{ order.rent_end_at || '未设置' }}

+

开始:{{ formatDateTime(order.rent_start_at, '未开始') }}

+

结束:{{ formatDateTime(order.rent_end_at, '未设置') }}

取消订单并释放账号 @@ -220,7 +221,7 @@ function readError(error: unknown, fallback: string) {
{{ record.type }}

{{ record.content }}

- {{ record.created_at }} + {{ formatDateTime(record.created_at) }}
diff --git a/frontend/src/views/account/RealnameView.vue b/frontend/src/views/account/RealnameView.vue index fce3ad8..3c8319e 100644 --- a/frontend/src/views/account/RealnameView.vue +++ b/frontend/src/views/account/RealnameView.vue @@ -4,6 +4,7 @@ import { onMounted, reactive, ref } from 'vue' import { getRealnameStatus, startRealname, type RealnameStatus } from '@/api/realname' import { useSessionStore } from '@/stores/session' +import { formatDateTime } from '@/utils/time' const session = useSessionStore() const loading = ref(false) @@ -61,7 +62,7 @@ function readError(error: unknown, fallback: string) { {{ status.status }}

姓名:{{ status.masked_name }}

证件号:{{ status.masked_id_no }}

-

通过时间:{{ status.verified_at }}

+

通过时间:{{ formatDateTime(status.verified_at) }}

diff --git a/frontend/src/views/account/WalletView.vue b/frontend/src/views/account/WalletView.vue index 7d125ca..593e29e 100644 --- a/frontend/src/views/account/WalletView.vue +++ b/frontend/src/views/account/WalletView.vue @@ -2,6 +2,7 @@ import { onMounted, ref } from 'vue' import { fetchWalletBalance, fetchWalletLedger, type WalletAccount, type WalletLedger } from '@/api/wallet' +import { formatDateTime } from '@/utils/time' const loading = ref(false) const account = ref(null) @@ -52,7 +53,9 @@ async function loadWallet() { - + + + diff --git a/frontend/src/views/admin/AdminAuditLogsView.vue b/frontend/src/views/admin/AdminAuditLogsView.vue index 62edd2e..3af6f29 100644 --- a/frontend/src/views/admin/AdminAuditLogsView.vue +++ b/frontend/src/views/admin/AdminAuditLogsView.vue @@ -3,6 +3,7 @@ import { Search } from '@element-plus/icons-vue' import { computed, onMounted, reactive, ref } from 'vue' import { fetchAdminAuditLogs, type AdminAuditLog } from '@/api/adminAudit' +import { formatDateTime } from '@/utils/time' const loading = ref(false) const logs = ref([]) @@ -133,7 +134,9 @@ function actionType(action: string) { - + + +