menu.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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: 'new_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: 'ismenu', align: 'center', valign: 'middle', sortable: true,
  24. formatter: function (value) {
  25. if (value == 1) {
  26. return "是";
  27. }
  28. return "否";
  29. }
  30. },
  31. {title: '状态', field: 'status', align: 'center', valign: 'middle', sortable: true,
  32. formatter: function (value) {
  33. if (value == 1) {
  34. return "正常";
  35. }
  36. return "停用";
  37. }
  38. }
  39. ]
  40. return columns;
  41. };
  42. /**
  43. * 检查是否选中
  44. */
  45. Menu.check = function () {
  46. var selected = $('#' + this.id).bootstrapTreeTable('getSelections');
  47. if (selected.length == 0) {
  48. Feng.info("请先选中表格中的某一记录!");
  49. return false;
  50. } else {
  51. Menu.seItem = selected[0];
  52. return true;
  53. }
  54. };
  55. /**
  56. * 点击添加菜单
  57. */
  58. Menu.openAddMenu = function () {
  59. var index = layer.open({
  60. type: 2,
  61. title: '添加菜单',
  62. area: ['830px', '450px'], //宽高
  63. fix: false, //不固定
  64. maxmin: true,
  65. content: Feng.ctxPath + '/admin/menu/add'
  66. });
  67. this.layerIndex = index;
  68. };
  69. /**
  70. * 点击修改
  71. */
  72. Menu.openChangeMenu = function () {
  73. if (this.check()) {
  74. var index = layer.open({
  75. type: 2,
  76. title: '修改菜单',
  77. area: ['800px', '450px'], //宽高
  78. fix: false, //不固定
  79. maxmin: true,
  80. content: Feng.ctxPath + '/admin/menu/edit/id/' + this.seItem.id
  81. });
  82. this.layerIndex = index;
  83. }
  84. };
  85. /**
  86. * 删除
  87. */
  88. Menu.delMenu = function () {
  89. if (this.check()) {
  90. var operation = function () {
  91. var ajax = new $ax(Feng.ctxPath + "/admin/menu/delete", function (data) {
  92. Feng.success("删除成功!");
  93. Menu.table.refresh();
  94. }, function (data) {
  95. Feng.error("删除失败!" + data.responseJSON.message + "!");
  96. });
  97. ajax.set("id", Menu.seItem.id);
  98. ajax.start();
  99. };
  100. Feng.confirm("是否刪除该菜单?", operation);
  101. }
  102. };
  103. /**
  104. * 搜索
  105. */
  106. Menu.search = function () {
  107. var queryData = {};
  108. queryData['menuName'] = $("#menuName").val();
  109. queryData['level'] = $("#level").val();
  110. Menu.table.refresh({query: queryData});
  111. }
  112. $(function () {
  113. var defaultColunms = Menu.initColumn();
  114. var table = new BSTreeTable(Menu.id, "/admin/menu/list", defaultColunms);
  115. table.setExpandColumn(2);
  116. table.setIdField("id");
  117. table.setCodeField("code");
  118. table.setParentCodeField("pcode");
  119. table.setExpandAll(true);
  120. table.init();
  121. Menu.table = table;
  122. });