main.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="keywords" content="">
  8. <meta name="description" content="">
  9. <title text="用户管理"></title>
  10. <link rel="stylesheet" href="../../../component/pear/css/pear.css" />
  11. <link rel="stylesheet" href="../../../admin/css/other/user.css" />
  12. </head>
  13. <body class="pear-container">
  14. <div class="layui-card">
  15. <div class="layui-card-body">
  16. <form class="layui-form">
  17. <div class="layui-form-item">
  18. <label class="layui-form-label">用户帐号</label>
  19. <div class="layui-input-inline">
  20. <input type="text" name="username" placeholder="" class="layui-input">
  21. </div>
  22. <label class="layui-form-label">用户姓名</label>
  23. <div class="layui-input-inline">
  24. <input type="text" name="realName" placeholder="" class="layui-input">
  25. </div>
  26. <button class="pear-btn pear-btn-md-0 pear-btn-primary" lay-submit lay-filter="query">
  27. <i class="layui-icon layui-icon-search"></i> 查询
  28. </button>
  29. <button type="reset" class="pear-btn pear-btn-md-0">
  30. <i class="layui-icon layui-icon-refresh"></i> 重置
  31. </button>
  32. </div>
  33. </form>
  34. </div>
  35. </div>
  36. <div class="layui-card">
  37. <div class="layui-card-body">
  38. <table id="table" lay-filter="table"></table>
  39. </div>
  40. </div>
  41. </body>
  42. <script type="text/html" id="toolbar">
  43. <div permission="sys:user:add">
  44. <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
  45. <i class="pear-icon pear-icon-add"></i> 新增
  46. </button>
  47. </div>
  48. </script>
  49. <script type="text/html" id="bar">
  50. <a class="cool-line-btn cool-bg-blue" lay-event="edit">编辑</a>
  51. <div class="cool-line-divider"></div>
  52. <a class="cool-line-btn cool-bg-blue" lay-event="remove">删除</a>
  53. </script>
  54. <script type="text/html" id="enableTpl">
  55. <input type="checkbox" name="enable" value="{{d.id}}" lay-skin="switch"
  56. lay-text="启用|禁用" lay-filter="switch" {{ (d.enable ? 'checked' : '') }} />
  57. </script>
  58. <script type="text/html" id="sexTpl">
  59. {{#if (d.sex == 0) { }}
  60. {{# } else if(d.sex == 1){ }}
  61. {{# } }}
  62. </script>
  63. <script type="text/html" id="createTimeTpl">
  64. {{layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss')}}
  65. </script>
  66. <script src="../../../component/layui/layui.js"></script>
  67. <script src="../../../component/pear/pear.js"></script>
  68. <script>
  69. layui.use(['request', 'table', 'form', 'popup', 'common'], function () {
  70. var request = layui.request,
  71. table = layui.table,
  72. form = layui.form,
  73. popup = layui.popup,
  74. common = layui.common;
  75. var MODULE_PATH = "/system/user/v1/";
  76. request.tableRender({
  77. url: MODULE_PATH,
  78. cols: [
  79. [
  80. {type: 'checkbox'},
  81. {title: '用户帐号', field: 'username', align: 'center'},
  82. {title: '用户姓名', field: 'realName', align: 'center'},
  83. {title: '性别', field: 'sex', align: 'center', templet: '#sexTpl'},
  84. {title: '联系电话', field: 'phone', align: 'center'},
  85. {title: '用户状态', field: 'enable', align: 'center',templet: '#enableTpl'},
  86. {title: '注册时间', field: 'createTime', align: 'center', templet: '#createTimeTpl'},
  87. {title: '操作', toolbar: '#bar', align: 'center', width: 130}
  88. ]
  89. ]
  90. });
  91. table.on('tool(table)', function (obj) {
  92. if (obj.event === 'edit') {
  93. f.edit(obj);
  94. }
  95. else if (obj.event === 'remove') {
  96. f.remove(obj.data.id);
  97. }
  98. });
  99. table.on('toolbar(table)', function (obj) {
  100. if (obj.event === 'add') {
  101. f.add();
  102. }
  103. else if (obj.event === 'removeBatch') {
  104. f.remove(common.checkField(obj,'id'));
  105. }
  106. });
  107. form.on('submit(query)', function (data) {
  108. refresh(data.field);
  109. return false;
  110. });
  111. form.on('switch(switch)', function (obj) {
  112. var params = {
  113. id: obj.value,
  114. enable: obj.elem.checked
  115. };
  116. request.http({
  117. type: 'put',
  118. url: MODULE_PATH + 'switch',
  119. data: params,
  120. loading: true,
  121. success: function (result) {
  122. refresh();
  123. if (result.success) {
  124. popup.success(result.msg);
  125. } else {
  126. popup.failure(result.msg);
  127. }
  128. }
  129. });
  130. });
  131. var f = {
  132. add: function() {
  133. layer.open({
  134. type: 2,
  135. title: '新增',
  136. shade: 0.1,
  137. area: ['480px', '500px'],
  138. content: ['add.html', 'no']
  139. });
  140. },
  141. edit: function(obj) {
  142. layer.open({
  143. type: 2,
  144. title: '编辑',
  145. shade: 0.1,
  146. area: ['480px', '500px'],
  147. content: ['add.html?id=' + obj.data.id, 'no']
  148. });
  149. },
  150. remove: function(ids) {
  151. if (ids === '' || ids === undefined) {
  152. layer.alert('请先选择删除数据!');
  153. return false;
  154. }
  155. layer.confirm("是否确认删除这些项?", function () {
  156. request.http({
  157. type: "delete",
  158. url: MODULE_PATH + ids,
  159. loading: true,
  160. success: function (result) {
  161. refresh();
  162. if (result.success) {
  163. popup.success(result.msg);
  164. } else {
  165. popup.failure(result.msg);
  166. }
  167. }
  168. })
  169. });
  170. }
  171. };
  172. window.refresh = function (param) {
  173. table.reload('table', {where: param});
  174. };
  175. })
  176. </script>
  177. </html>