dictList.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <%@ page contentType="text/html;charset=UTF-8" %>
  2. <script type="text/javascript">
  3. $(document).ready(function() {
  4. $('#table').bootstrapTable({
  5. //请求方法
  6. method: 'post',
  7. //类型json
  8. dataType: "json",
  9. contentType: "application/x-www-form-urlencoded",
  10. //是否显示行间隔色
  11. striped: true,
  12. //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  13. cache: false,
  14. //显示检索按钮
  15. showSearch: true,
  16. //显示刷新按钮
  17. showRefresh: true,
  18. //显示切换手机试图按钮
  19. showToggle: true,
  20. //显示 内容列下拉框
  21. showColumns: true,
  22. //显示切换分页按钮
  23. //是否显示分页(*)
  24. pagination: true,
  25. pageList: [10, 25, 50, 100],
  26. //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
  27. url: "${ctx}/sys/dict/data",
  28. //默认值为 'limit',传给服务端的参数为:limit, offset, search, sort, order Else
  29. //queryParamsType:'',
  30. ////查询参数,每次调用是会带上这个参数,可自定义
  31. queryParams : function(params) {
  32. var searchParam = $("#searchForm").serializeJSON();
  33. searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
  34. searchParam.pageSize = params.limit === undefined? -1 : params.limit;
  35. searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+ params.order;
  36. return searchParam;
  37. },
  38. onShowSearch: function () {
  39. $("#search-collapse").slideToggle();
  40. },
  41. //分页方式:client客户端分页,server服务端分页(*)
  42. sidePagination: "server",
  43. contextMenuTrigger:"right",//pc端 按右键弹出菜单
  44. contextMenuTriggerMobile:"press",//手机端 弹出菜单,click:单击, press:长按。
  45. contextMenu: '#context-menu',
  46. onContextMenuItem: function(row, $el){
  47. if($el.data("item") == "edit"){
  48. edit(row.id);
  49. } else if($el.data("item") == "delete"){
  50. del(row.id);
  51. }
  52. },
  53. columns: [{
  54. checkbox: true
  55. }, {
  56. field: 'type',
  57. title: '类型',
  58. sortable:true
  59. }, {
  60. field: 'description',
  61. title: '描述',
  62. sortable:true
  63. }, {
  64. field: 'operate',
  65. title: '操作',
  66. align: 'center',
  67. events: {
  68. 'click .view': function (e, value, row, index) {
  69. jp.openViewDialog('查看字典', '${ctx}/sys/dict/form?id=' + row.id,'800px', '500px');
  70. },
  71. 'click .edit': function (e, value, row, index) {
  72. jp.openSaveDialog('编辑字典', '${ctx}/sys/dict/form?id=' + row.id,'800px', '500px');
  73. },
  74. 'click .del': function (e, value, row, index) {
  75. del(row.id);
  76. },
  77. 'click .setDictValue': function (e, value, row, index) {
  78. $("#left").attr("class", "col-sm-6");
  79. setTimeout(function(){
  80. $("#right").fadeIn(500);
  81. },500)
  82. $("#dictTypeLabel").html(row.type);
  83. $("#dictTypeId").val(row.id);
  84. $('#dictValueTable').bootstrapTable("refresh",{query:{dictTypeId:row.id}})
  85. }
  86. },
  87. formatter: function operateFormatter(value, row, index) {
  88. return [
  89. <shiro:hasPermission name="sys:dict:view">
  90. '<a href="#" class="view" title="查看" ><i class="fa fa-eye"></i> </a>',
  91. </shiro:hasPermission>
  92. <shiro:hasPermission name="sys:dict:edit">
  93. '<a href="#" class="edit" title="修改"><i class="fa fa-edit"></i> </a>',
  94. </shiro:hasPermission>
  95. <shiro:hasPermission name="sys:dict:del">
  96. '<a href="#" class="del" title="删除"><i class="fa fa-trash"></i> </a>',
  97. </shiro:hasPermission>
  98. <shiro:hasPermission name="sys:dict:edit">
  99. '<a href="#" class="setDictValue" title="管理键值"><i class="fa fa-cog"></i> </a>'
  100. </shiro:hasPermission>
  101. ].join('');
  102. }
  103. }]
  104. });
  105. if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端,默认关闭tab
  106. $('#table').bootstrapTable("toggleView");
  107. }
  108. $('#table').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
  109. 'check-all.bs.table uncheck-all.bs.table', function () {
  110. $('#remove').prop('disabled', ! $('#table').bootstrapTable('getSelections').length);
  111. $('#edit').prop('disabled', $('#table').bootstrapTable('getSelections').length!=1);
  112. });
  113. $("#search").click("click", function() {// 绑定查询按扭
  114. $('#table').bootstrapTable('refresh');
  115. });
  116. $("#reset").click("click", function() {// 绑定查询按扭
  117. $("#searchForm input").val("");
  118. $("#searchForm select").val("");
  119. $('#table').bootstrapTable('refresh');
  120. });
  121. });
  122. function getIdSelections() {
  123. return $.map($("#table").bootstrapTable('getSelections'), function (row) {
  124. return row.id
  125. });
  126. }
  127. function add(){
  128. jp.openSaveDialog('新建字典', '${ctx}/sys/dict/form','800px', '500px')
  129. }
  130. function edit(id){
  131. if(!id){
  132. id = getIdSelections();
  133. }
  134. jp.openSaveDialog('编辑字典', "${ctx}/sys/dict/form?id=" + id,'800px', '500px')
  135. }
  136. function del(ids){
  137. if(!ids){
  138. ids = getIdSelections();
  139. }
  140. jp.loading();
  141. jp.confirm('确认要删除选中字典吗?', function(){
  142. $.get("${ctx}/sys/dict/deleteAll?ids=" + ids, function(data){
  143. if(data.success){
  144. $('#table').bootstrapTable('refresh');
  145. jp.success(data.msg);
  146. }else{
  147. jp.error(data.msg);
  148. }
  149. })
  150. })
  151. }
  152. function refresh(){
  153. $('#table').bootstrapTable('refresh');
  154. }
  155. function refreshDictValue(){
  156. $('#dictValueTable').bootstrapTable("refresh");
  157. }
  158. $(document).ready(function() {
  159. var $dictValueTable = $('#dictValueTable').bootstrapTable({
  160. //请求方法
  161. method: 'post',
  162. //类型json
  163. dataType: "json",
  164. contentType: "application/x-www-form-urlencoded",
  165. //是否显示行间隔色
  166. striped: true,
  167. //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  168. cache: false,
  169. //是否显示分页(*)
  170. pagination: false,
  171. //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
  172. url: "${ctx}/sys/dict/getDictValue",
  173. //默认值为 'limit',传给服务端的参数为:limit, offset, search, sort, order Else
  174. //queryParamsType:'',
  175. ////查询参数,每次调用是会带上这个参数,可自定义
  176. queryParams : function(params) {
  177. return {dictTypeId:$("#dictTypeId").val()};
  178. },
  179. //分页方式:client客户端分页,server服务端分页(*)
  180. sidePagination: "server",
  181. columns: [{
  182. field: 'label',
  183. title: '标签'
  184. }, {
  185. field: 'value',
  186. title: '键值'
  187. },{
  188. field: 'sort',
  189. title: '排序'
  190. }, {
  191. field: 'operate',
  192. title: '操作',
  193. align: 'center',
  194. events: {
  195. 'click .edit': function (e, value, row, index) {
  196. jp.openSaveDialog('编辑键值', '${ctx}/sys/dict/dictValueForm?dictTypeId=' + $("#dictTypeId").val()+"&dictValueId="+row.id,'800px', '500px');
  197. },
  198. 'click .del': function (e, value, row, index) {
  199. jp.confirm('确认要删除键值吗?',function(){
  200. jp.loading();
  201. $.get('${ctx}/sys/dict/deleteDictValue?dictValueId='+row.id+'&dictTypeId=' + $("#dictTypeId").val(), function(data){
  202. if(data.success){
  203. $('#dictValueTable').bootstrapTable("refresh");
  204. jp.success(data.msg);
  205. }else{
  206. jp.error(data.msg);
  207. }
  208. })
  209. });
  210. }
  211. },
  212. formatter: function operateFormatter(value, row, index) {
  213. return [
  214. <shiro:hasPermission name="sys:dict:edit">
  215. '<a href="#" class="edit" title="编辑" >[编辑] </a>',
  216. </shiro:hasPermission>
  217. <shiro:hasPermission name="sys:dict:edit">
  218. '<a href="#" class="del" title="删除" >[删除] </a>'
  219. </shiro:hasPermission>
  220. ].join('');
  221. }
  222. }]
  223. });
  224. if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端
  225. $('#dictValueTable').bootstrapTable("toggleView");
  226. }
  227. $("#dictValueButton").click(function(){
  228. jp.openSaveDialog('添加键值', '${ctx}/sys/dict/dictValueForm?dictTypeId=' + $("#dictTypeId").val(),'800px', '500px');
  229. });
  230. });
  231. </script>