auth.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. define(["jquery", "easy-admin"], function ($, ea) {
  2. var init = {
  3. table_elem: '#currentTable',
  4. table_render_id: 'currentTableRenderId',
  5. index_url: 'system.auth/index',
  6. add_url: 'system.auth/add',
  7. edit_url: 'system.auth/edit',
  8. delete_url: 'system.auth/delete',
  9. export_url: 'system.auth/export',
  10. modify_url: 'system.auth/modify',
  11. authorize_url: 'system.auth/authorize',
  12. };
  13. var Controller = {
  14. index: function () {
  15. ea.table.render({
  16. init: init,
  17. cols: [[
  18. {type: "checkbox"},
  19. {field: 'id', width: 80, title: 'ID'},
  20. {field: 'sort', width: 80, title: '排序', edit: 'text'},
  21. {field: 'title', minWidth: 80, title: '权限名称'},
  22. {field: 'remark', minWidth: 80, title: '备注信息'},
  23. {field: 'status', title: '状态', width: 85, search: 'select', selectList: {0: '禁用', 1: '启用'}, templet: ea.table.switch},
  24. {field: 'create_time', minWidth: 80, title: '创建时间', search: 'range'},
  25. {
  26. width: 250,
  27. title: '操作',
  28. templet: ea.table.tool,
  29. operat: [
  30. 'edit',
  31. [{
  32. text: '授权',
  33. url: init.authorize_url,
  34. method: 'open',
  35. auth: 'authorize',
  36. class: 'layui-btn layui-btn-normal layui-btn-xs',
  37. }],
  38. 'delete'
  39. ]
  40. }
  41. ]],
  42. });
  43. ea.listen();
  44. },
  45. add: function () {
  46. ea.listen();
  47. },
  48. edit: function () {
  49. ea.listen();
  50. },
  51. authorize: function () {
  52. var tree = layui.tree;
  53. ea.request.get(
  54. {
  55. url: window.location.href,
  56. }, function (res) {
  57. res.data = res.data || [];
  58. tree.render({
  59. elem: '#node_ids',
  60. data: res.data,
  61. showCheckbox: true,
  62. id: 'nodeDataId',
  63. });
  64. }
  65. );
  66. ea.listen(function (data) {
  67. var checkedData = tree.getChecked('nodeDataId');
  68. var ids = [];
  69. $.each(checkedData, function (i, v) {
  70. ids.push(v.id);
  71. if (v.children !== undefined && v.children.length > 0) {
  72. $.each(v.children, function (ii, vv) {
  73. ids.push(vv.id);
  74. });
  75. }
  76. });
  77. data.node = JSON.stringify(ids);
  78. return data;
  79. });
  80. }
  81. };
  82. return Controller;
  83. });