Преглед изворни кода

新增表格复制功能并优化实验过程区域滚动样式

yusheng пре 5 месеци
родитељ
комит
a8c1f2f40d

+ 33 - 1
src/components/templateDiv/customTable.vue

@@ -8,6 +8,8 @@
     <el-button type="primary" @click="addRow(columns[0].length)" v-if="edit"
       >新增行</el-button
     >
+    <el-button type="primary" @click="copy()" v-if="edit">复制表格</el-button>
+
     <el-checkbox v-model="isMerge" style="margin-left: 10px" v-if="edit"
       >合并单元格</el-checkbox
     >
@@ -365,6 +367,9 @@
             this.columns[columnIndex].forEach((cell, rowIndex) => {
               if (cell.colspanKey.length) {
                 //当前删除的列其他行有合并过单元格的处理
+                if (!this.columns[columnIndex + 1]) {
+                  return;
+                }
                 let data = this.columns[columnIndex + 1][rowIndex];
 
                 data.colspan = cell.colspan - 1;
@@ -535,7 +540,34 @@
           });
         }
       },
-
+      copy() {
+        let columns = JSON.parse(JSON.stringify(this.columns));
+        columns.forEach((item, index) => {
+          item.forEach((cell, _index) => {
+            if (cell.colspanKey.length) {
+              cell.colspanKey.forEach((key, index) => {
+                let id = generateRandomString(5);
+                let { columnIndex, rowIndex } = this.getIndex(key);
+                columns[columnIndex][rowIndex]['copyId'] = id;
+                cell.colspanKey[index] = id;
+              });
+            }
+            if (cell.copyId) {
+              cell.id = cell.copyId;
+            } else {
+              cell.id = generateRandomString(5);
+            }
+          });
+        });
+        this.$emit('copy', {
+          value: null,
+          equation: {},
+          units: {},
+          valueObj: {
+            columns
+          }
+        });
+      },
       inputClick(item, type) {
         if (!this.edit) {
           return;

+ 16 - 1
src/components/templateDiv/experimentationProcess.vue

@@ -21,7 +21,7 @@
         group="project1"
         :animation="300"
         handle=".sort-handle"
-        style="flex: 1"
+        style="flex: 1; max-height: calc(100vh - 500px); overflow: auto"
       >
         <div
           class="demo-drag-list-item ele-cell"
@@ -62,6 +62,7 @@
               @calculation="calculation"
               @editShow="editShowFn"
               :readonly="readonly"
+              @copy="copy"
               :edit="edit"
             ></customTable>
           </div>
@@ -501,6 +502,20 @@
           valueObj: {}
         });
       },
+      copy(data) {
+        let id = generateRandomString(6);
+        this.list.push({
+          id,
+          type: 'customTable',
+          ...data
+        });
+        this.$nextTick(() => {
+          this.$refs['customTextRef' + id][0].init({
+            form: null,
+            ...data
+          });
+        });
+      },
       getValue() {
         this.list.forEach((item, index) => {
           let { form, valueObj, equation, units } =