index.jsp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <%@ page contentType="text/html; charset=utf-8"%>
  2. <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
  3. <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
  4. <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
  5. <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
  6. <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
  7. <%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
  8. <c:set var="basePath" value="${pageContext.request.contextPath}"/>
  9. <!DOCTYPE HTML>
  10. <html lang="zh-cn">
  11. <head>
  12. <meta charset="utf-8">
  13. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  14. <meta name="viewport" content="width=device-width, initial-scale=1">
  15. <title>用户管理</title>
  16. <link href="${basePath}/resources/zheng-ui/plugins/bootstrap-3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
  17. <link href="${basePath}/resources/zheng-ui/plugins/material-design-iconic-font-2.2.0/css/material-design-iconic-font.min.css" rel="stylesheet"/>
  18. <link href="${basePath}/resources/zheng-ui/plugins/bootstrap-table-1.11.0/bootstrap-table.min.css" rel="stylesheet"/>
  19. <link href="${basePath}/resources/zheng-ui/plugins/waves-0.7.5/waves.min.css" rel="stylesheet"/>
  20. <link href="${basePath}/resources/zheng-ui/plugins/jquery-confirm/jquery-confirm.min.css" rel="stylesheet"/>
  21. <link href="${basePath}/resources/zheng-ui/css/common.css" rel="stylesheet"/>
  22. </head>
  23. <body>
  24. <div id="main">
  25. <div id="toolbar">
  26. <shiro:hasPermission name="upms:user:create"><a class="waves-effect waves-button" href="javascript:;" onclick="createAction()"><i class="zmdi zmdi-plus"></i> 新增用户</a></shiro:hasPermission>
  27. <shiro:hasPermission name="upms:user:update"><a class="waves-effect waves-button" href="javascript:;" onclick="updateAction()"><i class="zmdi zmdi-edit"></i> 编辑用户</a></shiro:hasPermission>
  28. <shiro:hasPermission name="upms:user:delete"><a class="waves-effect waves-button" href="javascript:;" onclick="deleteAction()"><i class="zmdi zmdi-close"></i> 删除用户</a></shiro:hasPermission>
  29. </div>
  30. <table id="table"></table>
  31. </div>
  32. <!-- 新增 -->
  33. <div id="createDialog" class="crudDialog" hidden>
  34. <form>
  35. <div class="form-group">
  36. <label for="input1">帐号</label>
  37. <input id="input1" type="text" class="form-control">
  38. </div>
  39. <div class="form-group">
  40. <label for="input2">姓名</label>
  41. <input id="input2" type="text" class="form-control">
  42. </div>
  43. <div class="form-group">
  44. <label for="input3">头像</label>
  45. <input id="input3" type="text" class="form-control">
  46. </div>
  47. <div class="form-group">
  48. <label for="input4">电话</label>
  49. <input id="input4" type="text" class="form-control">
  50. </div>
  51. <div class="form-group">
  52. <label for="input5">邮箱</label>
  53. <input id="input5" type="text" class="form-control">
  54. </div>
  55. <div class="form-group">
  56. <label for="input6">性别</label>
  57. <input id="input6" type="text" class="form-control">
  58. </div>
  59. </form>
  60. </div>
  61. <script src="${basePath}/resources/zheng-ui/plugins/jquery.1.12.4.min.js"></script>
  62. <script src="${basePath}/resources/zheng-ui/plugins/bootstrap-3.3.0/js/bootstrap.min.js"></script>
  63. <script src="${basePath}/resources/zheng-ui/plugins/bootstrap-table-1.11.0/bootstrap-table.min.js"></script>
  64. <script src="${basePath}/resources/zheng-ui/plugins/bootstrap-table-1.11.0/locale/bootstrap-table-zh-CN.min.js"></script>
  65. <script src="${basePath}/resources/zheng-ui/plugins/waves-0.7.5/waves.min.js"></script>
  66. <script src="${basePath}/resources/zheng-ui/plugins/jquery-confirm/jquery-confirm.min.js"></script>
  67. <script src="${basePath}/resources/zheng-ui/js/common.js"></script>
  68. <script>
  69. var $table = $('#table');
  70. $(function() {
  71. $(document).on('focus', 'input[type="text"]', function() {
  72. $(this).parent().find('label').addClass('active');
  73. }).on('blur', 'input[type="text"]', function() {
  74. if ($(this).val() == '') {
  75. $(this).parent().find('label').removeClass('active');
  76. }
  77. });
  78. // bootstrap table初始化
  79. $table.bootstrapTable({
  80. url: '${basePath}/manage/user/list',
  81. height: getHeight(),
  82. striped: true,
  83. search: true,
  84. showRefresh: true,
  85. showColumns: true,
  86. minimumCountColumns: 2,
  87. clickToSelect: true,
  88. detailView: true,
  89. detailFormatter: 'detailFormatter',
  90. pagination: true,
  91. paginationLoop: false,
  92. sidePagination: 'server',
  93. silentSort: false,
  94. smartDisplay: false,
  95. escape: true,
  96. searchOnEnterKey: true,
  97. idField: 'userId',
  98. maintainSelected: true,
  99. toolbar: '#toolbar',
  100. columns: [
  101. {field: 'state', checkbox: true},
  102. {field: 'userId', title: '编号', sortable: true, align: 'center'},
  103. {field: 'username', title: '帐号'},
  104. {field: 'realname', title: '姓名'},
  105. {field: 'avatar', title: '头像', align: 'center', formatter: 'avatarFormatter'},
  106. {field: 'phone', title: '电话'},
  107. {field: 'email', title: '邮箱'},
  108. {field: 'sex', title: '性别', formatter: 'sexFormatter'},
  109. {field: 'locked', title: '状态', sortable: true, align: 'center', formatter: 'statusFormatter'},
  110. {field: 'action', title: '操作', align: 'center', formatter: 'actionFormatter', events: 'actionEvents', clickToSelect: false}
  111. ]
  112. }).on('all.bs.table', function (e, name, args) {
  113. $('[data-toggle="tooltip"]').tooltip();
  114. $('[data-toggle="popover"]').popover();
  115. });
  116. });
  117. // 格式化操作按钮
  118. function actionFormatter(value, row, index) {
  119. return [
  120. '<a class="update" href="javascript:;" onclick="updateAction()" data-toggle="tooltip" title="Edit"><i class="glyphicon glyphicon-edit"></i></a> ',
  121. '<a class="delete" href="javascript:;" onclick="deleteAction()" data-toggle="tooltip" title="Remove"><i class="glyphicon glyphicon-remove"></i></a>'
  122. ].join('');
  123. }
  124. // 格式化图标
  125. function avatarFormatter(value, row, index) {
  126. return '<img src="${basePath}' + value + '" style="width:20px;height:20px;"/>';
  127. }
  128. // 格式化性别
  129. function sexFormatter(value, row, index) {
  130. if (value == 1) {
  131. return '男';
  132. }
  133. if (value == 2) {
  134. return '女';
  135. }
  136. return '-';
  137. }
  138. // 格式化状态
  139. function statusFormatter(value, row, index) {
  140. if (value == 1) {
  141. return '<span class="label label-danger">锁定</span>';
  142. } else {
  143. return '<span class="label label-success">正常</span>';
  144. }
  145. }
  146. // 新增
  147. function createAction() {
  148. $.confirm({
  149. type: 'dark',
  150. animationSpeed: 300,
  151. title: '新增用户',
  152. content: $('#createDialog').html(),
  153. buttons: {
  154. confirm: {
  155. text: '确认',
  156. btnClass: 'waves-effect waves-button',
  157. action: function () {
  158. $.alert('确认');
  159. }
  160. },
  161. cancel: {
  162. text: '取消',
  163. btnClass: 'waves-effect waves-button'
  164. }
  165. }
  166. });
  167. }
  168. // 编辑
  169. function updateAction() {
  170. var rows = $table.bootstrapTable('getSelections');
  171. if (rows.length == 0) {
  172. $.confirm({
  173. title: false,
  174. content: '请至少选择一条记录!',
  175. autoClose: 'cancel|3000',
  176. backgroundDismiss: true,
  177. buttons: {
  178. cancel: {
  179. text: '取消',
  180. btnClass: 'waves-effect waves-button'
  181. }
  182. }
  183. });
  184. } else {
  185. $.confirm({
  186. type: 'blue',
  187. animationSpeed: 300,
  188. title: '编辑用户',
  189. content: $('#createDialog').html(),
  190. buttons: {
  191. confirm: {
  192. text: '确认',
  193. btnClass: 'waves-effect waves-button',
  194. action: function () {
  195. $.alert('确认');
  196. }
  197. },
  198. cancel: {
  199. text: '取消',
  200. btnClass: 'waves-effect waves-button'
  201. }
  202. }
  203. });
  204. }
  205. }
  206. // 删除
  207. function deleteAction() {
  208. var rows = $table.bootstrapTable('getSelections');
  209. if (rows.length == 0) {
  210. $.confirm({
  211. title: false,
  212. content: '请至少选择一条记录!',
  213. autoClose: 'cancel|3000',
  214. backgroundDismiss: true,
  215. buttons: {
  216. cancel: {
  217. text: '取消',
  218. btnClass: 'waves-effect waves-button'
  219. }
  220. }
  221. });
  222. } else {
  223. $.confirm({
  224. type: 'red',
  225. animationSpeed: 300,
  226. title: false,
  227. content: '确认删除该用户吗?',
  228. buttons: {
  229. confirm: {
  230. text: '确认',
  231. btnClass: 'waves-effect waves-button',
  232. action: function () {
  233. var ids = new Array();
  234. for (var i in rows) {
  235. ids.push(rows[i].userId);
  236. }
  237. $.alert('删除:id=' + ids.join("-"));
  238. }
  239. },
  240. cancel: {
  241. text: '取消',
  242. btnClass: 'waves-effect waves-button'
  243. }
  244. }
  245. });
  246. }
  247. }
  248. </script>
  249. </body>
  250. </html>