<title>客户端管理</title>
  
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>ucentre</cite></a>
    <a><cite>客户端管理</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <div style="padding-bottom: 10px;">
        <a href="#client_popup_tpl" class="layui-btn J_popup" title="添加客户端"><i class="layui-icon layui-icon-add-circle"></i>添加客户端</a>
      </div>
      
      <table id="J_table_list" lay-filter="J_table_list"></table>
    </div>
  </div>
</div>

<script type="text/html" id="J_table_tool">
  <a href="#client_popup_tpl" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="popup" title="编辑客户端"><i class="layui-icon layui-icon-edit"></i>编辑</a>
  <a href="ucentre/client/remove" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="req"title="确定要删除吗？"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>

<script type="text/html" id="status_tpl">
<span id="status-{{d.id}}"><i class="layui-icon layui-anim layui-anim-rotate layui-anim-loop">&#xe63d;</i></span>
{{#
        layui.admin.req({
          url: '{:url('ucentre/client/test')}'
          ,type: 'post'
          ,data: {id:d.id}
          ,done: function(res){
            
            var text = '<font color="#5FB878">正常</font>';
            if(res.code>0){
              text = '<font color="#FF5722">失败</font>';
            }
            layui.$('#status-'+d.id).html(text);
          }
        });
}}
</script>

<script>
;!function(){
  var $ = layui.$
  ,admin = layui.admin
  ,setter = layui.setter
  ,table = layui.table;

        //请求成功后，写入 access_token
        layui.data(setter.tableName, {
          key: setter.request.tokenName
          ,value: '{:token('csrf_token')}'
        });
        
  //执行渲染
table.render({
  elem: '#J_table_list'
  ,url: '{:url('ucentre/client/list')}'
  ,cols: [[
      {field:'id',title:'ID',width:80,align:'center',sort: true}
      ,{field:'name',title:'客户端名称',minWidth:120}
      ,{field:'url',title:'通讯地址',minWidth:150}
      ,{field:'secretkey',title:'通讯密钥',minWidth:200}
      ,{field:'status',title:'通讯状态',width:200,templet:'#status_tpl'}
      ,{title:'操作',width:150,align:'center',toolbar:'#J_table_tool'}
  ]]
  ,page: true
  ,limit: 20
  ,height: 'auto'
  ,text: {
    none: '对不起，加载出现异常！'
  }
});

}();
</script>

<script type="text/html" id="client_popup_tpl">
<form class="layui-form" lay-filter="J_ajaxForm_info" style="padding: 20px 0 0 0;" action="{:url('ucentre/client/post')}" method="post">
  <input type="hidden" name="id" value="{{ d.id || '' }}">
  
            <div class="layui-form-item">
              <label class="layui-form-label">客户端名称</label>
              <div class="layui-input-block">
                <input type="text" name="name" value="{{ d.name || '' }}" lay-verify="required" autocomplete="off" class="layui-input">
              </div>
            </div>

            <div class="layui-form-item">
              <label class="layui-form-label">客户端地址</label>
              <div class="layui-input-block">
                <input type="text" name="url" value="{{ d.url || '' }}" lay-verify="required|url" autocomplete="off" class="layui-input">
              </div>
            </div>
            
            <div class="layui-form-item">
              <label class="layui-form-label">通讯密钥</label>
              <div class="layui-input-block">
                <input type="text" name="secretkey" value="{{ d.secretkey || '' }}" lay-verify="required" autocomplete="off" class="layui-input">
              </div>
            </div>
 
             <div class="layui-form-item">
              <label class="layui-form-label">客户端接口文件</label>
              <div class="layui-input-block">
                <input type="text" name="apifile" value="{{ d.apifile || 'wendid.php' }}" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">为空默认为wendid.php</div>
            </div>
          
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="J_ajax_submit_btn"><i class="layui-icon layui-icon-ok-circle"></i>提交</button>
              </div>
            </div>
            
          </form>
</script>