index.jsp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. <jsp:include page="/resources/inc/head.jsp" flush="true"/>
  17. </head>
  18. <body>
  19. <div id="main">
  20. <div id="toolbar">
  21. <shiro:hasPermission name="cms:menu:create"><a class="waves-effect waves-button" href="javascript:;" onclick="createAction()"><i class="zmdi zmdi-plus"></i> 新增菜单</a></shiro:hasPermission>
  22. <shiro:hasPermission name="cms:menu:update"><a class="waves-effect waves-button" href="javascript:;" onclick="updateAction()"><i class="zmdi zmdi-edit"></i> 编辑菜单</a></shiro:hasPermission>
  23. <shiro:hasPermission name="cms:menu:delete"><a class="waves-effect waves-button" href="javascript:;" onclick="deleteAction()"><i class="zmdi zmdi-close"></i> 删除菜单</a></shiro:hasPermission>
  24. <shiro:hasPermission name="cms:menu:up"><a class="waves-effect waves-button" href="javascript:;" onclick="upAction()"><i class="zmdi zmdi-long-arrow-up"></i> 上移菜单</a></shiro:hasPermission>
  25. <shiro:hasPermission name="cms:menu:down"><a class="waves-effect waves-button" href="javascript:;" onclick="downAction()"><i class="zmdi zmdi-long-arrow-down"></i> 下移菜单</a></shiro:hasPermission>
  26. </div>
  27. <table id="table"></table>
  28. </div>
  29. <jsp:include page="/resources/inc/footer.jsp" flush="true"/>
  30. <script>
  31. var $table = $('#table');
  32. $(function() {
  33. // bootstrap table初始化
  34. $table.bootstrapTable({
  35. url: '${basePath}/manage/menu/list',
  36. height: getHeight(),
  37. striped: true,
  38. search: true,
  39. showRefresh: true,
  40. showColumns: true,
  41. minimumCountColumns: 2,
  42. clickToSelect: true,
  43. detailView: true,
  44. detailFormatter: 'detailFormatter',
  45. pagination: true,
  46. paginationLoop: false,
  47. sidePagination: 'server',
  48. silentSort: false,
  49. smartDisplay: false,
  50. escape: true,
  51. searchOnEnterKey: true,
  52. idField: 'menuId',
  53. maintainSelected: true,
  54. toolbar: '#toolbar',
  55. columns: [
  56. {field: 'ck', checkbox: true},
  57. {field: 'menuId', title: '编号', sortable: true, align: 'center'},
  58. {field: 'pid', title: '父菜单'},
  59. {field: 'name', title: '名称'},
  60. {field: 'url', title: '链接'},
  61. {field: 'target', title: '打开方式', formatter: 'targetFormatter'}
  62. ]
  63. });
  64. });
  65. // 格式化打开方式
  66. function targetFormatter(value, row, index) {
  67. if (value == '_self') {
  68. return '<span class="label label-primary">当前窗口</span>';
  69. }
  70. if (value == '_blank') {
  71. return '<span class="label label-danger">新窗口</span>';
  72. }
  73. }
  74. // 新增
  75. var createDialog;
  76. function createAction() {
  77. createDialog = $.dialog({
  78. animationSpeed: 300,
  79. title: '新增菜单',
  80. content: 'url:${basePath}/manage/menu/create',
  81. onContentReady: function () {
  82. initMaterialInput();
  83. $('select').select2();
  84. }
  85. });
  86. }
  87. // 编辑
  88. var updateDialog;
  89. function updateAction() {
  90. var rows = $table.bootstrapTable('getSelections');
  91. if (rows.length != 1) {
  92. $.confirm({
  93. title: false,
  94. content: '请选择一条记录!',
  95. autoClose: 'cancel|3000',
  96. backgroundDismiss: true,
  97. buttons: {
  98. cancel: {
  99. text: '取消',
  100. btnClass: 'waves-effect waves-button'
  101. }
  102. }
  103. });
  104. } else {
  105. updateDialog = $.dialog({
  106. animationSpeed: 300,
  107. title: '编辑菜单',
  108. content: 'url:${basePath}/manage/menu/update/' + rows[0].menuId,
  109. onContentReady: function () {
  110. initMaterialInput();
  111. $('select').select2();
  112. }
  113. });
  114. }
  115. }
  116. // 删除
  117. var deleteDialog;
  118. function deleteAction() {
  119. var rows = $table.bootstrapTable('getSelections');
  120. if (rows.length == 0) {
  121. $.confirm({
  122. title: false,
  123. content: '请至少选择一条记录!',
  124. autoClose: 'cancel|3000',
  125. backgroundDismiss: true,
  126. buttons: {
  127. cancel: {
  128. text: '取消',
  129. btnClass: 'waves-effect waves-button'
  130. }
  131. }
  132. });
  133. } else {
  134. deleteDialog = $.confirm({
  135. type: 'red',
  136. animationSpeed: 300,
  137. title: false,
  138. content: '确认删除该菜单吗?',
  139. buttons: {
  140. confirm: {
  141. text: '确认',
  142. btnClass: 'waves-effect waves-button',
  143. action: function () {
  144. var ids = new Array();
  145. for (var i in rows) {
  146. ids.push(rows[i].menuId);
  147. }
  148. $.ajax({
  149. type: 'get',
  150. url: '${basePath}/manage/menu/delete/' + ids.join("-"),
  151. success: function(result) {
  152. if (result.code != 1) {
  153. if (result.data instanceof Array) {
  154. $.each(result.data, function(index, value) {
  155. $.confirm({
  156. theme: 'dark',
  157. animation: 'rotateX',
  158. closeAnimation: 'rotateX',
  159. title: false,
  160. content: value.errorMsg,
  161. buttons: {
  162. confirm: {
  163. text: '确认',
  164. btnClass: 'waves-effect waves-button waves-light'
  165. }
  166. }
  167. });
  168. });
  169. } else {
  170. $.confirm({
  171. theme: 'dark',
  172. animation: 'rotateX',
  173. closeAnimation: 'rotateX',
  174. title: false,
  175. content: result.data.errorMsg,
  176. buttons: {
  177. confirm: {
  178. text: '确认',
  179. btnClass: 'waves-effect waves-button waves-light'
  180. }
  181. }
  182. });
  183. }
  184. } else {
  185. deleteDialog.close();
  186. $table.bootstrapTable('refresh');
  187. }
  188. },
  189. error: function(XMLHttpRequest, textStatus, errorThrown) {
  190. $.confirm({
  191. theme: 'dark',
  192. animation: 'rotateX',
  193. closeAnimation: 'rotateX',
  194. title: false,
  195. content: textStatus,
  196. buttons: {
  197. confirm: {
  198. text: '确认',
  199. btnClass: 'waves-effect waves-button waves-light'
  200. }
  201. }
  202. });
  203. }
  204. });
  205. }
  206. },
  207. cancel: {
  208. text: '取消',
  209. btnClass: 'waves-effect waves-button'
  210. }
  211. }
  212. });
  213. }
  214. }
  215. </script>
  216. </body>
  217. </html>