Bläddra i källkod

大司空过滤项目和多余文件夹

ellisran 1 år sedan
förälder
incheckning
a74e7aab86
2 ändrade filer med 56 tillägg och 6 borttagningar
  1. 2 1
      app/lib/dsk.js
  2. 54 5
      app/public/js/change_revise.js

+ 2 - 1
app/lib/dsk.js

@@ -82,7 +82,8 @@ class DSK {
             token,
             mobile,
         };
-        return this.dealWith(await this.ctx.helper.sendRequest(url, postData, 'POST', 'json', true));
+        const result = this.dealWith(await this.ctx.helper.sendRequest(url, postData, 'POST', 'json', true));
+        return result.filter(item => { return !item.property || !item.property.fileType || (item.property.fileType && [1, 5, 15, 16].indexOf(item.property.fileType) === -1); });
     }
 
     async getProjectTree(compilationId, projectId) {

+ 54 - 5
app/public/js/change_revise.js

@@ -3546,6 +3546,10 @@ $(document).ready(() => {
                 const tenderChildren = _.filter(tenders, { parentID: node.pid });
                 const checkChildren = _.orderBy([...children, ...tenderChildren], ['seq', 'asc']);
                 for (const c of checkChildren) {
+                    // if (c.type === 1 && _.filter(files, { parentID: c.ID }).length === 0 && _.filter(tenders, { parentID: c.ID }).length === 0) {
+                    //     // 判断文件夹下有无东西,没有就不插入
+                    //     continue;
+                    // }
                     const child = {
                         pid: c.ID,
                         parentID: c.parentID,
@@ -3560,11 +3564,10 @@ $(document).ready(() => {
 
             function convert (projects) {
                 tenderTree.clearDatas();
-
-                // 区分文件夹及项目
-                const topLevel = _.orderBy(_.filter(projects, { parentID: '-1' }), ['seq', 'asc']);
-                const files = _.filter(projects, { type: 1 });
-                const tenders = _.filter(projects, { type: 2 });
+                const result = filterFolders(projects);
+                const topLevel = _.orderBy(_.filter(result, { parentID: '-1' }), ['seq', 'asc']);
+                const files = _.filter(result, { type: 1 });
+                const tenders = _.filter(result, { type: 2 });
 
                 for (const t of topLevel) {
                     const node = {
@@ -3583,6 +3586,52 @@ $(document).ready(() => {
             return { tenderTree, convert }
         })();
 
+        function filterFolders(data) {
+            // 构建ID到节点的映射
+            const idMap = data.reduce((map, node) => {
+                map[node.ID] = node;
+                return map;
+            }, {});
+
+            // 建立父子关系映射
+            const parentMap = data.reduce((map, node) => {
+                if (node.parentID !== '-1') {
+                    if (!map[node.parentID]) {
+                        map[node.parentID] = [];
+                    }
+                    map[node.parentID].push(node.ID);
+                }
+                return map;
+            }, {});
+
+            // 检查节点及其子节点是否包含清单(type=1)
+            const hasChecklist = (id) => {
+                const node = idMap[id];
+                if (node.type === 2) {
+                    return true;
+                }
+                if (!parentMap[id]) {
+                    return false;
+                }
+                return parentMap[id].some(childID => hasChecklist(childID));
+            };
+
+            // 过滤节点
+            const filteredIDs = new Set();
+            data.forEach(node => {
+                if (node.type === 2 || hasChecklist(node.ID)) {
+                    let currentID = node.ID;
+                    while (currentID !== '-1') {
+                        filteredIDs.add(currentID);
+                        currentID = idMap[currentID].parentID;
+                    }
+                }
+            });
+
+            // 返回过滤后的数据
+            return data.filter(node => filteredIDs.has(node.ID));
+        }
+
         $('#set-dsk-project').click(function () {
             postData('/profile/dsk/api', { type: 'save_projects', tid: window.location.pathname.split('/')[2], project_list: gsObj.grArray }, function (result) {
                 // dskAccountData.select_project = result;