<!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 onload="InitParams({{.Username}}, {{.Operate}})">
    <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="username" type="text" />

          操作:<input id="operate" type="text" />
          <br>
          <br>
          开始时间:<input type="date" id="start_time" name="trip-start" value={{.Start_time}} min="2018-01-01 00:00:00" max="2018-12-31 00:00:00" />
              
          结束时间:<input type="date" id="end_time" name="trip-start" value={{.End_time}} min="2018-01-01 23:59:59" max="2018-12-31 23:59:59" />
          <br>
          <br>
          <input class="layui-btn" type="button" onclick="submitUpdate()" value=查询>
        </blockquote>
    </div>
    <table border="1">
      <thead>
        <th style="width:64px;">ID</th>
        <th style="width:128px;">用户名</th>
        <th style="width:256px;">时间</th>
        <th style="width:128px;">操作</th>
        <th style="width:256px;">消息内容</th>
      </thead>
      <tbody>
        {{range .logs}}
          <tr>
            <td style = "text-align:center;">{{.Id}}</td>
            <td style = "text-align:center;">{{.Name}}</td>
            <td style = "text-align:center;">{{TimeToStr .Time}}</td>
            <td style = "text-align:center;">{{.Operate}}</td>
            <td style = "text-align:center;word-wrap:break-word;word-break:break-all;">{{.Data}}</td>
          </tr>
        {{end}}
      </tbody>
    </table>
    <script language="JavaScript">
      function InitParams(Username, Operate) {
        if (Username != null && Username.length > 0) {
            document.getElementById("username").value = Username;
        }
        if (Operate != null && Operate.length > 0) {
            document.getElementById("operate").value = Operate;
        }
      }
    
      function submitUpdate () {
        var token = document.getElementById("token").value;
        var username = document.getElementById("username").value;
        var start_time = document.getElementById("start_time").value;
        var end_time = document.getElementById("end_time").value;
        var operate = document.getElementById("operate").value;

        var text = "token=" + encodeURI(token);
        text += "&username=" + encodeURI(username);
        text += "&start_time=" + encodeURI(start_time);
        text += "&end_time=" + encodeURI(end_time);
        text += "&operate=" + encodeURI(operate);
        text += "&action=query"
        
        $.ajax({
          type:"get",
          url:"/log?" + text,
          success:function (data) {
            // alert(data.status);
            if (data.status){
              window.location.href="/log?"+text;
              if (data.info){
                layer.msg(data.info,{icon:1,time:1000});
              }
            }else{
              if (data.info){
                alert(data.info);
              }else{
                window.location.href="/log?"+text;
              }
            }
          }
        });
      }
      function submitDownload () {
        var token = document.getElementById("token").value;
        var username = document.getElementById("username").value;
        var start_time = document.getElementById("start_time").value;
        var end_time = document.getElementById("end_time").value;
        var operate = document.getElementById("operate").value;

        var text = "token=" + encodeURI(token);
        text += "&username=" + encodeURI(username);
        text += "&start_time=" + encodeURI(start_time);
        text += "&end_time=" + encodeURI(end_time);
        text += "&operate=" + encodeURI(operate);
        text += "&querydata=" + encodeURI(log);
        
        $.ajax({
          type:"get",
          url:"/log?" + text,
          success:function (data) {
            // alert(data.status);
            if (data.status){
              window.location.href="/log?"+text;
              if (data.info){
                layer.msg(data.info,{icon:1,time:1000});
              }
            }else{
              if (data.info){
                alert(data.info);
              }else{
                window.location.href="/log?"+text;
              }
            }
          }
        });
      }
    </script>
    </body>
</html>