wangzhibo
2026-05-09 53418655c061ac26f66058253f39200aced1ab1d
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
111
112
113
114
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title><%= documentTitle %></title>
  <link rel="stylesheet" href="<%= basePath %>/static/style.css" />
</head>
<body class="page-view page-view--tabs<%= slides.length ? '' : ' page-view--empty' %>">
  <% if (slides.length) { %>
    <div id="viewTabsStack" class="view-tabs-stack">
      <% slides.forEach(function (s, i) { %>
        <iframe
          class="view-tab-iframe<%= i === startIndex ? ' is-active' : '' %>"
          data-index="<%= i %>"
          src="<%= s.boardUrl %>"
          title="<%= s.title %>"
          aria-hidden="<%= i === startIndex ? 'false' : 'true' %>"
        ></iframe>
      <% }); %>
    </div>
  <% } else { %>
    <p class="view-empty-hint">该场景下没有可轮播的页面,请在 config/scenarios.config.json 中配置 pages。</p>
  <% } %>
  <script type="application/json" id="boardViewStackSlides"><%- slidesJson %></script>
  <script>
    (function () {
      const SCENARIO_NAME = <%- JSON.stringify(scenarioName) %>;
      const slidesEl = document.getElementById("boardViewStackSlides");
      let slides = [];
      try {
        slides = JSON.parse(slidesEl ? slidesEl.textContent : "[]");
      } catch {
        slides = [];
      }
      if (!Array.isArray(slides) || !slides.length) {
        return;
      }
 
      const iframes = document.querySelectorAll("#viewTabsStack .view-tab-iframe");
      if (!iframes.length) {
        return;
      }
      if (slides.length === 1) {
        const f = iframes[0];
        f.classList.add("is-active");
        f.setAttribute("aria-hidden", "false");
        document.title = slides[0].title + " — " + SCENARIO_NAME;
        return;
      }
 
      const START = <%= startIndex %>;
      const i0 = Math.min(START, Math.max(0, slides.length - 1));
 
      function setActiveIndex(i) {
        const s = slides[i];
        for (let n = 0; n < iframes.length; n++) {
          const el = iframes[n];
          if (n === i) {
            el.classList.add("is-active");
            el.setAttribute("aria-hidden", "false");
          } else {
            el.classList.remove("is-active");
            el.setAttribute("aria-hidden", "true");
          }
        }
        document.title = s.title + " — " + SCENARIO_NAME;
      }
 
      let t = 0;
      function showAt(i) {
        setActiveIndex(i);
        const s = slides[i];
        const sec = Math.max(1, Number(s.staytime) || 30);
        if (t) {
          clearTimeout(t);
        }
        t = setTimeout(function () {
          showAt((i + 1) % slides.length);
        }, sec * 1000);
      }
      showAt(i0);
    })();
  </script>
  <script>
    (function () {
      const LS_KEY = "board_recent_v2";
      const MAX = 5;
      function readRecent() {
        try {
          const raw = localStorage.getItem(LS_KEY);
          const arr = raw ? JSON.parse(raw) : [];
          return Array.isArray(arr) ? arr : [];
        } catch {
          return [];
        }
      }
      function writeRecent(items) {
        localStorage.setItem(LS_KEY, JSON.stringify(items.slice(0, MAX)));
      }
      const entry = <%- JSON.stringify({
        scenarioId,
        scenarioName,
        image: scenarioImage,
      }) %>;
      const cur = readRecent().filter(
        (x) => x.scenarioId !== entry.scenarioId
      );
      cur.unshift(entry);
      writeRecent(cur);
    })();
  </script>
</body>
</html>