role.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <title>角色管理</title>
  2. <div class="layui-card layadmin-header">
  3. <div class="layui-breadcrumb" lay-filter="breadcrumb">
  4. <a lay-href="">主页</a>
  5. <a><cite>用户</cite></a>
  6. <a><cite>角色管理</cite></a>
  7. </div>
  8. </div>
  9. <div class="layui-fluid">
  10. <div class="layui-card">
  11. <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-useradminrole-formlist">
  12. <div class="layui-form-item">
  13. <div class="layui-inline">
  14. 角色筛选
  15. </div>
  16. <div class="layui-inline">
  17. <!--<select name="rolename" lay-filter="LAY-user-adminrole-type">-->
  18. <select name="position" lay-filter="LAY-user-adminrole-type">
  19. <!--<option value="-1">全部角色</option>-->
  20. <!--<option value="0">管理员</option>-->
  21. <!--<option value="1">超级管理员</option>-->
  22. <!--<option value="2">纠错员</option>-->
  23. <!--<option value="3">采购员</option>-->
  24. <!--<option value="4">推销员</option>-->
  25. <!--<option value="5">运营人员</option>-->
  26. <!--<option value="6">编辑</option>-->
  27. </select>
  28. </div>
  29. </div>
  30. </div>
  31. <div class="layui-card-body">
  32. <div style="padding-bottom: 10px;">
  33. <button class="layui-btn layuiadmin-btn-role" data-type="batchdel">删除</button>
  34. <button class="layui-btn layuiadmin-btn-role" data-type="add">添加</button>
  35. <button class="layui-btn layuiadmin-btn-role" data-type="reset">重置密码</button>
  36. </div>
  37. <table id="LAY-user-back-role" lay-filter="LAY-user-back-role"></table>
  38. <script type="text/html" id="buttonTpl">
  39. {{# if(d.check == true){ }}
  40. <button class="layui-btn layui-btn-xs">已审核</button>
  41. {{# } else { }}
  42. <button class="layui-btn layui-btn-primary layui-btn-xs">未审核</button>
  43. {{# } }}
  44. </script>
  45. <script type="text/html" id="table-useradmin-admin">
  46. <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
  47. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
  48. </script>
  49. </div>
  50. </div>
  51. </div>
  52. <script>
  53. layui.use('useradmin', layui.factory('useradmin')).use(['admin', 'useradmin', 'table'], function(){
  54. var $ = layui.$
  55. ,admin = layui.admin
  56. ,view = layui.view
  57. ,table = layui.table
  58. ,form = layui.form;
  59. $.ajax({
  60. url:"/login/getPosition",
  61. success:function (res) {
  62. var data = res;
  63. $.each(data,function (index,item) {
  64. $('select').append('<option value="'+item.position+'">'+item.position+'</option>');
  65. })
  66. form.render(null, 'layadmin-useradminrole-formlist');
  67. }
  68. })
  69. // form.render(null, 'layadmin-useradminrole-formlist');
  70. //搜索角色
  71. form.on('select(LAY-user-adminrole-type)', function(data){
  72. //执行重载
  73. table.reload('LAY-user-back-role', {
  74. where: {
  75. // role: data.value
  76. position: data.value
  77. }
  78. });
  79. });
  80. //事件
  81. var active = {
  82. batchdel: function(){
  83. var checkStatus = table.checkStatus('LAY-user-back-role')
  84. ,checkData = checkStatus.data; //得到选中的数据
  85. if(checkData.length === 0){
  86. return layer.msg('请选择数据');
  87. }
  88. layer.confirm('确定删除吗?', function(index) {
  89. var id = [];
  90. var username = [];
  91. checkData.forEach(function (item) {
  92. id.push(item.id);
  93. username.push(item.username)
  94. })
  95. //执行 Ajax 后重载
  96. $.ajax({
  97. url: '/login/delUser',
  98. data:{"id":id,"username":username},
  99. type:'post',
  100. dataType:"json",
  101. traditional:true,
  102. success:function (res) {
  103. table.reload('LAY-user-back-role');
  104. layer.msg(res.msg);
  105. }
  106. });
  107. // table.reload('LAY-user-back-role');
  108. // layer.msg('已删除');
  109. });
  110. },
  111. add: function(){
  112. admin.popup({
  113. title: '添加新角色'
  114. ,area: ['500px', '480px']
  115. ,id: 'LAY-popup-user-add'
  116. ,success: function(layero, index){
  117. view(this.id).render('user/administrators/roleform').done(function(){
  118. form.render(null, 'layuiadmin-form-role');
  119. //监听提交
  120. form.on('submit(LAY-user-role-submit)', function(data){
  121. var field = data.field; //获取提交的字段
  122. // console.log(field)
  123. //提交 Ajax 成功后,关闭当前弹层并重载表格
  124. $.ajax({
  125. type:"POST",
  126. url:"/login/addUser",
  127. data:field,
  128. success:function (res) {
  129. if (res && res.code === 1){
  130. layer.msg(res.msg)
  131. }
  132. }
  133. });
  134. layui.table.reload('LAY-user-back-role'); //重载表格
  135. layer.close(index); //执行关闭
  136. });
  137. });
  138. }
  139. });
  140. },
  141. reset:function () {
  142. var checkStatus = table.checkStatus('LAY-user-back-role')
  143. ,checkData = checkStatus.data; //得到选中的数据
  144. if(checkData.length === 0){
  145. return layer.msg('请选择数据');
  146. }
  147. layer.confirm('确定重置吗?', function(index) {
  148. var id = [];
  149. checkData.forEach(function (item) {
  150. id.push(item.id);
  151. });
  152. //执行 Ajax 后重载
  153. $.ajax({
  154. url: '/login/resetPw',
  155. data:{"id":id},
  156. type:'post',
  157. dataType:"json",
  158. traditional:true,
  159. success:function (res) {
  160. table.reload('LAY-user-back-role');
  161. layer.msg(res.msg);
  162. }
  163. });
  164. });
  165. }
  166. }
  167. $('.layui-btn.layuiadmin-btn-role').on('click', function(){
  168. var type = $(this).data('type');
  169. active[type] ? active[type].call(this) : '';
  170. });
  171. });
  172. </script>