|
@@ -3350,21 +3350,16 @@ export default {
|
|
|
|
|
|
// 添加目录编号更新方法
|
|
|
updateDirectoryNumbers() {
|
|
|
- this.coms.forEach((com, moduleIndex) => {
|
|
|
- if (com.attrs) {
|
|
|
- // 获取当前模块中的所有目录类型属性
|
|
|
- const directoryAttrs = com.attrs.filter(
|
|
|
- (attr) => attr.type === "Directory"
|
|
|
- );
|
|
|
-
|
|
|
- // 更新每个目录的编号
|
|
|
- directoryAttrs.forEach((dir, index) => {
|
|
|
- // 生成新的编号
|
|
|
- const number = this.generateLevelPrefix(moduleIndex, dir.level);
|
|
|
- // 更新目录编号
|
|
|
- this.$set(dir, "number", number);
|
|
|
- });
|
|
|
- }
|
|
|
+ this.coms.forEach((module, moduleIndex) => {
|
|
|
+ const directoryAttrs = module.attrs.filter(
|
|
|
+ (attr) => attr.type === "Directory"
|
|
|
+ );
|
|
|
+ directoryAttrs.forEach((dir, index) => {
|
|
|
+ // 生成新的编号
|
|
|
+ const number = this.generateLevelPrefix(moduleIndex, dir.level);
|
|
|
+ // 更新目录编号
|
|
|
+ this.$set(dir, "number", number);
|
|
|
+ });
|
|
|
});
|
|
|
},
|
|
|
|
|
@@ -3850,7 +3845,7 @@ export default {
|
|
|
moduleIndex: moduleIndex,
|
|
|
number: attr.number,
|
|
|
children: [],
|
|
|
- content:content
|
|
|
+ content:attr.content
|
|
|
};
|
|
|
|
|
|
// 根据层级放置节点
|
|
@@ -3886,7 +3881,7 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- // 添加新方法:递归排序目录数据
|
|
|
+ // 修改 sortCatalogDataRecursive 方法
|
|
|
sortCatalogDataRecursive(data) {
|
|
|
if (!Array.isArray(data)) {
|
|
|
return [];
|
|
@@ -3921,8 +3916,19 @@ export default {
|
|
|
item.label = newLabel;
|
|
|
item.content = newContent;
|
|
|
|
|
|
- // 更新对应的组件属性
|
|
|
+ // 更新对应的组件中的目录内容
|
|
|
this.updateComponentDirectory(item.moduleIndex, item.id, newContent, chapterNumber);
|
|
|
+ } else {
|
|
|
+ // 处理子目录的内容
|
|
|
+ const currentNumber = item.number;
|
|
|
+ const newContent = `${currentNumber} ${item.content.split(' ').slice(1).join(' ')}`;
|
|
|
+
|
|
|
+ // 更新目录树节点
|
|
|
+ item.label = newContent;
|
|
|
+ item.content = newContent;
|
|
|
+
|
|
|
+ // 更新对应的组件中的目录内容
|
|
|
+ this.updateComponentDirectory(item.moduleIndex, item.id, newContent, currentNumber);
|
|
|
}
|
|
|
|
|
|
// 递归处理子目录
|
|
@@ -3934,7 +3940,7 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- // 添加新方法:更新组件中的目录属性
|
|
|
+ // 添加/修改 updateComponentDirectory 方法
|
|
|
updateComponentDirectory(moduleIndex, directoryId, newContent, newNumber) {
|
|
|
const module = this.coms[moduleIndex];
|
|
|
if (!module || !module.attrs) return;
|
|
@@ -3942,12 +3948,14 @@ export default {
|
|
|
// 更新 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');
|
|
|
+ // 使用正则表达式替换目录引用
|
|
|
+ const pattern = new RegExp(`(\\d+(\\.\\d+)*\\s*)?{{${attr.id}}}`, 'g');
|
|
|
module.content = module.content.replace(pattern, `${newNumber} {{${attr.id}}}`);
|
|
|
}
|
|
|
}
|