auth.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. {extend name="common/common2" /}
  2. {block name="main"}
  3. <style>
  4. .submit-btn{
  5. position: fixed;
  6. z-index: 10;
  7. top: 3px;
  8. right: 5px;
  9. }
  10. .submit-btn2{
  11. position: fixed;
  12. z-index: 10;
  13. top: 3px;
  14. right: 90px;
  15. }
  16. .panel-body{
  17. height: 90%;
  18. overflow: auto;
  19. }
  20. </style>
  21. <div class="tabs-container" id="app">
  22. <ul class="nav nav-tabs">
  23. <li {if $cate==0} class="active" {/if}><a href="{:url('auth',['id'=>$rolesId,'cate'=>0])}" aria-expanded="true">后台权限</a>
  24. </li>
  25. <li {if $cate==1} class="active" {/if}><a href="{:url('auth',['id'=>$rolesId,'cate'=>1])}" aria-expanded="true">APP权限</a>
  26. </li>
  27. </ul>
  28. <div class="tab-content">
  29. <div id="tab-1" class="tab-pane active">
  30. <div class="panel-body">
  31. <div >
  32. <p>
  33. <el-checkbox
  34. @change="handleCheckedTreeNodeAll($event, 'tree')"
  35. >全选/全不选</el-checkbox>
  36. </p>
  37. <p>
  38. <el-input
  39. clearable
  40. size="mini"
  41. placeholder="输入关键字"
  42. v-model="filterText">
  43. </el-input>
  44. </p>
  45. <p>
  46. <el-tree
  47. :data="data"
  48. :empty-text="emTxt"
  49. show-checkbox
  50. default-expand-all
  51. :filter-node-method="filterNode"
  52. node-key="id"
  53. ref="tree"
  54. highlight-current
  55. :default-checked-keys="value"
  56. @check="handleClick1"
  57. :check-strictly="strictly"
  58. :props="defaultProps">
  59. </el-tree>
  60. </p>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. <button type="button" @click="save" class="btn btn-primary submit-btn">保存权限</button>
  66. <a href="{:url('auth',['id'=>$rolesId,'type'=>1])}" class="btn btn-warning submit-btn2">推荐权限</a>
  67. </div>
  68. </div>
  69. <div class="ibox" style="display: none">
  70. <div class="ibox-content">
  71. </div>
  72. </div>
  73. {/block}
  74. {block name="script"}
  75. <script>
  76. new Vue({
  77. el: '#app',
  78. data: function() {
  79. return {
  80. data: {:json_encode($menus)},
  81. defaultProps: {
  82. children: 'children',
  83. label: 'title',
  84. value: 'id',
  85. },
  86. value:[],
  87. emTxt:"没有数据",
  88. checkValue:false,
  89. arr:[],
  90. filterText: '',
  91. checked:false,
  92. strictly:false,
  93. menuNodeAll: false,
  94. }
  95. },
  96. watch: {
  97. filterText(val) {
  98. this.$refs.tree.filter(val);
  99. }
  100. },
  101. mounted(){
  102. this.strictly = true;
  103. this.$nextTick(() => {
  104. this.value = {:json_encode($sauth)};
  105. this.strictly = false;
  106. })
  107. },
  108. methods: {
  109. // 树权限(全选/全不选)
  110. handleCheckedTreeNodeAll(value) {
  111. this.$refs.tree.setCheckedNodes(value ? this.data : []);
  112. },
  113. handleClick1(data) {
  114. // const node = this.$refs.tree.getNode(data.id);
  115. // this.setNode(node);
  116. },
  117. setNode(node) {
  118. if (node.checked) {
  119. //选中,递归设置所有父节点选中
  120. this.setParentNode(node);
  121. } else {
  122. //取消选中,所有子节点取消选中
  123. this.setChildenNode(node);
  124. }
  125. },
  126. setParentNode(node) {
  127. if (node.parent) {
  128. for (const key in node) {
  129. if (key === "parent") {
  130. node[key].checked = true;
  131. this.setParentNode(node[key]);
  132. }
  133. }
  134. }
  135. },
  136. setChildenNode(node) {
  137. for (let i = 0; i < node.childNodes.length; i++) {
  138. node.childNodes[i].checked = false;
  139. this.setChildenNode(node.childNodes[i]);
  140. }
  141. },
  142. filterNode(value, data) {
  143. if (!value) return true;
  144. return data.title.indexOf(value) !== -1;
  145. },
  146. handleCheckAllChange(e){
  147. var list = this.$refs.tree.store._getAllNodes();
  148. for (let i = 0;i < list.length;i++) {
  149. this.$refs.tree.store._getAllNodes()[i].checked = e;
  150. }
  151. for (var i = 0; i <= this.value.length; i++) {
  152. if (this.checked == false) {
  153. this.value.splice(this.value.indexOf(this.i), 1)
  154. }
  155. }
  156. },
  157. all(){
  158. },
  159. handleNodeClick(e){ //点击节点
  160. console.log(e);
  161. },
  162. handleCheckChange(e,checked){ //多选框
  163. // this.all();
  164. this.value = this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHalfCheckedKeys())
  165. for (var i = 0; i <= this.value.length; i++) {
  166. if (this.checked == false) {
  167. this.value.splice(this.value.indexOf(this.i), 1)
  168. }
  169. }
  170. console.log(this.value);
  171. },
  172. save(){
  173. // 获取选中的子节点
  174. let checkedKeys = this.$refs.tree.getCheckedKeys();
  175. // 获取选中的父节点
  176. let hafCheckedKeys = this.$refs.tree.getHalfCheckedKeys();
  177. // 合并
  178. let functionIdList = checkedKeys.concat(hafCheckedKeys)
  179. var checkedId = functionIdList;
  180. console.log(checkedId)
  181. // this.value = checkedId;
  182. var that = this;
  183. if(checkedId.length===0){
  184. this.$message.error('请选择权限');
  185. return ;
  186. }
  187. $.post("{:url('auth')}",{cate:"{$cate}",rolesId:"{$rolesId}",ids:checkedId},function (res) {
  188. if(res.code==1){
  189. that.$message({
  190. message: res.msg,
  191. type: 'success',
  192. showClose: true,
  193. onClose:function () {
  194. parent.layer.closeAll();
  195. }
  196. });
  197. }else {
  198. that.$message.error(res.msg);
  199. }
  200. })
  201. }
  202. }
  203. })
  204. $(document).on('click','.app-check-all',function(){
  205. $(".appids").prop("checked", $(this).prop('checked'));
  206. });
  207. function checkSubClick(id,_this){
  208. if($(_this).prop('checked') == true){
  209. $('.sub_'+id).prop("checked", $(_this).prop('checked'));
  210. }else {
  211. $('.sub_'+id).prop("checked", false);
  212. }
  213. }
  214. </script>
  215. {/block}