Prechádzať zdrojové kódy

feat: 添加新列配置方案,支持动态切换列展示(润天环境使用)

xieyong 1 týždeň pred
rodič
commit
6ad414e461

+ 166 - 5
src/views/material/BOMmanage/components/detailedList.vue

@@ -9,7 +9,7 @@
       :pagination="pagination"
       :datasource="datasource"
       :page-size="20"
-      cache-key="routed_detailed_list"
+      :cache-key="useNewColumns ? 'routed_detailed_list_v2' : 'routed_detailed_list'"
       class="dict-table"
       tool-class="ele-toolbar-actions"
       :height="tableHeight"
@@ -280,7 +280,7 @@
 
   import clientDialog from './clientDialog.vue';
 
-  import { getByCode } from '@/api/system/dictionary-data';
+  import { getByCode, parameterGetByCode } from '@/api/system/dictionary-data';
 
   import bomTreeDialog from './bomTreeDialog.vue';
   import { produceTypeList } from '@/enum/dict.js';
@@ -294,11 +294,13 @@
       return {
         produceTypeList,
         clientEnvironmentId: this.$store.state.user.info.clientEnvironmentId,
+        // 是否启用新 columns 方案(true=新方案,false=老方案)
+        useNewColumns: false,
         pagination: {
           tableTotal: 0
         },
-        // 表格列配置
-        columns: [
+        // 老 columns 方案(保持原有 28 列可见)
+        oldColumnsConfig: [
           {
             label: '序号',
             columnKey: 'index',
@@ -446,7 +448,7 @@
           },
 
           {
-            prop: 'status ',
+            prop: 'status',
             label: '状态',
             formatter: (row) => {
               return this.statusOpt[+row.status];
@@ -476,6 +478,102 @@
             width: 120
           }
         ],
+        // 新 columns 方案:默认展示这 14 列,老方案里独有列由 computed 拼到末尾且 show:false
+        newColumnsConfig: [
+          {
+            prop: 'level',
+            label: '零部件层级',
+            align: 'center',
+            showOverflowTooltip: true,
+            width: 100
+          },
+          {
+            label: '序号',
+            columnKey: 'index',
+            type: 'index',
+            width: 55,
+            align: 'center',
+            showOverflowTooltip: true
+          },
+          {
+            prop: 'categoryCode',
+            label: '物料编码',
+            showOverflowTooltip: true,
+            width: 120
+          },
+          {
+            prop: 'imgCode',
+            label: '零部件图号(规格型号)',
+            showOverflowTooltip: true,
+            width: 150
+          },
+          {
+            prop: 'versions',
+            slot: 'versions',
+            label: '图纸版本',
+            showOverflowTooltip: true,
+            align: 'center',
+            width: 90
+          },
+          {
+            prop: 'updateTime',
+            label: '修改时间',
+            width: 160,
+            showOverflowTooltip: true
+          },
+          {
+            prop: 'name',
+            label: '零件名称',
+            showOverflowTooltip: true,
+            width: 150
+          },
+          {
+            prop: 'dosage',
+            slot: 'dosage',
+            label: '单台用量',
+            width: 100,
+            headerSlot: 'dosageHead'
+          },
+          {
+            prop: 'measuringUnit',
+            label: '计量单位',
+            showOverflowTooltip: true,
+            align: 'center',
+            width: 90
+          },
+          {
+            prop: 'brandNum',
+            label: '材质',
+            showOverflowTooltip: true,
+            width: 100
+          },
+          {
+            prop: 'netWeight',
+            label: '单重',
+            showOverflowTooltip: true,
+            align: 'right',
+            width: 100
+          },
+          {
+            prop: 'totalWeight',
+            label: '总重',
+            showOverflowTooltip: true,
+            align: 'right',
+            width: 100
+          },
+          {
+            prop: 'createName',
+            label: '创建人',
+            showOverflowTooltip: true,
+            width: 100
+          },
+          {
+            prop: 'createTime',
+            label: '创建日期',
+            width: 160,
+            showOverflowTooltip: true
+          }
+        ],
         statusOpt: {
           '': '全部',
           0: '草稿',
@@ -615,6 +713,7 @@
       // this.getDictList('productionType');
       // this.getZeroPartPros('zeroPartPros');
       this.getContactList();
+      this.getRuntianConfig();
     },
 
     props: {
@@ -677,6 +776,53 @@
     //     });
     //   }
     // },
+    computed: {
+      // 操作列:固定右侧,不参与新老的合并
+      actionColumn() {
+        return {
+          action: 'action',
+          slot: 'action',
+          fixed: 'right',
+          label: '操作',
+          width: 120
+        };
+      },
+      // 新方案默认展示的 prop 集合(与 newColumnsConfig 保持一致)
+      newPropSet() {
+        return new Set([
+          'level',
+          'categoryCode',
+          'imgCode',
+          'versions',
+          'updateTime',
+          'name',
+          'dosage',
+          'measuringUnit',
+          'brandNum',
+          'netWeight',
+          'totalWeight',
+          'createName',
+          'createTime'
+        ]);
+      },
+      // 表格列:按 useNewColumns 决定输出老方案还是新方案
+      columns() {
+        if (this.useNewColumns) {
+          // 老方案里独有、且不在新方案里的列 → 追加到末尾,默认隐藏,用户可手动显示
+          const extras = this.oldColumnsConfig
+            .filter((c) => {
+              if (c.action === 'action') return false; // 操作列单独追加
+              if (c.type === 'index' || c.columnKey === 'index') return false;
+              if (c.prop && this.newPropSet.has(c.prop)) return false;
+              return true;
+            })
+            .map((c) => ({ ...c, show: false }));
+          return [...this.newColumnsConfig, ...extras, this.actionColumn];
+        }
+        // 老方案:保持原有顺序
+        return [...this.oldColumnsConfig];
+      }
+    },
 
     methods: {
       attributeTypeText(v) {
@@ -697,6 +843,21 @@
         });
       },
 
+      // 根据系统参数 is_runtian 判断是否启用新 columns 方案
+      // 兼容常见返回:'1' / 1 / { value: 1 } / { paramValue: '1' } / true
+      async getRuntianConfig() {
+        try {
+          const data = await parameterGetByCode({ code: 'is_runtian' });
+          const val =
+            typeof data === 'object' && data !== null
+              ? data.value ?? data.paramValue ?? data.val
+              : data;
+          this.useNewColumns = val === '1' || val === 1 || val === true;
+        } catch (e) {
+          this.useNewColumns = false;
+        }
+      },
+
       rootCategoryLevelIdText(v) {
         console.log(v, '111111');
         console.log(