list.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <div class="row">
  2. <div class="col-md-12">
  3. <div class="tile">
  4. <div class="tile-body">
  5. <table class="table table-hover table-bordered" id="sampleTable">
  6. <thead>
  7. <tr>
  8. <th>Id</th>
  9. <th>备注</th>
  10. <th>客户端Id</th>
  11. <th>监听端口</th>
  12. <th>内网目标</th>
  13. <th>压缩方式</th>
  14. <th>加密传输</th>
  15. <th>TCP多路复用</th>
  16. <th>用户名</th>
  17. <th>密码</th>
  18. <th>客户端状态</th>
  19. <th>状态</th>
  20. <th>出口流量</th>
  21. <th>入口流量</th>
  22. <th>操作</th>
  23. </tr>
  24. </thead>
  25. <tbody>
  26. </tbody>
  27. </table>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </main>
  33. <script type="text/javascript">
  34. function del(id) {
  35. if (confirm("确定要删除数据吗?")) {
  36. $.ajax({
  37. type: "POST",
  38. url: "/index/del",
  39. data: {"id": id},
  40. success: function (res) {
  41. alert(res.msg)
  42. if (res.status) {
  43. document.location.reload();
  44. }
  45. }
  46. })
  47. }
  48. }
  49. function start(id) {
  50. if (confirm("确定要开始任务吗?")) {
  51. $.ajax({
  52. type: "POST",
  53. url: "/index/start",
  54. data: {"id": id},
  55. success: function (res) {
  56. alert(res.msg)
  57. if (res.status) {
  58. document.location.reload();
  59. }
  60. }
  61. })
  62. }
  63. }
  64. function stop(id) {
  65. if (confirm("确定要暂停吗?")) {
  66. $.ajax({
  67. type: "POST",
  68. url: "/index/stop",
  69. data: {"id": id},
  70. success: function (res) {
  71. alert(res.msg)
  72. if (res.status) {
  73. document.location.reload();
  74. }
  75. }
  76. })
  77. }
  78. }
  79. function edit(id) {
  80. window.location.href = "/index/edit?id=" + id
  81. }
  82. function add() {
  83. window.location.href = "/index/add?type={{.type}}" + "&client_id={{.client_id}}"
  84. }
  85. $(document).ready(function () {
  86. var table = $('#sampleTable').DataTable({
  87. responsive: {
  88. details: {
  89. display: $.fn.dataTable.Responsive.display.childRowImmediate
  90. }
  91. },
  92. dom: 'Bfrtip',
  93. processing: true,
  94. serverSide: true,
  95. autoWidth: false,
  96. ordering: false,
  97. ajax: {
  98. url: '/index/gettunnel?type={{.type}}' + "&client_id=" +{{.client_id}},
  99. type: 'POST'
  100. },
  101. dom: '<"top"fl><"toolbar">rt<"bottom"ip><"clear">',
  102. columns: [ //这个是显示到界面上的个数据 格式为 {data:'显示的字段名'}
  103. {data: 'Id'},
  104. {data: 'Remark'},
  105. {data: 'ClientId'},
  106. {data: 'TcpPort'},
  107. {data: 'Target'},
  108. {data: 'Compress'},
  109. {data: 'Crypt'},
  110. {data: 'Mux'},
  111. {data: 'U'},
  112. {data: 'P'},
  113. {data: 'ClientStatus'},
  114. {data: 'Status'},
  115. {data: 'ExportFlow'},
  116. {data: 'InletFlow'},
  117. {data: "Id"}
  118. ],
  119. bFilter: false,
  120. columnDefs: [{
  121. targets: -1,
  122. render: function (data, type, row, meta) {
  123. if (row.Status == 1) {
  124. btn = "<button onclick=\"stop('" + row.Id + "')\" class=\"btn btn-secondary btn-sm\" type=\"button\">关闭</button>"
  125. } else {
  126. btn = "<button onclick=\"start('" + row.Id + "')\" class=\"btn btn-success btn-sm\" type=\"button\">打开</button>"
  127. }
  128. btn_edit = '<button onclick="edit(\'' + row.Id + '\')" type="button" class="btn btn-primary btn-sm">查看编辑</button> '
  129. return '<div class="btn-group" role="group" aria-label="..."> ' +
  130. '<button onclick="del(\'' + row.Id + '\')" type="button" class="btn btn-danger btn-sm">删除</button>' +
  131. btn_edit + btn + ' </div>'
  132. }
  133. }, {
  134. targets: 2,
  135. render: function (data, type, row, meta) {
  136. return row.Client.Id
  137. }
  138. }, {
  139. targets: 5,
  140. render: function (data, type, row, meta) {
  141. if (row.UseClientCnf == true) {
  142. return row.Client.Cnf.Compress
  143. } else {
  144. return row.Config.Compress
  145. }
  146. }
  147. }, {
  148. targets: 8,
  149. render: function (data, type, row, meta) {
  150. if (row.UseClientCnf == true) {
  151. return row.Client.Cnf.U
  152. } else {
  153. return row.Config.U
  154. }
  155. }
  156. }, {
  157. targets: 9,
  158. render: function (data, type, row, meta) {
  159. if (row.UseClientCnf == true) {
  160. return row.Client.Cnf.P
  161. } else {
  162. return row.Config.P
  163. }
  164. }
  165. },
  166. {
  167. targets: -4,
  168. render: function (data, type, row, meta) {
  169. if (data == false) {
  170. return "<span class=\"badge badge-pill badge-secondary\">暂停</span>"
  171. } else {
  172. return "<span class=\"badge badge-pill badge-success\">正常</span>"
  173. }
  174. }
  175. },
  176. {
  177. targets: -9,
  178. render: function (data, type, row, meta) {
  179. if (row.UseClientCnf == true) {
  180. crypt = row.Client.Cnf.Crypt
  181. } else {
  182. crypt = row.Config.Crypt
  183. }
  184. if (crypt == "0") {
  185. return "不加密"
  186. } else {
  187. return "加密"
  188. }
  189. }
  190. },
  191. {
  192. targets: -8,
  193. render: function (data, type, row, meta) {
  194. if (row.UseClientCnf == true) {
  195. mux = row.Client.Cnf.Mux
  196. } else {
  197. mux = row.Config.Mux
  198. }
  199. if (mux == "0") {
  200. return "不启用"
  201. } else {
  202. return "启用"
  203. }
  204. }
  205. },
  206. {
  207. targets: -5,
  208. render: function (data, type, row, meta) {
  209. if (row.Client.IsConnect == false) {
  210. return "<span class=\"badge badge-pill badge-secondary\">离线</span>"
  211. } else {
  212. return "<span class=\"badge badge-pill badge-success\">在线</span>"
  213. }
  214. }
  215. },
  216. {
  217. targets: -2,
  218. render: function (data, type, row, meta) {
  219. return change(row.Flow.InletFlow)
  220. }
  221. },
  222. {
  223. targets: -3,
  224. render: function (data, type, row, meta) {
  225. return change(row.Flow.ExportFlow)
  226. }
  227. }
  228. ],
  229. buttons: []
  230. });
  231. $("#sampleTable_length").html('<button class="btn btn-primary" onclick="add()" type="button">新增</button>')
  232. })
  233. ;
  234. </script>