users_list.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. layui.use(['table', 'jquery', 'madmin', 'mhttp', 'layer', 'form', 'common'], function () {
  2. let table = layui.table;
  3. let $ = layui.jquery;
  4. let admin = layui.madmin;
  5. let layer = layui.layer;
  6. let form = layui.form;
  7. let common = layui.common;
  8. let mhttp = layui.mhttp;
  9. admin.getConfig();
  10. //搜索条件
  11. let username = GetQueryString('username') ?? null;
  12. let nick = GetQueryString('nick') ?? null;
  13. $('.username').val(username);
  14. $('.nick').val(nick);
  15. let cols = [
  16. [
  17. {
  18. title: 'UID',
  19. field: 'manager_uid',
  20. align: 'center'
  21. },
  22. {
  23. title: '昵称',
  24. field: 'nick',
  25. align: 'center'
  26. },
  27. {
  28. title: '账号',
  29. field: 'username',
  30. align: 'center'
  31. },
  32. {
  33. title: '最近登录时间',
  34. field: 'login_at',
  35. align: 'center'
  36. },
  37. {
  38. title: '更新时间',
  39. field: 'updated_at',
  40. align: 'center'
  41. },
  42. {
  43. title: '操作',
  44. toolbar: '#users-bar',
  45. align: 'center'
  46. }
  47. ]
  48. ]
  49. let search = httpRequestPostData({
  50. username: username,
  51. nick: nick,
  52. });
  53. table.render({
  54. elem: '#users-table',
  55. method: 'POST',
  56. request: {
  57. pageName: 'page',
  58. limitName: 'page_size'
  59. },
  60. async: false,
  61. headers: {
  62. "AUTH-TOKEN": localStorage.getItem('XSRF-TOKEN') ?? ''
  63. },
  64. contentType: 'application/json',
  65. where: search,
  66. url: getMyApiUrl('/manager/lists'),
  67. limit: 20,
  68. limits: [20, 30, 40, 50, 80, 100],
  69. parseData: function (res) {
  70. return httpRequestPagesParseData(res);
  71. },
  72. response: {
  73. "statusCode": 200,
  74. },
  75. done: function (data, page, total) {
  76. var intCode = parseInt(data.code);
  77. if (intCode === 403) {
  78. cbRespnseRedirectLogin(data);
  79. } else if (intCode === 401) {
  80. // 仅仅是过期了,这里可以有其他逻辑补偿.
  81. // 暂时跳到登陆页面
  82. cbRespnse401(data);
  83. }
  84. onloadRender();
  85. },
  86. error: function (obj, message) {
  87. cbRespnseReloadPage(obj, message);
  88. },
  89. page: true,
  90. cols: cols,
  91. skin: 'line',
  92. toolbar: '#users-toolbar',
  93. defaultToolbar: [{
  94. title: '刷新',
  95. layEvent: 'refresh',
  96. icon: 'layui-icon-refresh',
  97. }, 'filter', 'print', 'exports']
  98. });
  99. table.on('toolbar(users-table)', function (obj) {
  100. if (obj.event === 'add') {
  101. window.add();
  102. } else if (obj.event === 'refresh') {
  103. window.refresh();
  104. } else if (obj.event === 'batchRemove') {
  105. window.batchRemove(obj);
  106. }
  107. });
  108. window.add = function () {
  109. layer.open({
  110. id: 'users_create',
  111. type: 2,
  112. title: '添加',
  113. shade: 0.1,
  114. offset: '80px',
  115. area: ['450px', '400px'],
  116. maxWidth: 500,
  117. maxHeight: 500,
  118. scrollbar: true,
  119. content: 'users_create.html',
  120. });
  121. }
  122. // 表单内
  123. table.on('tool(users-table)', function (obj) {
  124. if (obj.event === 'remove') {
  125. window.remove(obj);
  126. } else if (obj.event === 'edit') {
  127. window.edit(obj);
  128. }
  129. });
  130. window.edit = function (obj) {
  131. layer.open({
  132. id: 'users-edit',
  133. type: 2,
  134. title: '修改',
  135. shade: 0.1,
  136. offset: '80px',
  137. area: ['450px', '450px'],
  138. maxWidth: 500,
  139. maxHeight: 500,
  140. scrollbar: true,
  141. content: 'users_edit.html?manager_uid=' + obj.data.manager_uid,
  142. });
  143. }
  144. // 删除
  145. window.remove = function (obj) {
  146. layer.confirm('确定要删除 ID 为:' + obj.data.manager_uid + ' 标签?', {
  147. icon: 3,
  148. title: '提示'
  149. }, function () {
  150. let deleteLoading = layer.msg('操作数据中...', {icon: 16, time: 0, shade: 0.3, shadeClose: false});
  151. let postData = {
  152. manager_uid: obj.data.manager_uid
  153. };
  154. let ret = mhttp.ajax({
  155. url: '/manager/delete',
  156. data: postData,
  157. });
  158. ret.then((data) => {
  159. layer.close(deleteLoading);
  160. if (data.code === 200) {
  161. layer.msg(data.message, {icon: 1, time: 1000});
  162. obj.del();
  163. } else {
  164. layer.msg(data.message, {icon: 2, time: 1000});
  165. }
  166. });
  167. });
  168. }
  169. window.refresh = function (param) {
  170. table.reload('users-table');
  171. }
  172. })