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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>场景 - Board</title>
  <link rel="stylesheet" href="<%= basePath %>/static/style.css" />
</head>
<body class="page-home">
  <div class="shell">
    <header class="topbar">
      <div class="brand brand-nav">
        <a href="<%= basePath %>/">Board</a>
        <span class="brand-sep" aria-hidden="true">·</span>
        <a href="<%= basePath %>/warehouse-calendar">仓库计划日历</a>
      </div>
      <div class="userbar">
        <a
          class="userbar-edit"
          href="<%= basePath %>/config/scenarios"
          target="_blank"
          rel="noopener"
        >设置</a>
        <span class="userbar-sep" aria-hidden="true">|</span>
        <span class="username"><%= username %></span>
        <button type="button" class="btn ghost" id="btnLogout">退出</button>
      </div>
    </header>
    <div class="home-body">
      <section class="panel recent-panel">
        <h2>最近使用</h2>
        <div id="recentList" class="recent-list page-link-grid"></div>
      </section>
      <section class="panel catalog-panel">
        <h2>场景清单</h2>
        <div class="catalog">
          <% categories.forEach(function (cat) { %>
            <div class="cat-block">
              <div class="cat-title"><%= cat.name %></div>
              <div class="scenario-tiles page-link-grid">
                <% cat.scenarios.forEach(function (sc) { %>
                  <a
                    class="page-link page-tile"
                    target="_blank"
                    rel="noopener"
                    href="<%= basePath %>/view?scenarioId=<%= encodeURIComponent(sc.id) %>"
                    data-scenario-id="<%= sc.id %>"
                    data-scenario-name="<%= sc.name %>"
                    data-scenario-image="<%= sc.image %>"
                  >
                    <img
                      class="page-thumb"
                      src="<%= basePath %>/static/<%= sc.image %>"
                      alt=""
                      loading="lazy"
                    />
                    <span class="page-link-text"><%= sc.name %></span>
                  </a>
                <% }); %>
              </div>
            </div>
          <% }); %>
        </div>
      </section>
    </div>
  </div>
  <script type="application/json" id="boardScenarioImages"><%- scenarioImagesJson %></script>
  <script>
    (function () {
      const LS_KEY = "board_recent_v2";
      const MAX = 5;
      const base = "<%= basePath %>";
 
      const SCENARIO_IMAGE_MAP = (function () {
        try {
          const el = document.getElementById("boardScenarioImages");
          const raw = el ? el.textContent : "{}";
          return JSON.parse(raw || "{}");
        } catch {
          return {};
        }
      })();
 
      function resolveScenarioImage(it) {
        if (it.image) {
          return it.image;
        }
        return SCENARIO_IMAGE_MAP[it.scenarioId] || "";
      }
 
      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)));
      }
      function pushRecent(entry) {
        const cur = readRecent().filter(
          (x) => x.scenarioId !== entry.scenarioId
        );
        cur.unshift(entry);
        writeRecent(cur);
      }
      function renderRecent() {
        const box = document.getElementById("recentList");
        const items = readRecent();
        box.innerHTML = "";
        if (!items.length) {
          box.innerHTML = '<span class="muted recent-empty">暂无记录,打开场景后将显示在此</span>';
          return;
        }
        items.forEach((it) => {
          const a = document.createElement("a");
          a.className = "page-link page-tile";
          a.target = "_blank";
          a.rel = "noopener";
          a.href =
            base + "/view?scenarioId=" + encodeURIComponent(it.scenarioId);
          a.setAttribute("data-scenario-id", it.scenarioId);
          a.setAttribute("data-scenario-name", it.scenarioName);
          const imgPath = resolveScenarioImage(it);
          if (imgPath) {
            a.setAttribute("data-scenario-image", imgPath);
            const img = document.createElement("img");
            img.className = "page-thumb";
            img.alt = "";
            img.loading = "lazy";
            img.src = base + "/static/" + imgPath;
            a.appendChild(img);
          } else {
            const ph = document.createElement("div");
            ph.className = "page-thumb page-thumb--placeholder";
            ph.setAttribute("aria-hidden", "true");
            a.appendChild(ph);
          }
          const span = document.createElement("span");
          span.className = "page-link-text";
          span.textContent = it.scenarioName;
          a.appendChild(span);
          box.appendChild(a);
        });
      }
      function readRecentEntryFromLink(anchor) {
        const scenarioId = anchor.getAttribute("data-scenario-id") || "";
        const fromAttr = anchor.getAttribute("data-scenario-image") || "";
        const image =
          fromAttr || resolveScenarioImage({ scenarioId, image: "" });
        return {
          scenarioId,
          scenarioName: anchor.getAttribute("data-scenario-name") || "",
          image,
        };
      }
 
      document.body.addEventListener("click", (e) => {
        const a = e.target.closest("a.page-tile");
        if (!a || !a.href || a.href.indexOf("/view") === -1) {
          return;
        }
        pushRecent(readRecentEntryFromLink(a));
      });
      document.getElementById("btnLogout").addEventListener("click", async () => {
        await fetch(base + "/api/logout", { method: "POST", credentials: "include" });
        location.href = base + "/login";
      });
      renderRecent();
    })();
  </script>
</body>
</html>