index.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. {extend name="common/base"/}
  2. <!-- 主体 -->
  3. {block name="body"}
  4. <div class="p-3">
  5. <table class="layui-hide" id="admin" lay-filter="admin"></table>
  6. </div>
  7. <script type="text/html" id="thumb">
  8. <img src="{{d.thumb}}" width="30" height="30" />
  9. </script>
  10. <script type="text/html" id="status">
  11. <i class="layui-icon {{# if(d.status == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
  12. </script>
  13. <script type="text/html" id="toolbarDemo">
  14. <div class="layui-btn-container">
  15. <span class="layui-btn layui-btn-sm add-user">+ 添加关联账号</span>
  16. </div>
  17. </script>
  18. <script type="text/html" id="barDemo">
  19. <div class="layui-btn-group">
  20. <span class="layui-btn layui-btn-xs layui-btn-normal" lay-event="view">详情</span>
  21. <span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</span>
  22. </div>
  23. </script>
  24. {/block}
  25. <!-- /主体 -->
  26. <!-- 脚本 -->
  27. {block name="script"}
  28. <script>
  29. const moduleInit = ['tool'];
  30. function gouguInit() {
  31. var table = layui.table, tool = layui.tool, form = layui.form;
  32. var allcount;
  33. layui.pageTable = table.render({
  34. elem: '#admin',
  35. title: '管理员列表',
  36. toolbar: '#toolbarDemo',
  37. url: '/acctconnect/connect/index', //数据接口
  38. page: true, //开启分页
  39. limit: 20,
  40. parseData: function(res) { // 数据解析回调函数
  41. // 在这里可以获取数据总数
  42. allcount = res.count;
  43. return {
  44. code: res.code, // 数据状态码
  45. msg: res.msg, // 状态信息
  46. count: res.count, // 数据总数
  47. data: res.data // 当前页数据
  48. };
  49. },
  50. cols: [
  51. [
  52. {fixed: 'left', field: 'id', title: '编号', align: 'center', width: 80,
  53. templet: function(d){
  54. return allcount - (d.LAY_NUM-1);
  55. }
  56. },
  57. {
  58. field: 'username',
  59. title: '登录账号',
  60. width: 120,
  61. templet:function(d){
  62. var html = "";
  63. html = '<a class="side-a" lay-event="read">' + d.username + '</a>';
  64. return '<div style="text-align:left">' + html + '</div>'
  65. }
  66. },
  67. {
  68. field: 'thumb',
  69. title: '头像',
  70. toolbar: '#thumb',
  71. align: 'center',
  72. width: 60
  73. },
  74. {
  75. field: 'nickname',
  76. title: '用户名',
  77. width: 120
  78. },
  79. {
  80. field: 'groupName',
  81. title: '权限角色'
  82. },
  83. {
  84. field: 'department_title',
  85. title: '所属单位',
  86. width: 200
  87. },
  88. {
  89. field: 'login_num',
  90. title: '累计登录',
  91. align: 'center',
  92. width: 80
  93. },
  94. {
  95. field: 'last_login_time',
  96. title: '最后登录时间',
  97. align: 'center',
  98. width: 142
  99. },
  100. {
  101. field: 'last_login_ip',
  102. title: '最后登录IP',
  103. width: 130
  104. },
  105. {
  106. field: 'status',
  107. title: '状态',
  108. toolbar: '#status',
  109. align: 'center',
  110. width: 60
  111. },
  112. {
  113. field: 'right',
  114. fixed: 'right',
  115. title: '操作',
  116. toolbar: '#barDemo',
  117. width: 132,
  118. align: 'center'
  119. }
  120. ]
  121. ]
  122. });
  123. //表头工具栏事件
  124. $('body').on('click','.add-user', function () {
  125. tool.side("/acctconnect/connect/add");
  126. return;
  127. });
  128. //监听行工具事件
  129. table.on('tool(admin)', function (obj) {
  130. var data = obj.data;
  131. if (obj.event === 'view') {
  132. tool.side('/acctconnect/connect/view?id='+data.id);
  133. return;
  134. }else if(obj.event === 'read'){
  135. layer.confirm('您确定要切换到该账户吗?',{
  136. icon: 3,
  137. title: '提示'
  138. }, function(index){
  139. $.ajax({
  140. url: "/acctconnect/connect/switchLogin?id=" + data.id,
  141. data: $('#gougu-login').serialize(),
  142. type: 'post',
  143. async: false,
  144. success: function (res) {
  145. layer.tips(res.msg, '#login-submit');
  146. if (res.code === 0) {
  147. setTimeout(function () {
  148. // parent.document.location.reload();
  149. parent.document.location.href = "{:url('/admin/index')}";
  150. }, 1500);
  151. } else {
  152. $('[alt="captcha"]').click();
  153. }
  154. }
  155. })
  156. layer.close(index);
  157. });
  158. }else if (obj.event === 'del') {
  159. layer.confirm('您确定要删除该账户', {
  160. icon: 3,
  161. title: '提示'
  162. }, function (index) {
  163. let callback = function (e) {
  164. layer.msg(e.msg);
  165. if (e.code == 0) {
  166. obj.del();
  167. }
  168. }
  169. tool.delete("/acctconnect/connect/delete", { id: data.id }, callback);
  170. layer.close(index);
  171. });
  172. }
  173. });
  174. //监听搜索提交
  175. form.on('submit(webform)', function (data) {
  176. layui.pageTable.reload({
  177. where: {
  178. keywords: data.field.keywords
  179. },
  180. page: {
  181. curr: 1
  182. }
  183. });
  184. return false;
  185. });
  186. }
  187. </script>
  188. {/block}
  189. <!-- /脚本 -->