list.html 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <div class="layui-layout layui-layout-admin" style="padding-left: 20px;">
  2. <div class="layui-row" style="margin-top: 20px;">
  3. <div class="layui-col-xs6">
  4. <div class="layui-btn-group">
  5. <button class="layui-btn" id="add_api">增加</button>
  6. <button class="layui-btn" id="add_audit">提交审核</button>
  7. <button class="layui-btn" id="audit">审核通过</button>
  8. </div>
  9. <!-- <a class="layui-btn" data-type="tabAdd" href="/api/add">新增</a> -->
  10. <!-- <a href="javascript:;" id="add_api" class="layui-btn"> 新增接口 </a>
  11. <a href="javascript:;" id="add_audit" class="layui-btn layui-btn-primary"> 提交审核 </a> -->
  12. </div>
  13. <div class="layui-col-xs6 search_text">
  14. <form class="layui-form" action="" onsubmit="javascript:return false;">
  15. <div class="demoTable">
  16. <div class="layui-inline" style="width: 40%">
  17. <input class="layui-input" name="apiName" id="apiName" autocomplete="off" placeholder="接口名称" >
  18. </div>
  19. <div class="layui-inline" style="width: 20%;text-align: left;">
  20. <select name="status" id="status" lay-verify="required" lay-search="">
  21. <option value="-1">全部状态</option>
  22. {{range $index,$elem := .auditStatus}}
  23. <option value="{{$index}}"> {{$elem}}</option>
  24. {{end}}
  25. </select>
  26. </div>
  27. <button class="layui-btn" data-type="reload" id="reload">查询</button>
  28. </div>
  29. </form>
  30. </div>
  31. {{/*<div class="col-5 f-l text text-r">背景图(必须):</div>*/}}
  32. {{/*<div class="img-box">*/}}
  33. {{/*<label>*/}}
  34. {{/*<span class="copy-btn Hui-iconfont">&#xe679;</span>*/}}
  35. {{/*<input type="file" class="up-file">*/}}
  36. {{/*</label>*/}}
  37. {{/*</div>*/}}
  38. {{/*<div class="img-file col-offset-5">*/}}
  39. {{/*<img src="" id="img1"/>*/}}
  40. {{/*<input type="button" id="add1" value="add" >*/}}
  41. {{/*</div>*/}}
  42. </div>
  43. <table class="layui-hide" id="table_list" lay-filter="table_filter">
  44. </table>
  45. <script type="text/html" id="bar">
  46. <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详细</a>
  47. <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  48. <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="audit">审核</a>
  49. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">启|停</a>
  50. </script>
  51. </div>
  52. <script>
  53. layui.use(['table','form','element'], function(){
  54. var table = layui.table;
  55. var form = layui.form;
  56. var element = layui.element;
  57. //方法级渲染
  58. table.render({
  59. elem: '#table_list'
  60. ,url: '/api/table'
  61. ,cols: [[
  62. {checkbox: true, fixed: true},
  63. {field:'id', title: 'ID', align:'center',sort: true, width:50}
  64. ,{field:'api_name',title: '接口名称'}
  65. ,{field:'api_url',title: '接口地址'}
  66. ,{field:'method',title: '请求方式'}
  67. ,{field:'source_name',title: '所属资源'}
  68. ,{field:'status_text',title: '接口状态'}
  69. ,{field:'create_time', title: '创建时间'}
  70. ,{field:'update_time', title: '修改时间'}
  71. ,{fixed: 'right', width:260, align:'center', toolbar: '#bar'}
  72. ]]
  73. ,id: 'listReload'
  74. ,page: true
  75. ,height: "full-130"
  76. });
  77. var $ = layui.$, active = {
  78. reload: function(){
  79. table.reload('listReload', {
  80. where: {
  81. apiName: $('#apiName').val(),
  82. status:$("#status").val()
  83. }
  84. });
  85. }
  86. };
  87. // //读取图片
  88. // function loadImg(){
  89. // //获取文件
  90. // var file = $(".up-file")[0].files[0];
  91. // //创建读取文件的对象
  92. // var reader = new FileReader();
  93. // //创建文件读取相关的变量
  94. // var imgFile;
  95. // //为文件读取成功设置事件
  96. // reader.onload=function(e) {
  97. // var e=window.event||e;
  98. // imgFile = e.target.result;
  99. // console.log(imgFile);
  100. // $('#img1').attr("src",imgFile)
  101. //
  102. // };
  103. //
  104. // //正式读取文件
  105. // reader.readAsDataURL(file);
  106. //
  107. // }
  108. //
  109. //
  110. // function addData(){
  111. // loadImg()
  112. // var url=$('#img1').attr("src")
  113. // var data1={"name":"url","value":url};
  114. // $.ajax({
  115. // url:"/uploadimg",
  116. // data:data1,
  117. // type:"post",
  118. // ContentType:"application/json",
  119. // success:function(resp){
  120. //
  121. // }
  122. // });
  123. // }
  124. //
  125. // $("#add1").on("click",function() {
  126. // addData()
  127. // })
  128. $("#add_api").on("click",function() {
  129. window.location.href="/api/add"
  130. })
  131. //提交审核
  132. $("#add_audit").on("click",function() {
  133. var checkStatus = table.checkStatus('listReload');
  134. var ids = "";
  135. $.each(checkStatus["data"],function(k,v){
  136. if (v.status==1) {
  137. ids += v.id+",";
  138. }
  139. })
  140. ids = (ids.substring(ids.length-1)==',')?ids.substring(0,ids.length-1):ids;
  141. if (!ids) {
  142. layer.msg("请选择状态为正在开发的数据")
  143. return false;
  144. }
  145. layer.confirm("确定要选中的接口提交审核吗?", function(){
  146. var add_audit_data = {"ids":ids,"status":1}
  147. $.post('{{urlfor "ApiController.AjaxChangeStatus"}}', add_audit_data, function (out) {
  148. if (out.status == 0) {
  149. layer.msg("操作成功",{icon: 1},function () {
  150. $("#reload").click();
  151. })
  152. } else {
  153. layer.msg(out.message)
  154. }
  155. }, "json");
  156. return false;
  157. });
  158. })
  159. //批量审核
  160. $("#audit").on("click",function() {
  161. var checkStatus = table.checkStatus('listReload');
  162. var ids = "";
  163. $.each(checkStatus["data"],function(k,v){
  164. if (v.status==2) {
  165. ids += v.id+",";
  166. }
  167. })
  168. ids = (ids.substring(ids.length-1)==',')?ids.substring(0,ids.length-1):ids;
  169. if (!ids) {
  170. layer.msg("请选择状态为正在审核的数据")
  171. return false;
  172. }
  173. layer.confirm("确定要选中的接口审核通过吗?", function(){
  174. var add_audit_data = {"ids":ids,"status":3}
  175. $.post('{{urlfor "ApiController.AjaxChangeStatus"}}', add_audit_data, function (out) {
  176. if (out.status == 0) {
  177. layer.msg("操作成功",{icon: 1},function () {
  178. $("#reload").click();
  179. })
  180. } else {
  181. layer.msg(out.message)
  182. }
  183. }, "json");
  184. return false;
  185. });
  186. })
  187. //监听工具条
  188. table.on('tool(table_filter)', function(obj){
  189. var data = obj.data;
  190. if(obj.event === 'edit'){
  191. window.location.href="/api/edit?id="+data.id
  192. } else if(obj.event === 'del'){
  193. var msg = "";
  194. if(data.status==0){
  195. msg = '真的启用【'+data.api_name+'】么';
  196. }else{
  197. msg = '真的停用【'+data.api_name+'】么';
  198. }
  199. layer.confirm(msg, function(){
  200. var del_data = {"id":data.id}
  201. $.post('{{urlfor "ApiController.AjaxDel"}}', del_data, function (out) {
  202. if (out.status == 0) {
  203. layer.msg("操作成功",{icon: 1},function () {
  204. $("#reload").click();
  205. })
  206. } else {
  207. layer.msg(out.message)
  208. }
  209. }, "json");
  210. return false;
  211. });
  212. return false;
  213. }else if(obj.event === 'detail'){
  214. window.location.href="/api/detail?id="+data.id
  215. }else if(obj.event === 'audit'){
  216. window.location.href="/api/audit?id="+data.id
  217. }else{
  218. layer.msg('操作不存在');
  219. }
  220. });
  221. $('.demoTable .layui-btn').on('click', function(){
  222. var type = $(this).data('type');
  223. active[type] ? active[type].call(this) : '';
  224. });
  225. });
  226. </script>