From a241b66efcc41e973290a6722fb7a4d79b833ea1 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 13 十月 2026 09:54:32 +0800
Subject: [PATCH] feat(bi): 为图表配置接口添加名称字段

---
 src/adapter/vxe-table.ts |   50 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/src/adapter/vxe-table.ts b/src/adapter/vxe-table.ts
index 554ae3a..dfcad08 100644
--- a/src/adapter/vxe-table.ts
+++ b/src/adapter/vxe-table.ts
@@ -3,7 +3,7 @@
 
 import type { ComponentPropsMap, ComponentType } from './component';
 
-import { h } from 'vue';
+import { h, watch } from 'vue';
 
 import { IconifyIcon } from '@vben/icons';
 import { $te } from '@vben/locales';
@@ -35,6 +35,8 @@
 
 import { DictTag } from '#/components/dict-tag';
 import { $t } from '#/locales';
+import { automaticApproval } from '#/store/audit-policy';
+import { isAuditField } from '#/utils/audit-ui-policy';
 
 import { useVbenForm } from './form';
 
@@ -120,11 +122,42 @@
     });
 
     // 琛ㄦ牸閰嶇疆椤瑰彲浠ョ敤 cellRender: { name: 'CellTag' },
+    // props: { data: [{value, color}], labels?: {[value]: label} }
+    // 鏀寔涓ょ鍖归厤妯″紡:
+    //   1. 绮剧‘鍖归厤: data 鍜� labels 涓兘鏄簿纭�� (鐘舵��/绫诲瀷鏋氫妇)
+    //   2. 闃堝�煎尮閰�: data 涓洪檷搴忛槇鍊�, label 鏄剧ず鍘熷鏁板�� (璇勫垎)
     vxeUI.renderer.add('CellTag', {
       renderTableDefault(renderOpts, params) {
         const { props } = renderOpts;
         const { column, row } = params;
-        return h(Tag, { color: props?.color }, () => row[column.field]);
+        const rawValue = row[column.field];
+
+        // 鏌ユ壘鏄剧ず鏂囨湰
+        let label = rawValue;
+        if (props?.labels && rawValue !== undefined && rawValue !== null) {
+          label = props.labels[rawValue] ?? rawValue;
+        }
+
+        // 鏌ユ壘棰滆壊: 浼樺厛绮剧‘鍖归厤锛屽惁鍒欓槇鍊煎尮閰�
+        let color: string | undefined;
+        if (props?.data) {
+          const exact = props.data.find(
+            (item: any) => item.value === rawValue,
+          );
+          if (exact) {
+            color = exact.color;
+          } else {
+            const sorted = [...props.data]
+              .filter((item: any) => typeof item.value === 'number')
+              .sort((a: any, b: any) => b.value - a.value);
+            const threshold = sorted.find(
+              (item: any) => Number(rawValue) >= item.value,
+            );
+            if (threshold) color = threshold.color;
+          }
+        }
+
+        return h(Tag, { color }, () => label);
       },
     });
 
@@ -372,6 +405,17 @@
 export * from '#/components/table-action';
 export const useVbenVxeGrid = <T extends Record<string, any>>(
   ...rest: Parameters<typeof useGrid<T, ComponentType, ComponentPropsMap>>
-) => useGrid<T, ComponentType, ComponentPropsMap>(...rest);
+) => {
+  const options = rest[0];
+  const columns = options.gridOptions?.columns;
+  const schema = options.formOptions?.schema;
+  const applyPolicy = () => ({
+    ...(columns ? { gridOptions: { columns: columns.filter((item) => !automaticApproval.value || !isAuditField(item)) } } : {}),
+    ...(schema ? { formOptions: { schema: schema.filter((item) => !automaticApproval.value || !isAuditField(item)) } } : {}),
+  });
+  const result = useGrid<T, ComponentType, ComponentPropsMap>(options);
+  watch(automaticApproval, () => result[1].setState(applyPolicy()), { immediate: true });
+  return result;
+};
 
 export type * from '@vben/plugins/vxe-table';

--
Gitblit v1.9.3