Menu.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. <div id="menuTree"></div>
  9. </div>
  10. <div class="col-sm-6">
  11. <p class="text-warning">在菜单上点击鼠标右键来新建或编辑菜单。</p>
  12. </div>
  13. </div>
  14. </div>
  15. </div>
  16. <operationDailog mainDiv="mainDiv" :title="operDailogTitle" ref="operForm" :callback="saveMenu">
  17. <div class="row">
  18. <div class="col-sm-6">
  19. <el-form :model="menu" :rules="rules" ref="menuForm">
  20. <el-form-item label="名称" label-width="100px" prop="menuName">
  21. <el-input v-model="menu.menuName" ></el-input>
  22. </el-form-item>
  23. <el-form-item label="URL" label-width="100px">
  24. <el-input v-model="menu.menuUrl" placeholder="如果创建目录则不用填写URL"></el-input>
  25. </el-form-item>
  26. <el-form-item label="排序" label-width="100px">
  27. <el-input-number v-model="menu.menuOrder" :min="0" :max="100"></el-input-number>
  28. </el-form-item>
  29. <el-form-item label="备注" label-width="100px">
  30. <el-input v-model="menu.menuDesc" ></el-input>
  31. </el-form-item>
  32. <el-form-item label="图标" label-width="100px">
  33. <div id="picview" style="font-size:20px;"></div>
  34. </el-form-item>
  35. </el-form>
  36. </div>
  37. <div class="col-sm-6">
  38. <div style="height:400px; overflow:auto;">
  39. <template v-for="(m) in menuIcons">
  40. <a href="javascript:;" @click="showPic(m.cls)" style='color:#403a3a; text-decoration:none' :key="m.index"><i :class="m.cls"></i> &nbsp; </a>
  41. </template>
  42. </div>
  43. </div>
  44. </div>
  45. </operationDailog>
  46. </div>
  47. </template>
  48. <script>
  49. import { baseUrl, ajax } from "@/common/biConfig";
  50. import operationDailog from '@/components/OperationDailog'
  51. import $ from "jquery";
  52. import "jstree";
  53. import "jstree/dist/themes/default/style.min.css";
  54. import menuData from "@/assets/data/menu-icons.json"
  55. export default {
  56. data() {
  57. return {
  58. menu:{
  59. menuId:null,
  60. menuPid:null,
  61. menuName:"",
  62. menuDesc:"",
  63. menuOrder:0,
  64. menuUrl:"",
  65. avatar:""
  66. },
  67. rules:{
  68. menuName:[
  69. { required: true, message: '必填', trigger: 'blur' }
  70. ]
  71. },
  72. operDailog:false,
  73. operDailogTitle:"",
  74. menuIcons : menuData
  75. };
  76. },
  77. components: {
  78. operationDailog
  79. },
  80. mounted() {
  81. this.initTree();
  82. },
  83. computed: {},
  84. methods: {
  85. addMenu:function(node, isupdate){
  86. this.operDailogTitle = isupdate?"修改菜单":"创建菜单";
  87. this.$refs.operForm.showDailog();
  88. },
  89. delMenu:function(node){
  90. },
  91. showPic:function(cls){
  92. $("#picview").html(`<i class='${cls}'></i>`);
  93. },
  94. //在 operationDailog 里面进行回掉的函数
  95. saveMenu:function(){
  96. return true;
  97. },
  98. //初始化 jstree
  99. initTree: function () {
  100. let ts = this;
  101. $("#menuTree")
  102. .jstree({
  103. core: {
  104. check_callback: true,
  105. data: function (obj, callback) {
  106. if (obj.id == "#") {
  107. callback.call(this, [
  108. {
  109. id: "0",
  110. text: "系统菜单",
  111. children: true,
  112. state: { opened: true },
  113. icon: "fa fa-home",
  114. },
  115. ]);
  116. } else {
  117. ajax({
  118. type: "GET",
  119. data: {id: obj.id},
  120. postJSON: false,
  121. url: 'frame/menu/loadData.action',
  122. success: function (resp) {
  123. callback.call(this, resp.rows);
  124. },
  125. }, ts);
  126. }
  127. },
  128. },
  129. contextmenu: {
  130. items: {
  131. add: {
  132. label: "新增",
  133. icon: "glyphicon glyphicon-plus",
  134. action: function (data) {
  135. const inst = $.jstree.reference(data.reference),
  136. node = inst.get_node(data.reference);
  137. ts.addMenu(node, false);
  138. },
  139. },
  140. modify: {
  141. label: "修改",
  142. icon: "glyphicon glyphicon-edit",
  143. action: function (data) {
  144. const inst = $.jstree.reference(data.reference),
  145. node = inst.get_node(data.reference);
  146. ts.addMenu(node, true);
  147. },
  148. _disabled: function (data) {
  149. const inst = $.jstree.reference(data.reference),
  150. node = inst.get_node(data.reference);
  151. if (node.id == "0") {
  152. return true;
  153. } else {
  154. return false;
  155. }
  156. },
  157. },
  158. remove: {
  159. label: "删除",
  160. icon: "glyphicon glyphicon-trash",
  161. _disabled: function (data) {
  162. const inst = $.jstree.reference(data.reference),
  163. node = inst.get_node(data.reference);
  164. if (node.id == "0") {
  165. return true;
  166. } else {
  167. return false;
  168. }
  169. },
  170. action: function (data) {
  171. const inst = $.jstree.reference(data.reference),
  172. node = inst.get_node(data.reference);
  173. ts.delMenu(node);
  174. },
  175. },
  176. },
  177. },
  178. plugins: ["wholerow", "contextmenu"],
  179. })
  180. .bind("open_node.jstree", function (a, b) {
  181. if (b.node.id == "0") {
  182. return;
  183. }
  184. const ref = $("#menuTree").jstree(true);
  185. ref.set_icon(b.node, "fa fa-folder-open-o");
  186. })
  187. .bind("close_node.jstree", function (a, b) {
  188. if (b.node.id == "0") {
  189. return;
  190. }
  191. const ref = $("#menuTree").jstree(true);
  192. ref.set_icon(b.node, "fa fa-folder-o");
  193. });
  194. },
  195. },
  196. watch: {},
  197. };
  198. </script>
  199. <style lang="less" scoped>
  200. @import "../../style/mixin";
  201. </style>