menu.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * 角色管理的单例
  3. */
  4. var Menu = {
  5. id: "menuTable", //表格id
  6. seItem: null, //选中的条目
  7. table: null,
  8. layerIndex: -1
  9. };
  10. /**
  11. * 初始化表格的列
  12. */
  13. Menu.initColumn = function () {
  14. var columns = [
  15. {field: 'selectItem', radio: true},
  16. {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
  17. {title: '菜单名称', field: 'name', align: 'center', valign: 'middle', sortable: true},
  18. {title: '菜单编号', field: 'code', align: 'center', valign: 'middle', sortable: true},
  19. {title: '菜单父编号', field: 'pcode', align: 'center', valign: 'middle', sortable: true},
  20. {title: '请求地址', field: 'url', align: 'center', valign: 'middle', sortable: true},
  21. {title: '排序', field: 'num', align: 'center', valign: 'middle', sortable: true},
  22. {title: '层级', field: 'levels', align: 'center', valign: 'middle', sortable: true},
  23. {title: '是否是菜单', field: 'isMenuName', align: 'center', valign: 'middle', sortable: true},
  24. {title: '状态', field: 'statusName', align: 'center', valign: 'middle', sortable: true}]
  25. return columns;
  26. };
  27. /**
  28. * 检查是否选中
  29. */
  30. Menu.check = function () {
  31. var selected = $('#' + this.id).bootstrapTreeTable('getSelections');
  32. if (selected.length == 0) {
  33. Feng.info("请先选中表格中的某一记录!");
  34. return false;
  35. } else {
  36. Menu.seItem = selected[0];
  37. return true;
  38. }
  39. };
  40. /**
  41. * 点击添加菜单
  42. */
  43. Menu.openAddMenu = function () {
  44. var index = layer.open({
  45. type: 2,
  46. title: '添加菜单',
  47. area: ['830px', '450px'], //宽高
  48. fix: false, //不固定
  49. maxmin: true,
  50. content: Feng.ctxPath + '/menu/menu_add'
  51. });
  52. this.layerIndex = index;
  53. };
  54. /**
  55. * 点击修改
  56. */
  57. Menu.openChangeMenu = function () {
  58. if (this.check()) {
  59. var index = layer.open({
  60. type: 2,
  61. title: '修改菜单',
  62. area: ['800px', '450px'], //宽高
  63. fix: false, //不固定
  64. maxmin: true,
  65. content: Feng.ctxPath + '/menu/menu_edit/' + this.seItem.id
  66. });
  67. this.layerIndex = index;
  68. }
  69. };
  70. /**
  71. * 删除
  72. */
  73. Menu.delMenu = function () {
  74. if (this.check()) {
  75. var operation = function () {
  76. var ajax = new $ax(Feng.ctxPath + "/menu/remove", function (data) {
  77. Feng.success("删除成功!");
  78. Menu.table.refresh();
  79. }, function (data) {
  80. Feng.error("删除失败!" + data.responseJSON.message + "!");
  81. });
  82. ajax.set("menuId", Menu.seItem.id);
  83. ajax.start();
  84. };
  85. Feng.confirm("是否刪除该菜单?", operation);
  86. }
  87. };
  88. /**
  89. * 搜索
  90. */
  91. Menu.search = function () {
  92. var queryData = {};
  93. queryData['menuName'] = $("#menuName").val();
  94. queryData['level'] = $("#level").val();
  95. Menu.table.refresh({query: queryData});
  96. }
  97. $(function () {
  98. var defaultColunms = Menu.initColumn();
  99. var table = new BSTreeTable(Menu.id, "/menu/list", defaultColunms);
  100. table.setExpandColumn(2);
  101. table.setIdField("id");
  102. table.setCodeField("code");
  103. table.setParentCodeField("pcode");
  104. table.setExpandAll(true);
  105. table.init();
  106. Menu.table = table;
  107. });