roleList.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <%@ page contentType="text/html;charset=UTF-8" %>
  2. <script>
  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. showSearch: true,
  15. //显示刷新按钮
  16. showRefresh: true,
  17. //显示切换手机试图按钮
  18. showToggle: true,
  19. //显示 内容列下拉框
  20. showColumns: true,
  21. //显示切换分页按钮
  22. //是否显示分页(*)
  23. pagination: false,
  24. //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
  25. url: "${ctx}/sys/role/data",
  26. //默认值为 'limit',传给服务端的参数为:limit, offset, search, sort, order Else
  27. //queryParamsType:'',
  28. ////查询参数,每次调用是会带上这个参数,可自定义
  29. queryParams : function(params) {
  30. var searchParam = $("#searchForm").serializeJSON();
  31. searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
  32. searchParam.pageSize = params.limit === undefined? -1 : params.limit;
  33. searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+ params.order;
  34. return searchParam;
  35. },
  36. onShowSearch: function () {
  37. $("#search-collapse").slideToggle();
  38. },
  39. //分页方式:client客户端分页,server服务端分页(*)
  40. sidePagination: "server",
  41. contextMenuTrigger:"right",//pc端 按右键弹出菜单
  42. contextMenuTriggerMobile:"press",//手机端 弹出菜单,click:单击, press:长按。
  43. contextMenu: '#context-menu',
  44. onContextMenuItem: function(row, $el){
  45. if($el.data("item") == "edit"){
  46. edit(row.id);
  47. } else if($el.data("item") == "delete"){
  48. del(row.id);
  49. }
  50. },
  51. columns: [{
  52. checkbox: true
  53. }, {
  54. field: 'name',
  55. title: '角色名称',
  56. formatter:function(value, row, index){
  57. return '<a href="#" onclick="jp.openViewDialog(\'查看角色\', \'${ctx}/sys/role/form?id='+row.id+'\',\'800px\', \'500px\')">'+value+'</a>'
  58. }
  59. }, {
  60. field: 'enname',
  61. title: '英文名称'
  62. }, {
  63. field: 'useable',
  64. title: '状态',
  65. formatter:function(value, row , index){
  66. return value=="0" ? '<font color="red">禁用</font>':'<font color="green">正常</font>';
  67. }
  68. }, {
  69. field: 'operate',
  70. title: '操作',
  71. align: 'center',
  72. events: {
  73. 'click .view': function (e, value, row, index) {
  74. jp.openViewDialog('查看角色', '${ctx}/sys/role/form?id=' + row.id,'800px', '500px');
  75. },
  76. 'click .edit': function (e, value, row, index) {
  77. jp.openSaveDialog('编辑角色', '${ctx}/sys/role/form?id=' + row.id,'800px', '500px');
  78. },
  79. 'click .del': function (e, value, row, index) {
  80. del(row.id);
  81. },
  82. 'click .auth': function (e, value, row, index) {
  83. jp.openSaveDialog('权限设置', '${ctx}/sys/role/auth?id=' + row.id,'350px', '700px');
  84. },
  85. 'click .assign': function (e, value, row, index) {
  86. $("#left").attr("class", "col-sm-6");
  87. setTimeout(function(){
  88. $("#right").fadeIn(500);
  89. },500)
  90. $("#roleLabel").html(row.name);
  91. $("#roleId").val(row.id);
  92. $('#userTable').bootstrapTable("refresh",{query:{id:row.id}})
  93. }
  94. },
  95. formatter: function operateFormatter(value, row, index) {
  96. return [
  97. <shiro:hasPermission name="sys:role:view">
  98. '<a href="#" class="view" title="查看" ><i class="fa fa-eye"></i> </a>',
  99. </shiro:hasPermission>
  100. <shiro:hasPermission name="sys:role:edit">
  101. <c:if test="${(role.sysData eq fns:getDictValue('是', 'yes_no', '1') && fns:getUser().admin)||!(role.sysData eq fns:getDictValue('是', 'yes_no', '1'))}">
  102. '<a href="#" class="edit" title="修改"><i class="fa fa-edit"></i> </a>',
  103. </c:if>
  104. </shiro:hasPermission>
  105. <shiro:hasPermission name="sys:role:del">
  106. '<a href="#" class="del" title="删除"><i class="fa fa-trash"></i> </a>',
  107. </shiro:hasPermission>
  108. <shiro:hasPermission name="sys:role:assign">
  109. '<a href="#" class="auth" title="权限设置"><i class="fa fa-cog"></i> </a>',
  110. </shiro:hasPermission>
  111. <shiro:hasPermission name="sys:role:assign">
  112. '<a href="#" class="assign" title="分配用户"><i class="fa fa-users"></i> </a>'
  113. </shiro:hasPermission>
  114. ].join('');
  115. }
  116. }]
  117. });
  118. if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端,默认关闭tab
  119. $('#table').bootstrapTable("toggleView");
  120. }
  121. $('#table').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
  122. 'check-all.bs.table uncheck-all.bs.table', function () {
  123. $('#remove').prop('disabled', ! $('#table').bootstrapTable('getSelections').length);
  124. $('#edit, #auth').prop('disabled', $('#table').bootstrapTable('getSelections').length!=1);
  125. });
  126. $("#search").click("click", function() {// 绑定查询按扭
  127. $('#table').bootstrapTable('refresh');
  128. });
  129. $("#reset").click("click", function() {// 绑定查询按扭
  130. $("#searchForm input").val("");
  131. $("#searchForm select").val("");
  132. $('#table').bootstrapTable('refresh');
  133. });
  134. });
  135. function getIdSelections() {
  136. return $.map($("#table").bootstrapTable('getSelections'), function (row) {
  137. return row.id
  138. });
  139. }
  140. function add(){
  141. jp.openSaveDialog('新建角色', '${ctx}/sys/role/form','800px', '500px')
  142. }
  143. function edit(id){
  144. if(!id){
  145. id = getIdSelections();
  146. }
  147. jp.openSaveDialog('编辑角色', "${ctx}/sys/role/form?id=" + id,'800px', '500px')
  148. }
  149. function del(ids){
  150. if(!ids){
  151. ids = getIdSelections();
  152. }
  153. jp.confirm('确认要删除选中角色吗?', function(){
  154. jp.loading();
  155. jp.get("${ctx}/sys/role/delete?ids=" + ids, function(data){
  156. if(data.success){
  157. $('#table').bootstrapTable('refresh');
  158. jp.success(data.msg);
  159. }else{
  160. jp.error(data.msg);
  161. }
  162. })
  163. })
  164. }
  165. function refresh() {
  166. $('#table').bootstrapTable('refresh');
  167. }
  168. function auth(id) {
  169. if(!id){
  170. id = getIdSelections();
  171. }
  172. jp.openSaveDialog('权限设置', '${ctx}/sys/role/auth?id=' + id,'350px', '700px');
  173. }
  174. </script>