<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<link href="bootstrap/js/jquery-confirm/jquery-confirm.min.css" rel="stylesheet">
<link href="bootstrap/css/materialdesignicons.min.css" rel="stylesheet">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="bootstrap/css/style.min.css" rel="stylesheet">
</head>
  
<body>
<div class="container-fluid p-t-15">
  <div class="row">
    <div class="col-lg-6">
      <div class="card">
        <header class="card-header"><div class="card-title">初始化</div></header>
        <div class="card-body">
          <div class="callout callout-warning mb-3">注意：请在 <code>Mac</code> 或 <code>Linux</code> 环境执行。</div>
          <p>初始化项目所需信息：</p>
          <p><i class="mdi mdi-checkbox-marked-circle"></i> <span>MySQL 数据表：<code>user_demo</code> ；</span></p>
          <p><i class="mdi mdi-checkbox-marked-circle"></i> <span>MySQL 数据表：<code>authorized</code> ；</span></p>
          <p><i class="mdi mdi-checkbox-marked-circle"></i> <span>MySQL 数据表：<code>authorized_api</code> ；</span></p>
          <p><i class="mdi mdi-checkbox-marked-circle"></i> <span>MySQL 数据表：<code>admin</code> ；</span></p>
          <p>
            <button type="button" id="btnOk" class="btn btn-primary">确认</button>
            <button type="button" id="btnLoading" class="btn btn-primary" disabled style="display: none">
              <span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
              执行中...
            </button>
          </p>
        </div>
      </div>
    </div>

    <div class="col-lg-6">
      <div class="card">
        <header class="card-header"><div class="card-title">执行结果</div></header>
        <div class="card-body">
          <pre id="resultDiv"></pre>
        </div>
      </div>
    </div>

  </div>
</div>

<script type="text/javascript" src="bootstrap/js/jquery.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="bootstrap/js/jquery-confirm/jquery-confirm.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    $("#btnOk").click(function(){

      $("#resultDiv").text("");
      $(this).hide();
      $("#btnLoading").show();

      $.post("/init_exec","",function (data) {
        $("#resultDiv").text(data);
        $("#btnLoading").hide();
        $("#btnOk").show();

        if (getQueryString("init")) {
          $.alert({
            title: '操作成功',
            icon: 'mdi mdi-check-decagram',
            type: 'green',
            content: '初始化完成。',
            buttons: {
              okay: {
                text: '系统首页',
                action: function () {
                  location.href = "/";
                }
              }
            }
          });
        }
      })

    });

    function getQueryString(name) {
      let reg = new RegExp('(?:(?:&|\\?)' + name + '=([^&]*))|(?:/' + name + '/([^/]*))', 'i');
      let r = window.location.href.match(reg);
      if (r != null)
        return decodeURI(r[1] || r[2]);
      return null;
    }
  })
</script>
</body>
</html>
