|
@@ -183,59 +183,63 @@ export default {
|
|
|
watch: {
|
|
|
coms: {
|
|
|
handler(val) {
|
|
|
-
|
|
|
// 如果正在保存或没有值,则跳过处理
|
|
|
if (this.isSaving || !val || !Array.isArray(val)) return;
|
|
|
|
|
|
try {
|
|
|
- // 检查是否需要更新
|
|
|
- const needsUpdate = val.some((item, index) => {
|
|
|
- const currentCom = this.comList[index];
|
|
|
- if (!currentCom) return true;
|
|
|
-
|
|
|
- // 比较关键属性是否发生变化
|
|
|
- return (
|
|
|
- item.content !== currentCom.content ||
|
|
|
- item.dcb_nr !== currentCom.dcb_nr ||
|
|
|
- JSON.stringify(item.attrs) !== JSON.stringify(currentCom.attrs) ||
|
|
|
- JSON.stringify(item.dcb_attrs) !== JSON.stringify(currentCom.dcb_attrs)||
|
|
|
- item.isEdit!==currentCom.isEdit||
|
|
|
- item!==currentCom
|
|
|
- );
|
|
|
- });
|
|
|
+ // 检查数组长度变化或内容更新
|
|
|
+ const needsUpdate =
|
|
|
+ val.length !== this.comList.length || // 检查长度变化
|
|
|
+ val.some((item, index) => {
|
|
|
+ const currentCom = this.comList[index];
|
|
|
+ if (!currentCom) return true;
|
|
|
+
|
|
|
+ // 比较关键属性是否发生变化
|
|
|
+ return (
|
|
|
+ item.content !== currentCom.content ||
|
|
|
+ item.dcb_nr !== currentCom.dcb_nr ||
|
|
|
+ JSON.stringify(item.attrs) !== JSON.stringify(currentCom.attrs) ||
|
|
|
+ JSON.stringify(item.dcb_attrs) !== JSON.stringify(currentCom.dcb_attrs) ||
|
|
|
+ item.isEdit !== currentCom.isEdit ||
|
|
|
+ item !== currentCom
|
|
|
+ );
|
|
|
+ });
|
|
|
|
|
|
// 如果不需要更新,直接返回
|
|
|
if (!needsUpdate) return;
|
|
|
+ // 处理数据,确保属性正确转换
|
|
|
+ const processedComs = val.map((item) => ({
|
|
|
+ ...item,
|
|
|
+ attrs: Array.isArray(item.attrs) ? item.attrs : [],
|
|
|
+ dcb_attrs: Array.isArray(item.dcb_attrs)
|
|
|
+ ? item.dcb_attrs
|
|
|
+ : (typeof item.dcb_attrs === 'string'
|
|
|
+ ? JSON.parse(item.dcb_attrs || '[]')
|
|
|
+ : []),
|
|
|
+ content: item.content || item.dcb_nr || '',
|
|
|
+ dcb_nr: item.content || item.dcb_nr || '',
|
|
|
+ type: item.dcb_type || item.type,
|
|
|
+ name: item.dcb_name || item.name,
|
|
|
+ }));
|
|
|
|
|
|
- // 处理拖拽数据,确保属性正确转换
|
|
|
- const processedComs = val.map((item) => {
|
|
|
- // 首先创建基础对象
|
|
|
- return {
|
|
|
- ...item,
|
|
|
- // 确保 attrs 和 dcb_attrs 都是数组
|
|
|
- attrs: Array.isArray(item.attrs) ? item.attrs : [],
|
|
|
- dcb_attrs: Array.isArray(item.dcb_attrs)
|
|
|
- ? item.dcb_attrs
|
|
|
- : (typeof item.dcb_attrs === 'string'
|
|
|
- ? JSON.parse(item.dcb_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("comList:",this.comList);
|
|
|
// 使用 Vue.set 更新整个数组
|
|
|
this.$set(this, 'comList', processedComs);
|
|
|
- // 仅在数据确实发生变化时才触发父组件更新
|
|
|
+
|
|
|
+ // 触发父组件更新
|
|
|
this.$emit("onSetComs", this.comList);
|
|
|
+
|
|
|
+ // 如果长度减少,可能需要更新其他相关状态
|
|
|
+ if (val.length < this.comList.length) {
|
|
|
+ this.$nextTick(() => {
|
|
|
+ // 更新目录序号
|
|
|
+ this.updateDirectoryNumbers();
|
|
|
+ // 触发重建
|
|
|
+ this.$emit("onRebuild", this.comList);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
} catch (error) {
|
|
|
console.error('处理组件数据时出错:', error);
|
|
|
- // 确保即使出错也有一个有效的数组
|
|
|
if (!Array.isArray(this.comList)) {
|
|
|
this.$set(this, 'comList', Array.isArray(val) ? val : []);
|
|
|
}
|