|
@@ -215,34 +215,42 @@ export default {
|
|
|
},
|
|
|
watch: {
|
|
|
coms: {
|
|
|
- handler(val) {
|
|
|
- if (val == null) return;
|
|
|
- // 处理拖拽数据,确保属性正确转换
|
|
|
- this.comList = val.map((item) => {
|
|
|
- // 首先创建基础对象
|
|
|
- const processedItem = {
|
|
|
- ...item,
|
|
|
- // 确保 attrs 是数组
|
|
|
- dcb_attrs: Array.isArray(item.attrs)
|
|
|
- ? item.attrs
|
|
|
- : JSON.parse(item.attrs || "[]"),
|
|
|
- // 同步最新内容,优先使用当前显示的内容
|
|
|
- content: item.content || item.dcb_nr || "",
|
|
|
- dcb_nr: item.content || item.dcb_nr || "",
|
|
|
- // 确保 type 使用 dcb_type
|
|
|
- type: item.dcb_type || item.type,
|
|
|
- // 确保 name 使用 dcb_name
|
|
|
- name: item.dcb_name || item.name,
|
|
|
- };
|
|
|
- console.log("processedItem:", processedItem);
|
|
|
- // 确保 content 和 dcb_nr 同步
|
|
|
- if (processedItem.content !== processedItem.dcb_nr) {
|
|
|
- processedItem.dcb_nr = processedItem.content;
|
|
|
- }
|
|
|
+ async handler(val) {
|
|
|
+ // 如果正在保存,则跳过处理
|
|
|
+ if (this.isSaving || !val) return;
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 处理拖拽数据,确保属性正确转换
|
|
|
+ const processedComs = val.map((item) => {
|
|
|
+ // 首先创建基础对象
|
|
|
+ const processedItem = {
|
|
|
+ ...item,
|
|
|
+ // 确保 attrs 是数组
|
|
|
+ dcb_attrs: Array.isArray(item.attrs)
|
|
|
+ ? item.attrs
|
|
|
+ : JSON.parse(item.attrs || "[]"),
|
|
|
+ // 同步最新内容,优先使用当前显示的内容
|
|
|
+ content: item.content || item.dcb_nr || "",
|
|
|
+ dcb_nr: item.content || item.dcb_nr || "",
|
|
|
+ // 确保 type 使用 dcb_type
|
|
|
+ type: item.dcb_type || item.type,
|
|
|
+ // 确保 name 使用 dcb_name
|
|
|
+ name: item.dcb_name || item.name,
|
|
|
+ };
|
|
|
+
|
|
|
+ // 确保 content 和 dcb_nr 同步
|
|
|
+ if (processedItem.content !== processedItem.dcb_nr) {
|
|
|
+ processedItem.dcb_nr = processedItem.content;
|
|
|
+ }
|
|
|
|
|
|
- return processedItem;
|
|
|
- });
|
|
|
- this.$emit("onSetComs:", this.comList);
|
|
|
+ return processedItem;
|
|
|
+ });
|
|
|
+
|
|
|
+ this.comList = processedComs;
|
|
|
+ this.$emit("onSetComs:", this.comList);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('处理组件数据时出错:', error);
|
|
|
+ }
|
|
|
},
|
|
|
immediate: true,
|
|
|
deep: true,
|
|
@@ -290,6 +298,7 @@ export default {
|
|
|
overflowY: "auto",
|
|
|
},
|
|
|
type: "",
|
|
|
+ isSaving: false, // 添加保存状态标志
|
|
|
};
|
|
|
},
|
|
|
mounted() {
|
|
@@ -625,36 +634,54 @@ export default {
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
- onEdit(e, state) {
|
|
|
- this.comList = this.comList.map((it, index) => {
|
|
|
- it.isEdit = 2;
|
|
|
-
|
|
|
- // 当切换到预览状态时(state === 2),触发保存
|
|
|
- if (index === e && state === 2) {
|
|
|
- // 找到对应的TextArea组件实例并调用save方法
|
|
|
- this.$nextTick(() => {
|
|
|
- console.log(111);
|
|
|
- const componentRef = this.$refs[`component_${index}`];
|
|
|
- if (componentRef && componentRef.save) {
|
|
|
- componentRef.save();
|
|
|
- }
|
|
|
- });
|
|
|
+ async onEdit(e, state) {
|
|
|
+ try {
|
|
|
+ // 如果是切换到预览模式,先等待保存完成
|
|
|
+ if (state === 2) {
|
|
|
+ console.log("isEditor:",'001');
|
|
|
+ this.isSaving = true; // 设置保存状态
|
|
|
+ const componentRef = this.$refs[`component_${e}`];
|
|
|
+ if (componentRef && componentRef.save) {
|
|
|
+ // 等待保存完成
|
|
|
+ await componentRef.save();
|
|
|
+
|
|
|
+ // 在保存完成后,手动更新组件状态
|
|
|
+ this.$set(this.comList[e], 'isEdit', 2);
|
|
|
+
|
|
|
+ // 立即触发更新
|
|
|
+ await this.$nextTick();
|
|
|
+
|
|
|
+ // 通知父组件更新
|
|
|
+ this.$emit("onRebuild", this.comList);
|
|
|
+
|
|
|
+ this.isSaving = false; // 重置保存状态
|
|
|
+ return; // 直接返回,不执行后续的批量更新
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // 当切换到编辑状态时,对当前项进行 attrs 过滤
|
|
|
- if (index === e && state === 1) {
|
|
|
- this.filterAttrs(it);
|
|
|
+ // 如果是切换到编辑模式,执行原有逻辑
|
|
|
+ this.comList = this.comList.map((it, index) => {
|
|
|
+ it.isEdit = 2;
|
|
|
+
|
|
|
+ if (index === e && state === 1) {
|
|
|
+ this.filterAttrs(it);
|
|
|
+ }
|
|
|
+ return it;
|
|
|
+ });
|
|
|
+
|
|
|
+ if (state === 1) {
|
|
|
+ this.comList[e].isEdit = 1;
|
|
|
+ this.onSetActive(e);
|
|
|
}
|
|
|
|
|
|
- return it;
|
|
|
- });
|
|
|
+ this.$emit("onRebuild", this.comList);
|
|
|
|
|
|
- if (state == 1) {
|
|
|
- this.comList[e].isEdit = 1;
|
|
|
- this.onSetActive(e);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('保存失败:', error);
|
|
|
+ this.$message.error('切换模式失败,请重试');
|
|
|
+ } finally {
|
|
|
+ this.isSaving = false; // 确保在出错时也重置保存状态
|
|
|
}
|
|
|
-
|
|
|
- this.$emit("onRebuild", this.comList);
|
|
|
},
|
|
|
|
|
|
// 新增 filterAttrs 方法
|