Explorar o código

[门户] 更新: 协同提醒改为常驻红绿状态灯+点击详情面板(绿已最新/红待同步/灰未连通,事件列表含待同步高亮)

lio hai 2 meses
pai
achega
3e3db74b66
Modificáronse 1 ficheiros con 75 adicións e 19 borrados
  1. 75 19
      index.html

+ 75 - 19
index.html

@@ -26,6 +26,29 @@
   .upd-banner .btn-ok { margin-left:auto; height:26px; padding:0 12px; line-height:24px; border-radius:4px;
           border:1px solid #fdba74; background:#fff; color:#b45309; cursor:pointer; font-size:12px; white-space:nowrap; }
   .upd-banner .btn-ok:hover { background:#fef3c7; }
+  /* 协同状态灯(常驻):绿=已最新 红=有待同步 灰=hub未连通;点击弹详情面板 */
+  .hub-wrap { position:relative; }
+  .hub-dot { display:inline-flex; align-items:center; gap:6px; height:30px; padding:0 10px; border:1px solid #dcdfe6;
+          border-radius:15px; background:#fff; cursor:pointer; font-size:12px; color:#606266; white-space:nowrap; }
+  .hub-dot:hover { border-color:#93c5fd; }
+  .hub-dot .led { width:9px; height:9px; border-radius:50%; background:#c0c4cc; transition:background .3s; }
+  .hub-dot.s-green .led { background:#22c55e; box-shadow:0 0 5px rgba(34,197,94,.7); }
+  .hub-dot.s-red .led { background:#ef4444; box-shadow:0 0 5px rgba(239,68,68,.8); animation:hubPulse 1.2s infinite; }
+  .hub-dot.s-gray .led { background:#c0c4cc; }
+  @keyframes hubPulse { 50% { opacity:.45; } }
+  .hub-pop { display:none; position:absolute; right:0; top:36px; width:360px; background:#fff; border:1px solid #e4e7ed;
+          border-radius:8px; box-shadow:0 6px 24px rgba(31,45,61,.16); z-index:50; overflow:hidden; }
+  .hub-pop.show { display:block; }
+  .hub-pop .hp-head { padding:10px 14px; border-bottom:1px solid #f2f4f7; font-size:12.5px; display:flex; align-items:center; gap:8px; }
+  .hub-pop .hp-head .st-green { color:#16a34a; } .hub-pop .hp-head .st-red { color:#dc2626; } .hub-pop .hp-head .st-gray { color:#909399; }
+  .hub-pop .hp-head .btn-ok { margin-left:auto; height:24px; padding:0 10px; line-height:22px; border-radius:4px;
+          border:1px solid #fdba74; background:#fff; color:#b45309; cursor:pointer; font-size:11.5px; white-space:nowrap; }
+  .hub-pop ul { list-style:none; max-height:240px; overflow-y:auto; }
+  .hub-pop li { padding:8px 14px; border-bottom:1px solid #f7f8fa; font-size:12px; line-height:1.6; }
+  .hub-pop li .u { color:#2563eb; font-weight:600; }
+  .hub-pop li .t { color:#c0c4cc; font-size:11px; margin-left:6px; }
+  .hub-pop li.pending { background:#fff7ed; }
+  .hub-pop .hp-empty { padding:18px 14px; color:#909399; font-size:12px; text-align:center; }
   .topbar input { height:32px; border:1px solid #dcdfe6; border-radius:4px; padding:0 10px; width:220px; outline:none; }
   .topbar input:focus { border-color:#2563eb; }
   .topbar a.btn, .topbar .btn { height:30px; padding:0 12px; line-height:28px; border-radius:4px; font-size:12px; cursor:pointer; text-decoration:none; border:1px solid #dcdfe6; color:#606266; background:#fff; white-space:nowrap; }
@@ -66,14 +89,21 @@
     <div id="domains"></div>
   </div>
   <div class="mid">
-    <div class="upd-banner" id="updBanner">
-      🔔 <b>原型有更新:</b><span id="updText"></span>
-      <button class="btn-ok" onclick="ackSync()">✔ 我已同步(proto_sync)</button>
-    </div>
     <div class="topbar">
       <b>原型门户</b>
       <span class="sub" id="subTitle"></span>
       <input id="kw" placeholder="搜索页面名称/状态…">
+      <span class="hub-wrap">
+        <span class="hub-dot s-gray" id="hubDot" title="协同状态,点击查看详情">
+          <span class="led"></span><span id="hubLabel">协同…</span>
+        </span>
+        <div class="hub-pop" id="hubPop">
+          <div class="hp-head"><span id="hubState"></span>
+            <button class="btn-ok" id="hubAck" onclick="ackSync()">✔ 我已同步(proto_sync)</button>
+          </div>
+          <ul id="hubList"></ul>
+        </div>
+      </span>
       <a class="btn" id="liveBtn" target="_blank">🖥 线上系统</a>
       <a class="btn" id="repoBtn" target="_blank">📦 Gogs 仓库</a>
     </div>
@@ -156,36 +186,62 @@ function closePv() {
   curPage = null; render();
 }
 render();
-/* ── 协同提醒:轮询 wedo-hub,他人有新改动时横幅提示(本页无法执行git,同步动作交给AI/MCP) ── */
+/* ── 协同状态灯(常驻):绿=已最新 红=有待同步 灰=hub未连通;点击弹详情面板,同步动作交给AI/MCP ── */
 (function () {
   var H = window.PROTO_META.hub;
-  if (!H || !H.url) return;
+  var dot = document.getElementById("hubDot"), pop = document.getElementById("hubPop");
+  if (!H || !H.url) { dot.classList.add("s-gray"); document.getElementById("hubLabel").textContent = "协同未配置"; return; }
   var LS = "wedo_lastSynced_" + (H.repo || "default");
+  var lastEvs = [];                     /* 最近一次轮询到的事件(详情面板渲染用) */
   function fetchAll() {
     return fetch(H.url.replace(/\/$/, "") + "/events?repo=" + encodeURIComponent(H.repo || "") + "&since=0",
       { headers: H.token ? { "x-wedo-token": H.token } : {} }).then(function (r) { return r.json(); });
   }
+  function fmtTs(ts) {
+    var t = new Date(ts);
+    return ("0" + t.getHours()).slice(-2) + ":" + ("0" + t.getMinutes()).slice(-2);
+  }
+  function setState(st, label) {        /* st: green|red|gray */
+    dot.classList.remove("s-green", "s-red", "s-gray");
+    dot.classList.add("s-" + st);
+    document.getElementById("hubLabel").textContent = label;
+    var head = document.getElementById("hubState");
+    head.className = "st-" + st;
+    head.textContent = st === "green" ? "✓ 已是最新,无待同步改动"
+      : st === "red" ? "🔔 有待同步的原型更新(下方橙色条目)" : "⚠ hub 未连通(检查网络/服务)";
+    document.getElementById("hubAck").style.display = st === "red" ? "" : "none";
+  }
+  function renderPop(pendingTs) {
+    var ul = document.getElementById("hubList");
+    if (!lastEvs.length) { ul.innerHTML = '<div class="hp-empty">暂无协同事件</div>'; return; }
+    ul.innerHTML = lastEvs.slice(-8).reverse().map(function (e) {
+      return '<li class="' + (e.ts > pendingTs ? "pending" : "") + '"><span class="u">' + e.user + '</span><span class="t">' + fmtTs(e.ts) + '</span><br>' + e.message + "</li>";
+    }).join("");
+  }
   function check() {
     fetchAll().then(function (d) {
-      var evs = (d && d.events) || [];
-      if (!evs.length) return;
-      var last = evs[evs.length - 1];
+      lastEvs = (d && d.events) || [];
+      if (!lastEvs.length) { setState("green", "协同·无事件"); renderPop(Infinity); return; }
+      var last = lastEvs[lastEvs.length - 1];
       var mine = localStorage.getItem(LS);
-      if (mine === null) { localStorage.setItem(LS, String(last.ts)); return; }  /* 首访以最新为基线,不误报 */
-      if (last.ts > Number(mine)) {
-        var t = new Date(last.ts), hh = ("0" + t.getHours()).slice(-2) + ":" + ("0" + t.getMinutes()).slice(-2);
-        document.getElementById("updText").textContent =
-          last.user + " 于 " + hh + " " + last.message + " —— 请让 AI 执行 proto_sync {pull:true} 同步后刷新本页";
-        document.getElementById("updBanner").classList.add("show");
-      }
-    }).catch(function () { /* hub不可达:静默,不影响浏览 */ });
+      if (mine === null) { localStorage.setItem(LS, String(last.ts)); mine = String(last.ts); }  /* 首访以最新为基线,不误报 */
+      if (last.ts > Number(mine)) { setState("red", "有更新待同步"); renderPop(Number(mine)); }
+      else { setState("green", "协同·已最新"); renderPop(Infinity); }
+    }).catch(function () { setState("gray", "协同·未连通"); });
   }
+  dot.addEventListener("click", function (e) {
+    e.stopPropagation();
+    pop.classList.toggle("show");
+  });
+  document.addEventListener("click", function (e) {
+    if (!e.target.closest(".hub-wrap")) pop.classList.remove("show");
+  });
   window.ackSync = function () {
-    document.getElementById("updBanner").classList.remove("show");
     fetchAll().then(function (d) {
       var evs = (d && d.events) || [];
       if (evs.length) localStorage.setItem(LS, String(evs[evs.length - 1].ts));
-    }).catch(function () { });
+      setState("green", "协同·已最新"); renderPop(Infinity);
+    }).catch(function () { setState("gray", "协同·未连通"); });
   };
   check();
   setInterval(check, 2 * 60 * 1000);