<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>访问令牌管理</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header">
                <span>访问令牌管理</span>
                <button class="layui-btn layui-btn-sm layui-btn-normal" id="create-token">
                    <i class="layui-icon">&#xe654;</i> 创建令牌
                </button>
            </div>
            <div class="layui-card-body">
                <!-- 搜索表单 -->
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">设备UID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="device_uid" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">令牌类型</label>
                            <div class="layui-input-inline">
                                <select name="token_type">
                                    <option value="">全部</option>
                                    <option value="api">API</option>
                                    <option value="device">设备</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                                <select name="status">
                                    <option value="">全部</option>
                                    <option value="active">有效</option>
                                    <option value="revoked">已撤销</option>
                                    <option value="expired">已过期</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn" lay-submit lay-filter="search">
                                <i class="layui-icon">&#xe615;</i> 搜索
                            </button>
                        </div>
                    </div>
                </form>

                <!-- 数据表格 -->
                <table id="token-table" lay-filter="token-table"></table>
            </div>
        </div>
    </div>

    <!-- 表格工具栏模板 -->
    <script type="text/html" id="tableToolbar">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="refresh">
                <i class="layui-icon">&#xe669;</i> 刷新
            </button>
            <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchRevoke">
                <i class="layui-icon">&#xe640;</i> 批量撤销
            </button>
        </div>
    </script>

    <!-- 行工具栏模板 -->
    <script type="text/html" id="tableRowBar">
        <a class="layui-btn layui-btn-xs" lay-event="view">查看</a>
        <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="logs">日志</a>
        [[# if(d.status === 'active'){ ]]
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="revoke">撤销</a>
        [[# } ]]
    </script>

    <!-- 创建令牌表单模板 -->
    <script type="text/html" id="createTokenTpl">
        <form class="layui-form" style="padding: 20px;" lay-filter="tokenForm">
            <div class="layui-form-item">
                <label class="layui-form-label">设备UID</label>
                <div class="layui-input-block">
                    <select name="device_uid" lay-verify="required" lay-search>
                        <option value="">请选择设备</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">令牌类型</label>
                <div class="layui-input-block">
                    <select name="token_type" lay-verify="required">
                        <option value="api">API</option>
                        <option value="device">设备</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">有效期</label>
                <div class="layui-input-block">
                    <input type="number" name="expire_days" required lay-verify="required|number" 
                        placeholder="请输入有效期天数" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">IP限制</label>
                <div class="layui-input-block">
                    <textarea name="ip_list" placeholder="请输入允许访问的IP地址，多个IP用逗号分隔" 
                        class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="tokenSubmit">创建</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </script>

    <script src="/static/layui/layui.js"></script>
    <script src="/static/js/tokens.js"></script>
</body>
</html> 