From 1390eec135de33236c025457d5b21008b67f33c8 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期日, 11 十月 2026 14:06:21 +0800
Subject: [PATCH] fix: 优化日期格式化显示逻辑

---
 src/components/PIMTable/PIMTable.vue |   98 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 82 insertions(+), 16 deletions(-)

diff --git a/src/components/PIMTable/PIMTable.vue b/src/components/PIMTable/PIMTable.vue
index a418280..aa5a030 100644
--- a/src/components/PIMTable/PIMTable.vue
+++ b/src/components/PIMTable/PIMTable.vue
@@ -135,14 +135,12 @@
             <el-button
               v-show="o.type != 'upload'"
               v-if="o.showHide ? o.showHide(scope.row) : true"
-              :disabled="o.disabled ? o.disabled(scope.row) : false"
+              :disabled="isOperationDisabled(o, scope.row)"
               :plain="o.plain"
               type="primary"
               :style="{
-                color:
-                  o.name === '鍒犻櫎' || o.name === 'delete'
-                    ? '#f56c6c'
-                    : o.color,
+                color: getOperationColor(o, scope.row),
+                fontWeight: 'bold',
               }"
               link
               @click.stop="o.clickFun(scope.row)"
@@ -160,7 +158,7 @@
               ref="uploadRef"
               :multiple="o.multiple ? o.multiple : false"
               :limit="1"
-              :disabled="o.disabled ? o.disabled(scope.row) : false"
+              :disabled="isOperationDisabled(o, scope.row)"
               :accept="
                 o.accept
                   ? o.accept
@@ -188,7 +186,10 @@
               <el-button
                 link
                 type="primary"
-                :disabled="o.disabled ? o.disabled(scope.row) : false"
+                :disabled="isOperationDisabled(o, scope.row)"
+                :style="{
+                  color: getOperationColor(o, scope.row),
+                }"
                 >{{ o.name }}</el-button
               >
             </el-upload>
@@ -201,14 +202,11 @@
           style="width: 100%"
           @click="goLink(scope.row, item.linkMethod)"
         >
-          <span v-if="!item.formatData">{{ scope.row[item.prop] }}</span>
+          <span>{{ formatters(scope.row[item.prop], item.formatData) }}</span>
         </div>
         <!-- 榛樿绾睍绀烘暟鎹� -->
         <div v-else class="cell" style="width: 100%">
-          <span v-if="!item.formatData">{{ scope.row[item.prop] }}</span>
-          <span v-else>{{
-            formatters(scope.row[item.prop], item.formatData)
-          }}</span>
+          <span>{{ formatters(scope.row[item.prop], item.formatData) }}</span>
         </div>
       </template>
     </el-table-column>
@@ -227,6 +225,7 @@
 import pagination from "./Pagination.vue";
 import { ref, inject, getCurrentInstance } from "vue";
 import { ElMessage } from "element-plus";
+import { dateOnly } from "@/utils/ruoyi";
 
 // 鑾峰彇鍏ㄥ眬鐨� uploadHeader
 const { proxy } = getCurrentInstance();
@@ -241,7 +240,9 @@
 };
 
 const formatters = (val, format) => {
-  return typeof format === "function" ? format(val) : val;
+  if (typeof format === "function") return format(val);
+  // 鏈樉寮忔寚瀹氭牸寮忓寲鍑芥暟鏃讹細鏃ユ湡鏃堕棿缁熶竴鍙樉绀哄勾鏈堟棩锛堥潪鏃ユ湡鍊煎師鏍疯繑鍥烇級
+  return dateOnly(val);
 };
 
 // Props锛堜娇鐢� defineProps 鐨勯潪 TS 褰㈠紡锛�
@@ -366,11 +367,76 @@
     return format(val);
   } else return val;
 };
+const validTagTypes = ["primary", "success", "info", "warning", "danger"];
 
 const formatType = (val, format) => {
-  if (typeof format === "function") {
-    return format(val);
-  } else return "";
+  const type = typeof format === "function" ? format(val) : undefined;
+  return validTagTypes.includes(type) ? type : undefined;
+};
+
+const isOperationDisabled = (operation, row) => {
+  if (!operation?.disabled) return false;
+  return typeof operation.disabled === "function"
+    ? !!operation.disabled(row)
+    : !!operation.disabled;
+};
+
+const parseHexToRgb = (hex) => {
+  const normalized = String(hex || "").trim().replace("#", "");
+  if (normalized.length === 3) {
+    const r = parseInt(normalized[0] + normalized[0], 16);
+    const g = parseInt(normalized[1] + normalized[1], 16);
+    const b = parseInt(normalized[2] + normalized[2], 16);
+    if ([r, g, b].some((n) => Number.isNaN(n))) return null;
+    return { r, g, b };
+  }
+  if (normalized.length === 6 || normalized.length === 8) {
+    const r = parseInt(normalized.slice(0, 2), 16);
+    const g = parseInt(normalized.slice(2, 4), 16);
+    const b = parseInt(normalized.slice(4, 6), 16);
+    if ([r, g, b].some((n) => Number.isNaN(n))) return null;
+    return { r, g, b };
+  }
+  return null;
+};
+
+const fadeColor = (color, alpha = 0.35) => {
+  const c = String(color || "").trim();
+  if (!c) return undefined;
+  if (c.startsWith("#")) {
+    const rgb = parseHexToRgb(c);
+    if (!rgb) return c;
+    return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${alpha})`;
+  }
+  const rgbMatch = c.match(/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*[\d.]+\s*)?\)$/i);
+  if (rgbMatch) {
+    const r = Number(rgbMatch[1]);
+    const g = Number(rgbMatch[2]);
+    const b = Number(rgbMatch[3]);
+    if ([r, g, b].some((n) => Number.isNaN(n))) return c;
+    return `rgba(${r}, ${g}, ${b}, ${alpha})`;
+  }
+  if (c.includes("--el-color-primary")) {
+    return "var(--el-color-primary-light-5)";
+  }
+  if (c.includes("--el-color-danger")) {
+    return "var(--el-color-danger-light-5)";
+  }
+  return "var(--el-text-color-disabled)";
+};
+
+const getOperationColor = (operation, row) => {
+  const baseColor =
+    operation?.name === "鍒犻櫎" || operation?.name === "delete"
+      ? "#D93025"
+      : operation?.name === "璇︽儏"
+      ? "#67C23A"
+      : operation?.color || "var(--el-color-primary)";
+
+  if (isOperationDisabled(operation, row)) {
+    return fadeColor(baseColor, 0.35);
+  }
+  return baseColor;
 };
 
 // 鏂囦欢鍙樺寲澶勭悊

--
Gitblit v1.9.3