auth.apply.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. {extend name='extra@admin/content'}
  2. {block name="content"}
  3. <style>
  4. ul.ztree li span.button.switch{margin-right:5px}
  5. ul.ztree ul ul li{display:inline-block;white-space:normal}
  6. ul.ztree>li>ul>li{padding:5px}
  7. ul.ztree>li{background: #dae6f0}
  8. ul.ztree>li:nth-child(even)>ul>li:nth-child(even){background: #eef5fa}
  9. ul.ztree>li:nth-child(even)>ul>li:nth-child(odd){background: #f6fbff}
  10. ul.ztree>li:nth-child(odd)>ul>li:nth-child(even){background: #eef5fa}
  11. ul.ztree>li:nth-child(odd)>ul>li:nth-child(odd){background: #f6fbff}
  12. ul.ztree>li>ul{margin-top:12px}
  13. ul.ztree>li{padding:15px;padding-right:25px}
  14. ul.ztree li{white-space:normal!important}
  15. ul.ztree>li>a>span{font-size:15px;font-weight:700}
  16. </style>
  17. <ul id="zTree" class="ztree loading">
  18. <li style="height:100px;"></li>
  19. </ul>
  20. <div class="hr-line-dashed"></div>
  21. <div class="layui-form-item text-center">
  22. <button class="layui-btn" data-submit-role type='button'>保存数据</button>
  23. <button class="layui-btn layui-btn-danger" type='button' onclick="window.history.back()">取消编辑</button>
  24. </div>
  25. <script>
  26. require(['jquery.ztree'], function () {
  27. function showTree() {
  28. this.data = {};
  29. this.ztree = null;
  30. this.setting = {
  31. view: {showLine: false, showIcon: false, dblClickExpand: false},
  32. check: {enable: true, nocheck: false, chkboxType: {"Y": "ps", "N": "ps"}},
  33. callback: {
  34. beforeClick: function (treeId, treeNode) {
  35. if (treeNode.children.length < 1) {
  36. window.roleForm.ztree.checkNode(treeNode, !treeNode.checked, null, true);
  37. } else {
  38. window.roleForm.ztree.expandNode(treeNode);
  39. }
  40. return false;
  41. }}};
  42. this.listen();
  43. }
  44. showTree.prototype = {
  45. constructor: showTree,
  46. listen: function () {
  47. this.getData(this);
  48. },
  49. getData: function (self) {
  50. $.msg.loading();
  51. jQuery.get('{:url()}?id={$vo.id}', {action: 'getNode'}, function (ret) {
  52. $.msg.close();
  53. function renderChildren(data, level) {
  54. var childrenData = [];
  55. for (var i in data) {
  56. var children = {};
  57. children.open = true;
  58. children.node = data[i].node;
  59. children.name = data[i].title || data[i].node;
  60. children.checked = data[i].checked || false;
  61. children.children = renderChildren(data[i]._sub_, level + 1);
  62. childrenData.push(children);
  63. }
  64. return childrenData;
  65. }
  66. self.data = renderChildren(ret.data, 1);
  67. self.showTree();
  68. }, 'JSON');
  69. },
  70. showTree: function () {
  71. this.ztree = jQuery.fn.zTree.init(jQuery("#zTree"), this.setting, this.data);
  72. while (true) {
  73. var reNodes = this.ztree.getNodesByFilter(function (node) {
  74. return (!node.node && node.children.length < 1);
  75. });
  76. if (reNodes.length < 1) {
  77. break;
  78. }
  79. for (var i in reNodes) {
  80. this.ztree.removeNode(reNodes[i]);
  81. }
  82. }
  83. },
  84. submit: function () {
  85. var nodes = [];
  86. var data = this.ztree.getCheckedNodes(true);
  87. for (var i in data) {
  88. (data[i].node) && nodes.push(data[i].node);
  89. }
  90. $.form.load('{:url()}?id={$vo.id}&action=save', {nodes: nodes}, 'POST');
  91. }};
  92. window.roleForm = new showTree();
  93. $('[data-submit-role]').on('click', function () {
  94. window.roleForm.submit();
  95. });
  96. });
  97. </script>
  98. {/block}