fix: 修改待接待日期显示
parent
2643f637a9
commit
141f6708b8
|
|
@ -1,14 +1,52 @@
|
|||
// 通用格式化 / 校验纯函数(无状态,供 composable 与页面复用)。
|
||||
|
||||
/** Date → `YYYY-MM-DD` */
|
||||
export const formatDate = (date: Date | string): string => {
|
||||
/** Date 格式化。支持自定义格式,默认 `YYYY-MM-DD`。
|
||||
*
|
||||
* 支持的 token:
|
||||
* - YYYY / MM / DD / HH / mm / ss(补零)
|
||||
* - M / D / H / m / s(不补零)
|
||||
*
|
||||
* @example
|
||||
* formatDate(new Date()) // '2026-08-12'
|
||||
* formatDate('2025-12-05', 'YYYY/MM/DD') // '2025/12/05'
|
||||
* formatDate(date, 'YYYY-MM-DD HH:mm:ss') // '2026-08-12 09:05:30'
|
||||
*/
|
||||
export const formatDate = (
|
||||
date: Date | string,
|
||||
format: string = "YYYY-MM-DD"
|
||||
): 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}`;
|
||||
const month = transformedDate.getMonth() + 1;
|
||||
const day = transformedDate.getDate();
|
||||
const hours = transformedDate.getHours();
|
||||
const minutes = transformedDate.getMinutes();
|
||||
const seconds = transformedDate.getSeconds();
|
||||
|
||||
const pad = (n: number) => String(n).padStart(2, "0");
|
||||
|
||||
// 按长度从长到短替换,避免短 token 干扰
|
||||
const replacements: Array<[string, string]> = [
|
||||
["YYYY", String(year)],
|
||||
["MM", pad(month)],
|
||||
["DD", pad(day)],
|
||||
["HH", pad(hours)],
|
||||
["mm", pad(minutes)],
|
||||
["ss", pad(seconds)],
|
||||
["M", String(month)],
|
||||
["D", String(day)],
|
||||
["H", String(hours)],
|
||||
["m", String(minutes)],
|
||||
["s", String(seconds)],
|
||||
];
|
||||
|
||||
let result = format;
|
||||
for (const [token, value] of replacements) {
|
||||
result = result.split(token).join(value);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
/** 手机号输入格式化:仅保留数字并截断到 11 位。 */
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
<div class="flex items-center gap-8">
|
||||
<span class="min-w-0 truncate text-[4rem] font-600 leading-none text-[#000]">{{ item.studentName || "-" }}</span>
|
||||
<span class="shrink-0 rounded-2 bg-[#E7F2FF] px-4 py-3 text-[2.5rem] leading-none text-[#1580FF]">
|
||||
签到:{{ item.checkinTime }}
|
||||
签到:{{ formatDate(item.checkinTime, "MM-DD HH:mm:ss") }}
|
||||
</span>
|
||||
<span
|
||||
v-if="activeTab === 'available' && item.waitingMinutes > 0"
|
||||
|
|
@ -89,6 +89,7 @@
|
|||
import "vant/es/tabs/style";
|
||||
import type { ReceptionTaskDTO } from "@/api/reception";
|
||||
import { useReceptionTasks, type ReceptionTaskTab } from "@/composables/useReceptionTasks";
|
||||
import { formatDate } from "@/utils/format";
|
||||
|
||||
const tabs: ReadonlyArray<{ label: string; value: ReceptionTaskTab }> = [
|
||||
{ label: "待接待", value: "available" },
|
||||
|
|
|
|||
Loading…
Reference in New Issue