<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>网站设置</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/admin/res/layui/css/layui.css" media="all">
<link rel="stylesheet" href="/admin/res/adminui/dist/css/admin.css"
  media="all">
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">网站设置</div>
          <div class="layui-card-body" pad15>

            <div class="layui-form" wid100 lay-filter="">
              <div class="layui-form-item">
                <label class="layui-form-label">Tushare Token</label>
                <div class="layui-input-block">
                  <input type="text" name="tushareToken"
                    th:value="${@systemConfig.tushareToken}"
                    placeholder="Name" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">代理类型</label>
                <div class="layui-input-block">
                  <select name="proxyType" lay-filter="proxyType">
                    <option value="DIRECT"
                      th:selected="${@systemConfig.proxyType == ProxyTypeEnum.DIRECT}">无</option>
                    <option value="HTTP"
                      th:selected="${@systemConfig.proxyType == ProxyTypeEnum.HTTP}">Http(s)</option>
                    <option value="SOCKS"
                      th:selected="${@systemConfig.proxyType == ProxyTypeEnum.SOCKS}">Socks</option>
                  </select>
                </div>
              </div>


              <div class="layui-form-item">
                <label class="layui-form-label">代理地址</label>
                <div class="layui-input-block">
                  <input class="layui-input" autocomplete="off"
                    th:value="${@systemConfig.proxyHost}"
                    name="proxyHost" />
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">代理端口</label>
                <div class="layui-input-block">
                  <input class="layui-input" autocomplete="off"
                    type="number" min="1" max="65535"
                    th:value="${@systemConfig.proxyPort}"
                    name="proxyPort" lay-verify="number|gt:0|le:65535" />
                </div>
              </div>

              <div class="layui-form-item">
                <label class="layui-form-label">忽略 HTTPS 证书校验<span>*</span></label>
                <div class="layui-input-block">
                  <input type="checkbox" lay-skin="switch"
                    lay-text="ON|OFF" lay-filter="isAnonymous"
                    th:value="${@systemConfig.ignoreHttpsVerification}"
                    th:checked="${@systemConfig.ignoreHttpsVerification}"
                    name="ignoreHttpsVerification" lay-verify="required" />
                </div>
                <div class="layui-form-mid layui-word-aux">
                  出于安全考虑，当且仅当使用 Fiddler/BurpSuite 调试时才建议启用</div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-block">
                  <button class="layui-btn" lay-submit
                    lay-filter="set_website">确认保存</button>
                </div>
              </div>
            </div>

          </div>
        </div>
      </div>
    </div>
  </div>

  <script src="/admin/res/layui/layui.js"></script>
  <script>
  layui.config({
    base: '/admin/res/' // 静态资源所在路径
  }).use(['index'], function() {
    
    let form = layui.form, layer = layui.layer, $ = layui.$;
    
    document.querySelectorAll('[lay-skin="switch"]').forEach(check => {
        form.on(`switch(${check.getAttribute('lay-filter')})`, (data) => {
            var el = data.elem;
            el.value = !!el.checked;
        });
    })
    
  form.on('submit', function (res) {
    console.log(res);
    $.ajax({
      url: location.href,
      method: 'POST',
      contentType: 'application/json',
      data: JSON.stringify(res.field),
      success: function (res) {
        layer.msg('操作成功');
      },
      error: function (res) {
        layer.msg(res.message || '操作失败');
      }
    })
  })
  });
  </script>
</body>
</html>