yusheng před 5 měsíci
rodič
revize
e1590edf48

+ 21 - 6
src/components/common/MaterialAdd.vue

@@ -105,17 +105,28 @@
             fixed: 'left'
           },
           {
-            label: '设备名称',
-            prop: 'name'
+            prop: 'category.name',
+            label: '名称',
+            showOverflowTooltip: true,
+            minWidth: 110
           },
           {
-            label: '编码',
-            prop: 'code'
+            prop: 'fixCode',
+            label: '固资编码',
+            showOverflowTooltip: true,
+            minWidth: 110
           },
           {
-            label: '固资编码',
-            prop: 'fixCode'
+            prop: 'codeNumber',
+            label: '编号',
+            showOverflowTooltip: true,
+            minWidth: 110
           },
+          {
+            label: '编码',
+            prop: 'code'
+          },
+
           {
             label: '使用人',
             prop: 'usePerson'
@@ -195,6 +206,10 @@
           console.log('res---treeList----------', res);
           this.treeLoading = false;
           this.treeList = res.data;
+          this.handleNodeClick(res.data[0])
+          this.$nextTick(()=>{
+            this.$refs.treeRef.setCurrentKey(res.data[0].id)
+          })
         } catch (error) {
           console.log(error);
         }

+ 110 - 0
src/directives/tableScrollSync.js

@@ -0,0 +1,110 @@
+// 工具函数:获取 .el-table__body-wrapper 下的滚动容器
+function getBodyWrapper(el) {
+  return el.querySelector('.el-table__body-wrapper');
+}
+
+// 创建滚动条并绑定事件,返回清理函数
+function setupScrollSync(el) {
+  const table = el; // el 就是容器元素
+  if (!table) return null;
+
+  const outerWidth = table.offsetWidth;
+  // 取第一个内部 table 的宽度作为内容宽度
+  const innerTable = table.querySelector('table');
+  const contentWidth = innerTable ? innerTable.offsetWidth : outerWidth;
+
+  const bodyWrapper = getBodyWrapper(table);
+  if (!bodyWrapper) {
+    console.warn('未找到 .el-table__body-wrapper,无法创建滚动同步');
+    return null;
+  }
+  // 隐藏原生横向滚动条,但保留纵向滚动条
+  bodyWrapper.style.overflowX = 'hidden';
+  bodyWrapper.style.overflowY = 'auto';
+  
+  // 创建自定义样式标签来隐藏横向滚动条
+  const styleId = 'v-scroll-sync-hide-x-scrollbar';
+  let styleEl = document.getElementById(styleId);
+  if (!styleEl) {
+    styleEl = document.createElement('style');
+    styleEl.id = styleId;
+    styleEl.textContent = `
+      .el-table__body-wrapper.v-scroll-sync-hide-x::-webkit-scrollbar {
+        width: 6px;
+        height: 0;
+      }
+      .el-table__body-wrapper.v-scroll-sync-hide-x::-webkit-scrollbar-track {
+        background: transparent;
+      }
+      .el-table__body-wrapper.v-scroll-sync-hide-x::-webkit-scrollbar-thumb {
+        background: #d9d9d9;
+        border-radius: 3px;
+      }
+    `;
+    document.head.appendChild(styleEl);
+  }
+  bodyWrapper.classList.add('v-scroll-sync-hide-x');
+  // 避免重复创建
+  const existingDiv = table.querySelector('.v-scroll-sync-bar');
+  if (existingDiv) existingDiv.remove();
+
+  const div = document.createElement('div');
+  div.className = 'v-scroll-sync-bar';
+  div.style.width = outerWidth + 'px';
+  div.style.height = '12px';
+  div.style.overflowX = 'auto';
+  div.innerHTML = `<div style="width:${contentWidth}px; height:1px;"></div>`;
+
+  const onScroll = () => {
+    bodyWrapper.scrollLeft = div.scrollLeft;
+  };
+  div.addEventListener('scroll', onScroll);
+
+  const tableContainer = table.querySelector('.el-table');
+
+  // 在tableContainer后面插入div(作为兄弟元素)
+  tableContainer.insertAdjacentElement('afterend', div);
+
+  // table.appendChild(div);
+
+  // 返回清理函数和事件引用
+  return {
+    div,
+    bodyWrapper,
+    handler: onScroll,
+    destroy() {
+      div.removeEventListener('scroll', onScroll);
+      if (div.parentNode) div.parentNode.removeChild(div);
+      // 移除添加的class
+      bodyWrapper.classList.remove('v-scroll-sync-hide-x');
+    }
+  };
+}
+
+// Vue 2 自定义指令
+const tableScrollSync = {
+  bind(el) {
+    // bind 时可能未插入文档,先不做操作,统一在 inserted 中处理
+    el._scrollSyncData = null;
+  },
+  inserted(el) {
+    // 元素插入 DOM 后初始化
+    el._scrollSyncData = setupScrollSync(el);
+  },
+  update(el) {
+    // 当表格数据变化导致内容宽度改变时(如切换分页、动态列),重新初始化
+    if (el._scrollSyncData) {
+      el._scrollSyncData.destroy();
+    }
+    el._scrollSyncData = setupScrollSync(el);
+  },
+  unbind(el) {
+    // 指令解绑时销毁
+    if (el._scrollSyncData) {
+      el._scrollSyncData.destroy();
+      el._scrollSyncData = null;
+    }
+  }
+};
+
+export default tableScrollSync;

+ 6 - 1
src/main.js

@@ -20,8 +20,12 @@ import clickOnce from './utils/clickOnce.js';
 import noChinese from './utils/noChinese.js';
 import { VirtualScroller } from 'vue-virtual-scroller';
 import 'vue-virtual-scroller/dist/vue-virtual-scroller.css';
+import { getSummaries } from '@/utils/util.js';
+import dataV from '@jiaminghi/data-view';
+import tableScrollSync from '@/directives/tableScrollSync';
 Vue.component('virtual-scroller', VirtualScroller);
-import dataV from '@jiaminghi/data-view'
+
+Vue.directive('table-scroll-sync', tableScrollSync);
 
 import { all, create } from 'mathjs'; // 引入mathjs工具并初始化
 // 注册全局自定义指令
@@ -39,6 +43,7 @@ Vue.prototype.$math = create(all, {
   number: 'BigNumber',
   precision: 64
 });
+Vue.prototype.$getSummaries = getSummaries;
 Vue.use(Vue2OrgTree);
 Vue.use(dataV);
 

+ 1 - 1
src/utils/util.js

@@ -156,4 +156,4 @@ export function convertToChinese(num) {
   } else {
     return chineseInteger + cnIntLast + chineseDecimal;
   }
-}
+}

+ 8 - 4
src/views/alarmConfiguration/index.vue

@@ -20,6 +20,7 @@
           :datasource="datasource"
           :cache-key="cacheKeyUrl"
           height="calc(100vh - 350px)"
+          @columns-change="handleColumnChange"
         >
           <template v-slot:toolbar
             ><el-button
@@ -70,11 +71,14 @@
 
 <script>
   import AlarmDialog from './alarmDialog.vue';
-
+  import tabMixins from '@/mixins/tableColumnsMixin';
+  import dictMixins from '@/mixins/dictMixins';
   export default {
     components: {
       AlarmDialog
     },
+    mixins: [tabMixins, dictMixins],
+
     data() {
       return {
         // 表格列配置
@@ -194,9 +198,9 @@
       // 获取告警级别类型
       getAlarmLevelType(level) {
         const typeMap = {
-          '严重': 'danger',
-          '紧急': 'warning',
-          '一般': 'success'
+          严重: 'danger',
+          紧急: 'warning',
+          一般: 'success'
         };
         return typeMap[level] || 'info';
       },

+ 33 - 1
src/views/centralizedMeterReading/collectionList.vue

@@ -158,7 +158,7 @@
             </div>
 
             <!-- 列表视图 -->
-            <div class="list-view">
+            <div class="list-view" v-table-scroll-sync>
               <ele-pro-table
                 ref="table"
                 row-key="id"
@@ -168,6 +168,8 @@
                 :cache-key="cacheKeyUrl"
                 autoAmendPage
                 height="calc(100vh - 300px)"
+                show-summary
+                :summary-method="getSummaries"
               >
               </ele-pro-table>
             </div>
@@ -286,7 +288,13 @@
               prop: i < 10 ? 'hour0' + i : 'hour' + i,
               label: i + '时',
               align: 'center',
+              isSummarie: true,
               minWidth: 90,
+              formatter: (_row, _column, cellValue) => {
+                if (cellValue) {
+                  return cellValue + ' ' + _row.unit;
+                }
+              },
               showOverflowTooltip: true
             });
           }
@@ -302,6 +310,12 @@
               label: i + '日',
               align: 'center',
               minWidth: 90,
+              isSummarie: true,
+              formatter: (_row, _column, cellValue) => {
+                if (cellValue) {
+                  return cellValue + ' ' + _row.unit;
+                }
+              },
               showOverflowTooltip: true
             });
           }
@@ -314,6 +328,12 @@
               label: i + '月',
               align: 'center',
               minWidth: 100,
+              isSummarie: true,
+              formatter: (_row, _column, cellValue) => {
+                if (cellValue) {
+                  return cellValue + ' ' + _row.unit;
+                }
+              },
               showOverflowTooltip: true
             });
           }
@@ -327,7 +347,13 @@
               prop: year + '',
               label: year + '年',
               align: 'center',
+              isSummarie: true,
               minWidth: 100,
+              formatter: (_row, _column, cellValue) => {
+                if (cellValue) {
+                  return cellValue + ' ' + _row.unit;
+                }
+              },
               showOverflowTooltip: true
             });
           }
@@ -336,6 +362,12 @@
       }
     },
     methods: {
+      getSummaries(param) {
+        const arr = this.columns
+          .filter((item) => item.isSummarie)
+          .map((item) => item.prop);
+        return this.$getSummaries(param, arr, ' ');
+      },
       // 初始化默认日期
       initDefaultDate() {
         const today = dayjs();

+ 1 - 1
src/views/centralizedMeterReading/meterReadingDialog.vue

@@ -221,7 +221,7 @@
       handleChooseEquipment(row) {
         console.log('选择设备:', row);
         this.form.substanceId = row.id;
-        this.form.substanceName = row.name;
+        this.form.substanceName = row?.category?.name;
         this.form.substanceCode = row.code;
         this.form.areaCode = row.areaCode;
         this.form.areaId = row.areaId;