ソースを参照

[Mod 0000]修改数据质量和矿山信息数据处理逻辑

wangkeyi 3 ヶ月 前
コミット
ff6833864c

+ 2 - 2
src/views/dashboard/basicInfo/closedStatistics/index.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="p-4">
-    <BasicTable @register="registerTable" :scroll="{ x: 'max-content' }">
+    <BasicTable @register="registerTable" :scroll="{ x: 'fit-content' }">
       <template #action="{ record }">
           <button @click="handleGoToPage(record, `/sealed/${record.code}`)" class="action-btn">
             <SvgIcon name="view" />
@@ -24,7 +24,7 @@
     title: '密闭统计',
     api: getClosedAccessCount, // 数据统计接口
     columns: dataColumns,
-    pagination: true,
+    pagination: false,
     useSearchForm: false,
     // showTableSetting: true,
     bordered: true,

+ 116 - 138
src/views/dashboard/basicInfo/dataQuality/dataQuality.data.ts

@@ -1,155 +1,133 @@
 import { BasicColumn, FormSchema } from '/@/components/Table';
 import { h } from 'vue';
+import { Ref } from 'vue';
 
-// 生产状态映射表(扩展所有状态)
-export const productionStatusMap: Record<string | number, { label: string; value: number; color: string }> = {
-  0: { label: '正常生产矿井', value: 0, color: 'green' },
-  1: { label: '拟建矿井', value: 1, color: 'blue' },
-  2: { label: '正常建设煤矿', value: 2, color: 'red' },
-  3: { label: '自行停产矿井', value: 3, color: 'red' },
-  4: { label: '正在关闭', value: 4, color: 'red' },
-  5: { label: '责令停产整顿', value: 5, color: 'red' },
-  6: { label: '责令停止建设', value: 6, color: 'red' },
-  7: { label: '已关闭矿井', value: 7, color: 'red' },
-  8: { label: '长期停产矿井', value: 8, color: 'red' },
-  9: { label: '长期停建矿井', value: 9, color: 'red' },
-  10: { label: '停产整改矿井', value: 10, color: 'red' },
-  11: { label: '长期停建无法联系', value: 11, color: 'red' },
-  12: { label: '停建整改', value: 12, color: 'red' },
-  13: { label: '自行停建', value: 13, color: 'red' },
-  14: { label: '正在实施关闭', value: 14, color: 'red' },
-  // 15: { label: '已关闭矿井', value: 15, color: 'red' },
-};
-
-// 基于productionStatusMap生成下拉选项
-export const productionStatusOptions = Object.entries(productionStatusMap).map(([key, item]) => ({
-  label: item.label, // 状态名称
-  value: key,        // 状态值(转字符串,和原硬编码格式一致)
-}));
-
-// 颜色映射
-const colorHexMap: Record<string, string> = {
+// 1. 颜色映射(固定规则,可根据业务调整)
+export const colorHexMap: Record<string, string> = {
   blue: '#1890ff',
   green: '#208840',
   gold: '#faad14',
   red: '#f5222d',
   gray: '#8c8c8c',
-  black: '#000000',
+  black: '#000000', 
 };
 
-/** 表格列配置 */
-export const columns: BasicColumn[] = [
-  {
-    title: '煤矿名称',
-    dataIndex: 'mineName',
-    width: 250,
-  },
-  {
-    title: '煤矿简称',
-    dataIndex: 'mineNameAbbr',
-    width: 150,
-  },
-  {
-    title: '生产状态',
-    dataIndex: 'mineProStatus',
-    width: 120,
-    customRender: ({ record }) => {
-      // 空值/异常值处理
-      const status = record.mineProStatus;
-      const { label, color } = productionStatusMap[status] || { label: '未知状态', color: 'balck' };
-      return h('span', { style: { color: colorHexMap[color] || colorHexMap.gray } }, label);
+// 2. 定义动态映射的类型(供外部传入)
+export type ProductionStatusMap = Record<string | number, { 
+  label: string; 
+  value: number | string; 
+  color: string; 
+}>;
+
+// 3. 生成表格列(支持传入动态映射)
+export function getColumns(dynamicStatusMap: Ref<ProductionStatusMap>) {
+  const columns: BasicColumn[] = [
+    {
+      title: '煤矿名称',
+      dataIndex: 'mineName',
+      width: 250,
     },
-  },
-  {
-    title: '在线状态',
-    dataIndex: 'mineLinkStatus',
-    width: 100,
-    customRender: ({ record }) => {
-      const status = record.mineLinkStatus;
-      if (status === undefined || status === null) {
-        return h('span', { style: { color: colorHexMap.black } }, '/');
-      }
-      const text = status === 1 ? '在线' : '离线';
-      const textColor = status === 1 ? colorHexMap.green : colorHexMap.red;
-      return h('span', { style: { color: textColor } }, text);
+    {
+      title: '煤矿简称',
+      dataIndex: 'mineNameAbbr',
+      width: 150,
     },
-  },
-  {
-    title: '质量问题详情',
-    dataIndex: 'queJson',
-    width: 400,
-    ellipsis: true,
-    slots: {
-      customRender : 'queJson'
-    }
-  },
-  {
-    title: '当前状态',
-    dataIndex: 'isOk',
-    width: 100,
-    customRender: ({ record }) => {
-      const status = record.isOk;
-      const text = status ? '已解决' : '未解决';
-      const textColor = status ? colorHexMap.green : colorHexMap.red;
-      return h('span', { style: { color: textColor } }, text);
+    {
+      title: '生产状态',
+      dataIndex: 'mineProStatus',
+      width: 120,
+      customRender: ({ record }) => {
+        // 空值/异常值处理
+        const status = record.mineProStatus;
+        // 从动态映射中取值,兜底未知状态
+        const { label, color } = dynamicStatusMap.value[status] || { 
+          label: '-', 
+        };
+        return h('span', { 
+          style: { color: colorHexMap[color] } 
+        }, label);
+      },
     },
-  },
-  {
-    title: '处理时间',
-    dataIndex: 'updateTime',
-    width: 180,
-  },
-];
-
-/** 查询表单配置 */
-export const searchFormSchema: FormSchema[] = [
-  {
-    field: 'mineCode',
-    label: '煤矿名称',
-    component: 'MineCascader',
-    colProps: { span: 6 },
-    groupName: '常规查询',
-  },
-  // {
-  //   field: 'mineNameAbbr',
-  //   label: '煤矿简称',
-  //   component: 'Input',
-  //   colProps: { span: 6 },
-  //   groupName: '常规查询',
-  // },
-  // {
-  //   field: 'productionStatus',
-  //   label: '生产状态',
-  //   component: 'Select',
-  //   componentProps: {
-  //     options: productionStatusOptions
-  //   },
-  //   colProps: { span: 6 },
-  //   groupName: '常规查询',
-  // },
-
-  // {
-  //   field: 'mineLinkStatus',
-  //   label: '在线状态',
-  //   component: 'Select',
-  //   componentProps: {
-  //     options: [
-  //       { label: '离线', value: '0' },
-  //       { label: '在线', value: '1' },
-  //       { label: '未连接', value: '2' },
-  //     ],
-  //   },
-  //   colProps: { span: 6 },
-  //   groupName: '常规查询',
-  // },
-];
+    {
+      title: '在线状态',
+      dataIndex: 'mineLinkStatus',
+      width: 100,
+      customRender: ({ record }) => {
+        const status = record.mineLinkStatus;
+        if (status === undefined || status === null) {
+          return h('span', { style: { color: colorHexMap.black } }, '/');
+        }
+        const text = status === 1 ? '在线' : '离线';
+        const textColor = status === 1 ? colorHexMap.green : colorHexMap.red;
+        return h('span', { style: { color: textColor } }, text);
+      },
+    },
+    {
+      title: '质量问题详情',
+      dataIndex: 'queJson',
+      width: 400,
+      ellipsis: true,
+      slots: { customRender: 'queJson' },
+    },
+    {
+      title: '当前状态',
+      dataIndex: 'isOk',
+      width: 100,
+      customRender: ({ record }) => {
+        const status = record.isOk;
+        const text = status ? '已解决' : '未解决';
+        const textColor = status ? colorHexMap.green : colorHexMap.red;
+        return h('span', { style: { color: textColor } }, text);
+      },
+    },
+    {
+      title: '处理时间',
+      dataIndex: 'updateTime',
+      width: 180,
+    },
+  ];
+  return columns;
+}
 
-// 模拟煤矿在线状态选项数据
-export const mineLinkStatusOptions = [
-  { label: '在线', value: 1 },
-  { label: '离线', value: 0 },
-];
-export const topFormSchema: FormSchema[]= [
+// 4. 查询表单配置(下拉框改为动态options)
+export function getSearchFormSchema(dynamicStatusOptions: Ref<{ label: string; value: string | number }[]>) {
+  const searchFormSchema: FormSchema[] = [
+    {
+      field: 'mineCode',
+      label: '煤矿名称',
+      component: 'MineCascader',
+      colProps: { span: 6 },
+      groupName: '常规查询',
+    },
+    // 启用生产状态下拉框(动态options)
+    {
+      field: 'productionStatus',
+      label: '生产状态',
+      component: 'Select',
+      componentProps: {
+        // 动态绑定下拉选项
+        options: dynamicStatusOptions,
+      },
+      colProps: { span: 6 },
+      groupName: '常规查询',
+    },
+    {
+      field: 'mineLinkStatus',
+      label: '在线状态',
+      component: 'Select',
+      componentProps: {
+        options: [
+          { label: '离线', value: '0' },
+          { label: '在线', value: '1' },
+        ],
+      },
+      colProps: { span: 6 },
+      groupName: '常规查询',
+    },
+  ];
+  return searchFormSchema;
+}
+export const topFormSchema: FormSchema[] = [
   {
     field: 'mineCode',
     label: '煤矿名称',

+ 144 - 53
src/views/dashboard/basicInfo/dataQuality/index.vue

@@ -1,7 +1,7 @@
 <!-- eslint-disable vue/multi-word-component-names -->
 <template>
   <!-- Tab标签页 -->
-  <Tabs v-model:activeKey="activeKey" class="common-page-tabs" type="line">
+  <Tabs v-model:activeKey="activeKey" class="common-page-tabs" type="line" @change="handleTabChange">
     <TabPane key="unresolved" tab="未解决">
       <div class="add-button">
         <a-button type="default" preIcon="mdi:download" @click="handleExportExcel" style="margin-right: 8px"> 导出 </a-button>
@@ -86,18 +86,23 @@
 </template>
 
 <script setup lang="ts">
-  import { ref, nextTick, computed } from 'vue';
+  import { ref, nextTick, computed, onMounted } from 'vue';
   import { useRouter } from 'vue-router';
-  import { BasicTable, useTable } from '/@/components/Table';
+  import { BasicTable, useTable, BasicColumn, FormSchema  } from '/@/components/Table';
   import { useModal } from '/@/components/Modal';
   import { Tabs, TabPane, Popconfirm, message } from 'ant-design-vue';
   import DataQualityModal from './components/DataQualityModal.vue';
   import { SvgIcon } from '/@/components/Icon';
-  import { columns, searchFormSchema, productionStatusMap } from './dataQuality.data';
+  import { 
+    getColumns, 
+    getSearchFormSchema, 
+    type ProductionStatusMap,
+  } from './dataQuality.data';
   import { getDataQuaQueList, addDataQuaQue, deleteDataQuaQue, editDataQuaQue } from '../basicInfo.api';
-  import { findNode, findPath, listToTree } from '/@/utils/helper/treeHelper';
+  import { findNode } from '/@/utils/helper/treeHelper';
   import { useMineStore } from '/@/store/modules/mine';
-  import dayjs from 'dayjs';
+  import { getDictItemsByCode } from '/@/utils/dict';
+  import dayjs from 'dayjs'; 
   import * as XLSX from 'xlsx';
   // 路由实例
   const router = useRouter();
@@ -106,13 +111,67 @@
   // 响应式数据
   const activeKey = ref('unresolved'); // 激活的Tab键
   const pageMode = ref('add');
+
+  // ========== 定义动态状态映射/下拉选项 ==========
+  // 1. 动态生产状态映射(key: 状态value,value: 包含label/color的配置)
+  const dynamicProductionStatusMap = ref<ProductionStatusMap>({});
+  // 2. 动态下拉选项(供搜索表单使用)
+  const dynamicProductionStatusOptions = ref<{ label: string; value: string | number }[]>([]);
+
+  // 3. 颜色分配规则(可根据业务灵活调整)
+  const getStatusColor = (statusText: string) => {
+    if (statusText.includes('正常生产')) return 'green'; // 正常生产 → 绿色
+    if (statusText.includes('拟建矿井')) return 'blue';   // 拟建矿井 → 蓝色
+    else return 'red'; // 停产/停建/关闭/整改/责令 → 红色
+  };
+
+  // 4. 从接口获取生产状态列表并生成动态映射/下拉选项
+  const fetchProductionStatus = async () => {
+    try {
+      // 调用接口获取状态列表
+      const statusList = await getDictItemsByCode('mineProStatus');
+      if (!Array.isArray(statusList)) return;
+
+      // 生成动态映射和下拉选项
+      const statusMap: ProductionStatusMap = {};
+      const statusOptions: { label: string; value: string | number }[] = [];
+      
+      statusList.forEach((item) => {
+        const value = item.value; // 接口返回的value(数字/字符串)
+        const label = item.text || item.label; // 接口返回的文本
+        const color = getStatusColor(label); // 按规则分配颜色
+        
+        // 填充映射表
+        statusMap[value] = { label, value, color };
+        // 填充下拉选项
+        statusOptions.push({ label, value });
+      });
+
+      // 赋值到响应式变量
+      dynamicProductionStatusMap.value = statusMap;
+      dynamicProductionStatusOptions.value = statusOptions;
+
+      // 刷新表格(确保表格使用最新的映射)
+      await safeReloadActiveTable(); 
+    } catch (error) {
+      console.error('获取生产状态列表失败:', error);
+      message.error('生产状态数据加载失败');
+    }
+  };
+
+  // 生成动态列和搜索表单配置
+  const columns = computed(() => getColumns(dynamicProductionStatusMap));
+  const searchFormSchema = computed(() => getSearchFormSchema(dynamicProductionStatusOptions));
+
   // 未解决表格注册
   const [registerUnresolvedTable, { reload: reloadUnresolved }] = useTable({
-    api: getQuaQueListByTab(),
-    columns,
+    api: async (params: any) => {
+      return await getDataQuaQueList({ ...params, isOk: false });
+    },
+    columns: columns, // 绑定动态列
     formConfig: {
       labelWidth: 120,
-      schemas: searchFormSchema,
+      schemas: searchFormSchema.value, 
       showAdvancedButton: false,
       schemaGroupNames: ['常规查询'],
     },
@@ -129,16 +188,18 @@
       dataIndex: 'action',
       slots: { customRender: 'action' },
     },
-    immediate: true,
+    immediate: false, // 先不立即加载,等状态数据获取后再加载
   });
 
   // 已解决表格注册
   const [registerResolvedTable, { reload: reloadResolved }] = useTable({
-    api: getQuaQueListByTab(),
-    columns,
+    api: async (params: any) => {
+      return await getDataQuaQueList({ ...params, isOk: true });
+    },
+    columns: columns,
     formConfig: {
       labelWidth: 120,
-      schemas: searchFormSchema,
+      schemas: searchFormSchema.value,
       showAdvancedButton: false,
       schemaGroupNames: ['常规查询'],
     },
@@ -156,7 +217,7 @@
       dataIndex: 'action',
       slots: { customRender: 'action' },
     },
-    immediate: true,
+    immediate: false, // 先不立即加载
   });
 
   // 弹框注册
@@ -176,7 +237,47 @@
       console.error('解析质量问题JSON失败:', error);
       return '问题数据解析失败';
     }
+  };
+
+  // 安全重载当前激活的表格
+  async function safeReloadActiveTable() {
+    await nextTick();
+    if (activeKey.value === 'unresolved') {
+      try {
+        await reloadUnresolved();
+      } catch (e) {
+        console.warn('未解决表格重载失败:', e);
+      }
+    } else {
+      try {
+        await reloadResolved();
+      } catch (e) {
+        console.warn('已解决表格重载失败:', e);
+      }
+    }
   }
+  // 按需重载双表格(仅在「标记已解决」等跨Tab操作时用)
+  async function reloadBothTableSafely() {
+    await nextTick();
+    // 未解决表格:await + try/catch 捕获异步错误
+    try {
+      await reloadUnresolved(); 
+    } catch (e) {
+      console.warn('未解决表格暂未就绪,跳过重载:', e);
+    }
+    // 已解决表格:同理,一个报错不影响另一个
+    try {
+      await reloadResolved(); 
+    } catch (e) {
+      console.warn('已解决表格暂未就绪,跳过重载:', e);
+    }
+  }
+
+  // tabs切换事件
+  async function handleTabChange(key: string) {
+    activeKey.value = key;
+    await safeReloadActiveTable();
+  };
 
   /**
    * 根据标签获取表格数据(已解决/未解决)
@@ -195,10 +296,7 @@
    */
   function handleOpenModal(record: any, mode: 'view' | 'edit' | 'add' = 'view') {
     pageMode.value = mode;
-    openModal(true, {
-      record,
-      mode,
-    });
+    openModal(true, { record, mode });
   }
 
   /**
@@ -208,43 +306,39 @@
   async function handleModalSuccess(result: any) {
     try {
       if (pageMode.value === 'add') {
-        console.log(result);
         await addDataQuaQue(result);
       } else if (pageMode.value === 'edit') {
         await editDataQuaQue(result);
       }
-      // 刷新表格
-      await nextTick();
-      reloadUnresolved();
-      reloadResolved();
+      await safeReloadActiveTable(); 
     } catch (error) {
       console.log('操作失败:', error);
     }
   }
   /**
-   * 通用页面跳转方法
-   * @param record 当前行数据
-   * @param path 目标路径(树形结构所在页面的路由地址)
-   */
+ * 通用页面跳转方法
+ * @param record 当前行数据
+ * @param path 目标路径(树形结构所在页面的路由地址)
+ */
   async function handleGoToPage(record: any) {
     try {
       const mineCode = record.mineCode;
-      const targetNode = findNode(mineStore.getMineTree, (item) => item.id === mineCode, { id: 'id', pid: 'parentId', children: 'childDepart' });
+      const targetNode = findNode(
+        mineStore.getMineTree,
+        (item) => item.id === mineCode,
+        { id: 'id', pid: 'parentId', children: 'childDepart' }
+      );
 
       let minePath = '';
       if (targetNode) {
-        minePath = targetNode.parentId; // 取parentId作为minePath
-        console.log('minePath(当前节点的parentId):', minePath);
+        minePath = targetNode.parentId;
       } else {
         message.warning(`未找到矿码【${mineCode}】对应的矿井节点`);
         return;
       }
 
       // 跳转页面(可携带拼接后的矿名/路径等参数)
-      router.push({
-        path: `/sealed/${minePath}`,
-        query: {},
-      });
+      router.push({ path: `/sealed/${minePath}`, query: {} });
     } catch (error) {
       console.error('矿节点定位失败:', error);
       message.error('矿节点定位失败,请稍后重试');
@@ -262,7 +356,7 @@
    * 生成已解决气泡提示文案:XX矿井XX问题是否解决了吗?
    */
   const getResolveDesc = computed(() => (record: any) => {
-    const mineName = record.mineName || '该'; // 矿井名称兜底
+    const mineName = record.mineName || '该';
     return `是否确认${mineName}矿井问题已解决?`;
   });
 
@@ -274,7 +368,7 @@
     try {
       await deleteDataQuaQue({ id: record.id });
       await nextTick();
-      reloadUnresolved();
+      await safeReloadActiveTable(); 
     } catch (error) {
       console.error('删除失败:', error);
     }
@@ -288,15 +382,12 @@
     const copyRecord = {
       ...record,
       isOk: true,
-      updateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
+      updateTime: dayjs().format('YYYY-MM-DD HH:mm:ss')
     };
-    copyRecord.isOk = true;
     try {
       await editDataQuaQue(copyRecord);
-      await nextTick();
-      reloadUnresolved();
-      reloadResolved();
-    } catch (error) {
+      await safeReloadActiveTable(); 
+    }catch (error) {
       console.error('操作失败:', error);
     }
   }
@@ -307,7 +398,7 @@
   async function getAllUnresolvedData() {
     try {
       const res = await getDataQuaQueList({ pageNum: 1, pageSize: 9999, isOk: false });
-      return res.records || []; // 请根据实际接口返回结构调整(比如res.list / res.data等)
+      return res.records || [];
     } catch (error) {
       console.error('获取未解决数据失败:', error);
       return [];
@@ -320,7 +411,7 @@
   async function getAllResolvedData() {
     try {
       const res = await getDataQuaQueList({ pageNum: 1, pageSize: 9999, isOk: true });
-      return res.records || []; // 请根据实际接口返回结构调整
+      return res.records || [];
     } catch (error) {
       console.error('获取已解决数据失败:', error);
       return [];
@@ -334,7 +425,7 @@
     return dataList.map((item) => ({
       煤矿名称: item.mineName || '',
       煤矿简称: item.mineNameAbbr || '',
-      生产状态: productionStatusMap[item.mineProStatus]?.label || '未知状态',
+      生产状态: dynamicProductionStatusMap.value[item.mineProStatus]?.label || '-',
       在线状态: item.mineLinkStatus === 1 ? '在线' : item.mineLinkStatus === 0 ? '离线' : '/',
       质量问题详情: formatQueJson(item.queJson),
       当前状态: item.isOk ? '已解决' : '未解决',
@@ -346,12 +437,10 @@
    * 导出Excel核心方法
    */
   async function handleExportExcel() {
-    // 声明关闭函数
     let hideLoading: () => void = () => {};
     try {
-      // 初始化loading并获取关闭函数
       hideLoading = message.loading('正在导出数据,请稍候...');
-
+      
       const unresolvedList = await getAllUnresolvedData();
       const resolvedList = await getAllResolvedData();
 
@@ -368,18 +457,20 @@
       const fileName = `数据质量问题_${dayjs().format('YYYYMMDDHHmmss')}.xlsx`;
       XLSX.writeFile(workbook, fileName);
 
-      // 关闭加载提示
       hideLoading();
       message.success('导出成功!');
     } catch (error) {
-      // 容错:若loading已初始化,再调用关闭
-      if (hideLoading) {
-        hideLoading();
-      }
+      if (hideLoading) hideLoading();
       console.error('Excel导出失败:', error);
       message.error('导出失败,请稍后重试');
     }
   }
+
+  // ========== 初始化:先获取状态数据,再加载表格 ==========
+  onMounted(async () => {
+    await fetchProductionStatus(); // 先获取动态状态数据
+    await safeReloadActiveTable(); 
+  });
 </script>
 
 <style scoped lang="less">

+ 88 - 13
src/views/dashboard/basicInfo/minesInfo/index.vue

@@ -16,54 +16,129 @@
 </template>
 
 <script setup lang="ts">
+  import { ref, nextTick, computed, onMounted } from 'vue';
   import { useRouter } from 'vue-router';
   import { BasicTable, useTable } from '/@/components/Table';
-  import { columns, searchFormSchema } from './minesInfo.data';
   import { SvgIcon } from '/@/components/Icon';
+  import { message } from 'ant-design-vue';
+  // 引入动态列/表单配置函数 + 类型
+  import { getColumns, getSearchFormSchema, type ProductionStatusMap } from './minesInfo.data';
   import { getMineData } from '../basicInfo.api';
+  // 引入字典获取方法
+  import { getDictItemsByCode } from '/@/utils/dict';
 
   // 路由实例
   const router = useRouter();
-  // 注册表格并获取相关方法
-  const [registerTable] = useTable({
+
+  // ========== 动态生产状态配置 ==========
+  // 1. 响应式存储动态状态映射(key: 状态值,value: 配置)
+  const dynamicProductionStatusMap = ref<ProductionStatusMap>({});
+  // 2. 响应式存储动态下拉选项(供搜索表单使用)
+  const dynamicProductionStatusOptions = ref<{ label: string; value: string | number }[]>([]);
+
+  // 3. 生产状态颜色分配规则(和dataQuality保持一致)
+  const getStatusColor = (statusText: string) => {
+    if (statusText.includes('正常生产')) return 'green';
+    if (statusText.includes('拟建矿井')) return 'blue';
+    return 'red'; // 其他状态统一红色
+  };
+
+  // 4. 从接口获取生产状态字典,生成动态映射/选项
+  const fetchProductionStatus = async () => {
+    try {
+      const statusList = await getDictItemsByCode('mineProStatus');
+      if (!Array.isArray(statusList)) return;
+
+      const statusMap: ProductionStatusMap = {};
+      const statusOptions: { label: string; value: string | number }[] = [];
+      
+      statusList.forEach((item) => {
+        const value = item.value;
+        const label = item.text || item.label;
+        const color = getStatusColor(label);
+        
+        statusMap[value] = { label, value, color };
+        statusOptions.push({ label, value });
+      });
+
+      // 赋值到响应式变量
+      dynamicProductionStatusMap.value = statusMap;
+      dynamicProductionStatusOptions.value = statusOptions;
+
+      // 刷新表格(使用最新的状态映射)
+      await safeReloadTable();
+    } catch (error) {
+      console.error('获取生产状态字典失败:', error);
+      message.error('生产状态数据加载失败');
+    }
+  };
+
+  // 5. 生成动态列和搜索表单(computed响应式更新)
+  const columns = computed(() => getColumns(dynamicProductionStatusMap));
+  const searchFormSchema = computed(() => getSearchFormSchema(dynamicProductionStatusOptions));
+
+  // ========== 表格注册 ==========
+  const [registerTable, { reload: reloadTable }] = useTable({
     title: '矿山信息表格',
     api: getMineData, // 数据统计接口
-    columns,
+    columns: columns, // 绑定动态列
     formConfig: {
       labelWidth: 120,
-      schemas: searchFormSchema,
+      schemas: searchFormSchema.value, // 绑定动态搜索表单
       showAdvancedButton: false,
       schemaGroupNames: ['常规查询'],
     },
     pagination: true,
     useSearchForm: true,
-    // showTableSetting: true,
     bordered: true,
     showIndexColumn: false,
     scroll: { x: 'max-content' },
-    // canResize: false,
     actionColumn: {
       width: 180,
       title: '操作',
       dataIndex: 'action',
       slots: { customRender: 'action' },
     },
+    immediate: false, // 先不加载,等字典获取后再加载
   });
 
+  // ========== 辅助方法 ==========
+  // 安全刷新表格(避免表格未初始化导致的报错)
+  async function safeReloadTable() {
+    await nextTick();
+    try {
+      await reloadTable();
+    } catch (e) {
+      console.warn('矿山信息表格重载失败:', e);
+    }
+  }
+
   /**
    * 通用页面跳转方法
    * @param record 当前行数据
    * @param path 目标路径
    */
   function handleGoToPage(record: any, path: string) {
-    // 跳转时携带当前煤矿的编号作为参数(根据实际需求调整携带的参数)
     router.push({
       path,
-      // query: {
-      //   orderNo: record.orderNo, // 煤矿编号
-      //   mineName: record.mineName // 煤矿名称
-      // }
     });
   }
+
+  // ========== 初始化 ==========
+  onMounted(async () => {
+    // 先获取生产状态字典,再加载表格
+    await fetchProductionStatus();
+  });
 </script>
-<style lang="less" scoped></style>
+
+<style lang="less" scoped>
+  .action-btn {
+    height: 30px;
+    cursor: pointer;
+    margin-right: 10px;
+
+    &:last-child {
+      margin-right: 0;
+    }
+  }
+</style>

+ 165 - 170
src/views/dashboard/basicInfo/minesInfo/minesInfo.data.ts

@@ -1,34 +1,10 @@
 import { BasicColumn } from '/@/components/Table';
 import { FormSchema } from '/@/components/Table';
 import { h } from 'vue';
+import { Ref } from 'vue';
 
-// 生产状态映射表(扩展所有状态)
-const productionStatusMap: Record<string | number, { text: string; value: number; color: string }> = {
-  0: { text: '正常生产矿井', value: 0, color: 'green' },
-  1: { text: '拟建矿井', value: 1, color: 'blue' },
-  2: { text: '正常建设煤矿', value: 2, color: 'red' },
-  3: { text: '自行停产矿井', value: 3, color: 'red' },
-  4: { text: '正在关闭', value: 4, color: 'red' },
-  5: { text: '责令停产整顿', value: 5, color: 'red' },
-  6: { text: '责令停止建设', value: 6, color: 'red' },
-  7: { text: '已关闭矿井', value: 7, color: 'red' },
-  8: { text: '长期停产矿井', value: 8, color: 'red' },
-  9: { text: '长期停建矿井', value: 9, color: 'red' },
-  10: { text: '停产整改矿井', value: 10, color: 'red' },
-  11: { text: '长期停建无法联系', value: 11, color: 'red' },
-  12: { text: '停建整改', value: 12, color: 'red' },
-  13: { text: '自行停建', value: 13, color: 'red' },
-  14: { text: '正在实施关闭', value: 14, color: 'red' },
-  // 15: { text: '已关闭矿井', color: 'red' },
-};
-
-// 基于productionStatusMap生成下拉选项
-export const productionStatusOptions = Object.entries(productionStatusMap).map(([key, item]) => ({
-  label: item.text, // 状态名称
-  value: key, // 状态值
-}));
-// 颜色映射
-const colorHexMap: Record<string, string> = {
+// 1. 颜色映射(修正原拼写错误,统一规则)
+export const colorHexMap: Record<string, string> = {
   blue: '#1890ff',
   green: '#208840',
   gold: '#faad14',
@@ -37,147 +13,166 @@ const colorHexMap: Record<string, string> = {
   black: '#000000',
 };
 
-export const columns: BasicColumn[] = [
-  {
-    title: '煤矿编号',
-    dataIndex: 'mineCode',
-    width: 100,
-  },
-  {
-    title: '所属执法处',
-    dataIndex: 'managementName',
-    width: 100,
-  },
-  {
-    title: '煤矿名称',
-    dataIndex: 'mineName',
-    width: 200,
-  },
-  {
-    title: '煤矿简称',
-    dataIndex: 'mineNameAbbr',
-    width: 100,
-  },
-  {
-    title: '生产状态',
-    dataIndex: 'productionStatus',
-    width: 100,
-    customRender: ({ record }) => {
-      // 空值/异常值处理
-      const status = String(record.productionStatus || '');
-      const { text, color } = productionStatusMap[status] || { text: '未知状态', color: 'balck' };
-      // 渲染普通span,仅设置文字颜色
-      return h('span', { style: { color: colorHexMap[color] || colorHexMap.gray } }, text);
-    },
-  },
-  {
-    title: '自燃情况',
-    dataIndex: 'alarmLevel',
-    width: 100,
-  },
-  {
-    title: '接入状态',
-    dataIndex: 'accessStatus',
-    width: 100,
-    customRender: ({ record }) => {
-      // 空值/异常值处理
-      const status = String(record.accessStatus || '');
-      if (!status || status === 'undefined' || status === 'null') {
-        return h('span', { style: { color: colorHexMap.black } }, '/');
-      }
-      const text = status === '1' ? '接入' : '未接入';
-      const textColor = status === '1' ? colorHexMap.green : colorHexMap.gold;
-      return h('span', { style: { color: textColor } }, text);
-    },
-  },
-  {
-    title: '在线状态',
-    dataIndex: 'status',
-    width: 100,
-    customRender: ({ record }) => {
-      const status = String(record.status || '');
-      if (!status || status === 'undefined' || status === 'null') {
-        return h('span', { style: { color: colorHexMap.black } }, '/');
-      }
-      const text = status === '1' ? '在线' : '离线';
-      const textColor = status === '1' ? colorHexMap.green : colorHexMap.red;
-      return h('span', { style: { color: textColor } }, text);
-    },
-  },
-  {
-    title: '应接数量',
-    dataIndex: 'yingjieNum',
-    width: 100,
-  },
-  {
-    title: '已接数量',
-    dataIndex: 'accessGoafNum',
-    width: 100,
-  },
-  {
-    title: '未接数量',
-    dataIndex: 'notAccessGoafNum',
-    width: 100,
-  },
-];
+// 2. 定义生产状态映射类型(和dataQuality保持一致)
+export type ProductionStatusMap = Record<string | number, { 
+  label: string; 
+  value: number | string; 
+  color: string; 
+}>;
+
+// 3. 生成动态表格列(接收动态状态映射)
+export function getColumns(dynamicStatusMap: Ref<ProductionStatusMap>): BasicColumn[] {
+  return [
+    {
+      title: '煤矿编号',
+      dataIndex: 'mineCode',
+      width: 100,
+    },
+    {
+      title: '所属执法处',
+      dataIndex: 'managementName',
+      width: 100,
+    },
+    {
+      title: '煤矿名称',
+      dataIndex: 'mineName',
+      width: 200,
+    },
+    {
+      title: '煤矿简称',
+      dataIndex: 'mineNameAbbr',
+      width: 100,
+    },
+    {
+      title: '生产状态',
+      dataIndex: 'productionStatus',
+      width: 100,
+      customRender: ({ record }) => {
+        // 空值/异常值处理
+        const status = String(record.productionStatus || '');
+        // 从动态映射取值,兜底未知状态
+        const { label, color } = dynamicStatusMap.value[status] || { 
+          label: '-', 
+        };
+        // 渲染带颜色的文字
+        return h('span', { 
+          style: { color: colorHexMap[color] } 
+        }, label);
+      },
+    },
+    {
+      title: '自燃情况',
+      dataIndex: 'alarmLevel',
+      width: 100,
+    },
+    {
+      title: '接入状态',
+      dataIndex: 'accessStatus',
+      width: 100,
+      customRender: ({ record }) => {
+        // 空值/异常值处理
+        const status = String(record.accessStatus || '');
+        if (!status || status === 'undefined' || status === 'null') {
+          return h('span', { style: { color: colorHexMap.black } }, '/');
+        }
+        const text = status === '1' ? '接入' : '未接入';
+        const textColor = status === '1' ? colorHexMap.green : colorHexMap.gold;
+        return h('span', { style: { color: textColor } }, text);
+      },
+    },
+    {
+      title: '在线状态',
+      dataIndex: 'status',
+      width: 100,
+      customRender: ({ record }) => {
+        const status = String(record.status || '');
+        if (!status || status === 'undefined' || status === 'null') {
+          return h('span', { style: { color: colorHexMap.black } }, '/');
+        }
+        const text = status === '1' ? '在线' : '离线';
+        const textColor = status === '1' ? colorHexMap.green : colorHexMap.red;
+        return h('span', { style: { color: textColor } }, text);
+      },
+    },
+    {
+      title: '应接数量',
+      dataIndex: 'yingjieNum',
+      width: 100,
+    },
+    {
+      title: '已接数量',
+      dataIndex: 'accessGoafNum',
+      width: 100,
+    },
+    {
+      title: '未接数量',
+      dataIndex: 'notAccessGoafNum',
+      width: 100,
+    },
+  ];
+}
 
-export const searchFormSchema: FormSchema[] = [
-  {
-    field: 'mineCode',
-    label: '煤矿名称',
-    component: 'MineCascader',
-    colProps: { span: 6 },
-  },
-  {
-    field: 'mineNameAbbr',
-    label: '煤矿简称',
-    component: 'Input',
-    colProps: { span: 6 },
-  },
-  {
-    field: 'productionStatus',
-    label: '生产状态',
-    component: 'Select',
-    componentProps: {
-      options: productionStatusOptions,
-    },
-    colProps: { span: 6 },
-  },
-  {
-    field: 'accessStatus',
-    label: '接入状态',
-    component: 'Select',
-    componentProps: {
-      options: [
-        { label: '接入', value: 1 },
-        { label: '未接入', value: 0 },
-      ],
-    },
-    colProps: { span: 6 },
-  },
-  {
-    field: 'status',
-    label: '在线状态',
-    component: 'Select',
-    componentProps: {
-      options: [
-        { label: '离线', value: '0' },
-        { label: '在线', value: '1' },
-      ],
-    },
-    colProps: { span: 6 },
-  },
-  {
-    field: 'riskLevel',
-    label: '风险等级',
-    component: 'Select',
-    componentProps: {
-      options: [
-        { label: 'Ⅰ类容易自燃', value: '0' },
-        { label: 'Ⅱ类自燃', value: '1' },
-        { label: 'Ⅲ类不易自燃', value: '2' },
-      ],
-    },
-    colProps: { span: 6 },
-  },
-];
+// 4. 生成动态搜索表单配置(接收动态下拉选项)
+export function getSearchFormSchema(dynamicStatusOptions: Ref<{ label: string; value: string | number }[]>): FormSchema[] {
+  return [
+    {
+      field: 'mineCode',
+      label: '煤矿名称',
+      component: 'MineCascader',
+      colProps: { span: 6 },
+    },
+    {
+      field: 'mineNameAbbr',
+      label: '煤矿简称',
+      component: 'Input',
+      colProps: { span: 6 },
+    },
+    {
+      field: 'productionStatus',
+      label: '生产状态',
+      component: 'Select',
+      componentProps: {
+        // 动态绑定下拉选项
+        options: dynamicStatusOptions,
+      },
+      colProps: { span: 6 },
+    },
+    {
+      field: 'accessStatus',
+      label: '接入状态',
+      component: 'Select',
+      componentProps: {
+        options: [
+          { label: '接入', value: 1 },
+          { label: '未接入', value: 0 },
+        ],
+      },
+      colProps: { span: 6 },
+    },
+    {
+      field: 'status',
+      label: '在线状态',
+      component: 'Select',
+      componentProps: {
+        options: [
+          { label: '离线', value: '0' },
+          { label: '在线', value: '1' },
+        ],
+      },
+      colProps: { span: 6 },
+    },
+    {
+      field: 'riskLevel',
+      label: '风险等级',
+      component: 'Select',
+      componentProps: {
+        options: [
+          { label: 'Ⅰ类容易自燃', value: '0' },
+          { label: 'Ⅱ类自燃', value: '1' },
+          { label: 'Ⅲ类不易自燃', value: '2' },
+        ],
+      },
+      colProps: { span: 6 },
+    },
+  ];
+}