|
@@ -73,10 +73,13 @@
|
|
|
ref="component"
|
|
|
:key="`grid-${grid.id}`"
|
|
|
:class="[grid.id]"
|
|
|
+ :data-row="i"
|
|
|
+ :data-col="j"
|
|
|
+ :data-grid="k"
|
|
|
:border-color="computedBorderColor(row.row_id)"
|
|
|
:style="computedGridStyle(grid, row.row_id)"
|
|
|
- :delete-component="deleteComponent(i, j, k)"
|
|
|
:component-move="componentMove(i, j, k)"
|
|
|
+ @deleteComponent="deleteComponent"
|
|
|
@showSetting="showSetting"
|
|
|
@changeData="changeData"
|
|
|
/>
|
|
@@ -699,54 +702,55 @@ export default {
|
|
|
},
|
|
|
/**
|
|
|
* 删除组件
|
|
|
- * @param {number} i 行
|
|
|
- * @param {number} j 列
|
|
|
- * @param {number} k 格子
|
|
|
+ * @param {String} id 组件 id
|
|
|
*/
|
|
|
- deleteComponent(i, j, k) {
|
|
|
- return () => {
|
|
|
- const gridList = this.data.row_list[i].col_list[j].grid_list;
|
|
|
- let delRow = gridList[k].row; // 删除的 grid 的 row
|
|
|
- let delW = gridList[k].width; // 删除的 grid 的 width
|
|
|
- gridList.splice(k, 1);
|
|
|
-
|
|
|
- // 如果删除后没有 grid 了则删除列
|
|
|
- const colList = this.data.row_list[i].col_list[j];
|
|
|
- if (colList.grid_list.length === 0) {
|
|
|
- this.data.row_list[i].col_list.splice(j, 1);
|
|
|
- let width_list = this.data.row_list[i].width_list;
|
|
|
- const delW = width_list[j];
|
|
|
- width_list.splice(j, 1);
|
|
|
- this.data.row_list[i].width_list = width_list.map((item) => {
|
|
|
- return `${Number(item.replace('fr', '')) + Number(delW.replace('fr', '') / width_list.length)}fr`;
|
|
|
- });
|
|
|
- }
|
|
|
+ deleteComponent(id) {
|
|
|
+ const attrs = this.findChildComponentByKey(`grid-${id}`)?.$attrs;
|
|
|
+ if (!attrs) return;
|
|
|
+ const i = Number(attrs['data-row']);
|
|
|
+ const j = Number(attrs['data-col']);
|
|
|
+ const k = Number(attrs['data-grid']);
|
|
|
+ const gridList = this.data.row_list[i].col_list[j].grid_list;
|
|
|
+ let delRow = gridList[k].row; // 删除的 grid 的 row
|
|
|
+ let delW = gridList[k].width; // 删除的 grid 的 width
|
|
|
+ gridList.splice(k, 1);
|
|
|
+
|
|
|
+ // 如果删除后没有 grid 了则删除列
|
|
|
+ const colList = this.data.row_list[i].col_list[j];
|
|
|
+ if (colList.grid_list.length === 0) {
|
|
|
+ this.data.row_list[i].col_list.splice(j, 1);
|
|
|
+ let width_list = this.data.row_list[i].width_list;
|
|
|
+ const delW = width_list[j];
|
|
|
+ width_list.splice(j, 1);
|
|
|
+ this.data.row_list[i].width_list = width_list.map((item) => {
|
|
|
+ return `${Number(item.replace('fr', '')) + Number(delW.replace('fr', '') / width_list.length)}fr`;
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- // 如果删除后没有列了则删除行
|
|
|
- if (this.data.row_list[i].col_list.length === 0) {
|
|
|
- this.data.row_list.splice(i, 1);
|
|
|
- }
|
|
|
+ // 如果删除后没有列了则删除行
|
|
|
+ if (this.data.row_list[i].col_list.length === 0) {
|
|
|
+ this.data.row_list.splice(i, 1);
|
|
|
+ }
|
|
|
|
|
|
- // 如果删除后还有 grid 则重新计算 grid 的 row 和 width
|
|
|
- if (gridList?.length > 0) {
|
|
|
- let delNum = gridList.filter(({ row }) => row === delRow).length;
|
|
|
- let diff = Number(delW.replace('fr', '')) / delNum;
|
|
|
- if (delNum === 0) {
|
|
|
- // 删除 grid 后面的 row 都减 1
|
|
|
- gridList.forEach((item) => {
|
|
|
- if (item.row > delRow) {
|
|
|
- item.row -= 1;
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- gridList.forEach((item) => {
|
|
|
- if (item.row === delRow) {
|
|
|
- item.width = `${Number(item.width.replace('fr', '')) + diff}fr`;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+ // 如果删除后还有 grid 则重新计算 grid 的 row 和 width
|
|
|
+ if (gridList?.length > 0) {
|
|
|
+ let delNum = gridList.filter(({ row }) => row === delRow).length;
|
|
|
+ let diff = Number(delW.replace('fr', '')) / delNum;
|
|
|
+ if (delNum === 0) {
|
|
|
+ // 删除 grid 后面的 row 都减 1
|
|
|
+ gridList.forEach((item) => {
|
|
|
+ if (item.row > delRow) {
|
|
|
+ item.row -= 1;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ gridList.forEach((item) => {
|
|
|
+ if (item.row === delRow) {
|
|
|
+ item.width = `${Number(item.width.replace('fr', '')) + diff}fr`;
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
- };
|
|
|
+ }
|
|
|
},
|
|
|
computedColStyle(col) {
|
|
|
let grid = col.grid_list;
|