edit.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <!DOCTYPE html>
  2. <html xmlns:th="http://www.thymeleaf.org"
  3. xmlns:sec="http://www.pollix.at/thymeleaf/shiro">
  4. <head th:replace="admin/common/html/tableHead :: tableHead(~{::title},~{::link},~{::style})">
  5. <title th:text=${title}></title>
  6. <!-- 这儿引用单独的css link -->
  7. <!-- Ladda for Bootstrap 3按钮加载进度插件 -->
  8. <link rel="stylesheet" th:href="@{/static/admin/assets/js/button/ladda/ladda.min.css}">
  9. <!-- bootstrap-table表单样式 -->
  10. <link th:href="@{/static/admin/assets/js/bootstrap/css/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet"/>
  11. <!-- treeview -->
  12. <link th:href="@{/static/admin/assets/js/bootstrap/bootstrap-treeview/css/bootstrap-treeview.css}" rel="stylesheet"/>
  13. <style type="text/css">
  14. body {
  15. color: #9ea7b3;
  16. font-family: "Open Sans", Arial, sans-serif!important;
  17. font-size: 13px!important;
  18. line-height: 20px;
  19. overflow-x: hidden!important;
  20. min-height: 100%;
  21. z-index: -2;
  22. margin: 0px !important;
  23. background-image: none;
  24. -moz-background-size: cover;
  25. -webkit-background-size: cover;
  26. -o-background-size: cover;
  27. background-size: cover;
  28. }
  29. label.error {
  30. position: absolute;
  31. right: 18px;
  32. top: 5px;
  33. color: #ef392b;
  34. font-size: 12px;
  35. }
  36. </style>
  37. </head>
  38. <body>
  39. <div class="content-wrap">
  40. <div class="row">
  41. <div class="col-sm-12">
  42. <div class="nest" id="elementClose">
  43. <div class="">
  44. </div>
  45. <div class="body-nest" id="element">
  46. <div class="panel-body">
  47. <form class="form-horizontal m" id="form-edit" th:object="${TvueRole}">
  48. <input id="id" name="id" type="hidden" th:value="*{id}"/>
  49. <div class="form-group">
  50. <!-- 验证用 -->
  51. <input class="form-control" type="hidden" id="checkname" th:value="*{name}"/>
  52. <label class="col-sm-3 control-label ">角色名称:</label>
  53. <div class="col-sm-8">
  54. <input class="form-control" type="text" id="name" name="name" th:value="*{name}"/>
  55. </div>
  56. </div>
  57. <div class="form-group">
  58. <input type="hidden" name="prem" id="prem">
  59. <label class="col-sm-3 control-label ">权限配置:</label>
  60. <div class="col-sm-8">
  61. <div id="tree"></div>
  62. </div>
  63. </div>
  64. <div class="form-group">
  65. <div class="form-control-static col-sm-offset-9">
  66. <button type="submit" class="btn btn-primary">提交</button>
  67. <button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
  68. </div>
  69. </div>
  70. </form>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. <!-- 通用js -->
  78. <div th:include="admin/common/html/js :: onload_js">
  79. </div>
  80. <!-- bootstarp 表格 -->
  81. <script th:src="@{/static/admin/assets/js/bootstrap/js/bootstrap-table/bootstrap-table.min.js}" type="text/javascript"></script>
  82. <script th:src="@{/static/admin/assets/js/bootstrap/js/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}" type="text/javascript"></script>
  83. <script th:src="@{/static/admin/assets/js/bootstrap/js/base_list.js}" type="text/javascript"></script>
  84. <!-- 弹窗 -->
  85. <script th:src="@{/static/admin/assets/js/layer/layer.js}" type="text/javascript"></script>
  86. <!-- 遮罩层 -->
  87. <script th:src="@{/static/admin/assets/js/blockUI/jquery.blockUI.js}" type="text/javascript"></script>
  88. <!--bootstarp threeView -->
  89. <script th:src="@{/static/admin/assets/js/bootstrap/bootstrap-treeview/js/bootstrap-treeview.js}" type="text/javascript"></script>
  90. <script type="text/javascript">
  91. $("#form-edit").validate({
  92. rules:{
  93. name:{
  94. required:true,
  95. minlength: 2,
  96. maxlength: 20,
  97. remote: {
  98. url: rootPath + "/RoleVueController/checkNameUnique",
  99. type: "post",
  100. dataType: "json",
  101. dataFilter: function(data, type) {
  102. if($("#checkname").val()==$("#name").val())
  103. return true;
  104. else{
  105. if (data == "0")
  106. return true;
  107. else
  108. return false;
  109. }
  110. }
  111. }
  112. }
  113. },
  114. messages: {
  115. "name": {
  116. remote: "角色已经存在"
  117. }
  118. },
  119. submitHandler:function(form){
  120. edit();
  121. }
  122. });
  123. function edit() {
  124. var x=$('#tree').treeview('getChecked');
  125. var prem=selectNodeIdArr(x);
  126. $("#prem").val(prem.join(","));
  127. var dataFormJson=$("#form-edit").serialize();
  128. $.ajax({
  129. cache : true,
  130. type : "POST",
  131. url : rootPath + "/RoleVueController/edit",
  132. data :dataFormJson,
  133. async : false,
  134. error : function(request) {
  135. $.modal.alertError("系统错误");
  136. },
  137. success : function(data) {
  138. $.operate.saveSuccess(data);
  139. }
  140. });
  141. }
  142. </script>
  143. <script type="text/javascript">
  144. /***权限配置***/
  145. function getTree() {
  146. var tree = [];
  147. $.ajax({
  148. url: rootPath + "/PermissionVueController/getCheckPrem",
  149. type:"post",
  150. async : false,
  151. cache : true,
  152. data:{"roleId":$("#id").val()},
  153. error : function(request) {
  154. $.modal.alertError("系统错误");
  155. },
  156. success : function(data) {
  157. if(!$.common.isEmpty(data)&&data.code==200){
  158. tree.push(data.data);
  159. }
  160. }
  161. })
  162. return tree;
  163. }
  164. /**
  165. * 获取子节点
  166. */
  167. function getChildNodeIdArr(node) {
  168. var ts = [];
  169. if (node.nodes) {
  170. for (x in node.nodes) {
  171. ts.push(node.nodes[x].nodeId);
  172. if (node.nodes[x].nodes) {
  173. var getNodeDieDai = getChildNodeIdArr(node.nodes[x]);
  174. for (j in getNodeDieDai) {
  175. ts.push(getNodeDieDai[j]);
  176. }
  177. }
  178. }
  179. } else {
  180. ts.push(node.nodeId);
  181. }
  182. return ts;
  183. }
  184. /**
  185. * 获取传入的选中节点id
  186. */
  187. function selectNodeIdArr(data){
  188. var ids=[];
  189. if(data){
  190. for(x in data){
  191. ids.push(data[x].id);
  192. }
  193. }
  194. return ids;
  195. }
  196. //选中父节点时,选中所有子节点
  197. function getChildNodeIdArr(node) {
  198. var ts = [];
  199. if (node.nodes) {
  200. for (x in node.nodes) {
  201. ts.push(node.nodes[x].nodeId);
  202. if (node.nodes[x].nodes) {
  203. var getNodeDieDai = getChildNodeIdArr(node.nodes[x]);
  204. for (j in getNodeDieDai) {
  205. ts.push(getNodeDieDai[j]);
  206. }
  207. }
  208. }
  209. } else {
  210. ts.push(node.nodeId);
  211. }
  212. return ts;
  213. }
  214. //选中所有子节点时,选中父节点 取消子节点时取消父节点
  215. function setParentNodeCheck(node) {
  216. var parentNode = $("#tree").treeview("getNode", node.parentId);
  217. if (parentNode.nodes) {
  218. var checkedCount = 0;
  219. for (x in parentNode.nodes) {
  220. if (parentNode.nodes[x].state.checked) {
  221. checkedCount ++;
  222. } else {
  223. break;
  224. }
  225. }
  226. if (checkedCount == parentNode.nodes.length) { //如果子节点全部被选 父全选
  227. $("#tree").treeview("checkNode", parentNode.nodeId);
  228. setParentNodeCheck(parentNode);
  229. }else { //如果子节点未全部被选 父未全选[当前注释是因为子节点取消的时候父节点不能取消]
  230. // $('#tree').treeview('uncheckNode', parentNode.nodeId);
  231. // setParentNodeCheck(parentNode);
  232. }
  233. }
  234. }
  235. //取消父节点时 取消所有子节点
  236. function setChildNodeUncheck(node) {
  237. if (node.nodes) {
  238. var ts = []; //当前节点子集中未被选中的集合
  239. for (x in node.nodes) {
  240. if (!node.nodes[x].state.checked) {
  241. ts.push(node.nodes[x].nodeId);
  242. }
  243. if (node.nodes[x].nodes) {
  244. var getNodeDieDai = node.nodes[x];
  245. for (j in getNodeDieDai) {
  246. if (!getNodeDieDai.state.checked) {
  247. ts.push(getNodeDieDai[j]);
  248. }
  249. }
  250. }
  251. }
  252. }
  253. return ts;
  254. }
  255. $(function() {
  256. $('#tree').treeview({
  257. levels : 2,//设置默认展开级别
  258. showCheckbox : 1,//这里之所以写1,是因为我引得js源码里定义1为true
  259. multiSelect : 1,//这里之所以写1,是因为我引得js源码里定义1为true
  260. data : getTree(),
  261. color : "#000000",//设置字体加载颜色
  262. backColor : "#FFFFFF",//设置背景颜色
  263. selectedColor : "#428bca",//设置选中的字体颜色
  264. onNodeSelected : function(event, data) {
  265. // 事件代码...
  266. //console.log(data);
  267. },
  268. onNodeChecked : function(event, node) { //选中节点
  269. var selectNodes = getChildNodeIdArr(node); //获取所有子节点
  270. if (selectNodes) { //子节点不为空,则选中所有子节点
  271. $('#tree').treeview('checkNode', [ selectNodes, {silent : true}]);
  272. }
  273. var parentNode = $("#tree").treeview("getNode", node.parentId);
  274. setParentNodeCheck(node);
  275. },
  276. onNodeUnchecked : function(event, node) { //取消选中节点
  277. // 取消父节点 子节点取消
  278. var selectNodes = setChildNodeUncheck(node); //获取未被选中的子节点
  279. var childNodes = getChildNodeIdArr(node); //获取所有子节点
  280. if (selectNodes && selectNodes.length == 0) { //有子节点且未被选中的子节点数目为0,则取消选中所有子节点
  281. $('#tree').treeview('uncheckNode', [ childNodes, {silent : true}]);
  282. }
  283. // 取消节点 父节点取消
  284. var parentNode = $("#tree").treeview("getNode", node.parentId); //获取父节点
  285. var selectNodes = getChildNodeIdArr(node);
  286. setParentNodeCheck(node);
  287. }
  288. });
  289. })
  290. </script>
  291. </body>
  292. </html>