index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. ;
  2. layui.config({
  3. base: "../../js/layuiPlugins/"
  4. }).use(['form', 'layer', 'jquery', 'table', 'laytpl'], function () {
  5. var form = layui.form,
  6. layer = layui.layer,
  7. laytpl = layui.laytpl,
  8. $ = layui.jquery,
  9. table = layui.table;
  10. var funcName = "user";
  11. form.verify({
  12. namelength: [
  13. /^.{0,12}$/,
  14. "长度限制在0-12个字符噢"
  15. ]
  16. });
  17. //工具条处理
  18. function toolOperating(obj) {
  19. var data = obj.data;
  20. var userName = (obj.data.userName == '' || obj.data.userName == null) ? '匿名用户' : obj.data.userName;
  21. if (obj.event === 'del') {
  22. layer.confirm('真的删除用户“' + userName + '”吗?', function (index) {
  23. layer.close(index);
  24. var index1 = layer.msg('删除中,请稍候', {
  25. icon: 16,
  26. time: false,
  27. shade: 0.8
  28. });
  29. $.ajax({
  30. type: "get",
  31. url: 'delete_user?guid=' + obj.data.guid,
  32. success: function (res) {
  33. layer.close(index1);
  34. if (!(res.code - 0)) {
  35. obj.del();
  36. table.reload(funcName);
  37. }
  38. }
  39. });
  40. });
  41. } else if (obj.event === 'edit') { //修改
  42. layer.open({
  43. type: 2,
  44. anim: 0,
  45. title: "修改",
  46. area: ['800px', '470px'],
  47. fixed: true,
  48. scrollbar: true,
  49. maxmin: true,
  50. content: 'add_change.html?event=edit&guid=' + data.guid,
  51. end: function () {
  52. table.reload(funcName); //重新载入表格
  53. }
  54. });
  55. } else if (obj.event === 'view') { //查看
  56. layer.open({
  57. type: 2,
  58. anim: 0,
  59. title: "查看",
  60. area: ['800px', '470px'],
  61. fixed: true,
  62. scrollbar: true,
  63. maxmin: true,
  64. content: 'add_change.html?event=view&guid=' + data.guid,
  65. end: function () { }
  66. });
  67. } else if (obj.event === 'reset') {
  68. layer.confirm('真的重置“' + (obj.data.userName || '') + '”用户密码吗?', function (index) {
  69. layer.close(index);
  70. var index1 = layer.msg('重置中,请稍候', {
  71. icon: 16,
  72. time: false,
  73. shade: 0.8
  74. });
  75. $.ajax({
  76. type: "get",
  77. url: 'restPwd?guid=' + obj.data.guid,
  78. success: function (res) {
  79. layer.close(index1);
  80. layer.alert('密码已经重置为123123');
  81. }
  82. });
  83. });
  84. }
  85. }
  86. //列表
  87. var DataList = {
  88. id: funcName,
  89. elem: '#DataTable',
  90. url: funcName + 'List',
  91. page: true,
  92. method: "post",
  93. contentType: 'application/json',
  94. loading: true,
  95. cellMinWidth: 80,
  96. cols: [
  97. [ //标题栏
  98. {
  99. field: 'account',
  100. title: '账号',
  101. align: 'left',
  102. minWidth: 90
  103. }, {
  104. field: 'userName',
  105. title: '姓名',
  106. align: 'left',
  107. minWidth: 160
  108. }, {
  109. field: 'roleName',
  110. title: '角色',
  111. align: 'left',
  112. minWidth: 160
  113. }, {
  114. field: 'mobileNo',
  115. title: '电话号码',
  116. align: 'center',
  117. minWidth: 140
  118. }, {
  119. field: 'lastLoginTime',
  120. title: '最后登录时间',
  121. align: 'center',
  122. minWidth: 200
  123. }, {
  124. field: 'isForbid',
  125. title: '是否锁定',
  126. width: 110,
  127. templet: '#checkboxTpl',
  128. unresize: true,
  129. align: 'center',
  130. minWidth: 160
  131. }, {
  132. field: 'operating',
  133. title: '操作',
  134. toolbar: '#operatingTool',
  135. align: 'center',
  136. fixed: 'right',
  137. minWidth: 240
  138. }
  139. ]
  140. ] //设置表头
  141. ,
  142. done: function (res) {
  143. resetButton(layui.sessionData(window.hywa.sessionTable.tableName).userData.menus.subMenuList, $);
  144. //res.button.add ? $('.add-btn-0').show() : $('.add-btn-0').hide();
  145. }
  146. };
  147. //执行默认渲染表格
  148. table.render(DataList);
  149. //监听产品工具事件条
  150. table.on('tool(DataTable)', function (obj) {
  151. toolOperating(obj);
  152. });
  153. //搜索响应函数
  154. var infoSearch = function (obj) {
  155. table.reload(funcName, { //执行重载
  156. where: obj.field
  157. });
  158. return false;
  159. };
  160. //监听搜索表单事件
  161. form.on("submit(DataSearch)", infoSearch);
  162. //监听可用操作
  163. form.on('checkbox(statusDemo)', function (obj) {
  164. $.ajax({
  165. url: 'forbidUser?guid=' + obj.elem.id + '&isForbid=' + this.value,
  166. type: 'get',
  167. contentType: 'application/json',
  168. success: function (res) {
  169. if (!(res.code - 0)) {
  170. parent.layer.msg(res.msg, {
  171. icon: 1
  172. });
  173. table.reload(funcName);
  174. } else {
  175. layer.msg(res.msg, {
  176. icon: 2
  177. });
  178. obj.elem.checked = !obj.elem.checked;
  179. form.render();
  180. }
  181. }
  182. });
  183. });
  184. $("#addBtn").on("click", function () {
  185. layer.open({
  186. type: 2,
  187. anim: 0,
  188. title: "新增",
  189. area: ['800px', '470px'],
  190. fixed: true,
  191. scrollbar: true,
  192. maxmin: true,
  193. content: 'add_change.html',
  194. end: function () {
  195. table.reload(funcName);
  196. }
  197. });
  198. });
  199. //类型下拉列表模板
  200. function typeTpl(obj) {
  201. laytpl(typeHtmlTpl.innerHTML).render(obj, function (html) {
  202. $(obj.elem).html(html);
  203. form.render();
  204. });
  205. }
  206. $("#rolesView").next().click(function (e) {
  207. if ($(this).hasClass('layui-form-selected')) {
  208. $.ajax({
  209. url: 'roleList',
  210. method: 'post',
  211. contentType: "application/json",
  212. data: JSON.stringify({}),
  213. success: function (res) {
  214. typeTpl({
  215. elem: "#rolesView",
  216. list: res.data
  217. });
  218. form.render('select');
  219. }
  220. });
  221. }
  222. });
  223. });