index.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. {extend name="common/base" /}
  2. <!-- 主体 -->
  3. {block name="body"}
  4. <div class="p-3">
  5. <form class="layui-form gg-form-bar border-t border-x">
  6. <div class="layui-input-inline" style="width:300px;">
  7. <input type="text" name="keywords" placeholder="名称/备注" class="layui-input" autocomplete="off" />
  8. </div>
  9. <div class="layui-input-inline">
  10. <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">提交搜索</button>
  11. </div>
  12. </form>
  13. <table class="layui-hide" id="role" lay-filter="role"></table>
  14. </div>
  15. <script type="text/html" id="status">
  16. <i class="layui-icon {{# if(d.status == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
  17. </script>
  18. <script type="text/html" id="toolbarDemo">
  19. <div class="layui-btn-container">
  20. <button class="layui-btn layui-btn-sm" lay-event="add">+ 添加权限组</button>
  21. </div>
  22. </script>
  23. {/block}
  24. <!-- /主体 -->
  25. <!-- 脚本 -->
  26. {block name="script"}
  27. <script>
  28. const moduleInit = ['tool'];
  29. function gouguInit() {
  30. var table = layui.table, tool = layui.tool, form = layui.form;
  31. var allcount;
  32. layui.pageTable = table.render({
  33. elem: '#role',
  34. toolbar: '#toolbarDemo',
  35. url: "/admin/role/index", //数据接口
  36. page: true, //开启分页
  37. limit: 20,
  38. parseData: function(res) { // 数据解析回调函数
  39. // 在这里可以获取数据总数
  40. allcount = res.count;
  41. return {
  42. code: res.code, // 数据状态码
  43. msg: res.msg, // 状态信息
  44. count: res.count, // 数据总数
  45. data: res.data // 当前页数据
  46. };
  47. },
  48. cols: [[ //表头
  49. {
  50. fixed: 'left', field: 'id', title: '编号', align: 'center', width: 80,
  51. templet: function(d){
  52. return allcount - (d.LAY_NUM-1);
  53. }
  54. },
  55. { field: 'title', title: '权限组名称', width: 200 },
  56. { field: 'd_title', title: '所属单位', width: 200 },
  57. { field: 'desc', title: '备注' },
  58. {
  59. field: 'user', title: '使用用户' ,templet:function (admin) {
  60. // console.log(1);
  61. // console.log(admin);
  62. // console.log(1);
  63. var user = '';
  64. for(i = 0; i < admin.admin.length; i++){
  65. if(i < admin.admin.length - 1){
  66. user = user + admin.admin[i]['nickname'] + ',';
  67. console.log(user);
  68. continue;
  69. }
  70. user = user + admin.admin[i]['nickname'];
  71. }
  72. return '用户量:' + admin.admin.length + ';' + user;
  73. }
  74. },
  75. { field: 'status', title: '状态', toolbar: '#status', align: 'center', width: 80 },
  76. { field: 'operator', title: '操作员', align: 'center', width: 100 },
  77. { width: 100,title: '操作',align: 'center',templet: function (d) {
  78. var html = '<div class="layui-btn-group"><button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</button><button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button></div>';
  79. return html;
  80. }
  81. }
  82. ]]
  83. });
  84. //表头工具栏事件
  85. table.on('toolbar(role)', function(obj){
  86. if (obj.event === 'add') {
  87. tool.side("/admin/role/add");
  88. return;
  89. }
  90. });
  91. //监听行工具事件
  92. table.on('tool(role)', function (obj) {
  93. var data = obj.data;
  94. if (obj.event === 'edit') {
  95. tool.side('/admin/role/add?id='+obj.data.id);
  96. return;
  97. }
  98. if (obj.event === 'del') {
  99. layer.confirm('确定要删除该权限角色吗?', { icon: 3, title: '提示' }, function (index) {
  100. let callback = function (res) {
  101. layer.msg(res.msg);
  102. if (res.code == 0) {
  103. obj.del();
  104. }
  105. }
  106. tool.delete("/admin/role/delete", { id: obj.data.id }, callback);
  107. layer.close(index);
  108. });
  109. }
  110. });
  111. //监听搜索提交
  112. form.on('submit(webform)', function (data) {
  113. layui.pageTable.reload({
  114. where: { keywords: data.field.keywords },
  115. page: { curr: 1 }
  116. });
  117. return false;
  118. });
  119. }
  120. </script>
  121. {/block}
  122. <!-- /脚本 -->