roleList.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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?oprType=view&id='+row.id+'\',\'800px\', \'500px\')">'+value+'</a>'
  58. }
  59. }/*, {
  60. field: 'enname',
  61. title: '英文名称'
  62. }, {
  63. field: 'office.name',
  64. title: '归属机构'
  65. }*/, {
  66. field: 'useable',
  67. title: '状态',
  68. formatter:function(value, row , index){
  69. return value=="0" ? '<font color="red">禁用</font>':'<font color="green">正常</font>';
  70. }
  71. }, {
  72. field: 'operate',
  73. title: '操作',
  74. align: 'center',
  75. events: {
  76. 'click .view': function (e, value, row, index) {
  77. jp.openViewDialog('查看角色', '${ctx}/sys/role/form?oprType=view&id=' + row.id,'800px', '500px');
  78. },
  79. 'click .edit': function (e, value, row, index) {
  80. jp.openSaveDialog('编辑角色', '${ctx}/sys/role/form?id=' + row.id,'800px', '500px');
  81. },
  82. 'click .del': function (e, value, row, index) {
  83. del(row.id);
  84. },
  85. 'click .auth': function (e, value, row, index) {
  86. jp.openSaveDialog('权限设置', '${ctx}/sys/role/auth?id=' + row.id,'350px', '700px');
  87. },
  88. 'click .assign': function (e, value, row, index) {
  89. $("#left").attr("class", "col-sm-6");
  90. setTimeout(function(){
  91. $("#right").fadeIn(500);
  92. },500)
  93. $("#roleLabel").html(row.name);
  94. $("#roleId").val(row.id);
  95. $('#userTable').bootstrapTable("refresh",{query:{id:row.id}})
  96. }
  97. },
  98. formatter: function operateFormatter(value, row, index) {
  99. return [
  100. <shiro:hasPermission name="sys:role:view">
  101. '<a href="#" class="view" title="查看" ><i class="fa fa-eye"></i> </a>',
  102. </shiro:hasPermission>
  103. <shiro:hasPermission name="sys:role:edit">
  104. <c:if test="${(role.sysData eq fns:getDictValue('是', 'yes_no', '1') && fns:getUser().admin)||!(role.sysData eq fns:getDictValue('是', 'yes_no', '1'))}">
  105. '<a href="#" class="edit" title="修改"><i class="fa fa-edit"></i> </a>',
  106. </c:if>
  107. </shiro:hasPermission>
  108. <shiro:hasPermission name="sys:role:del">
  109. '<a href="#" class="del" title="删除"><i class="fa fa-trash"></i> </a>',
  110. </shiro:hasPermission>
  111. <shiro:hasPermission name="sys:role:assign">
  112. '<a href="#" class="auth" title="权限设置"><i class="fa fa-cog"></i> </a>',
  113. </shiro:hasPermission>
  114. <shiro:hasPermission name="sys:role:assign">
  115. '<a href="#" class="assign" title="分配用户"><i class="fa fa-users"></i> </a>'
  116. </shiro:hasPermission>
  117. ].join('');
  118. }
  119. }]
  120. });
  121. if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端,默认关闭tab
  122. $('#table').bootstrapTable("toggleView");
  123. }
  124. $('#table').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
  125. 'check-all.bs.table uncheck-all.bs.table', function () {
  126. $('#remove').prop('disabled', ! $('#table').bootstrapTable('getSelections').length);
  127. $('#edit, #auth').prop('disabled', $('#table').bootstrapTable('getSelections').length!=1);
  128. });
  129. $("#search").click("click", function() {// 绑定查询按扭
  130. $('#table').bootstrapTable('refresh');
  131. });
  132. $("#reset").click("click", function() {// 绑定查询按扭
  133. $("#searchForm input").val("");
  134. $("#searchForm select").val("");
  135. $('#table').bootstrapTable('refresh');
  136. });
  137. });
  138. function getIdSelections() {
  139. return $.map($("#table").bootstrapTable('getSelections'), function (row) {
  140. return row.id
  141. });
  142. }
  143. function add(){
  144. jp.openSaveDialog('新建角色', '${ctx}/sys/role/form','800px', '500px')
  145. }
  146. function edit(id){
  147. if(!id){
  148. id = getIdSelections();
  149. }
  150. jp.openSaveDialog('编辑角色', "${ctx}/sys/role/form?id=" + id,'800px', '500px')
  151. }
  152. function del(ids){
  153. if(!ids){
  154. ids = getIdSelections();
  155. }
  156. jp.confirm('确认要删除选中角色吗?', function(){
  157. jp.loading();
  158. jp.get("${ctx}/sys/role/delete?ids=" + ids, function(data){
  159. if(data.success){
  160. $('#table').bootstrapTable('refresh');
  161. jp.success(data.msg);
  162. }else{
  163. jp.error(data.msg);
  164. }
  165. })
  166. })
  167. }
  168. function refresh() {
  169. $('#table').bootstrapTable('refresh');
  170. }
  171. function auth(id) {
  172. if(!id){
  173. id = getIdSelections();
  174. }
  175. jp.openSaveDialog('权限设置', '${ctx}/sys/role/auth?id=' + id,'350px', '700px');
  176. }
  177. </script>