useradmin.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /**
  2. @Name:layuiAdmin 用户管理 管理员管理 角色管理
  3. @Author:star1029
  4. @Site:http://www.layui.com/admin/
  5. @License:LPPL
  6. */
  7. layui.define(['table', 'form'], function(exports){
  8. var $ = layui.$
  9. ,table = layui.table
  10. ,form = layui.form;
  11. //用户管理
  12. table.render({
  13. elem: '#LAY-user-manage'
  14. ,url: layui.setter.base + 'json/useradmin/webuser.js' //模拟接口
  15. ,cols: [[
  16. {type: 'checkbox', fixed: 'left'}
  17. ,{field: 'id', width: 100, title: 'ID', sort: true}
  18. ,{field: 'username', title: '用户名', minWidth: 100}
  19. ,{field: 'avatar', title: '头像', width: 100, templet: '#imgTpl'}
  20. ,{field: 'phone', title: '手机'}
  21. ,{field: 'email', title: '邮箱'}
  22. ,{field: 'sex', width: 80, title: '性别'}
  23. ,{field: 'ip', title: 'IP'}
  24. ,{field: 'jointime', title: '加入时间', sort: true}
  25. ,{title: '操作', width: 150, align:'center', fixed: 'right', toolbar: '#table-useradmin-webuser'}
  26. ]]
  27. ,page: true
  28. ,limit: 30
  29. ,height: 'full-220'
  30. ,text: '对不起,加载出现异常!'
  31. });
  32. //监听工具条
  33. table.on('tool(LAY-user-manage)', function(obj){
  34. var data = obj.data;
  35. if(obj.event === 'del'){
  36. layer.prompt({
  37. formType: 1
  38. ,title: '敏感操作,请验证口令'
  39. }, function(value, index){
  40. layer.close(index);
  41. layer.confirm('真的删除行么', function(index){
  42. obj.del();
  43. layer.close(index);
  44. });
  45. });
  46. } else if(obj.event === 'edit'){
  47. var tr = $(obj.tr);
  48. layer.open({
  49. type: 2
  50. ,title: '编辑用户'
  51. ,content: '../../../views/user/user/userform.html'
  52. ,maxmin: true
  53. ,area: ['500px', '450px']
  54. ,btn: ['确定', '取消']
  55. ,yes: function(index, layero){
  56. var iframeWindow = window['layui-layer-iframe'+ index]
  57. ,submitID = 'LAY-user-front-submit'
  58. ,submit = layero.find('iframe').contents().find('#'+ submitID);
  59. //监听提交
  60. iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
  61. var field = data.field; //获取提交的字段
  62. //提交 Ajax 成功后,静态更新表格中的数据
  63. //$.ajax({});
  64. table.reload('LAY-user-front-submit'); //数据刷新
  65. layer.close(index); //关闭弹层
  66. });
  67. submit.trigger('click');
  68. }
  69. ,success: function(layero, index){
  70. }
  71. });
  72. }
  73. });
  74. //管理员管理
  75. table.render({
  76. elem: '#LAY-user-back-manage'
  77. ,url: layui.setter.base + 'json/useradmin/mangadmin.js' //模拟接口
  78. ,cols: [[
  79. {type: 'checkbox', fixed: 'left'}
  80. ,{field: 'id', width: 80, title: 'ID', sort: true}
  81. ,{field: 'loginname', title: '登录名'}
  82. ,{field: 'telphone', title: '手机'}
  83. ,{field: 'email', title: '邮箱'}
  84. ,{field: 'role', title: '角色'}
  85. ,{field: 'jointime', title: '加入时间', sort: true}
  86. ,{field: 'check', title:'审核状态', templet: '#buttonTpl', minWidth: 80, align: 'center'}
  87. ,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-useradmin-admin'}
  88. ]]
  89. ,text: '对不起,加载出现异常!'
  90. });
  91. //监听工具条
  92. table.on('tool(LAY-user-back-manage)', function(obj){
  93. var data = obj.data;
  94. if(obj.event === 'del'){
  95. layer.prompt({
  96. formType: 1
  97. ,title: '敏感操作,请验证口令'
  98. }, function(value, index){
  99. layer.close(index);
  100. layer.confirm('确定删除此管理员?', function(index){
  101. console.log(obj)
  102. obj.del();
  103. layer.close(index);
  104. });
  105. });
  106. }else if(obj.event === 'edit'){
  107. var tr = $(obj.tr);
  108. layer.open({
  109. type: 2
  110. ,title: '编辑管理员'
  111. ,content: '../../../views/user/administrators/adminform.html'
  112. ,area: ['420px', '420px']
  113. ,btn: ['确定', '取消']
  114. ,yes: function(index, layero){
  115. var iframeWindow = window['layui-layer-iframe'+ index]
  116. ,submitID = 'LAY-user-back-submit'
  117. ,submit = layero.find('iframe').contents().find('#'+ submitID);
  118. //监听提交
  119. iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
  120. var field = data.field; //获取提交的字段
  121. //提交 Ajax 成功后,静态更新表格中的数据
  122. //$.ajax({});
  123. table.reload('LAY-user-front-submit'); //数据刷新
  124. layer.close(index); //关闭弹层
  125. });
  126. submit.trigger('click');
  127. }
  128. ,success: function(layero, index){
  129. }
  130. })
  131. }
  132. });
  133. //角色管理
  134. table.render({
  135. elem: '#LAY-user-back-role'
  136. ,url: layui.setter.base + 'json/useradmin/role.js' //模拟接口
  137. ,cols: [[
  138. {type: 'checkbox', fixed: 'left'}
  139. ,{field: 'id', width: 80, title: 'ID', sort: true}
  140. ,{field: 'rolename', title: '角色名'}
  141. ,{field: 'limits', title: '拥有权限'}
  142. ,{field: 'descr', title: '具体描述'}
  143. ,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-useradmin-admin'}
  144. ]]
  145. ,text: '对不起,加载出现异常!'
  146. });
  147. //监听工具条
  148. table.on('tool(LAY-user-back-role)', function(obj){
  149. var data = obj.data;
  150. if(obj.event === 'del'){
  151. layer.confirm('确定删除此角色?', function(index){
  152. obj.del();
  153. layer.close(index);
  154. });
  155. }else if(obj.event === 'edit'){
  156. var tr = $(obj.tr);
  157. layer.open({
  158. type: 2
  159. ,title: '编辑角色'
  160. ,content: '../../../views/user/administrators/roleform.html'
  161. ,area: ['500px', '480px']
  162. ,btn: ['确定', '取消']
  163. ,yes: function(index, layero){
  164. var iframeWindow = window['layui-layer-iframe'+ index]
  165. ,submit = layero.find('iframe').contents().find("#LAY-user-role-submit");
  166. //监听提交
  167. iframeWindow.layui.form.on('submit(LAY-user-role-submit)', function(data){
  168. var field = data.field; //获取提交的字段
  169. //提交 Ajax 成功后,静态更新表格中的数据
  170. //$.ajax({});
  171. table.reload('LAY-user-back-role'); //数据刷新
  172. layer.close(index); //关闭弹层
  173. });
  174. submit.trigger('click');
  175. }
  176. ,success: function(layero, index){
  177. }
  178. })
  179. }
  180. });
  181. exports('useradmin', {})
  182. });