|
|
@@ -342,6 +342,23 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
+ isEdit: {
|
|
|
+ handler(val) {
|
|
|
+ if (val) {
|
|
|
+ const loading = this.$loading({
|
|
|
+ lock: true,
|
|
|
+ text: '组件加载中...',
|
|
|
+ spinner: 'el-icon-loading',
|
|
|
+ });
|
|
|
+ const timer = setInterval(() => {
|
|
|
+ if (this.componentIsAllLoader()) {
|
|
|
+ loading.close();
|
|
|
+ clearInterval(timer);
|
|
|
+ }
|
|
|
+ }, 200);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
},
|
|
|
created() {
|
|
|
const loading = this.$loading({
|
|
|
@@ -349,8 +366,8 @@ export default {
|
|
|
text: '组件加载中...',
|
|
|
spinner: 'el-icon-loading',
|
|
|
});
|
|
|
- ContentGetCoursewareContent({ id: this.courseware_id })
|
|
|
- .then(({ content, content_group_row_list, title_list, my_project_resource_popedom }) => {
|
|
|
+ ContentGetCoursewareContent({ id: this.courseware_id }).then(
|
|
|
+ ({ content, content_group_row_list, title_list, my_project_resource_popedom }) => {
|
|
|
if (content) {
|
|
|
let parsedContent = JSON.parse(content);
|
|
|
if (
|
|
|
@@ -363,9 +380,14 @@ export default {
|
|
|
} else {
|
|
|
this.data = parsedContent;
|
|
|
}
|
|
|
- this.componentsDataLoaded = true;
|
|
|
- loading.close();
|
|
|
}
|
|
|
+ const timer = setInterval(() => {
|
|
|
+ if (this.componentIsAllLoader()) {
|
|
|
+ loading.close();
|
|
|
+ clearInterval(timer);
|
|
|
+ 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 || [];
|
|
|
@@ -381,10 +403,8 @@ export default {
|
|
|
);
|
|
|
|
|
|
this.projectResourcePopedom = my_project_resource_popedom || [];
|
|
|
- })
|
|
|
- .finally(() => {
|
|
|
- loading.close();
|
|
|
- });
|
|
|
+ },
|
|
|
+ );
|
|
|
this.getBookUnifiedAttr();
|
|
|
},
|
|
|
mounted() {
|
|
|
@@ -399,6 +419,24 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
/**
|
|
|
+ * 判断所有组件是否加载完成
|
|
|
+ * @returns {boolean} 是否所有组件加载完成
|
|
|
+ */
|
|
|
+ componentIsAllLoader() {
|
|
|
+ const toList = (ref) => {
|
|
|
+ if (Array.isArray(ref)) return ref;
|
|
|
+ return ref ? [ref] : [];
|
|
|
+ };
|
|
|
+
|
|
|
+ if (this.isEdit) {
|
|
|
+ const components = toList(this.$refs?.component);
|
|
|
+ return components.length === 0 || components.every((item) => item?.property?.isGetContent);
|
|
|
+ }
|
|
|
+
|
|
|
+ const previews = toList(this.$refs?.previewEdit?.$refs?.preview);
|
|
|
+ return previews.length === 0 || previews.every((item) => item?.loader);
|
|
|
+ },
|
|
|
+ /**
|
|
|
* 将可见组件滚动到视图中心
|
|
|
*/
|
|
|
async visibleIdScrollIntoView() {
|
|
|
@@ -578,16 +616,7 @@ export default {
|
|
|
* @param {string} type 类型
|
|
|
*/
|
|
|
async saveCoursewareContent(type) {
|
|
|
- let isAllLoader = false;
|
|
|
-
|
|
|
- if (this.$refs?.component === undefined || this.$refs?.component.length === 0) {
|
|
|
- isAllLoader = true;
|
|
|
- } else if (this.isEdit) {
|
|
|
- isAllLoader = this.$refs?.component?.every((item) => item.property.isGetContent);
|
|
|
- } else {
|
|
|
- isAllLoader = this.$refs?.previewEdit?.$refs?.preview?.every((item) => item.loader);
|
|
|
- }
|
|
|
- if (!isAllLoader) {
|
|
|
+ if (!this.componentIsAllLoader()) {
|
|
|
this.$message.warning('有组件内容未加载完成,请稍后再试');
|
|
|
return false;
|
|
|
}
|
|
|
@@ -1253,27 +1282,31 @@ export default {
|
|
|
* 组件拖拽移动后,先删除组件,再根据拖拽位置计算插入行、列、格子
|
|
|
*/
|
|
|
async handleComponentMove() {
|
|
|
+ // 放置位置无效(curRow 未在 dragEnd 中被正确更新),放弃移动
|
|
|
+ if (this.curRow < -1) {
|
|
|
+ this.$message.warning('组件放置位置无效,已取消移动');
|
|
|
+ this.resetMoveData();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
const oldID = this.curParams?.id;
|
|
|
const component = this.findChildComponentByKey(`grid-${oldID}`);
|
|
|
// 获取组件内容,保存后再插入到新的位置
|
|
|
- const requestData = component.getComponentRequestContent();
|
|
|
+ const requestData = component?.getComponentRequestContent();
|
|
|
|
|
|
const data = component?.data;
|
|
|
this.curType = data?.type || 'select';
|
|
|
let col = component?.$attrs['data-col'];
|
|
|
let row = component?.$attrs['data-row'];
|
|
|
let grid = component?.$attrs['data-grid'];
|
|
|
- let rowNum = 0; // 当前行组件数量
|
|
|
- this.data.row_list[row].col_list.forEach((item) => {
|
|
|
- rowNum += item.grid_list.length;
|
|
|
- });
|
|
|
+ const oldId = component?.oldId || component?.$attrs?.oldId;
|
|
|
|
|
|
this.curParams = {
|
|
|
...this.curParams,
|
|
|
col,
|
|
|
row,
|
|
|
grid,
|
|
|
- rowNum,
|
|
|
+ oldId,
|
|
|
};
|
|
|
|
|
|
// 根据 oldID 改变 data.row_list 中,将对应ID 改为新ID,并返回新ID,在删除时使用
|
|
|
@@ -1296,8 +1329,6 @@ export default {
|
|
|
this.$nextTick(() => {
|
|
|
this.deleteComponent(deleteID);
|
|
|
});
|
|
|
-
|
|
|
- this.resetMoveData();
|
|
|
},
|
|
|
/**
|
|
|
* 根据旧组件 id 将 row_list 中对应 grid 的 id 替换为新 id,并返回新 id
|
|
|
@@ -1364,6 +1395,7 @@ export default {
|
|
|
calculateGridObject() {
|
|
|
const id = this.curParams?.id || `ID-${getRandomNumber(12, true)}`;
|
|
|
const letter = `L${getRandomNumber(6, true)}`;
|
|
|
+ const oldId = this.curParams?.oldId;
|
|
|
|
|
|
let row = this.data.row_list[this.curRow];
|
|
|
let col = row.col_list[this.curCol];
|
|
|
@@ -1380,6 +1412,7 @@ export default {
|
|
|
edit_height: 'auto',
|
|
|
row: rowNum,
|
|
|
type: this.curType,
|
|
|
+ oldId,
|
|
|
});
|
|
|
// 在新加入的 grid 后面的 row 都加 1
|
|
|
grid.forEach((item, i) => {
|
|
|
@@ -1399,6 +1432,7 @@ export default {
|
|
|
edit_height: 'auto',
|
|
|
row: rowNum,
|
|
|
type: this.curType,
|
|
|
+ oldId,
|
|
|
});
|
|
|
|
|
|
let allRowNum = grid.filter(({ row }) => row === rowNum).length;
|
|
|
@@ -1448,6 +1482,7 @@ export default {
|
|
|
height: 'auto',
|
|
|
edit_height: 'auto',
|
|
|
type: this.curType,
|
|
|
+ oldId: this.curParams?.oldId,
|
|
|
},
|
|
|
],
|
|
|
});
|
|
|
@@ -1479,6 +1514,7 @@ export default {
|
|
|
edit_height: 'auto',
|
|
|
row: 1,
|
|
|
type: this.curType,
|
|
|
+ oldId: this.curParams?.oldId,
|
|
|
},
|
|
|
],
|
|
|
},
|