menuList.jsp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
  2. <jsp:include page="../../common/include.jsp" />
  3. <% String basePath = request.getScheme()+ "://" + request.getServerName() + ":" +request.getServerPort() + request.getContextPath(); %>
  4. <script type="text/javascript">
  5. /**菜单显示区*/
  6. $(function() {
  7. $('#menuDataGrid').datagrid({
  8. rownumbers:true,
  9. fit:true,
  10. pageSize:10,
  11. pageList : [ 10, 20, 30, 40, 50 ],
  12. fitColumns:false,
  13. border:false,
  14. sortOrder:'desc',
  15. pagination:true,
  16. idField:'id',
  17. url:whzl.basePath + '/menuAction_listMenu',
  18. toolbar:'#searchtool',
  19. checkOnSelect:true,
  20. selectOnCheck:true,
  21. nowrap:true,
  22. loadFilter:function(result){
  23. if(result.success){
  24. return result.obj;
  25. }else{
  26. $.messager.alert('出错了',result.message,'error');
  27. return ;
  28. }
  29. }
  30. }
  31. );
  32. });
  33. /**查询*/
  34. function searchFun(){
  35. $("#menuDataGrid").datagrid("load", {
  36. "menu.text":$("#tblQuery").find("input[id='text']").val(),
  37. "menu.href":$("#tblQuery").find("input[id='href']").val()
  38. });
  39. }
  40. /*清除查询条件**/
  41. function ClearQuery() {
  42. $("#tblQuery").find("input").val("");
  43. $("#tblQuery").find("select").val("-1");
  44. }
  45. /**详细*/
  46. var parentNameFormatter = function(value , row , index){
  47. if("parent" in row){
  48. return row.parent.text;
  49. }else{
  50. return "";
  51. }
  52. };
  53. /**详细*/
  54. var detailsFormatter = function(value , row , index){
  55. return "<img src='<%=basePath%>/images/details.png' title='查看详情' onclick=btsqDetails(" + row.id + ") style='cursor:pointer' />";
  56. };
  57. var iconFormatter = function(value , row , index){
  58. return "<div class='iconImg " +value + "'/>";
  59. };
  60. /**详细页面对话框*/
  61. var btsqDetails = function(id){
  62. $("#detailMenuDialog").dialog(
  63. {
  64. buttons : [
  65. {
  66. text : '确定',
  67. iconCls : 'icon-ok',
  68. handler : function(){
  69. $("#detailMenuDialog").dialog("close");
  70. }
  71. }
  72. ],
  73. onLoad : function(){
  74. $.ajax({
  75. type: "post",//使用get方法访问后台
  76. dataType: "json",//返回json格式的数据
  77. url: "menuAction_findById",//要访问的后台地址
  78. data: "menu.id="+id,//要发送的数据
  79. complete :function(){$("#load").hide();},//AJAX请求完成时隐藏loading提示
  80. success: function(msg){//msg为返回的数据,在这里做数据绑定
  81. $("#id_detail").text(msg.obj.id);
  82. $("#text_detail").text(msg.obj.text);
  83. $("#parent_detail").text(msg.obj.parent.text);
  84. $("#href_detail").text(msg.obj.href);
  85. }
  86. });
  87. }
  88. }
  89. );
  90. };
  91. /**更新*/
  92. var updateFormatter = function(value , row , index){
  93. return "<img src='<%=basePath%>/js/easyui/themes/itemicon/update.png' title='修改' onclick=updateRow(" + row.id + ") style='cursor:pointer' />";
  94. };
  95. /**更新事件*/
  96. function updateRow(id){
  97. var updateIndex = $('#menuDataGrid').datagrid('getRowIndex', id);
  98. $('#updateMenuDialog').dialog(
  99. {
  100. buttons : [
  101. {
  102. text : '提交',
  103. iconCls : 'icon-ok',
  104. handler : function(){
  105. var menuId = $('#id_update').val();
  106. var updateId = $("input[name='menu.parent.id']").val()
  107. if(menuId == updateId){
  108. $.messager.alert("提示","不能选择自身节点作为父节点!");
  109. return;
  110. }
  111. $('#updateMenuForm').form('submit',
  112. {
  113. url : whzl.basePath+'/menuAction_updateMenu',
  114. success : function(result){
  115. var parseResult = $.parseJSON(result);
  116. if(parseResult.success){
  117. //修改完数据,更新对应行的数据
  118. $('#menuDataGrid').datagrid('updateRow',
  119. {
  120. index : updateIndex,
  121. row : parseResult.obj
  122. }
  123. );
  124. $('#allMenuTree').tree('reload');
  125. $("#updateMenuDialog").dialog("close");
  126. $('#iconDialog').dialog("destroy");
  127. }else{
  128. $.messager.alert('出错了',parseResult.message,'error');
  129. }
  130. }
  131. }
  132. );
  133. }
  134. },
  135. {
  136. text : '取消',
  137. iconCls : 'icon-cancel',
  138. handler : function(){
  139. $("#updateMenuDialog").dialog("close");
  140. }
  141. }
  142. ],
  143. onLoad : function(){
  144. $.ajax({
  145. type: "post",//使用get方法访问后台
  146. dataType: "json",//返回json格式的数据
  147. url: "menuAction_findById",//要访问的后台地址
  148. data: "menu.id="+id,//要发送的数据
  149. complete :function(){$("#load").hide();},//AJAX请求完成时隐藏loading提示
  150. success: function(msg){//msg为返回的数据,在这里做数据绑定
  151. $("#id_update").val(msg.obj.id);
  152. $("#text_update").val(msg.obj.text);
  153. $("#href_update").val(msg.obj.href);
  154. $("#iconCls").val(msg.obj.iconCls);
  155. $("#iconCls").attr('class',"iconImg " + msg.obj.iconCls);
  156. //$("#p_id_add").val(msg.obj.parentId);
  157. if(msg.obj.parentId >0){
  158. $('#p_id_update').combotree('setValue',msg.obj.parentId);
  159. }
  160. }
  161. });
  162. }
  163. }
  164. );
  165. }
  166. /**删除*/
  167. var delFormatter = function(value , row , index){
  168. return "<img src='<%=basePath%>/js/easyui/themes/itemicon/delete.png' title='删除' onclick=deleteRow(" + row.id + ") style='cursor:pointer' />";
  169. };
  170. /**删除功能*/
  171. function deleteRow(id){
  172. $.messager.confirm('删除提示', '确定删除这条记录吗?', function(r){
  173. if (r){
  174. $.ajax({
  175. type: "post",//使用get方法访问后台
  176. dataType: "json",//返回json格式的数据
  177. url: "menuAction_deleteMenu",//要访问的后台地址
  178. data: "menu.id="+id,//要发送的数据
  179. complete :function(){$("#load").hide();},//AJAX请求完成时隐藏loading提示
  180. success: function(msg){//msg为返回的数据,在这里做数据绑定
  181. if(msg.success){
  182. $.messager.alert('提示','删除成功!');
  183. $('#menuDataGrid').datagrid('reload');
  184. $('#allMenuTree').tree('reload');
  185. }else{
  186. $.messager.alert('提示','删除失败!');
  187. }
  188. }
  189. });
  190. }
  191. });
  192. }
  193. /**增加菜单*/
  194. function menuAdd(){
  195. $('#addMenuDialog').dialog(
  196. {
  197. buttons : [
  198. {
  199. text : '提交',
  200. iconCls : 'icon-ok',
  201. handler : function(){
  202. $('#addMenuForm').form('submit',
  203. {
  204. url : whzl.basePath+'/menuAction_addMenu',
  205. success : function(result){
  206. var parseResult = $.parseJSON(result);
  207. if(parseResult.success){
  208. $("#addMenuDialog").dialog("close");
  209. $('#menuDataGrid').datagrid('reload');
  210. $('#allMenuTree').tree('reload');
  211. $('#iconAddDialog').dialog("destroy");
  212. }else{
  213. $.messager.alert('提示',parseResult.message);
  214. }
  215. }
  216. }
  217. );
  218. }
  219. },
  220. {
  221. text : '取消',
  222. iconCls : 'icon-cancel',
  223. handler : function(){
  224. $("#addMenuDialog").dialog("close");
  225. }
  226. }
  227. ]
  228. }
  229. );
  230. }
  231. $(function(){
  232. $('#allMenuTree').tree({
  233. url:whzl.basePath+'/menuAction_menu',
  234. loadFilter: function(result){
  235. if(result.success){
  236. return result.obj;
  237. }else{
  238. $.messager.alert('提示',result.message);
  239. }
  240. }
  241. });
  242. });
  243. </script>
  244. <div style="width: 63%;height: 100%;boreder:1px solid red;float: left;background-color: #E0ECFF;">
  245. <div class="easyui-layout" data-options="fit:true,border:false" style="margin: 0px;padding: 0px;">
  246. <div data-options="region:'center',border:false">
  247. <div id="searchtool" data-options="region:'north' , border:false">
  248. <table id="tblQuery" style="width:100%;">
  249. <tr>
  250. <td align="right"><span>名称</span></td><td style="width: 200px;"><input id="text" name="menu.text" type="text"/></td>
  251. <td align="right"><span>地址</span></td><td style="width: 200px;"><input id="href" name="menu.href" type="text"/></td>
  252. <td align="center" colspan="2">
  253. <a href="javascript:searchFun();" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">查询</a>
  254. <a href="javascript:ClearQuery();" class="easyui-linkbutton" data-options="iconCls:'icon-emptied',plain:true">清空</a>
  255. <a href="javascript:menuAdd();" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">增加</a>
  256. </td>
  257. </tr>
  258. </table>
  259. </div>
  260. <table id="menuDataGrid">
  261. <thead frozen="true">
  262. <tr>
  263. <th data-options="field:'id',checkbox:true,width:50">ID</th>
  264. <th data-options="field:'text',sortable:true,width:150">名称</th>
  265. </tr>
  266. </thead>
  267. <thead>
  268. <tr>
  269. <th data-options="field:'iconCls',sortable:true,formatter:iconFormatter,width:40">图标</th>
  270. <th data-options="field:'href',sortable:true,width:200">地址</th>
  271. <!-- <th data-options="field:'parentId',sortable:false">父节点ID</th> -->
  272. <th data-options="field:'parentName',sortable:false,width:150,formatter:parentNameFormatter">父节点名称</th>
  273. <!-- <th data-options="field:'details',align:'center',formatter:detailsFormatter">查看详情</th> -->
  274. <th data-options="field:'update',align:'center',formatter:updateFormatter,width:50">修改</th>
  275. <th data-options="field:'delete',align:'center',formatter:delFormatter,width:50">删除</th>
  276. </tr>
  277. </thead>
  278. </table>
  279. </div>
  280. </div>
  281. </div>
  282. <div style="width: 37%;height: 100%;boreder:1px solid red;float: left;background-color: #E0ECFF;">
  283. <div class="easyui-accordion" data-options="fit:true,border:false">
  284. <div title="菜单" data-options="iconCls:'icon-menu'">
  285. <ul id="allMenuTree" class="easyui-tree" data-options="lines:true" style="margin-top:5px;margin-left: 20px;">
  286. </ul>
  287. </div>
  288. </div>
  289. </div>
  290. <div id="detailMenuDialog" data-options="title:'&nbsp;菜单详细信息',iconCls:'icon-details',width:400,height:185,modal:true,href:'<%=basePath %>/menuAction_toDetail'">
  291. </div>
  292. <div id="updateMenuDialog" data-options="title:'&nbsp;修改菜单信息',iconCls:'icon-edit',width:400,height:250,modal:true,href:'<%=basePath %>/menuAction_toUpdate'">
  293. </div>
  294. <div id="addMenuDialog" data-options="title:'&nbsp;增加菜单信息',iconCls:'icon-add',width:400,height:250,modal:true,href:'<%=basePath %>/menuAction_toAdd'">
  295. </div>
  296. <script type="text/javascript">
  297. <!--
  298. parent.$.messager.progress('close');
  299. //-->
  300. </script>