vian 6 éve
szülő
commit
aa6e8a79f2

+ 9 - 1
web/building_saas/pm/html/project-management.html

@@ -102,7 +102,15 @@
                         <div class="toolsbar">
                         <div class="toolsbar">
                             <legend class="m-0 px-4">项目管理
                             <legend class="m-0 px-4">项目管理
                                 <div class="tools-btn btn-group align-top px-3 mt-2">
                                 <div class="tools-btn btn-group align-top px-3 mt-2">
-                                    <a id="startA" href="javascript:void(0);" data-toggle="modal" data-target="#addPoj3" class="btn btn-sm"><i class="fa fa-sticky-note-o"></i> 新建</a>
+                                    <!--<a id="startA" href="javascript:void(0);" data-toggle="modal" data-target="#addPoj3" class="btn btn-sm"><i class="fa fa-sticky-note-o"></i> 新建</a>-->
+                                    <div class="btn btn-sm">
+                                        <a class="dropdown-toggle" id="addMenuBtn" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false"><i class="fa fa-plus"></i> 新建</a>
+                                        <div class="dropdown-menu dropright" id="addMenu">
+                                            <a href="javascript:;" id="addFolderSub" class="dropdown-item" data-toggle="modal" data-target="#add-folder-dialog"><i class="fa fa-folder-open-o" aria-hidden="true"></i> 新建文件夹</a>
+                                            <a href="javascript:;" id="addProjectSub" class="dropdown-item" data-toggle="modal" data-target="#add-project-dialog"><i class="fa fa-cubes" aria-hidden="true"></i> 新建建设项目</a>
+                                            <a href="javascript:;" id="addTenderSub" class="dropdown-item" data-toggle="modal" data-target="#add-tender-dialog"><i class="fa fa fa-sticky-note-o" aria-hidden="true"></i> 新建分段</a>
+                                        </div>
+                                    </div>
                                     <a id="upLevel" href="javascript:void(0);" class="btn btn-light btn-sm disabled" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="升级"><i class="fa fa-arrow-left" aria-hidden="true"></i></a>
                                     <a id="upLevel" href="javascript:void(0);" class="btn btn-light btn-sm disabled" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="升级"><i class="fa fa-arrow-left" aria-hidden="true"></i></a>
                                     <a id="downLevel" href="javascript:void(0);" class="btn btn-light btn-sm" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="降级"><i class="fa fa-arrow-right" aria-hidden="true"></i></a>
                                     <a id="downLevel" href="javascript:void(0);" class="btn btn-light btn-sm" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="降级"><i class="fa fa-arrow-right" aria-hidden="true"></i></a>
                                     <a id="upMove" href="javascript:void(0);" class="btn btn-light btn-sm" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="上移"><i class="fa fa-arrow-up" aria-hidden="true"></i></a>
                                     <a id="upMove" href="javascript:void(0);" class="btn btn-light btn-sm" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="上移"><i class="fa fa-arrow-up" aria-hidden="true"></i></a>

+ 56 - 29
web/building_saas/pm/js/pm_newMain.js

@@ -189,39 +189,64 @@ const projTreeObj = {
         }
         }
         return newWorkBook;
         return newWorkBook;
     },
     },
+    // 获取新建按钮是否是disabled
+    getAddBtnDisabled: function (action) {
+        switch (action) {
+            case projectType.folder:
+            case projectType.project:
+            case projectType.tender:
+                return false;
+            default:
+                return true;
+        }
+    },
+    refreshAddMenuItems: function () {
+        const items = [{
+            el: $('#addFolderSub'),
+            action: projectType.folder,
+        }, {
+            el: $('#addProjectSub'),
+            action: projectType.project,
+        }, {
+            el: $('#addTenderSub'),
+            action: projectType.tender,
+        }];
+        items.forEach(item => {
+            const disabled = this.getAddBtnDisabled(item.action);
+            if (disabled) {
+                item.el.addClass('disabled');
+            } else {
+                item.el.removeClass('disabled');
+            }
+        });
+    },
     //右键菜单项
     //右键菜单项
     contextMenuItems: {
     contextMenuItems: {
         addFolder: {
         addFolder: {
             name: "新建文件夹",
             name: "新建文件夹",
             icon: 'fa-folder-o',
             icon: 'fa-folder-o',
             disabled: function () {
             disabled: function () {
-                return false;
+                return projTreeObj.getAddBtnDisabled(projectType.folder);
             },
             },
             callback: function (key, opt) {
             callback: function (key, opt) {
                 $("#add-folder-dialog").modal("show");
                 $("#add-folder-dialog").modal("show");
-                setTimeout(function () {
-                    $('#folder-name')[0].focus();
-                }, 300);
             }
             }
         },
         },
         addProject: {
         addProject: {
             name: "新建建设项目",
             name: "新建建设项目",
             icon: 'fa-cubes',
             icon: 'fa-cubes',
             disabled: function () {
             disabled: function () {
-                return false;
+                return projTreeObj.getAddBtnDisabled(projectType.project);
             },
             },
             callback: function (key, opt) {
             callback: function (key, opt) {
                 $('#add-project-dialog').modal('show');
                 $('#add-project-dialog').modal('show');
-                setTimeout(function () {
-                    $('#project-name')[0].focus();
-                }, 300);
             },
             },
         },
         },
         addTender: {
         addTender: {
             name: "新建分段",
             name: "新建分段",
             icon: 'fa-sticky-note-o',
             icon: 'fa-sticky-note-o',
             disabled: function () {
             disabled: function () {
-                return false;
+                return projTreeObj.getAddBtnDisabled(projectType.tender);
             },
             },
             callback: function (key, opt) {
             callback: function (key, opt) {
                 //弹出新建单位工程之前,判断当前使用版本,且当前使用单位工程数是否已到最大值
                 //弹出新建单位工程之前,判断当前使用版本,且当前使用单位工程数是否已到最大值
@@ -348,9 +373,6 @@ const projTreeObj = {
                 let selectedItem = projTreeObj.tree.selected;
                 let selectedItem = projTreeObj.tree.selected;
                 return !(selectedItem && selectedItem.data.projType === projectType.project);
                 return !(selectedItem && selectedItem.data.projType === projectType.project);
             },
             },
-           /* visible:function () {
-                return false
-            },*/
             callback: function (key, opt) {
             callback: function (key, opt) {
                 //获取当前节点的建设项目ID
                 //获取当前节点的建设项目ID
                 projTreeObj.exportProject(projTreeObj.tree.selected.data.ID,projTreeObj.tree.selected.data.name);
                 projTreeObj.exportProject(projTreeObj.tree.selected.data.ID,projTreeObj.tree.selected.data.name);
@@ -372,14 +394,9 @@ const projTreeObj = {
                 }
                 }
                 return true;
                 return true;
             },
             },
-          /*  visible:function () {
-              return false
-            },*/
             callback: function (key, opt) {
             callback: function (key, opt) {
                 //获取当前节点的建设项目ID
                 //获取当前节点的建设项目ID
                 $("#import").modal('show');
                 $("#import").modal('show');
-
-               // projTreeObj.exportProject(projTreeObj.tree.selected.data.ID);
             }
             }
         }
         }
     },
     },
@@ -1614,18 +1631,19 @@ $(document).ready(function() {
     });
     });
     //绑定新建建设项目、新建文件夹、重命名Enter键事件
     //绑定新建建设项目、新建文件夹、重命名Enter键事件
     bindInputs($('#project-name'), $('#folder-name'), $('#rename-name'));
     bindInputs($('#project-name'), $('#folder-name'), $('#rename-name'));
-
+    //绑定新建窗口显示事件
+    bindModalShown($('#add-folder-dialog'), $('#add-project-dialog'), $('#add-tender-dialog'));
     //绑定新建建设项目、新建文件夹、重命名弹窗隐藏事件
     //绑定新建建设项目、新建文件夹、重命名弹窗隐藏事件
     bindModalsHidden($('#add-project-dialog'), $('#add-folder-dialog'), $('#rename-dialog'));
     bindModalsHidden($('#add-project-dialog'), $('#add-folder-dialog'), $('#rename-dialog'));
 
 
-    // 新增建设项目点击
-    /*$('#add-project-btn').click(function () {
-        let selectedItem = projTreeObj.tree.selected;
-        $('#add-project-dialog').modal('show');
-        setTimeout(function () {
-            $('#project-name')[0].focus();
-        }, 300);
-    });*/
+    // 新建子菜单有效性刷新
+    $('#addMenuBtn').click(function () {
+        const menuDisplay = !$('#addMenu').is(':visible');
+        if (!menuDisplay) {
+            return;
+        }
+        projTreeObj.refreshAddMenuItems();
+    });
 
 
     // 新增建设项目操作
     // 新增建设项目操作
     $('#addProjOk').click(function () {
     $('#addProjOk').click(function () {
@@ -1777,9 +1795,6 @@ $(document).ready(function() {
             setRegionOpts(regions);
             setRegionOpts(regions);
             $('#regionDiv').show();
             $('#regionDiv').show();
         }
         }
-        setTimeout(function () {
-            $('#tender-name')[0].focus();
-        }, 300);
     });
     });
 
 
     // 新增单位工程
     // 新增单位工程
@@ -2231,6 +2246,18 @@ function AddProject() {
     }
     }
 }
 }
 
 
+function bindModalShown(folderDialog, projDialog, tenderDialog) {
+    folderDialog.on('shown.bs.modal', function () {
+        $('#folder-name').focus();
+    });
+    projDialog.on('shown.bs.modal', function () {
+        $('#project-name').focus();
+    });
+    tenderDialog.on('shown.bs.modal', function () {
+        $('#tender-name').focus();
+    });
+}
+
 //新建建设项目、新建单项工程、新建文件夹、重命名弹窗隐藏事件
 //新建建设项目、新建单项工程、新建文件夹、重命名弹窗隐藏事件
 function bindModalsHidden(projDialog, folderDialog, renameDialog){
 function bindModalsHidden(projDialog, folderDialog, renameDialog){
     projDialog.on('hidden.bs.modal', function () {
     projDialog.on('hidden.bs.modal', function () {

+ 54 - 0
web/building_saas/pm/js/pm_tree.js

@@ -254,6 +254,7 @@ const pmTree = {
             };
             };
 
 
             Tree.prototype.loadData = function (arrData) {
             Tree.prototype.loadData = function (arrData) {
+                this.sourceData = arrData;
                 let i, that = this;
                 let i, that = this;
                 let nodesIndex = {};
                 let nodesIndex = {};
                 function getPreNode(id){
                 function getPreNode(id){
@@ -379,6 +380,59 @@ const pmTree = {
 
 
             };
             };
 
 
+            Tree.prototype.check = function (_root) {
+                if (this.sourceData.length !== this.items.length) {
+                    const data = this.sourceData.filter(item => {
+                        const findData = this.items.find(node => node.data.ID === item.ID);
+                        return !findData;
+                    });
+                    console.log('丢失数据:');
+                    console.log(data);
+                    return false;
+                }
+                return isValid(_root.children);
+                function isValid(nodes) {
+                    for (let node of nodes) {
+                        if (node.data.ParentID !== -1 &&
+                            (!node.parent || node.parent.data.ID !== node.data.ParentID)) {
+                            console.log(`${node.serialNo() + 1}:${node.data.name} parent对应错误`);
+                            return false;
+                        }
+                        if (node.data.ParentID === -1 && node.parent && node.parent !== _root) {
+                            console.log(`${node.serialNo() + 1}:${node.data.name} 不应有parent`);
+                            return false;
+                        }
+                        if (node.data.NextSiblingID !== -1 &&
+                            (!node.nextSibling || node.nextSibling.data.ID !== node.data.NextSiblingID)) {
+                            console.log(`${node.serialNo() + 1}:${node.data.name} next对应错误`);
+                            return false;
+                        }
+                        if (node.data.NextSiblingID === -1 && node.nextSibling) {
+                            console.log(`${node.serialNo() + 1}:${node.data.name} 不应有next`);
+                            return false;
+                        }
+                        let parent = node.parent,
+                            nodeIdx = parent.children.indexOf(node),
+                            nextIdx = parent.children.indexOf(node.nextSibling);
+                        if (nodeIdx !== -1 && nextIdx !== -1 && nodeIdx > nextIdx) {
+                            console.log(`${node.serialNo() + 1}:${node.data.name} node索引大于next索引`);
+                            return false;
+                        }
+                        if (node.nextSibling && node.parent !== node.nextSibling.parent) {
+                            console.log(`${node.serialNo() + 1}:${node.data.name} 与兄弟节点 ${node.nextSibling.serialNo() + 1}:${node.nextSibling.data.name} 父节点不同`);
+                            return false;
+                        }
+                        if (node.children.length) {
+                            let v = isValid(node.children);
+                            if (!v) {
+                                return false;
+                            }
+                        }
+                    }
+                    return true;
+                }
+            };
+
             Tree.prototype.refreshData = function () {
             Tree.prototype.refreshData = function () {
 
 
             };
             };