menu-setup.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>权限分配</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  7. <!-- 所有的 css & js 资源 -->
  8. <link rel="stylesheet" href="../../static/kj/element-ui/theme-chalk/index.css">
  9. <link rel="stylesheet" href="../../static/sa.css">
  10. <script src="../../static/kj/vue.min.js"></script>
  11. <script src="../../static/kj/element-ui/index.js"></script>
  12. <script src="../../static/kj/jquery.min.js"></script>
  13. <script src="../../static/kj/layer/layer.js"></script>
  14. <script src="../../static/sa.js"></script>
  15. <style>
  16. body,.el-tree{background-color: #eee;}
  17. .el-tree-node{margin: 0.15em 0 !important;}
  18. /* 悬浮时颜色更深一点 */
  19. .el-tree-node__content:hover{background-color: #CFE8FC !important;}
  20. </style>
  21. </head>
  22. <body>
  23. <div class="vue-box sbot" style="display: none;" :style="'display: block;'">
  24. <!-- ------- 内容部分 ------- -->
  25. <div class="s-body">
  26. <!-- 表格 -->
  27. <div style="padding: 1em 2em;">
  28. <el-form>
  29. <div class="c-title">所有权限</div>
  30. <!-- 此扩展能递归渲染一个权限树,点击深层次节点,父级节点中没有被选中的节点会被自动选中,单独点击父节点,子节点会全部 选中/去选中 -->
  31. <el-tree
  32. ref="tree"
  33. :data="dataList"
  34. show-checkbox
  35. node-key="id"
  36. :default-expand-all="true"
  37. :default-checked-keys="selectList"
  38. :expand-on-click-node="false"
  39. :check-on-click-node="true"
  40. :check-strictly="true"
  41. @node-click="node_click"
  42. @check="node_click"
  43. >
  44. <span class="custom-tree-node" slot-scope="s">
  45. <span style="color: #2D8CF0;" v-if="s.data.isShow == undefined || s.data.isShow == true">{{ s.data.name }}</span>
  46. <span style="color: #999;" v-if="s.data.isShow == false">{{ s.data.name }} (按钮权限)</span>
  47. <span style="color: #999;" v-if="s.data.info">&emsp;———— {{s.data.info}} </span>
  48. </span>
  49. </el-tree>
  50. </el-form>
  51. </div>
  52. </div>
  53. <!-- ------- 底部按钮 ------- -->
  54. <div class="s-foot">
  55. <el-button type="success" @click="checkedAll()">全选</el-button>
  56. <el-button type="primary" @click="ok()">确定</el-button>
  57. <el-button @click="sa.closeCurrIframe()">取消</el-button>
  58. </div>
  59. </div>
  60. <script src="../../sa-frame/menu-list.js"></script>
  61. <script src="../../sa-frame/menu-list-sp.js"></script>
  62. <script src="../../sa-frame/index/admin-util.js"></script>
  63. <script>
  64. var roleId = sa.p('roleId');
  65. var app = new Vue({
  66. el: '.vue-box',
  67. data: {
  68. p: [],
  69. dataList: [], // 数据集合
  70. selectList: [], // 默认选中
  71. ywList: [], // 一维数组
  72. haveList: [] // 这个角色用的权限id,拷贝
  73. },
  74. methods: {
  75. // 保存
  76. ok: function(clickCount){
  77. if(clickCount === undefined) {
  78. clickCount = 5;
  79. }
  80. // 判断是否改掉了关键权限
  81. var keys = this.$refs.tree.getCheckedKeys(); // 设置完拥有的id列表
  82. var rArr = ['1', '99', 'auth', 'role-list']; // 敏感菜单id列表
  83. var isR = false; // 是否给改掉了
  84. rArr.forEach(function(item) {
  85. // 只有原先有,现在没有,才会被这样判定
  86. if(this.haveList.indexOf(item) > -1 && keys.indexOf(item) == -1) {
  87. isR = true;
  88. console.log(item);
  89. console.log(this.haveList);
  90. }
  91. }.bind(this))
  92. // 提示
  93. if(isR) {
  94. var tipStr = '危险!系统检测到您取消了此角色的重要权限,这将导致与之关联的账号可能会无法正常使用后台,您无论如何都要这样设置吗?';
  95. tipStr += '<br/>为保证您不是误操作,您还需要继续点击按钮: ' + clickCount + '次'
  96. tipStr = '<b style="color: red;">' + tipStr + '</b>';
  97. sa.confirm(tipStr, function(res) {
  98. if(clickCount <= 1) {
  99. this.ok2();
  100. } else {
  101. clickCount--;
  102. this.ok(clickCount);
  103. }
  104. }.bind(this))
  105. } else {
  106. this.ok2();
  107. }
  108. },
  109. // 开始设置
  110. ok2: function() {
  111. var keys = this.$refs.tree.getCheckedKeys();
  112. var url = '/SpRolePermission/updatePcodeByRid';
  113. sa.ajax(url, {roleId: roleId, codes: keys.join(',')}, function (res) {
  114. sa.alert('设置成功', function(){
  115. sa.closeCurrIframe();
  116. });
  117. // 如果设置的角色与当前登录者的角色一致,则立即显示出来
  118. if(roleId == sa.$sys.getCurrUser().roleId) {
  119. top.sa_admin.initMenu(keys);
  120. sa.setAuth(keys);
  121. }
  122. }.bind(this))
  123. },
  124. // 点击回调, 处理其子节点跟随父节点的选中
  125. node_click: function(node) {
  126. console.log(node);
  127. var is_select = this.$refs.tree.getCheckedKeys().indexOf(node.id) != -1; // 此节点现在是否被选中
  128. if(node.children){
  129. node.children.forEach(function(item) {
  130. this.$refs.tree.setChecked(item.id, is_select);
  131. // 递归
  132. if(item.children) {
  133. this.node_click(item);
  134. }
  135. }.bind(this))
  136. }
  137. },
  138. // 全选/ 取消全选
  139. checkedAll: function() {
  140. // console.log(this.$refs.tree.getCheckedKeys().length);
  141. // console.log(this.ywList.length);
  142. if(this.$refs.tree.getCheckedKeys().length != this.ywList.length) {
  143. this.$refs['tree'].setCheckedNodes(this.ywList);
  144. } else {
  145. this.$refs['tree'].setCheckedNodes([]);
  146. }
  147. }
  148. },
  149. created: function(){
  150. // 全部
  151. menuList = sa_admin_code_util.arrayToTree(menuList); // 一维转tree
  152. menuList = sa_admin_code_util.refMenuList(menuList); // 属性处理
  153. this.dataList = menuList; // 数据
  154. this.ywList = sa_admin_code_util.treeToArray(this.dataList);
  155. // 拉取此 roleId 的
  156. sa.ajax('/SpRolePermission/getPcodeByRid?roleId=' + roleId, function(res) {
  157. this.selectList = res.data; // 选中的列表
  158. this.haveList = [].concat(this.selectList);
  159. }.bind(this))
  160. }
  161. })
  162. </script>
  163. </body>
  164. </html>