admin.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. define(["jquery", "easy-admin"], function ($, ea) {
  2. var init = {
  3. table_elem: '#currentTable',
  4. table_render_id: 'currentTableRenderId',
  5. index_url: 'system.admin/index',
  6. add_url: 'system.admin/add',
  7. edit_url: 'system.admin/edit',
  8. delete_url: 'system.admin/delete',
  9. modify_url: 'system.admin/modify',
  10. export_url: 'system.admin/export',
  11. password_url: 'system.admin/password',
  12. };
  13. return {
  14. index: function () {
  15. let _table = 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: 'username', minWidth: 80, title: '登录账户'},
  22. {field: 'head_img', minWidth: 80, title: '头像', search: false, templet: ea.table.image},
  23. {field: 'phone', minWidth: 80, title: '手机'},
  24. {field: 'login_num', minWidth: 80, title: '登录次数'},
  25. {
  26. field: 'role', minWidth: 80, title: '角色权限', align: 'left', search: 'none', templet: function (d) {
  27. let auth_ids = d.auth_ids || []
  28. let html = ``
  29. $.each(auth_ids, (idx, item) =>
  30. html += `<span class="layui-badge">${auth_list[item] || '-'}</span> `
  31. )
  32. return html
  33. }
  34. },
  35. {field: 'remark', minWidth: 80, title: '备注信息'},
  36. {field: 'status', title: '状态', width: 85, search: 'select', selectList: {0: '禁用', 1: '启用'}, templet: ea.table.switch},
  37. {field: 'create_time', minWidth: 80, title: '创建时间', search: 'range'},
  38. {
  39. width: 250,
  40. title: '操作',
  41. templet: ea.table.tool,
  42. operat: [
  43. 'edit',
  44. [{
  45. text: '设置密码',
  46. url: init.password_url,
  47. method: 'open',
  48. auth: 'password',
  49. class: 'layui-btn layui-btn-normal layui-btn-xs',
  50. }],
  51. 'delete'
  52. ]
  53. }
  54. ]],
  55. });
  56. $('body').on('click', '[data-table-reset]', function () {
  57. $('.layui-menu li').removeClass('layui-menu-item-checked').animate(
  58. {}, 0, () => $('.layui-menu li:eq(0)').addClass('layui-menu-item-checked')
  59. )
  60. })
  61. layui.util.on({
  62. authSearch: function (e) {
  63. let auth_id = $(this).data('auth_id')
  64. $('.layui-menu li').removeClass('layui-menu-item-checked').animate(
  65. {}, 0, () => $(this).parents('li').addClass('layui-menu-item-checked')
  66. )
  67. let _where = auth_id ? {
  68. filter: JSON.stringify({auth_ids: auth_id}),
  69. op: JSON.stringify({auth_ids: 'find_in_set'})
  70. } : {}
  71. _table.reload({where: _where})
  72. },
  73. })
  74. ea.listen();
  75. },
  76. add: function () {
  77. ea.listen();
  78. },
  79. edit: function () {
  80. ea.listen();
  81. },
  82. password: function () {
  83. ea.listen();
  84. }
  85. };
  86. });