<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('错外链监测列表')" />
</head>
<body class="gray-bg">
<style>
    .btn-nav {
        margin: 0 3px;  /* 减少左右边距 */
        padding: 4px 10px;  /* 减少内边距 */
        border-radius: 3px;
        font-size: 12px;  /* 缩小字体 */
        transition: all 0.2s;
        height: 26px;  /* 固定高度 */
        line-height: 18px;  /* 调整行高 */
    }
    .btn-nav i {
        margin-right: 3px;  /* 图标与文字间距缩小 */
        font-size: 12px;  /* 图标缩小 */
    }
    .dashboard-stat {
        align-items: center;  /* 垂直居中 */
    }
</style>
<script>
    function loadTab(tabType) {
        // 根据tabType加载不同内容
        if(tabType === 'weixin') {
            // 当前已经是微信，可以高亮按钮
            $('.btn-nav').removeClass('btn-primary').addClass('btn-default');
            $('.btn-nav:first').removeClass('btn-default').addClass('btn-primary');
            $('[name="sitetag"]').val('weixin');
            loadSites('weixin');
        } else if(tabType === 'weibo') {
            $('.btn-nav').removeClass('btn-primary').addClass('btn-default');
            $('.btn-nav:eq(1)').removeClass('btn-default').addClass('btn-primary');
            $('[name="sitetag"]').val('weibo');
            // 加载微博站点列表
            loadSites('weibo');
        } else if(tabType === 'dsp') {
            $('.btn-nav').removeClass('btn-primary').addClass('btn-default');
            $('.btn-nav:eq(2)').removeClass('btn-default').addClass('btn-primary');
            $('[name="sitetag"]').val('dsp');
            // 加载微博站点列表
            loadSites('dsp');
        } else if(tabType === 'toutiao') {
            $('.btn-nav').removeClass('btn-primary').addClass('btn-default');
            $('.btn-nav:eq(3)').removeClass('btn-default').addClass('btn-primary');
            $('[name="sitetag"]').val('toutiao');
            // 加载微博站点列表
            loadSites('toutiao');
        }
        // 自动触发搜索
        $.table.search();
        // 刷新统计数据
        //setTimeout(loadStatistics, 300);
    }

    // 页面加载时默认选中微信


    // 页面加载时默认选中微信并加载微信站点
    $(function() {
        $('.btn-nav:first').removeClass('btn-default').addClass('btn-primary');
        loadSites('weixin'); // 初始加载微信站点
    });
</script>

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <div class="dashboard-stat" style="justify-content: flex-start; height: 40px; padding: 0 10px;">
                <a class="btn btn-primary btn-nav" href="javascript:void(0)" onclick="loadTab('weixin')">
                    <i class="fa fa-weixin"></i> 微信监测
                </a>
                <a class="btn btn-default btn-nav" href="javascript:void(0)" onclick="loadTab('weibo')">
                    <i class="fa fa-globe"></i> 微博监测
                </a>
                <a class="btn btn-default btn-nav" href="javascript:void(0)" onclick="loadTab('dsp')">
                    <i class="fa fa-music"></i> 短视频监测
                </a>
                <a class="btn btn-default btn-nav" href="javascript:void(0)" onclick="loadTab('toutiao')">
                    <i class="fa fa-bolt"></i> 头条监测
                </a>
            </div>
        </div>
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" name="sitetag" value="weixin"/>
                    <div class="select-list">
                        <ul>
                            <!--<li>
                                <label>标识：</label>
                                <input type="text" name="record"/>
                            </li>-->
                            <li>
                                <label>站点名称：</label>
                                <select class="type" id="siteSelect" name="sitename" style="width: 200px;">
                                    <option value="">全部站点</option>
                                    <option th:each="site : ${sites}" th:value="${site.sitename}" th:text="${site.sitename}"></option>
                                </select>
                            </li>
                            <li>
                                <label>类型：</label>
                                <select name="type" th:with="type=${@dict.getType('trs_url_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>信息：</label>
                                <input type="text" name="msg"/>
                            </li>
                            <li class="select-time">
                                <label>扫描时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="project:wxurlresult:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="project:wxurlresult:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="project:wxurlresult:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="project:wxurlresult:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('project:wxurlresult:edit')}]];
        var removeFlag = [[${@permission.hasPermi('project:wxurlresult:remove')}]];
        var typeDatas = [[${@dict.getType('trs_url_type')}]];
        var prefix = ctx + "project/urlresult";
        // 加载站点列表函数
        function loadSites(type) {
            $.ajax({
                url: ctx + "project/wxurlresult/getSitesByType",
                type: "GET",
                data: { type: type },
                success: function(res) {
                    var select = $('#siteSelect');
                    select.empty(); // 清空现有选项
                    select.append('<option value="">全部站点</option>');

                    // 添加新选项
                    $.each(res.data, function(index, site) {
                        select.append('<option value="' + site.sitename + '">' + site.sitename + '</option>');
                    });
                }
            });
        }
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "错外链监测",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'record',
                    title: '标识'
                },
                {
                    field: 'sitename',
                    title: '站点名称'
                },
                {
                    field: 'url',
                    title: '所在页',
                    formatter: function(value, row, index) {
                        // 假设 row 对象中有 title 字段存储页面标题
                        var title = row.title || '无标题';  // 如果没有标题，显示"无标题"
                        var url = value;  // value 是页面URL

                        // 在新标签页中打开链接，显示标题但链接到URL
                        return '<a href="' + url + '" target="_blank" title="' + url + '">' + title + '</a>';
                    }
                },
/*                {
                    field: 'url',
                    title: '所在页',
                    formatter: function(value, row, index) {
                        // 在新标签页中打开链接
                        return '<a href="' + value + '" target="_blank">' + value + '</a>';
                    }
                },*/
                {
                    field: 'linkurl',
                    title: '链接',
                    width: 200,
                    formatter: function(value) {
                        if (value && value.length > 50) {
                            return '<a href="' + value + '" target="_blank" title="' + value + '">' + value.substring(0, 50) + '</a>';

                        }
                        return value;
                    }
                },
                {
                    field: 'type',
                    title: '类型',
                    width: '100px',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(typeDatas, value);
                    }
                },
                {
                    field: 'msg',
                    title: '信息'
                },
                {
                    field: 'time',
                    title: '发布时间',
                    width: '100px',
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        $(function() {
            // 监听表单的 Enter 键按下事件
            $('#formId').on('keydown', function(e) {
                if (e.key === 'Enter') {
                    e.preventDefault(); // 阻止默认提交行为
                    $.table.search();   // 触发搜索
                }
            });
        });
    </script>
</body>
</html>