如洲 陈
2025-05-29 65c2724981bb717e7f4d9084e8baff16f8c50b6b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>轮播</title>
    <link rel="stylesheet" href="js/layui/css/layui.css">
    <style>
        body {
            margin: 0;
            padding: 0;
            background: #000;
            overflow: hidden;
        }
        .iframe-container {
            position: relative;
            width: 100%;
            height: 100vh;
        }
        .iframe {
            position: absolute;
            width: 100%;
            height: 100%;
            border: none;
            transition: opacity 0.5s;
            opacity: 0;
        }
        .iframe.active {
            opacity: 1;
            z-index: 1;
        }
    </style>
</head>
<body>
 
<div id="iframeContainer" class="iframe-container"></div>
 
<script src="js/layui/layui.js"></script>
<script>
layui.use(['jquery'], function () {
    const $ = layui.jquery;
 
    // 从 URL 获取参数
    const urlParams = new URLSearchParams(window.location.search);
    const menuId = urlParams.get('menuId');
    const lbsj = urlParams.get('lbsj')*1000;
 
    if (!menuId) {
        alert("缺少 menuId 参数,请通过菜单点击进入此页面。");
        return;
    }
 
    let views = [];         // 存储视图链接
    let currentIndex = 0;   // 当前索引
    let autoPlayInterval;   // 自动播放定时器
    const container = $('#iframeContainer');
 
    // 请求后端接口获取视图链接列表
    $.ajax({
        url: 'http://localhost:9091/simple/listByMenuId/' + menuId,
        method: 'GET',
        success: function(res) {
            if (res.code === 0 && res.data && res.data.length > 0) {
                views = res.data.filter(item => item.pid == menuId).map(item => item.href);
 
                if (views.length > 0) {
                    // 预加载所有iframe
                    views.forEach((url, index) => {
                        const iframe = $(`<iframe class="iframe" data-index="${index}" src="${url}"></iframe>`);
                        container.append(iframe);
                        
                        // 第一个iframe立即显示
                        if (index === 0) {
                            iframe.addClass('active');
                        }
                    });
                    
                    startAutoPlay(lbsj);
                } else {
                    alert("未找到对应的视图链接!");
                }
            } else {
                alert("请求失败或数据为空!");
            }
        },
        error: function(xhr, status, error) {
            alert("请求失败:" + error);
        }
    });
 
    // 切换到下一个视图
    function nextView() {
        // 隐藏当前iframe
        $(`.iframe[data-index="${currentIndex}"]`).removeClass('active');
        
        // 更新索引
        currentIndex = (currentIndex + 1) % views.length;
        
        // 显示下一个iframe
        $(`.iframe[data-index="${currentIndex}"]`).addClass('active');
    }
 
    // 开始自动播放
    function startAutoPlay(lbsj) {
        autoPlayInterval = setInterval(nextView, lbsj);
    }
});
</script>
 
</body>
</html>