|
|
@@ -155,6 +155,7 @@ export default {
|
|
|
getBookUnifiedAttr: () => this.book_unified_attrib,
|
|
|
getTitleList: () => this.title_list,
|
|
|
getProjectResourcePopedom: () => this.projectResourcePopedom,
|
|
|
+ getMovedComponentContent: (id) => this.movedComponentContent[id],
|
|
|
moveComponentDragStart: this.dragStart,
|
|
|
getCoursewareId: () => this.courseware_id,
|
|
|
};
|
|
|
@@ -178,6 +179,8 @@ export default {
|
|
|
unified_attrib,
|
|
|
},
|
|
|
componentLoadingState: {},
|
|
|
+ movedComponentContent: {},
|
|
|
+ movedComponentIds: {},
|
|
|
canvasContentVersion: 0,
|
|
|
visibleBackground: false, // 背景设置弹窗
|
|
|
rowCheckList: {}, // 行复选框列表
|
|
|
@@ -767,6 +770,7 @@ export default {
|
|
|
throw new Error('课件框架保存失败');
|
|
|
}
|
|
|
|
|
|
+ this.resetMovedComponentState();
|
|
|
this.clearGridSource();
|
|
|
this.$message.success('保存成功');
|
|
|
if (type === 'quit') {
|
|
|
@@ -1081,6 +1085,10 @@ export default {
|
|
|
cancelButtonText: '取消',
|
|
|
type: 'warning',
|
|
|
});
|
|
|
+ if (this.movingComponent || this.savingCourseware) {
|
|
|
+ this.$message.warning('组件正在移动或课件正在保存,请稍后操作');
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.deleteComponent(id);
|
|
|
} catch (err) {
|
|
|
if (err === 'cancel') {
|
|
|
@@ -1414,18 +1422,14 @@ export default {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- try {
|
|
|
- component.background = background;
|
|
|
- const result = await component.saveCoursewareComponentContent();
|
|
|
- if (result?.status !== 1) throw new Error('组件内容保存失败');
|
|
|
- } catch (error) {
|
|
|
- console.error('移动组件前保存内容失败', error);
|
|
|
- this.$message.error('组件内容保存失败,已取消移动');
|
|
|
- this.resetMoveData();
|
|
|
- return;
|
|
|
- }
|
|
|
+ component.syncRichTextContent();
|
|
|
+ component.background = background;
|
|
|
+ this.$set(this.movedComponentContent, oldID, {
|
|
|
+ data: _.cloneDeep(component.data),
|
|
|
+ background,
|
|
|
+ });
|
|
|
+ this.$set(this.movedComponentIds, oldID, true);
|
|
|
|
|
|
- // 保存成功后再调整原组件 id,避免保存失败时留下不完整的页面结构
|
|
|
const deleteID = this.replaceGridIdByOldId(oldID);
|
|
|
|
|
|
if (this.curRow >= -1 && this.curCol <= -1) {
|
|
|
@@ -1442,8 +1446,19 @@ export default {
|
|
|
|
|
|
await this.$nextTick();
|
|
|
this.deleteComponent(deleteID);
|
|
|
+ await this.$nextTick();
|
|
|
const movedComponent = this.findChildComponentByKey(`grid-${oldID}`);
|
|
|
- if (movedComponent) movedComponent.background = background;
|
|
|
+ if (movedComponent && movedComponent.property?.isGetContent) {
|
|
|
+ movedComponent.background = background;
|
|
|
+ this.$delete(this.movedComponentContent, oldID);
|
|
|
+ if (this.getCurSettingId() === oldID) movedComponent.showSetting();
|
|
|
+ } else {
|
|
|
+ if (this.getCurSettingId() === oldID) {
|
|
|
+ this.curComponentId = '';
|
|
|
+ this.$emit('showSettingEmpty');
|
|
|
+ }
|
|
|
+ this.$message.error('组件移动后未能正常加载,请检查组件内容,确认无误后再保存。');
|
|
|
+ }
|
|
|
} finally {
|
|
|
this.movingComponent = false;
|
|
|
}
|
|
|
@@ -1914,6 +1929,7 @@ export default {
|
|
|
this.$emit('showSettingEmpty');
|
|
|
this.curComponentId = '';
|
|
|
this.componentLoadingState = {};
|
|
|
+ this.resetMovedComponentState();
|
|
|
this.canvasContentVersion += 1;
|
|
|
this.clearGridSource(templateData.row_list);
|
|
|
templateData.row_list.forEach((row) => {
|
|
|
@@ -2046,6 +2062,10 @@ export default {
|
|
|
* @param {String} position 放入位置类型
|
|
|
*/
|
|
|
pasteComponent(componentData, position) {
|
|
|
+ if (this.movingComponent || this.savingCourseware) {
|
|
|
+ this.$message.warning('组件正在移动或课件正在保存,请稍后操作');
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!componentData) return;
|
|
|
// 兼容只传组件内容的复制数据
|
|
|
const isClipboardData =
|
|
|
@@ -2137,30 +2157,78 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
// 交换组件位置
|
|
|
- switchComponent() {
|
|
|
- let checkedNum = 0;
|
|
|
- let components = [];
|
|
|
- this.$refs.component.forEach((child) => {
|
|
|
- if (child.$refs.base.checked) {
|
|
|
- checkedNum += 1;
|
|
|
- components.push(child.id);
|
|
|
- }
|
|
|
- });
|
|
|
- if (checkedNum !== 2) {
|
|
|
+ async switchComponent() {
|
|
|
+ if (this.movingComponent || this.savingCourseware) {
|
|
|
+ this.$message.warning('组件正在移动或课件正在保存,请稍后操作');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const selected = (this.$refs.component || []).filter((child) => child.$refs.base.checked);
|
|
|
+ if (selected.length !== 2) {
|
|
|
this.$message.error('请选择两个组件进行交换');
|
|
|
return;
|
|
|
}
|
|
|
- this.$confirm('组件未保存的改动将丢失。确定要交换这两个组件的位置吗?', '提示', {
|
|
|
- confirmButtonText: '确定',
|
|
|
- cancelButtonText: '取消',
|
|
|
- type: 'warning',
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- this.switchComponentData(components);
|
|
|
- })
|
|
|
- .catch(() => {
|
|
|
- // 取消交换
|
|
|
+ try {
|
|
|
+ await this.$confirm('组件未保存的改动将丢失。确定要交换这两个组件的位置吗?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning',
|
|
|
});
|
|
|
+ } catch (error) {
|
|
|
+ if (error === 'cancel' || error === 'close') return;
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ if (this.movingComponent || this.savingCourseware) {
|
|
|
+ this.$message.warning('组件正在移动或课件正在保存,请稍后操作');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const components = selected.map(({ id }) => id);
|
|
|
+ if (
|
|
|
+ selected.some(
|
|
|
+ (child) => !child.property?.isGetContent || this.findChildComponentByKey(`grid-${child.id}`) !== child,
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ this.$message.warning('组件内容尚未加载完成或已发生变化,请重新选择');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.movingComponent = true;
|
|
|
+ try {
|
|
|
+ const movedComponents = selected.filter((child) => this.movedComponentIds[child.id]);
|
|
|
+ const backgrounds = await Promise.all(movedComponents.map((child) => child.getComponentBackground()));
|
|
|
+ const snapshots = movedComponents.map((child, index) => {
|
|
|
+ child.syncRichTextContent();
|
|
|
+ return { data: _.cloneDeep(child.data), background: backgrounds[index] };
|
|
|
+ });
|
|
|
+ const previousSnapshots = movedComponents.map((child) => this.movedComponentContent[child.id]);
|
|
|
+ movedComponents.forEach((child, index) => {
|
|
|
+ child.background = backgrounds[index];
|
|
|
+ this.$set(this.movedComponentContent, child.id, snapshots[index]);
|
|
|
+ });
|
|
|
+ if (!this.switchComponentData(components)) {
|
|
|
+ movedComponents.forEach(({ id }, index) => {
|
|
|
+ if (previousSnapshots[index]) {
|
|
|
+ this.$set(this.movedComponentContent, id, previousSnapshots[index]);
|
|
|
+ } else {
|
|
|
+ this.$delete(this.movedComponentContent, id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ throw new Error('未找到需要交换的组件');
|
|
|
+ }
|
|
|
+ await this.$nextTick();
|
|
|
+ movedComponents.forEach(({ id }) => {
|
|
|
+ const component = this.findChildComponentByKey(`grid-${id}`);
|
|
|
+ if (component?.property?.isGetContent) {
|
|
|
+ this.$delete(this.movedComponentContent, id);
|
|
|
+ } else {
|
|
|
+ this.$message.error('交换后的组件尚未加载完成,请检查后再保存');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ console.error('交换组件失败', error);
|
|
|
+ this.$message.error('交换组件失败,请重试');
|
|
|
+ } finally {
|
|
|
+ this.movingComponent = false;
|
|
|
+ }
|
|
|
},
|
|
|
/**
|
|
|
* 合并遍历 data.row_list,找到两个网格对象并直接交换它们的属性
|
|
|
@@ -2183,20 +2251,40 @@ export default {
|
|
|
if (g1 && g2) break;
|
|
|
}
|
|
|
|
|
|
- if (!g1 || !g2) return;
|
|
|
+ if (!g1 || !g2) return false;
|
|
|
|
|
|
- const tmp = { grid_area: g1.grid_area, id: g1.id, type: g1.type }; // 临时存储 g1 的属性
|
|
|
+ const tmp = {
|
|
|
+ grid_area: g1.grid_area,
|
|
|
+ id: g1.id,
|
|
|
+ type: g1.type,
|
|
|
+ oldId: g1.oldId,
|
|
|
+ sourceCoursewareId: g1.sourceCoursewareId,
|
|
|
+ };
|
|
|
g1.grid_area = g2.grid_area;
|
|
|
g1.type = g2.type;
|
|
|
g1.id = g2.id;
|
|
|
+ this.$set(g1, 'oldId', g2.oldId);
|
|
|
+ this.$set(g1, 'sourceCoursewareId', g2.sourceCoursewareId);
|
|
|
|
|
|
g2.grid_area = tmp.grid_area;
|
|
|
g2.type = tmp.type;
|
|
|
g2.id = tmp.id;
|
|
|
+ this.$set(g2, 'oldId', tmp.oldId);
|
|
|
+ this.$set(g2, 'sourceCoursewareId', tmp.sourceCoursewareId);
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+ resetMovedComponentState() {
|
|
|
+ this.movedComponentContent = {};
|
|
|
+ this.movedComponentIds = {};
|
|
|
},
|
|
|
clearContent() {
|
|
|
+ if (this.movingComponent || this.savingCourseware) {
|
|
|
+ this.$message.warning('组件正在移动或课件正在保存,请稍后操作');
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.data.row_list = [];
|
|
|
this.content_group_row_list = [];
|
|
|
+ this.resetMovedComponentState();
|
|
|
},
|
|
|
showSetComponentBackground() {
|
|
|
this.$refs.previewEdit.showSetComponentBackground();
|