auth.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. return {
  14. index: function () {
  15. ea.table.render({
  16. init: init,
  17. cols: [[
  18. {type: "checkbox"},
  19. {field: 'id', width: 80, title: 'ID', searchOp: '='},
  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. let setting = {
  53. check: {
  54. enable: true,
  55. chkStyle: "checkbox",
  56. },
  57. view: {
  58. showIcon: true,
  59. showLine: true,
  60. selectedMulti: false,
  61. dblClickExpand: false
  62. }, callback: {
  63. onClick: function (e, treeId, treeNode, clickFlag) {
  64. treeObj.checkNode(treeNode, !treeNode.checked, true);
  65. }
  66. }
  67. };
  68. let treeObj
  69. let treeData = []
  70. ea.request.get({url: window.location.href}, function (res) {
  71. res.data = res.data || [];
  72. $.each(res.data, function (index, value) {
  73. treeData[index] = []
  74. treeData[index].id = value.id
  75. treeData[index].name = value.title
  76. treeData[index].pId = 0
  77. treeData[index].open = true
  78. let children = value.children
  79. treeData[index]['children'] = []
  80. $.each(children, function (idx, val) {
  81. treeData[index]['children'].push({id: val.id, name: val.title, checked: val.checked, pId: value.id})
  82. })
  83. })
  84. $.fn.zTree.init($("#tree"), setting, treeData);
  85. treeObj = $.fn.zTree.getZTreeObj("tree");
  86. }
  87. );
  88. ea.listen(function (data) {
  89. let checkedData = treeObj.getCheckedNodes();
  90. let ids = []
  91. for (var i = 0; i < checkedData.length; i++) {
  92. ids.push(checkedData[i].id)
  93. }
  94. data.node = JSON.stringify(ids);
  95. return data;
  96. });
  97. }
  98. }
  99. }
  100. )