admin-permission.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. $(function () {
  2. var colunms = Menu.initColumn();
  3. var table = new TreeTable(Menu.id, "/admin/permission/list", colunms);
  4. table.setExpandColumn(2);
  5. table.setIdField("id");
  6. table.setCodeField("id");
  7. table.setParentCodeField("parentId");
  8. table.setExpandAll(false);
  9. table.init();
  10. Menu.table = table;
  11. });
  12. var Menu = {
  13. id: "menuTable",
  14. seItem: null, //选中的条目
  15. table: null,
  16. layerIndex: -1
  17. };
  18. /**
  19. * 初始化表格的列
  20. */
  21. Menu.initColumn = function () {
  22. var columns = [
  23. {field: 'selectItem', radio: true},
  24. {title: '菜单ID', field: 'id', visible: false, align: 'center', valign: 'middle', width: '7%'},
  25. {title: '权限名称', field: 'name', visible: false, align: 'center', valign: 'middle', width: '15%'},
  26. {title: '父节点名称', field: 'parentName', align: 'center', valign: 'middle', sortable: true, width: '15%', formatter: function(item, index){
  27. return item.parentName == null ? '' : item.parentName;
  28. }},
  29. {title: '图标', field: 'icon', align: 'center', valign: 'middle', sortable: true, formatter: function(item, index){
  30. return item.icon == null ? '' : '<i class="Hui-iconfont">'+item.icon+'</i>';
  31. }},
  32. {title: '类型', field: 'type', align: 'center', valign: 'middle', sortable: true, formatter: function(item, index){
  33. if(item.type === "0"){
  34. return '<span class="label label-default radius">目录</span>';
  35. }
  36. if(item.type === "1"){
  37. return '<span class="label label-primary radiu">菜单</span>';
  38. }
  39. if(item.type === "2"){
  40. return '<span class="label label-secondary radius">按钮</span>';
  41. }
  42. }},
  43. {title: '访问URL', field: 'url', align: 'center', valign: 'middle', sortable: true, width: '17%'},
  44. {title: '权限标识', field: 'perms', align: 'center', valign: 'middle', sortable: true, width: '15%'},
  45. {title: '排序号', field: 'sort', align: 'center', valign: 'middle', sortable: true}];
  46. return columns;
  47. };
  48. /**
  49. * 检查是否选中
  50. */
  51. Menu.check = function () {
  52. var selected = $('#' + this.id).bootstrapTreeTable('getSelections');
  53. if (selected.length == 0) {
  54. errorMessage("请先选中一条记录!");
  55. return false;
  56. } else {
  57. Menu.seItem = selected[0];
  58. return true;
  59. }
  60. };
  61. /**
  62. * 搜索
  63. */
  64. Menu.search = function () {
  65. var queryData = {};
  66. queryData['menuName'] = $("#menuName").val();
  67. Menu.table.refresh({query: queryData});
  68. };
  69. /*
  70. 参数解释:
  71. title 标题
  72. url 请求的url
  73. id 需要操作的数据id
  74. w 弹出层宽度(缺省调默认值)
  75. h 弹出层高度(缺省调默认值)
  76. */
  77. /*管理员-权限-添加*/
  78. function admin_permission_add(title,url,w,h){
  79. layer_show(title,url,w,h);
  80. }
  81. /*管理员-权限-删除*/
  82. function admin_permission_del(obj, url){
  83. if(Menu.check()){
  84. layer.confirm('确认要删除吗?',function(index){
  85. //此处请求后台程序,下方是成功后的前台处理……
  86. $.ajax({
  87. type:"DELETE",
  88. dataType:"json",
  89. url: url+"/"+Menu.seItem.id,
  90. data:{
  91. "timestamp":new Date().getTime()
  92. },
  93. statusCode: {
  94. 200 : function(data){
  95. window.location.reload();
  96. },
  97. 404 : function(data){
  98. errorMessage(data.responseText);
  99. },
  100. 500 : function(){
  101. errorMessage('系统错误!');
  102. }
  103. }
  104. });
  105. });
  106. }
  107. }
  108. /*管理员-权限-编辑*/
  109. function admin_permission_edit(title,url,w,h){
  110. if(Menu.check()){
  111. layer_show(title,url+"/"+Menu.seItem.id,w,h);
  112. }
  113. }