|
|
@@ -19,7 +19,7 @@
|
|
|
<span class="drag-line" data-row="-1"></span>
|
|
|
<!-- 行 -->
|
|
|
<template v-for="(row, i) in data.row_list">
|
|
|
- <div :key="row.row_id || `row-${i}`" class="row" :style="computedRowStyle(i)">
|
|
|
+ <div :key="row.row_id" class="row" :style="computedRowStyle(i)">
|
|
|
<el-checkbox
|
|
|
v-if="row?.row_id"
|
|
|
v-model="rowCheckList[row.row_id]"
|
|
|
@@ -30,12 +30,12 @@
|
|
|
<template v-for="(col, j) in row.col_list">
|
|
|
<span
|
|
|
v-if="j === 0"
|
|
|
- :key="`start-${row.row_id || 'r' + i}-${col.col_id || 'c' + j}`"
|
|
|
+ :key="`start-${row.row_id}-${col.col_id}`"
|
|
|
class="drag-vertical-line col-start"
|
|
|
:data-row="i"
|
|
|
:data-col="j"
|
|
|
></span>
|
|
|
- <div :key="col.col_id || `col-${i}-${j}`" :class="['col', `col-${i}-${j}`]" :style="computedColStyle(col)">
|
|
|
+ <div :key="col.col_id" :class="['col', `col-${i}-${j}`]" :style="computedColStyle(col)">
|
|
|
<!-- 网格 -->
|
|
|
<template v-for="(grid, k) in col.grid_list">
|
|
|
<span
|
|
|
@@ -106,19 +106,14 @@
|
|
|
</template>
|
|
|
</div>
|
|
|
<span
|
|
|
- :key="`end-${row.row_id || 'r' + i}-${col.col_id || 'c' + j}`"
|
|
|
+ :key="`end-${row.row_id}-${col.col_id}`"
|
|
|
class="drag-vertical-line col-end"
|
|
|
:data-row="i"
|
|
|
:data-col="j + 1"
|
|
|
></span>
|
|
|
</template>
|
|
|
</div>
|
|
|
- <span
|
|
|
- v-if="i < data.row_list.length - 1"
|
|
|
- :key="`row-${row.row_id || i}`"
|
|
|
- class="drag-line"
|
|
|
- :data-row="i"
|
|
|
- ></span>
|
|
|
+ <span v-if="i < data.row_list.length - 1" :key="`row-${row.row_id}`" class="drag-line" :data-row="i"></span>
|
|
|
</template>
|
|
|
<span class="drag-line" :data-row="data.row_list.length - 1"></span>
|
|
|
</template>
|
|
|
@@ -335,9 +330,17 @@ export default {
|
|
|
created() {
|
|
|
ContentGetCoursewareContent({ id: this.courseware_id }).then(({ content, content_group_row_list }) => {
|
|
|
if (content) {
|
|
|
- this.data = JSON.parse(content);
|
|
|
- // 为旧数据补充 row_id / col_id,保证 v-for 使用稳定 key
|
|
|
- this.normalizeRowColIds();
|
|
|
+ let parsedContent = JSON.parse(content);
|
|
|
+ if (
|
|
|
+ parsedContent &&
|
|
|
+ Array.isArray(parsedContent.row_list) &&
|
|
|
+ parsedContent.row_list.length > 0 &&
|
|
|
+ !parsedContent.row_list[0]?.row_id
|
|
|
+ ) {
|
|
|
+ this.data = this.normalizeRowColIds(parsedContent);
|
|
|
+ } else {
|
|
|
+ this.data = parsedContent;
|
|
|
+ }
|
|
|
}
|
|
|
if (content_group_row_list) this.content_group_row_list = JSON.parse(content_group_row_list);
|
|
|
|
|
|
@@ -1281,17 +1284,18 @@ export default {
|
|
|
/**
|
|
|
* 归一化 row_list 中的 row_id / col_id(为后端旧数据补 id)
|
|
|
*/
|
|
|
- normalizeRowColIds() {
|
|
|
- if (!this.data || !Array.isArray(this.data.row_list)) return;
|
|
|
- this.data.row_list = this.data.row_list.map((row, ri) => {
|
|
|
+ normalizeRowColIds(data) {
|
|
|
+ if (!data || !Array.isArray(data.row_list)) return data;
|
|
|
+ data.row_list = data.row_list.map((row) => {
|
|
|
if (!row.row_id) row.row_id = `R${getRandomNumber(6, true)}`;
|
|
|
if (!Array.isArray(row.col_list)) row.col_list = [];
|
|
|
- row.col_list = row.col_list.map((col, ci) => {
|
|
|
+ row.col_list = row.col_list.map((col) => {
|
|
|
if (!col.col_id) col.col_id = `C${getRandomNumber(8, true)}`;
|
|
|
return col;
|
|
|
});
|
|
|
return row;
|
|
|
});
|
|
|
+ return data;
|
|
|
},
|
|
|
},
|
|
|
};
|