|
@@ -1174,7 +1174,6 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
-
|
|
|
this.catalogData = catalogData;
|
|
|
this.$nextTick(() => this.$forceUpdate());
|
|
|
},
|
|
@@ -3851,6 +3850,7 @@ export default {
|
|
|
moduleIndex: moduleIndex,
|
|
|
number: attr.number,
|
|
|
children: [],
|
|
|
+ content:content
|
|
|
};
|
|
|
|
|
|
// 根据层级放置节点
|
|
@@ -3875,6 +3875,11 @@ export default {
|
|
|
|
|
|
// 递归排序所有层级
|
|
|
this.catalogData = this.sortCatalogDataRecursive(catalogData);
|
|
|
+
|
|
|
+ // 强制更新视图
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$forceUpdate();
|
|
|
+ });
|
|
|
} catch (error) {
|
|
|
console.error("Error updating catalog:", error);
|
|
|
this.catalogData = [];
|
|
@@ -3883,13 +3888,96 @@ export default {
|
|
|
|
|
|
// 添加新方法:递归排序目录数据
|
|
|
sortCatalogDataRecursive(data) {
|
|
|
- return data.sort((a, b) => this.compareNumbers(a.number, b.number))
|
|
|
- .map(item => {
|
|
|
- if (item.children && item.children.length > 0) {
|
|
|
- item.children = this.sortCatalogDataRecursive(item.children);
|
|
|
+ if (!Array.isArray(data)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ return data.sort((a, b) => {
|
|
|
+ // 特殊处理一级目录
|
|
|
+ if (!a.number.includes('.') && !b.number.includes('.')) {
|
|
|
+ return parseInt(a.number) - parseInt(b.number);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 其他级别的目录使用完整的编号比较
|
|
|
+ const aNumbers = a.number.split('.').map(Number);
|
|
|
+ const bNumbers = b.number.split('.').map(Number);
|
|
|
+
|
|
|
+ for (let i = 0; i < Math.max(aNumbers.length, bNumbers.length); i++) {
|
|
|
+ const aNum = aNumbers[i] || 0;
|
|
|
+ const bNum = bNumbers[i] || 0;
|
|
|
+ if (aNum !== bNum) {
|
|
|
+ return aNum - bNum;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }).map((item, index) => {
|
|
|
+ // 处理一级目录的内容
|
|
|
+ if (!item.number.includes('.')) {
|
|
|
+ const chapterNumber = index + 1;
|
|
|
+ const newLabel = `${chapterNumber} ${item.label.split(' ').slice(1).join(' ')}`;
|
|
|
+ const newContent = `第${chapterNumber}章 ${item.content.split(' ').slice(1).join(' ')}`;
|
|
|
+
|
|
|
+ // 更新目录树节点
|
|
|
+ item.label = newLabel;
|
|
|
+ item.content = newContent;
|
|
|
+
|
|
|
+ // 更新对应的组件属性
|
|
|
+ this.updateComponentDirectory(item.moduleIndex, item.id, newContent, chapterNumber);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 递归处理子目录
|
|
|
+ if (item.children && item.children.length > 0) {
|
|
|
+ item.children = this.sortCatalogDataRecursive(item.children);
|
|
|
+ }
|
|
|
+
|
|
|
+ return item;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 添加新方法:更新组件中的目录属性
|
|
|
+ updateComponentDirectory(moduleIndex, directoryId, newContent, newNumber) {
|
|
|
+ const module = this.coms[moduleIndex];
|
|
|
+ if (!module || !module.attrs) return;
|
|
|
+
|
|
|
+ // 更新 attrs 中的目录
|
|
|
+ module.attrs.forEach(attr => {
|
|
|
+ if (attr.type === "Directory" && attr.id === directoryId) {
|
|
|
+ attr.content = newContent;
|
|
|
+ attr.number = String(newNumber);
|
|
|
+
|
|
|
+ // 更新组件内容中的目录引用
|
|
|
+ if (module.content) {
|
|
|
+ const pattern = new RegExp(`{{${attr.id}}}`, 'g');
|
|
|
+ module.content = module.content.replace(pattern, `${newNumber} {{${attr.id}}}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 如果存在 dcb_attrs,也更新它
|
|
|
+ if (module.dcb_attrs) {
|
|
|
+ const dcbAttrs = Array.isArray(module.dcb_attrs) ?
|
|
|
+ module.dcb_attrs :
|
|
|
+ JSON.parse(module.dcb_attrs);
|
|
|
+
|
|
|
+ dcbAttrs.forEach(attr => {
|
|
|
+ if (attr.type === "Directory" && attr.id === directoryId) {
|
|
|
+ attr.content = newContent;
|
|
|
+ attr.number = String(newNumber);
|
|
|
}
|
|
|
- return item;
|
|
|
});
|
|
|
+
|
|
|
+ // 如果 dcb_attrs 是字符串,需要重新序列化
|
|
|
+ if (typeof module.dcb_attrs === 'string') {
|
|
|
+ module.dcb_attrs = JSON.stringify(dcbAttrs);
|
|
|
+ } else {
|
|
|
+ module.dcb_attrs = dcbAttrs;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 强制更新视图
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$forceUpdate();
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
// 生成目录编号
|