|
@@ -3423,9 +3423,12 @@ export default {
|
|
|
// 保存当前组件的完整数据
|
|
|
const currentCom = JSON.parse(JSON.stringify(this.coms[index]));
|
|
|
|
|
|
- if (state === 2) {
|
|
|
- // 从编辑切换到预览
|
|
|
- const componentRef = this.$refs[`textArea${index}`];
|
|
|
+ if (state === 2) { // 从编辑切换到预览
|
|
|
+ // 过滤attrs中不存在于content的项
|
|
|
+ this.filterUnusedAttrs(currentCom);
|
|
|
+
|
|
|
+ const componentRef = this.$refs.wordEditor;/* [`textArea${index}`] */
|
|
|
+ console.log(componentRef);
|
|
|
if (componentRef && componentRef[0]) {
|
|
|
await componentRef[0].save();
|
|
|
}
|
|
@@ -3435,10 +3438,10 @@ export default {
|
|
|
this.coms = this.coms.map((it, idx) => {
|
|
|
if (idx === index) {
|
|
|
return {
|
|
|
- ...currentCom, // 保持原有属性
|
|
|
+ ...currentCom,
|
|
|
isEdit: state,
|
|
|
- attrs: currentCom.attrs || [], // 确保attrs不会丢失
|
|
|
- dcb_attrs: currentCom.dcb_attrs || [], // 确保dcb_attrs不会丢失
|
|
|
+ attrs: currentCom.attrs || [],
|
|
|
+ dcb_attrs: currentCom.dcb_attrs || [],
|
|
|
};
|
|
|
}
|
|
|
return {
|
|
@@ -3447,19 +3450,44 @@ export default {
|
|
|
};
|
|
|
});
|
|
|
|
|
|
- // 更新当前索引
|
|
|
this.comIndex = index;
|
|
|
-
|
|
|
- // 触发重建
|
|
|
await this.onRebuild(this.coms);
|
|
|
+
|
|
|
} catch (error) {
|
|
|
- /* console.error("切换模式失败:", error);
|
|
|
- this.$message.error("切换模式失败:" + error.message); */
|
|
|
+ console.error("切换模式失败:", error);
|
|
|
} finally {
|
|
|
this.isSaving = false;
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ // 添加新方法用于过滤未使用的attrs
|
|
|
+ filterUnusedAttrs(component) {
|
|
|
+ if (!component.content || !component.attrs) return;
|
|
|
+
|
|
|
+ // 从content中提取所有ID
|
|
|
+ const contentIds = (component.content.match(/{{([^}]+)}}/g) || [])
|
|
|
+ .map(match => match.slice(2, -2).trim());
|
|
|
+
|
|
|
+ // 过滤attrs,保留在content中使用的项和特殊类型
|
|
|
+ component.attrs = component.attrs.filter(attr => {
|
|
|
+ // 始终保留这些特殊类型的属性
|
|
|
+ const specialTypes = ['ProductAttr', 'variableNull'];
|
|
|
+ if (specialTypes.includes(attr.type)) return true;
|
|
|
+
|
|
|
+ // 检查ID是否在content中使用
|
|
|
+ return contentIds.includes(attr.id);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 如果有dcb_attrs,也进行同样的过滤
|
|
|
+ if (component.dcb_attrs) {
|
|
|
+ component.dcb_attrs = component.dcb_attrs.filter(attr => {
|
|
|
+ const specialTypes = ['ProductAttr', 'variableNull'];
|
|
|
+ if (specialTypes.includes(attr.type)) return true;
|
|
|
+ return contentIds.includes(attr.id);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
// 删除模块
|
|
|
onRemoveMdel(index) {
|
|
|
const removedComponent = this.coms[index];
|