Browse Source

菜单&数据权限新增(展开/折叠 全选/全不选 父子联动)

RuoYi 4 years ago
parent
commit
acfb6a56bb

+ 8 - 0
ruoyi-admin/src/main/resources/static/ruoyi/css/ry-ui.css

@@ -443,6 +443,14 @@ label.error {
 	background-position: -180px 0
 }
 
+/* ztree */
+div.ztree-border {
+    margin-top: 10px;
+    border: 1px solid #e5e6e7;
+    background: #FFFFFF none;
+    border-radius:4px;
+}
+
 /* 切换开关 */
 .toggle-switch {
 	display: -webkit-inline-box;

+ 1 - 0
ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js

@@ -1261,6 +1261,7 @@ var table = {
             		check: {
     				    enable: false,             // 置 zTree 的节点上是否显示 checkbox / radio
     				    nocheckInherit: true,      // 设置子节点是否自动继承
+    				    chkboxType: { "Y": "ps", "N": "ps" } // 父子节点的关联关系
     				},
     				data: {
     			        key: {

+ 32 - 2
ruoyi-admin/src/main/resources/templates/system/role/add.html

@@ -42,9 +42,15 @@
 				</div>
 			</div>
 			<div class="form-group">
-				<label class="col-sm-3 control-label">菜单权限</label>
+				<label class="col-sm-3 control-label">菜单权限</label>
 				<div class="col-sm-8">
-					<div id="menuTrees" class="ztree"></div>
+				    <label class="check-box">
+				        <input type="checkbox" value="1">展开/折叠</label>
+				    <label class="check-box">
+				        <input type="checkbox" value="2">全选/全不选</label>
+				    <label class="check-box">
+				        <input type="checkbox" value="3" checked>父子联动</label>
+				    <div id="menuTrees" class="ztree ztree-border"></div>
 				</div>
 			</div>
 		</form>
@@ -111,6 +117,30 @@
 		    focusCleanup: true
 		});
 		
+		$('input').on('ifChanged', function(obj){
+			var type = $(this).val();
+			var checked = obj.currentTarget.checked;
+			if (type == 1) {
+			    if (checked) {
+			        $._tree.expandAll(true);
+			    } else {
+			        $._tree.expandAll(false);
+			    }
+			} else if (type == "2") {
+			    if (checked) {
+			        $._tree.checkAllNodes(true);
+			    } else {
+			        $._tree.checkAllNodes(false);
+			    }
+			} else if (type == "3") {
+			    if (checked) {
+			        $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
+			    } else {
+			        $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
+			    }
+			}
+		})
+		
 		function submitHandler() {
 	        if ($.validate.form()) {
 	        	add();

+ 32 - 2
ruoyi-admin/src/main/resources/templates/system/role/dataScope.html

@@ -34,9 +34,15 @@
 				</div>
 			</div>
 			<div class="form-group" id="authDataScope" th:style="'display:' + @{(*{dataScope=='2'} ? 'block' : 'none')} + ''">
-				<label class="col-sm-3 control-label">数据权限</label>
+				<label class="col-sm-3 control-label">数据权限</label>
 				<div class="col-sm-8">
-					<div id="deptTrees" class="ztree"></div>
+				    <label class="check-box">
+				        <input type="checkbox" value="1" checked>展开/折叠</label>
+				    <label class="check-box">
+				        <input type="checkbox" value="2">全选/全不选</label>
+				    <label class="check-box">
+				        <input type="checkbox" value="3" checked>父子联动</label>
+				    <div id="deptTrees" class="ztree ztree-border"></div>
 				</div>
 			</div>
 		</form>
@@ -55,6 +61,30 @@
 		    };
 			$.tree.init(options);
 	    });
+	    
+	    $('input').on('ifChanged', function(obj){
+			var type = $(this).val();
+			var checked = obj.currentTarget.checked;
+			if (type == 1) {
+			    if (checked) {
+			        $._tree.expandAll(true);
+			    } else {
+			        $._tree.expandAll(false);
+			    }
+			} else if (type == "2") {
+			    if (checked) {
+			        $._tree.checkAllNodes(true);
+			    } else {
+			        $._tree.checkAllNodes(false);
+			    }
+			} else if (type == "3") {
+			    if (checked) {
+			        $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
+			    } else {
+			        $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
+			    }
+			}
+		})
 
 		function submitHandler() {
 	        if ($.validate.form()) {

+ 32 - 2
ruoyi-admin/src/main/resources/templates/system/role/edit.html

@@ -43,9 +43,15 @@
 				</div>
 			</div>
 			<div class="form-group">
-				<label class="col-sm-3 control-label">菜单权限</label>
+				<label class="col-sm-3 control-label">菜单权限</label>
 				<div class="col-sm-8">
-					<div id="menuTrees" class="ztree"></div>
+				    <label class="check-box">
+				        <input type="checkbox" value="1">展开/折叠</label>
+				    <label class="check-box">
+				        <input type="checkbox" value="2">全选/全不选</label>
+				    <label class="check-box">
+				        <input type="checkbox" value="3" checked>父子联动</label>
+				    <div id="menuTrees" class="ztree ztree-border"></div>
 				</div>
 			</div>
 		</form>
@@ -117,6 +123,30 @@
 		    },
 		    focusCleanup: true
 		});
+		
+		$('input').on('ifChanged', function(obj){
+			var type = $(this).val();
+			var checked = obj.currentTarget.checked;
+			if (type == 1) {
+			    if (checked) {
+			        $._tree.expandAll(true);
+			    } else {
+			        $._tree.expandAll(false);
+			    }
+			} else if (type == "2") {
+			    if (checked) {
+			        $._tree.checkAllNodes(true);
+			    } else {
+			        $._tree.checkAllNodes(false);
+			    }
+			} else if (type == "3") {
+			    if (checked) {
+			        $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
+			    } else {
+			        $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
+			    }
+			}
+		})
 
 		function edit() {
 			var roleId = $("input[name='roleId']").val();

+ 4 - 6
ruoyi-admin/src/main/resources/templates/system/user/add.html

@@ -251,12 +251,10 @@
 		
 		function doSubmit(index, layero){
 			var tree = layero.find("iframe")[0].contentWindow.$._tree;
-			if ($.tree.notAllowParents(tree)) {
-				var body = layer.getChildFrame('body', index);
-    			$("#treeId").val(body.find('#treeId').val());
-    			$("#treeName").val(body.find('#treeName').val());
-    			layer.close(index);
-			}
+			var body = layer.getChildFrame('body', index);
+   			$("#treeId").val(body.find('#treeId').val());
+   			$("#treeName").val(body.find('#treeName').val());
+   			layer.close(index);
 		}
 
 		$(function() {

+ 4 - 6
ruoyi-admin/src/main/resources/templates/system/user/edit.html

@@ -215,12 +215,10 @@
 		
 		function doSubmit(index, layero){
 			var tree = layero.find("iframe")[0].contentWindow.$._tree;
-			if ($.tree.notAllowParents(tree)) {
-    			var body = layer.getChildFrame('body', index);
-    			$("#treeId").val(body.find('#treeId').val());
-    			$("#treeName").val(body.find('#treeName').val());
-    			layer.close(index);
-			}
+   			var body = layer.getChildFrame('body', index);
+   			$("#treeId").val(body.find('#treeId').val());
+   			$("#treeName").val(body.find('#treeName').val());
+   			layer.close(index);
 		}
 
 		$(function() {