diff --git a/src/utils/format.ts b/src/utils/format.ts index 52b14b7..946c59c 100644 --- a/src/utils/format.ts +++ b/src/utils/format.ts @@ -1,10 +1,13 @@ // 通用格式化 / 校验纯函数(无状态,供 composable 与页面复用)。 /** Date → `YYYY-MM-DD` */ -export const formatDate = (date: Date): string => { - const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, "0"); - const day = String(date.getDate()).padStart(2, "0"); +export const formatDate = (date: Date | string): string => { + const transformedDate = typeof date === "string" ? new Date(date) : date; + if (Number.isNaN(transformedDate.getTime())) return ""; + + const year = transformedDate.getFullYear(); + const month = String(transformedDate.getMonth() + 1).padStart(2, "0"); + const day = String(transformedDate.getDate()).padStart(2, "0"); return `${year}-${month}-${day}`; }; diff --git a/src/views/reception/ReceptionTask.vue b/src/views/reception/ReceptionTask.vue index ab0a09f..3474ba2 100644 --- a/src/views/reception/ReceptionTask.vue +++ b/src/views/reception/ReceptionTask.vue @@ -32,7 +32,7 @@
{{ item.studentName || "-" }} - 签到:{{ formatCheckinTime(item.checkinTime) }} + 签到:{{ formatDate(item.checkinTime) }} = [ { label: "待接待", value: "available" }, @@ -99,10 +100,7 @@ const router = useRouter(); const { activeTab, tasks, loading, finished, error, claimingTaskId, showEmpty, emptyText, loadNextPage, claimTask } = useReceptionTasks(20); - const formatCheckinTime = (value: string): string => { - const normalized = value.replace("T", " "); - return normalized.length >= 16 ? normalized.slice(5, 16) : normalized || "-"; - }; + const formatDateOnly = (value: string): string => value.split(/[T ]/, 1)[0] || "-"; diff --git a/src/views/teacher/InvitationData.vue b/src/views/teacher/InvitationData.vue index 21111a0..50eb71e 100644 --- a/src/views/teacher/InvitationData.vue +++ b/src/views/teacher/InvitationData.vue @@ -1,49 +1,27 @@