<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>欢迎页面-X-admin2.0</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" href="./static/css/font.css">
        <link rel="stylesheet" href="./static/css/xadmin.css">
        
        <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
        <script src="./static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./static/js/xadmin.js"></script>
    </head>
    <body>
    <input type="text" id="token" value={{.token}} hidden=true>
    <div class="x-body layui-anim layui-anim-up">
        <blockquote class="layui-elem-quote">
    <input id="ip" name="ip" placeholder="IP"  type="text" lay-verify="required" class="layui-input">
    <br>
    <input class="layui-btn" type="button" onclick="addBanIP()" value=新增>
        </blockquote>
    </div>
    <table class="radio-table" border="1">
      <thead>
        <th style="width:128px;">IP</th>
        <th style="width:128px;">操作</th>
      </thead>
      <tbody>
        {{range .ipList}}
          <tr>
            <td style = "text-align:center;">{{.IP}}</td>
            <td style = "text-align:center;">
              <input class="layui-btn" type="button" onclick="submitDelete({{.IP}})" value=删除>
            </td>
          </tr>
        {{end}}
      </tbody>
    </table>
    <script language="JavaScript">
      function addBanIP () {
        var token = document.getElementById("token").value;
        var ip = document.getElementById("ip").value;

        var text = "token=" + encodeURI(token);
        text += "&ip=" + encodeURI(ip);
        
        $.ajax({
          type:"post",
          url:"/banip?" + text,
          success:function (data) {
            // alert(data.status);
            if (data.status){
              window.location.href="/banip";
              if (data.info){
                layer.msg(data.info,{icon:1,time:1000});
              }
            }else{
              if (data.info){
                alert(data.info);
              }else{
                window.location.href="/accountlogin";
              }
            }
          }
        });
      }
      
      function submitDelete(ip) {
        var token = document.getElementById("token").value;
        
        var text = "token=" + encodeURI(token);
        text += "&ip=" + encodeURI(ip);
        
        $.ajax({
          type:"delete",
          url:"/banip?" + text,
          success:function (data) {
            // alert(data.status);
            if (data.status){
              window.location.href="/banip";
              if (data.info){
                layer.msg(data.info,{icon:1,time:1000});
              }
            }else{
              if (data.info){
                alert(data.info);
              }else{
                window.location.href="/accountlogin";
              }
            }
          }
        });
      }
    </script>
    </body>
</html>