From 57a496e7d0aa5630180e841f31d9c6b1215cc7a2 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期一, 02 十一月 2026 17:54:44 +0800
Subject: [PATCH] 列表插槽列的时间也只展示年月日
---
src/utils/dateDisplay.js | 55 +++++++++++++++++++++++++++
src/main.js | 29 ++++++++++++++
src/views/collaborativeApproval/planTemplate/index.vue | 2
src/views/reportAnalysis/safetyDashboard/components/center-top.vue | 2
4 files changed, 85 insertions(+), 3 deletions(-)
diff --git a/src/main.js b/src/main.js
index d0282b7..9dccc9a 100644
--- a/src/main.js
+++ b/src/main.js
@@ -58,7 +58,7 @@
import PageHeader from "@/components/PageHeader/index.vue";
import { getToken } from "@/utils/auth";
-import { toDateOnly } from "@/utils/dateDisplay";
+import { toDateOnly, toDateOnlyVNode } from "@/utils/dateDisplay";
import {
calculateTaxExclusiveTotalPrice,
summarizeTable,
@@ -133,4 +133,31 @@
}
}
+// 鍒楄〃鏃堕棿缁熶竴鍙睍绀哄勾鏈堟棩锛堟彃妲藉垪锛夛細<template #default> 閲岀殑鍐呭涓嶈蛋鍒� formatter锛�
+// 杩欓噷鎶� el-table-column 鐨勬墍鏈夋彃妲借緭鍑鸿繃涓�閬嶏紝绾枃鏈腑鐨勬棩鏈熸椂闂村彧淇濈暀骞存湀鏃ャ��
+const tableColumn = app._context.components.ElTableColumn;
+if (
+ tableColumn &&
+ typeof tableColumn.setup === "function" &&
+ !tableColumn.__dateOnlyPatched
+) {
+ const originalSetup = tableColumn.setup;
+ tableColumn.setup = function (props, ctx) {
+ try {
+ const slots = ctx.slots;
+ if (slots) {
+ Object.keys(slots).forEach((name) => {
+ const original = slots[name];
+ if (typeof original !== "function") return;
+ slots[name] = (scope) => toDateOnlyVNode(original(scope));
+ });
+ }
+ } catch (e) {
+ // 鎻掓Ы鍙鏃堕��鍥炲垪 formatter 鍏滃簳锛屼笉褰卞搷琛ㄦ牸娓叉煋
+ }
+ return originalSetup(props, ctx);
+ };
+ tableColumn.__dateOnlyPatched = true;
+}
+
app.mount("#app");
diff --git a/src/utils/dateDisplay.js b/src/utils/dateDisplay.js
index db7deb4..7fcde29 100644
--- a/src/utils/dateDisplay.js
+++ b/src/utils/dateDisplay.js
@@ -2,6 +2,8 @@
* 鍒楄〃灞曠ず鐢ㄧ殑鏃ユ湡澶勭悊锛氬甫鏃跺垎绉掔殑鏃ユ湡鏃堕棿鍙繚鐣欏勾鏈堟棩锛�
* 鏈潵灏辨槸鏃ユ湡銆佹椂闂存垨鍏跺畠鍐呭鐨勫�煎師鏍疯繑鍥炪��
*/
+import { cloneVNode } from "vue";
+
const DATE_TIME_PATTERN =
/^(\d{4})[-/骞碷(\d{1,2})[-/鏈圿(\d{1,2})鏃�?[ T]\d{1,2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?$/;
@@ -30,3 +32,56 @@
return `${matched[1]}-${pad2(matched[2])}-${pad2(matched[3])}`;
}
+
+/**
+ * 閫掑綊澶勭悊鎻掓Ы娓叉煋鍑虹殑 vnode锛氭妸鍏朵腑鐨勭函鏂囨湰鎸� toDateOnly 鎴柇銆�
+ * 琛ㄦ牸鍒楃殑鎻掓Ы鍐呭锛�<template #default>锛変笉浼氳蛋鍒� formatter锛�
+ * 杩欓噷鍦� vnode 灞傜粺涓�鍏滃簳锛屽垪琛ㄩ噷灏变笉浼氬啀鍐掑嚭鏃跺垎绉掋��
+ */
+export function toDateOnlyVNode(node) {
+ if (node == null || typeof node === "number" || typeof node === "boolean") {
+ return node;
+ }
+
+ if (Array.isArray(node)) {
+ return mapIfChanged(node, toDateOnlyVNode);
+ }
+
+ if (typeof node === "string") {
+ return toDateOnly(node);
+ }
+
+ // vnode锛氭枃鏈瓙鑺傜偣
+ const children = node.children;
+ if (children == null) return node;
+
+ if (typeof children === "string") {
+ const next = toDateOnly(children);
+ return next === children ? node : withChildren(node, next);
+ }
+
+ if (Array.isArray(children)) {
+ const next = mapIfChanged(children, toDateOnlyVNode);
+ return next === children ? node : withChildren(node, next);
+ }
+
+ // 缁勪欢鎻掓Ы瀵硅薄绛夊叾瀹冨舰鎬佷笉澶勭悊
+ return node;
+}
+
+// cloneVNode 鐨勭浜屼釜鍙傛暟鍙悎骞跺埌 props锛宑hildren 瑕佸崟鐙祴鍊�
+function withChildren(vnode, children) {
+ const cloned = cloneVNode(vnode);
+ cloned.children = children;
+ return cloned;
+}
+
+function mapIfChanged(list, mapper) {
+ let changed = false;
+ const mapped = list.map((item) => {
+ const next = mapper(item);
+ if (next !== item) changed = true;
+ return next;
+ });
+ return changed ? mapped : list;
+}
diff --git a/src/views/collaborativeApproval/planTemplate/index.vue b/src/views/collaborativeApproval/planTemplate/index.vue
index fa2bfd9..f469b11 100644
--- a/src/views/collaborativeApproval/planTemplate/index.vue
+++ b/src/views/collaborativeApproval/planTemplate/index.vue
@@ -144,7 +144,7 @@
<div class="plan-meta">
<div class="meta-item">
<el-icon><Calendar /></el-icon>
- <span>{{ plan.startDate }} - {{ plan.endDate }}</span>
+ <span>{{ formatDateOnly(plan.startDate) }} - {{ formatDateOnly(plan.endDate) }}</span>
</div>
<div class="meta-item">
<el-icon><User /></el-icon>
diff --git a/src/views/reportAnalysis/safetyDashboard/components/center-top.vue b/src/views/reportAnalysis/safetyDashboard/components/center-top.vue
index 278490a..c055197 100644
--- a/src/views/reportAnalysis/safetyDashboard/components/center-top.vue
+++ b/src/views/reportAnalysis/safetyDashboard/components/center-top.vue
@@ -59,7 +59,7 @@
</div>
<div class="event-meta">
<span>{{ item.location || '鈥�' }}</span>
- <span>{{ item.eventTime }}</span>
+ <span>{{ formatDateOnly(item.eventTime) }}</span>
</div>
</li>
</ul>
--
Gitblit v1.9.3