From 1efd0d18574f7f3d9cfcd0adf1b2d8d8ca3decfd Mon Sep 17 00:00:00 2001 From: duanshuwen Date: Thu, 27 Aug 2026 10:11:24 +0800 Subject: [PATCH] fix: align dashboard lead presentation --- .../src/pages/DashboardPage.test.ts | 18 +++++ .../src/pages/DashboardPage.vue | 77 +++++++++++++++++-- 2 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 WonderQ-Admin-UI-Vue/src/pages/DashboardPage.test.ts diff --git a/WonderQ-Admin-UI-Vue/src/pages/DashboardPage.test.ts b/WonderQ-Admin-UI-Vue/src/pages/DashboardPage.test.ts new file mode 100644 index 0000000..122f8dd --- /dev/null +++ b/WonderQ-Admin-UI-Vue/src/pages/DashboardPage.test.ts @@ -0,0 +1,18 @@ +import { readFile } from "node:fs/promises"; +import { fileURLToPath } from "node:url"; +import { describe, expect, it } from "vitest"; + +describe("DashboardPage lead presentation", () => { + it("uses the same labels and date formatting as the leads page", async () => { + const source = await readFile( + fileURLToPath(new URL("./DashboardPage.vue", import.meta.url)), + "utf8", + ); + + expect(source).toContain('import { leadStatusLabel } from "@/lib/leads";'); + expect(source).toContain('const formatDate = (value?: string | null) =>'); + expect(source).toContain('row.contactName || "未填写联系人"'); + expect(source).toContain("leadStatusLabel(row.status)"); + expect(source).toContain("formatDate(row.createdAt)"); + }); +}); diff --git a/WonderQ-Admin-UI-Vue/src/pages/DashboardPage.vue b/WonderQ-Admin-UI-Vue/src/pages/DashboardPage.vue index d3c1777..30482af 100644 --- a/WonderQ-Admin-UI-Vue/src/pages/DashboardPage.vue +++ b/WonderQ-Admin-UI-Vue/src/pages/DashboardPage.vue @@ -2,6 +2,7 @@ import { onMounted, ref } from "vue"; import { ElMessage } from "element-plus"; import { getDashboard } from "@/api/client"; +import { leadStatusLabel } from "@/lib/leads"; import type { Dashboard } from "@/types"; const data = ref(null); @@ -11,19 +12,85 @@ const error = ref(""); async function load() { loading.value = true; error.value = ""; - try { data.value = await getDashboard(); } catch (err) { error.value = err instanceof Error ? err.message : "仪表盘加载失败"; ElMessage.error(error.value); } finally { loading.value = false; } + try { + data.value = await getDashboard(); + } catch (err) { + error.value = err instanceof Error ? err.message : "仪表盘加载失败"; + ElMessage.error(error.value); + } finally { + loading.value = false; + } } + +const formatDate = (value?: string | null) => { + if (!value) return "未填写"; + const date = new Date(value); + return Number.isNaN(date.valueOf()) + ? value + : new Intl.DateTimeFormat("zh-CN", { + dateStyle: "medium", + timeStyle: "short", + }).format(date); +}; + onMounted(load);