UserMenu.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <div class="wrapper-content">
  3. <div class="ibox" id="mainDiv">
  4. <div class="ibox-title">用户管理 >> 所辖菜单</div>
  5. <div class="ibox-content">
  6. <div class="row">
  7. <div class="col-sm-6">
  8. <a href="javascript:;" @click="openall">全部展开</a> &nbsp;&nbsp; <a href="javascript:;" @click="closeall">全部关闭</a>
  9. <div id="menuTree"></div>
  10. </div>
  11. <div class="col-sm-6" align="right">
  12. <el-button type="primary" @click="save()">确 定</el-button>
  13. <el-button @click="backpage()">取 消</el-button>
  14. </div>
  15. </div>
  16. </div>
  17. </div>
  18. </div>
  19. </template>
  20. <script>
  21. import { baseUrl, ajax } from "@/common/biConfig";
  22. import $ from "jquery";
  23. import "jstree";
  24. import "jstree/dist/themes/default/style.min.css";
  25. export default {
  26. data() {
  27. return {
  28. }
  29. },
  30. components: {
  31. },
  32. mounted() {
  33. this.initTree();
  34. },
  35. computed: {},
  36. methods: {
  37. //初始化 jstree
  38. initTree: function () {
  39. let ts = this;
  40. $("#menuTree")
  41. .jstree({
  42. core: {
  43. check_callback: true,
  44. data: function (obj, callback) {
  45. ajax({
  46. type: "GET",
  47. data: {userId:ts.$route.params.userId},
  48. postJSON: false,
  49. url: 'frame/user/userMenu.action',
  50. success: function (resp) {
  51. callback.call(this, resp.rows);
  52. },
  53. }, ts);
  54. },
  55. },
  56. plugins: ["checkbox","wholerow"],
  57. })
  58. .bind("open_node.jstree", function (a, b) {
  59. if (b.node.id == "0") {
  60. return;
  61. }
  62. const ref = $("#menuTree").jstree(true);
  63. ref.set_icon(b.node, "fa fa-folder-open-o");
  64. })
  65. .bind("close_node.jstree", function (a, b) {
  66. if (b.node.id == "0") {
  67. return;
  68. }
  69. const ref = $("#menuTree").jstree(true);
  70. ref.set_icon(b.node, "fa fa-folder-o");
  71. });
  72. this.treeRef = $("#menuTree").jstree(true);
  73. },
  74. save:function(){
  75. const ts = this;
  76. let ids = "";
  77. let nodes = this.treeRef.get_selected(true);
  78. for(let i=0; nodes&&i<nodes.length; i++){
  79. var n = nodes[i];
  80. if(n.state.disabled){
  81. continue;
  82. }
  83. ids = ids + n.id + ",";
  84. }
  85. $("#menutree").find(".jstree-undetermined").each(function (i, element) {
  86. var id = $(element).closest('.jstree-node').attr("id");
  87. if(id != 'root'){
  88. ids = ids + id + ",";
  89. }
  90. });
  91. if(ids.length > 0){
  92. ids = ids.substring(0, ids.length - 1);
  93. }
  94. ajax({
  95. type:"POST",
  96. url:"/frame/user/userMenu/save.action",
  97. dataType:"JSON",
  98. data:{userId:ts.$route.params.userId, menuIds:ids},
  99. success:function(resp){
  100. ts.$notify.success({
  101. title: '授权成功',
  102. offset: 50
  103. });
  104. ts.backpage();
  105. }
  106. }, ts);
  107. },
  108. backpage:function(){
  109. this.$router.push('user')
  110. },
  111. openall:function(){
  112. this.treeRef.open_all();
  113. },
  114. closeall:function(){
  115. this.treeRef.close_all();
  116. }
  117. },
  118. watch: {},
  119. beforeRouteLeave: function(to, from, next) {
  120. this.$destroy();
  121. next();
  122. }
  123. };
  124. </script>
  125. <style lang="css">
  126. .jstree-default .jstree-disabled.jstree-clicked {
  127. background:none;
  128. text-decoration: line-through;
  129. }
  130. </style>