testInterfaceList.jsp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <%@ page contentType="text/html;charset=UTF-8" %>
  2. <%@ include file="/webpage/include/taglib.jsp"%>
  3. <html>
  4. <head>
  5. <title>接口管理</title>
  6. <meta name="decorator" content="ani"/>
  7. <%@ include file="/webpage/include/bootstraptable.jsp"%>
  8. <script>
  9. $(document).ready(function() {
  10. $('#table').bootstrapTable({
  11. //请求方法
  12. method: 'post',
  13. //类型json
  14. dataType: "json",
  15. contentType: "application/x-www-form-urlencoded",
  16. //显示检索按钮
  17. showSearch: true,
  18. //显示刷新按钮
  19. showRefresh: true,
  20. //显示切换手机试图按钮
  21. showToggle: true,
  22. //显示 内容列下拉框
  23. showColumns: true,
  24. //显示到处按钮
  25. showExport: true,
  26. //显示切换分页按钮
  27. showPaginationSwitch: true,
  28. //最低显示2行
  29. minimumCountColumns: 2,
  30. //是否显示行间隔色
  31. striped: true,
  32. //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  33. cache: false,
  34. //是否显示分页(*)
  35. pagination: true,
  36. //排序方式
  37. sortOrder: "asc",
  38. //初始化加载第一页,默认第一页
  39. pageNumber:1,
  40. //每页的记录行数(*)
  41. pageSize: 10,
  42. //可供选择的每页的行数(*)
  43. pageList: [10, 25, 50, 100],
  44. //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
  45. url: "${ctx}/tools/testInterface/data",
  46. //默认值为 'limit',传给服务端的参数为:limit, offset, search, sort, order Else
  47. //queryParamsType:'',
  48. ////查询参数,每次调用是会带上这个参数,可自定义
  49. queryParams : function(params) {
  50. var searchParam = $("#searchForm").serializeJSON();
  51. searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
  52. searchParam.pageSize = params.limit === undefined? -1 : params.limit;
  53. searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+ params.order;
  54. return searchParam;
  55. },
  56. //分页方式:client客户端分页,server服务端分页(*)
  57. sidePagination: "server",
  58. contextMenuTrigger:"right",//pc端 按右键弹出菜单
  59. contextMenuTriggerMobile:"press",//手机端 弹出菜单,click:单击, press:长按。
  60. contextMenu: '#context-menu',
  61. onContextMenuItem: function(row, $el){
  62. if($el.data("item") == "edit"){
  63. jp.go("${ctx}/tools/testInterface/form?id=" + row.id);
  64. } else if($el.data("item") == "delete"){
  65. jp.confirm('确认要删除该测试接口记录吗?', function(){
  66. jp.loading();
  67. jp.get("${ctx}/tools/testInterface/delete?id="+row.id, function(data){
  68. if(data.success){
  69. $('#table').bootstrapTable('refresh');
  70. jp.success(data.msg);
  71. }else{
  72. jp.error(data.msg);
  73. }
  74. })
  75. });
  76. }
  77. },
  78. onShowSearch: function () {
  79. $("#search-collapse").slideToggle();
  80. },
  81. columns: [{
  82. checkbox: true
  83. }
  84. ,{
  85. field: 'name',
  86. title: '接口名称',
  87. sortable: true
  88. }
  89. ,{
  90. field: 'type',
  91. title: '接口类型',
  92. sortable: true
  93. }
  94. ,{
  95. field: 'url',
  96. width:"200px",
  97. title: '请求URL',
  98. sortable: true
  99. }
  100. ,{
  101. field: 'body',
  102. title: '请求body',
  103. sortable: true
  104. }
  105. ,{
  106. field: 'successmsg',
  107. title: '成功时返回消息',
  108. sortable: true
  109. }
  110. ,{
  111. field: 'errormsg',
  112. title: '失败时返回消息',
  113. sortable: true
  114. }
  115. ,{
  116. field: 'remarks',
  117. title: '备注信息',
  118. sortable: true
  119. }, {
  120. field: 'operate',
  121. title: '操作',
  122. width:"200px",
  123. class:"text-nowrap",
  124. align: 'center',
  125. events: {
  126. 'click .edit': function (e, value, row, index) {
  127. jp.go("${ctx}/tools/testInterface/form?id=" + row.id);
  128. },
  129. 'click .del': function (e, value, row, index) {
  130. jp.confirm('确认要删除该测试接口记录吗?', function(){
  131. jp.loading();
  132. jp.get('${ctx}/tools/testInterface/delete?id='+row.id, function(data){
  133. if(data.success){
  134. $('#table').bootstrapTable('refresh');
  135. jp.success(data.msg);
  136. }else{
  137. jp.error(data.msg);
  138. }
  139. })
  140. })
  141. },
  142. 'click .test': function (e, value, row, index) {
  143. test(row.id);
  144. }
  145. },
  146. formatter: function operateFormatter(value, row, index) {
  147. return [
  148. '<div class="btn-group" role="group">',
  149. <shiro:hasPermission name="tools:testInterface:edit">
  150. '<div class="btn-group" role="group">',
  151. '<button type="button" class="edit btn btn-warning">修改</button>',
  152. '</div>',
  153. </shiro:hasPermission>
  154. <shiro:hasPermission name="tools:testInterface:del">
  155. '<div class="btn-group" role="group">',
  156. '<button type="button" class="del btn btn-danger">删除</button>',
  157. '</div>',
  158. </shiro:hasPermission>
  159. '<div class="btn-group" role="group">',
  160. '<button type="button" class="test btn btn-success">测试</button>',
  161. '</div>',
  162. '</div>'
  163. ].join('');
  164. }
  165. }
  166. ]
  167. });
  168. $('#table').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
  169. 'check-all.bs.table uncheck-all.bs.table', function () {
  170. $('#remove').prop('disabled', ! $('#table').bootstrapTable('getSelections').length);
  171. $('#edit').prop('disabled', $('#table').bootstrapTable('getSelections').length!=1);
  172. });
  173. $("#btnImport").click(function(){
  174. jp.open({
  175. type: 1,
  176. area: [500, 300],
  177. title:"导入数据",
  178. content:$("#importBox").html() ,
  179. btn: ['下载模板','确定', '关闭'],
  180. btn1: function(index, layero){
  181. window.location='${ctx}/tools/testInterface/import/template';
  182. },
  183. btn2: function(index, layero){
  184. var inputForm =top.$("#importForm");
  185. var top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
  186. inputForm.attr("target",top_iframe);//表单提交成功后,从服务器返回的url在当前tab中展示
  187. inputForm.onsubmit = function(){
  188. jp.loading(' 正在导入,请稍等...');
  189. }
  190. inputForm.submit();
  191. jp.close(index);
  192. },
  193. btn3: function(index){
  194. jp.close(index);
  195. }
  196. });
  197. });
  198. $("#search").click("click", function() {// 绑定查询按扭
  199. $('#table').bootstrapTable('refresh');
  200. });
  201. $("#reset").click("click", function() {// 绑定查询按扭
  202. $("#searchForm input").val("");
  203. $("#searchForm select").val("");
  204. $('#table').bootstrapTable('refresh');
  205. });
  206. });
  207. function getIdSelections() {
  208. return $.map($("#table").bootstrapTable('getSelections'), function (row) {
  209. return row.id
  210. });
  211. }
  212. function deleteAll(){
  213. jp.confirm('确认要删除该测试接口记录吗?', function(){
  214. jp.loading();
  215. jp.get("${ctx}/tools/testInterface/deleteAll?ids=" + getIdSelections(), function(data){
  216. if(data.success){
  217. $('#table').bootstrapTable('refresh');
  218. jp.success(data.msg);
  219. }else{
  220. jp.error(data.msg);
  221. }
  222. })
  223. })
  224. }
  225. function edit(){
  226. jp.go("${ctx}/tools/testInterface/form?id=" + getIdSelections());
  227. }
  228. function test(id){
  229. if(!id){
  230. id = getIdSelections();
  231. }
  232. top.openTab("${ctx}/tools/testInterface/test?id="+id,"接口测试", false);
  233. }
  234. </script>
  235. <style type="text/css">
  236. .AutoNewline
  237. {
  238. Word-break: break-all;/*必须*/
  239. }
  240. </style>
  241. </head>
  242. <body>
  243. <div class="wrapper wrapper-content">
  244. <div class="panel panel-primary">
  245. <div class="panel-heading">
  246. <h3 class="panel-title">接口列表</h3>
  247. </div>
  248. <div class="panel-body">
  249. <!-- 搜索 -->
  250. <div id="search-collapse" class="collapse">
  251. <div class="accordion-inner">
  252. <form:form id="searchForm" modelAttribute="testInterface" class="form form-horizontal well clearfix">
  253. <div class="col-xs-12 col-sm-6 col-md-4">
  254. <label class="label-item single-overflow pull-left" title="接口名称">接口名称:</label>
  255. <form:input path="name" htmlEscape="false" maxlength="1024" class=" form-control"/>
  256. </div>
  257. <div class="col-xs-12 col-sm-6 col-md-4">
  258. <label class="label-item single-overflow pull-left" title="接口类型">接口类型:</label>
  259. <form:select path="type" class="form-control m-b">
  260. <form:option value="" label=""/>
  261. <form:options items="${fns:getDictList('interface_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
  262. </form:select>
  263. </div>
  264. <div class="col-xs-12 col-sm-6 col-md-4">
  265. <div style="margin-top:26px">
  266. <a id="search" class="btn btn-primary btn-rounded btn-bordered btn-sm"><i class="fa fa-search"></i> 查询</a>
  267. <a id="reset" class="btn btn-primary btn-rounded btn-bordered btn-sm" ><i class="fa fa-refresh"></i> 重置</a>
  268. </div>
  269. </div>
  270. </form:form>
  271. </div>
  272. </div>
  273. <!-- 工具栏 -->
  274. <div id="toolbar">
  275. <shiro:hasPermission name="tools:testInterface:add">
  276. <a id="add" class="btn btn-primary" href="${ctx}/tools/testInterface/form"><i class="glyphicon glyphicon-plus"></i> 新建</a>
  277. </shiro:hasPermission>
  278. <shiro:hasPermission name="tools:testInterface:edit">
  279. <button id="edit" class="btn btn-success" disabled onclick="edit()">
  280. <i class="glyphicon glyphicon-edit"></i> 修改
  281. </button>
  282. </shiro:hasPermission>
  283. <shiro:hasPermission name="tools:testInterface:del">
  284. <button id="remove" class="btn btn-danger" disabled onclick="deleteAll()">
  285. <i class="glyphicon glyphicon-remove"></i> 删除
  286. </button>
  287. </shiro:hasPermission>
  288. <button class="btn btn-info " onclick="test()"><i class="fa fa-check"></i> 测试</button>
  289. </div>
  290. <!-- 表格 -->
  291. <table id="table" data-toolbar="#toolbar" style="word-break:break-all; word-wrap:break-all;"></table>
  292. <!-- context menu -->
  293. <ul id="context-menu" class="dropdown-menu">
  294. <shiro:hasPermission name="tools:testInterface:edit">
  295. <li data-item="edit"><a>编辑</a></li>
  296. </shiro:hasPermission>
  297. <shiro:hasPermission name="tools:testInterface:del">
  298. <li data-item="delete"><a>删除</a></li>
  299. </shiro:hasPermission>
  300. <li data-item="action"><a>取消</a></li>
  301. </ul>
  302. </div>
  303. </div>
  304. </div>
  305. </body>
  306. </html>