forwardList.1.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <div class="layui-tab layui-tab-card">
  2. <ul class="layui-tab-title">
  3. <li class="layui-this">端口转发列表</li>
  4. <li>帮助说明</li>
  5. </ul>
  6. <div class="layui-tab-content" style="height: auto;">
  7. <div class="layui-tab-item layui-show">
  8. <button class="layui-btn layui-btn-small" onclick="addForward();"><i class="layui-icon"></i> 添加转发</button>
  9. <button class="layui-btn layui-btn-small" onclick="delForward();"><i class="layui-icon"></i> 批量删除</button>
  10. <div class="layui-form">
  11. <table class="layui-table">
  12. <colgroup>
  13. <col width="20">
  14. <col width="50">
  15. <col width="300">
  16. <col width="150">
  17. <col width="120">
  18. <col width="50">
  19. <col width="150">
  20. <col width="100">
  21. <col width="70">
  22. <col width="200">
  23. </colgroup>
  24. <thead>
  25. <tr>
  26. <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
  27. <th>ID</th>
  28. <th>名称</th>
  29. <th>本地监听地址</th>
  30. <th>本地监听端口</th>
  31. <th>协议</th>
  32. <th>转发到地址</th>
  33. <th>转发到端口</th>
  34. <th>状态</th>
  35. <th>操作</th>
  36. </tr>
  37. </thead>
  38. <tbody id="gridBody">
  39. </tbody>
  40. </table>
  41. </div>
  42. <div id="pagination"></div>
  43. </div>
  44. <div class="layui-tab-item">
  45. <pre class="layui-code">
  46. 说明文档请访问:<a href="https://github.com/tavenli/port-forward" target="_blank">https://github.com/tavenli/port-forward</a>
  47. 欢迎大家就使用问题或个性化需求在QQ群中讨论,QQ群号:99134862
  48. </pre>
  49. </div>
  50. </div>
  51. </div>
  52. <script id="grid_tpl" type="text/html">
  53. {Start{# if(d.Data === null || d.Data.length === 0){ }End}
  54. <tr>
  55. <td colspan="10">
  56. 请先添加一条端口转发配置规则
  57. </td>
  58. </tr>
  59. {Start{# } else { }End} {Start{# for(var i=0, len = d.Data.length; i<len;i++){ }End} <tr>
  60. <td><input type="checkbox" name="id" lay-skin="primary" value="{Start{ d.Data[i].Id }End}"></td>
  61. <td>{Start{ d.Data[i].Id }End}</td>
  62. <td>{Start{ d.Data[i].Name }End}</td>
  63. <td>{Start{ fmtAddr(d.Data[i].Addr,d.Data[i]) }End}</td>
  64. <td>{Start{ d.Data[i].Port }End}</td>
  65. <td>{Start{ d.Data[i].Protocol }End}</td>
  66. <td>{Start{ d.Data[i].TargetAddr }End}</td>
  67. <td>{Start{ d.Data[i].TargetPort }End}</td>
  68. <td>{Start{ fmtStatus(d.Data[i].Status,d.Data[i]) }End}</td>
  69. <td>
  70. {Start{ oprFormatLink(d.Data[i].Status,d.Data[i]) }End}
  71. </td>
  72. </tr>
  73. {Start{# } }End} {Start{# } }End}
  74. </script>
  75. <script type="text/javascript">
  76. $(document).ready(function () {
  77. layui.use(["jquery", "layer", "form", "element", "laytpl", "laypage"], function () {
  78. var $ = layui.jquery, layer = layui.layer, form = layui.form, laytpl = layui.laytpl, laypage = layui.laypage;
  79. //全选
  80. form.on('checkbox(allChoose)', function (data) {
  81. var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
  82. child.each(function (index, item) {
  83. item.checked = data.elem.checked;
  84. });
  85. form.render('checkbox');
  86. });
  87. layui.laytpl.config({ open: "{Start{", close: "}End}" });
  88. query(1);
  89. });
  90. });
  91. function query(pIndex) {
  92. // var columnFiled = $("#columnFiled").val();
  93. // var keyWord = $("#keyWord").val();
  94. $.post("ForwardList/json", { pIndex: pIndex, pSize: 10 }, function (json) {
  95. if (json.Code == 0) {//成功
  96. renderGrid(json.Data);
  97. var totalPages = json.Data.Pages;
  98. var totalRows = json.Data.TotalRows;
  99. //显示分页
  100. layui.laypage({
  101. cont: 'pagination', //容器
  102. pages: totalPages, //通过后台拿到的总页数
  103. total: totalRows,
  104. groups: 5, //连续分页数
  105. skin: "#51b921", //控制分页皮肤。目前支持:molv、yahei、flow 除此之外,还支持16进制颜色值,如:skin:'#c00'
  106. curr: pIndex || 1, //当前页
  107. skip: true,
  108. jump: function (obj, first) { //触发分页后的回调
  109. if (!first) { //点击跳页触发函数自身,并传递当前页:obj.curr
  110. query(obj.curr);
  111. }
  112. }
  113. });
  114. layui.form.render('checkbox');
  115. } else {//失败
  116. layui.layer.alert("失败:" + json.Msg, { icon: 2 });
  117. }
  118. }, 'json');
  119. }
  120. function renderGrid(data) {
  121. var grid_tpl = document.getElementById('grid_tpl').innerHTML;
  122. layui.laytpl(grid_tpl).render(data, function (html) {
  123. $("#gridBody").html(html);
  124. });
  125. }
  126. function oprFormatLink(val, row) {
  127. var html = "";
  128. if (row.Status == 1) {
  129. html += "<button class='layui-btn layui-btn-small layui-btn-danger' onclick='CloseForward(" + row.Id + ");'><i class='layui-icon'></i></button>";
  130. } else {
  131. html += "<button class='layui-btn layui-btn-small layui-btn-normal' onclick='OpenForward(" + row.Id + ");'><i class='layui-icon'></i></button>";
  132. }
  133. html += "<button class='layui-btn layui-btn-small' onclick='editForward(" + row.Id + ");'><i class='layui-icon'></i></button>";
  134. return html;
  135. }
  136. function fmtAddr(val, row) {
  137. if (val == "") {
  138. return "监听所有地址";
  139. } else {
  140. return val;
  141. }
  142. }
  143. function fmtStatus(val, row) {
  144. var html = "";
  145. switch (val) {
  146. case 0:
  147. html = "<font color='red'>停止</font>";
  148. break;
  149. case 1:
  150. html = "<font color='green'>转发中</font>";
  151. break;
  152. default:
  153. html = "<font color='gray'>其它:" + val + "</font>";
  154. break;
  155. }
  156. return html;
  157. }
  158. function addForward() {
  159. $.get('/u/AddForward', { rnd: Math.random() }, function (html) {
  160. layer.open({
  161. type: 1, //page层
  162. area: ['400px', '450px'],
  163. title: '添加网络转发端口',
  164. shade: 0.6, //遮罩透明度
  165. moveType: 1, //拖拽风格,0是默认,1是传统拖动
  166. shift: -1, //0-6的动画形式,-1不开启
  167. maxmin: false,
  168. content: html,
  169. btn: ['保存配置', '取消'],
  170. yes: function (index, layero) {
  171. submitForm(index);
  172. },
  173. btn2: function (index) {
  174. layer.close(index);
  175. },
  176. cancel: function (index) {
  177. layer.close(index);
  178. }
  179. });
  180. });
  181. }
  182. function editForward(id) {
  183. $.get('/u/EditForward', { rnd: Math.random(), id: id }, function (html) {
  184. layer.open({
  185. type: 1, //page层
  186. area: ['600px', '550px'],
  187. title: '编辑网络转发端口',
  188. shade: 0.6, //遮罩透明度
  189. moveType: 1, //拖拽风格,0是默认,1是传统拖动
  190. shift: -1, //0-6的动画形式,-1不开启
  191. maxmin: false,
  192. content: html,
  193. btn: ['保存配置', '取消'],
  194. yes: function (index, layero) {
  195. submitForm(index);
  196. },
  197. btn2: function (index) {
  198. layer.close(index);
  199. },
  200. cancel: function (index) {
  201. layer.close(index);
  202. }
  203. });
  204. });
  205. }
  206. function delForward() {
  207. var selectedItems = getChkValues("id");
  208. if (selectedItems.length == 0) {
  209. layer.alert("没有勾选要批量操作的数据.", { icon: 3, title: "警告信息" });
  210. return;
  211. }
  212. var ids = selectedItems.join(',');
  213. layer.confirm("确定批量删除勾选的数据吗?", {
  214. btn: ['确定', '取消']//按钮
  215. }, function (index, layero) {
  216. $.post("/u/DelForward", { rnd: Math.random(), ids: ids }, function (json) {
  217. if (json.Code == 0) {//成功
  218. layer.msg("执行成功.");
  219. query(1);
  220. } else {//失败
  221. layer.alert(json.Msg, { icon: 2 });
  222. query(1);
  223. }
  224. }, 'json');
  225. });
  226. }
  227. function refreshGrid() {
  228. query(1);
  229. }
  230. function OpenForward(id) {
  231. layer.confirm("确定启动该转发吗?", {
  232. btn: ['确定', '取消']//按钮
  233. }, function (index, layero) {
  234. $.post("/u/OpenForward", { rnd: Math.random(), id: id }, function (json) {
  235. if (json.Code == 0) {//成功
  236. layer.msg("执行成功.");
  237. query(1);
  238. } else {//失败
  239. layer.alert(json.Msg, { icon: 2 });
  240. query(1);
  241. }
  242. }, 'json');
  243. });
  244. }
  245. function CloseForward(id) {
  246. layer.confirm("确定停止该转发吗?", {
  247. btn: ['确定', '取消']//按钮
  248. }, function (index, layero) {
  249. $.post("/u/CloseForward", { rnd: Math.random(), id: id }, function (json) {
  250. if (json.Code == 0) {//成功
  251. layer.msg("执行成功.");
  252. query(1);
  253. } else {//失败
  254. layer.alert(json.Msg, { icon: 2 });
  255. query(1);
  256. }
  257. }, 'json');
  258. });
  259. }
  260. </script>
粤ICP备19079148号