|
|
@@ -374,18 +374,18 @@ export default {
|
|
|
});
|
|
|
ContentGetCoursewareContent({ id: this.courseware_id }).then(
|
|
|
({ content, content_group_row_list, title_list, my_project_resource_popedom }) => {
|
|
|
+ const groupRowList = content_group_row_list ? JSON.parse(content_group_row_list) : [];
|
|
|
if (content) {
|
|
|
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 (parsedContent && Array.isArray(parsedContent.row_list)) {
|
|
|
+ parsedContent = this.normalizeRowColIds(parsedContent);
|
|
|
+ const normalized = this.normalizeCanvasRows(parsedContent.row_list, groupRowList);
|
|
|
+ parsedContent.row_list = normalized.rowList;
|
|
|
+ this.content_group_row_list = normalized.groupRowList;
|
|
|
}
|
|
|
+ this.data = parsedContent;
|
|
|
+ } else {
|
|
|
+ this.content_group_row_list = [];
|
|
|
}
|
|
|
const timer = setInterval(() => {
|
|
|
if (this.componentIsAllLoader()) {
|
|
|
@@ -394,8 +394,6 @@ export default {
|
|
|
this.componentsDataLoaded = true;
|
|
|
}
|
|
|
}, 200);
|
|
|
- if (content_group_row_list) this.content_group_row_list = JSON.parse(content_group_row_list);
|
|
|
-
|
|
|
if (title_list) this.title_list = title_list || [];
|
|
|
|
|
|
this.$watch(
|
|
|
@@ -1725,6 +1723,46 @@ export default {
|
|
|
return data;
|
|
|
},
|
|
|
/**
|
|
|
+ * 过滤无组件的空行,并将分组记录按行顺序归一化为一行一条。
|
|
|
+ * @param {Array} rowList 行列表
|
|
|
+ * @param {Array} groupList 行分组列表
|
|
|
+ * @param {boolean} regenerateRowIds 是否为所有行重新生成 ID
|
|
|
+ */
|
|
|
+ normalizeCanvasRows(rowList, groupList, regenerateRowIds = false) {
|
|
|
+ const groupQueues = new Map();
|
|
|
+ (groupList || []).forEach((group) => {
|
|
|
+ if (!groupQueues.has(group.row_id)) groupQueues.set(group.row_id, []);
|
|
|
+ groupQueues.get(group.row_id).push(group);
|
|
|
+ });
|
|
|
+
|
|
|
+ const normalizedRows = [];
|
|
|
+ const normalizedGroups = [];
|
|
|
+ const usedRowIds = new Set();
|
|
|
+
|
|
|
+ (rowList || []).forEach((row) => {
|
|
|
+ const sourceRowId = row?.row_id;
|
|
|
+ const group = groupQueues.get(sourceRowId)?.shift() || {};
|
|
|
+ const columns = Array.isArray(row?.col_list) ? row.col_list : [];
|
|
|
+ if (!columns.some((col) => Array.isArray(col?.grid_list) && col.grid_list.length > 0)) return;
|
|
|
+
|
|
|
+ let rowId = sourceRowId;
|
|
|
+ if (regenerateRowIds || !rowId || usedRowIds.has(rowId)) {
|
|
|
+ do {
|
|
|
+ rowId = `R${getRandomNumber(6, true)}`;
|
|
|
+ } while (usedRowIds.has(rowId));
|
|
|
+ }
|
|
|
+ usedRowIds.add(rowId);
|
|
|
+ normalizedRows.push({ ...row, row_id: rowId });
|
|
|
+ normalizedGroups.push({
|
|
|
+ ...group,
|
|
|
+ row_id: rowId,
|
|
|
+ is_pre_same_group: normalizedGroups.length > 0 && Boolean(group.is_pre_same_group),
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ return { rowList: normalizedRows, groupRowList: normalizedGroups };
|
|
|
+ },
|
|
|
+ /**
|
|
|
* 删除行后归一化行分组列表
|
|
|
*
|
|
|
* is_pre_same_group 为 true 表示该行与其前一行同属一个分组。
|
|
|
@@ -1775,9 +1813,10 @@ export default {
|
|
|
// 深拷贝:避免与「选择模板」弹窗缓存的模板数据共享引用(否则画布改动会污染模板数据)
|
|
|
const templateData = _.cloneDeep(data) || { row_list: [] };
|
|
|
if (!Array.isArray(templateData.row_list)) templateData.row_list = [];
|
|
|
+ const normalized = this.normalizeCanvasRows(templateData.row_list, _.cloneDeep(content_group_row_list) || []);
|
|
|
+ templateData.row_list = normalized.rowList;
|
|
|
this.data = templateData;
|
|
|
- // 分组行列表同样深拷贝:归一化时会直接改写其中的 is_pre_same_group
|
|
|
- this.content_group_row_list = _.cloneDeep(content_group_row_list) || [];
|
|
|
+ this.content_group_row_list = normalized.groupRowList;
|
|
|
// 清空模板数据中残留的 oldId,避免按陈旧的来源组件 id 取到错误内容
|
|
|
this.clearGridOldId(this.data.row_list);
|
|
|
await this.insertComponentBackground(this.data.row_list, backgroundList, 'id');
|
|
|
@@ -1791,25 +1830,13 @@ export default {
|
|
|
* @param {Array} param.backgroundList - 组件背景列表
|
|
|
*/
|
|
|
async insertTemplateData_CreateCanvas({ row_list = [], content_group_row_list = [], backgroundList = [] }) {
|
|
|
- let contentGroupRowList = JSON.parse(JSON.stringify(content_group_row_list));
|
|
|
+ const normalized = this.normalizeCanvasRows(_.cloneDeep(row_list), content_group_row_list, true);
|
|
|
+ let contentGroupRowList = normalized.groupRowList;
|
|
|
// 插入的内容保持独立分组,不并入插入位置上方的分组(模板数据异常时兜底)
|
|
|
if (contentGroupRowList.length > 0) contentGroupRowList[0].is_pre_same_group = false;
|
|
|
|
|
|
- // 深拷贝后再改写 id:直接改写会污染「选择模板」弹窗缓存的模板数据,
|
|
|
- // 导致同一模板连续插入两次时把同一批对象重复放进 row_list(重复 key / 重复组件 id / oldId 被覆盖)
|
|
|
- let rowList = _.cloneDeep(row_list).map((row) => {
|
|
|
- const oldRowID = row.row_id;
|
|
|
- const newRowID = `R${getRandomNumber(6, true)}`;
|
|
|
- row.row_id = newRowID;
|
|
|
- // 更新内容分组行列表中的 row_id
|
|
|
- if (oldRowID) {
|
|
|
- for (let idx = 0; idx < contentGroupRowList.length; idx++) {
|
|
|
- if (contentGroupRowList[idx].row_id === oldRowID) {
|
|
|
- contentGroupRowList[idx] = { ...contentGroupRowList[idx], row_id: newRowID };
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ // 深拷贝后再改写列和组件 id,避免污染「选择模板」弹窗缓存的数据。
|
|
|
+ let rowList = normalized.rowList.map((row) => {
|
|
|
row.col_list = (row.col_list || []).map((col) => {
|
|
|
col.col_id = `C${getRandomNumber(8, true)}`;
|
|
|
|