menu-setup.html 6.2 KB

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