瀏覽代碼

修改目录树

yangg 5 月之前
父節點
當前提交
8801dde092
共有 1 個文件被更改,包括 8 次插入6 次删除
  1. 8 6
      ui/src/views/system/document/create.vue

+ 8 - 6
ui/src/views/system/document/create.vue

@@ -1139,7 +1139,9 @@ export default {
         const directoryAttrs = module.attrs
         const directoryAttrs = module.attrs
           .filter(attr => attr.type === "Directory")
           .filter(attr => attr.type === "Directory")
           .sort((a, b) => {
           .sort((a, b) => {
+            // 首先按层级排序
             if (a.level !== b.level) return a.level - b.level;
             if (a.level !== b.level) return a.level - b.level;
+            // 同层级按编号自然排序
             return a.number.localeCompare(b.number, undefined, { numeric: true });
             return a.number.localeCompare(b.number, undefined, { numeric: true });
           });
           });
 
 
@@ -1159,6 +1161,7 @@ export default {
           if (attr.level === 1) {
           if (attr.level === 1) {
             catalogData.push(catalogItem);
             catalogData.push(catalogItem);
           } else {
           } else {
+            // 查找父级目录并添加为子项
             const parent = this.findParentDirectory(catalogData, attr.number);
             const parent = this.findParentDirectory(catalogData, attr.number);
             if (parent) {
             if (parent) {
               parent.children.push(catalogItem);
               parent.children.push(catalogItem);
@@ -1171,13 +1174,13 @@ export default {
       this.$nextTick(() => this.$forceUpdate());
       this.$nextTick(() => this.$forceUpdate());
     },
     },
 
 
-    // 查找父级目录的辅助方法
+    // 添加 findParentDirectory 辅助方法
     findParentDirectory(catalogData, number) {
     findParentDirectory(catalogData, number) {
-      const parentNumber = number.split(".").slice(0, -1).join(".");
-
+      const parentNumber = number.split('.').slice(0, -1).join('.');
+      
       const findInChildren = (items) => {
       const findInChildren = (items) => {
         for (let item of items) {
         for (let item of items) {
-          if (item.label.startsWith(parentNumber + " ")) {
+          if (item.label.startsWith(parentNumber + ' ')) {
             return item;
             return item;
           }
           }
           if (item.children) {
           if (item.children) {
@@ -2428,7 +2431,6 @@ export default {
         return (moduleIndex + 1).toString();
         return (moduleIndex + 1).toString();
       }
       }
 
 
-      // 在当前模块中查找上一级目录的编号
       const module = this.coms[moduleIndex];
       const module = this.coms[moduleIndex];
       if (!module || !module.attrs) return '';
       if (!module || !module.attrs) return '';
 
 
@@ -2468,7 +2470,7 @@ export default {
 
 
       return { 
       return { 
         number, 
         number, 
-        content: `第${number}章` // 默认内容,可以根据需要修改
+        content: `第${number}章` // 默认内容
       };
       };
     },
     },