|
|
@@ -8,7 +8,7 @@
|
|
|
<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-button type="primary" @click="copy()" v-if="edit">复制表格</el-button>
|
|
|
<el-checkbox v-model="isMerge" style="margin-left: 10px" v-if="edit"
|
|
|
>合并单元格</el-checkbox
|
|
|
>
|
|
|
@@ -328,7 +328,7 @@
|
|
|
},
|
|
|
getIndex(id) {
|
|
|
let columnIndex, rowIndex;
|
|
|
- console.log(id);
|
|
|
+
|
|
|
this.columns.forEach((cell, _columnIndex) => {
|
|
|
let cellIndex = cell.findIndex((data) => data.id == id);
|
|
|
if (cellIndex != '-1') {
|
|
|
@@ -365,6 +365,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;
|
|
|
@@ -454,6 +457,7 @@
|
|
|
if (item.colspanKey.length) {
|
|
|
this.columns.forEach((cell) => {
|
|
|
cell.forEach((row) => {
|
|
|
+
|
|
|
if (item.colspanKey.includes(row.id)) {
|
|
|
width += Number(row.style.width);
|
|
|
}
|
|
|
@@ -535,16 +539,34 @@
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
- // copy() {
|
|
|
- // this.$emit('copy', {
|
|
|
- // form: null,
|
|
|
- // equation: JSON.parse(JSON.stringify(this.equation)),
|
|
|
- // units: JSON.parse(JSON.stringify(this.units)),
|
|
|
- // valueObj: {
|
|
|
- // columns: JSON.parse(JSON.stringify(this.valueObj))
|
|
|
- // }
|
|
|
- // });
|
|
|
- // },
|
|
|
+ copy() {
|
|
|
+ let columns = JSON.parse(JSON.stringify(this.columns));
|
|
|
+ columns.forEach((item, index) => {
|
|
|
+ item.forEach((cell) => {
|
|
|
+ if (cell.colspanKey.length&&!cell.copyId) {
|
|
|
+ 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;
|