diff --git a/server/web/index.html b/server/web/index.html index 932a266..8fe0779 100644 --- a/server/web/index.html +++ b/server/web/index.html @@ -657,14 +657,13 @@ max-width: 240px; flex-shrink: 1; } - /* 卡片操作图标(终端 / 删除):右上角,独立于卡片本体点击事件 - (onclick stopPropagation)。List 视图卡片是一行,改为垂直居中。 */ + /* 卡片操作:右上角只留一个「…」按钮,点开才弹出菜单(终端 / 绑定 / + 转移 / 删除),菜单项带简短功能说明。独立于卡片本体点击事件 + (onclick stopPropagation)。List 视图卡片是一行,按钮垂直居中。 */ .device-card .card-actions { position: absolute; top: 12px; right: 12px; - display: flex; - gap: 6px; z-index: 1; } .device-card .card-icon-btn { @@ -682,19 +681,57 @@ } .device-card .card-icon-btn:hover { background: rgba(255,255,255,0.14); color: #fff; } .device-card .card-icon-btn:active { transform: scale(0.92); } - .device-card .card-term-btn:hover { background: rgba(76, 175, 80, 0.25); color: #4caf50; } - .device-card .card-del-btn:hover { background: rgba(231, 76, 60, 0.25); color: #e74c3c; } - .device-card .card-bind-btn:hover { background: rgba(230, 126, 34, 0.25); color: #e67e22; } - .device-card .card-transfer-btn:hover { background: rgba(214, 137, 16, 0.25); color: #d68910; } - .device-card h3 { padding-right: 124px; } /* 给右上角操作图标让位 */ - /* 4 个操作图标(终端/绑定/转移/删除)= 4×32 + 3×6 + 右边距 12,比默认的 - 3 个宽 38px;不让位标题会钻到图标底下。list-view 的 h3 padding-right:0 - 选择器权重更高,不受影响。 */ - .device-card.many-actions h3 { padding-right: 162px; } + .device-card .card-more-btn[aria-expanded="true"] { background: rgba(255,255,255,0.14); color: #fff; } + .device-card h3 { padding-right: 56px; } /* 给右上角「…」按钮让位 */ .device-grid.list-view .device-card .card-actions { top: 50%; transform: translateY(-50%); } + /* 「…」的弹出菜单:fixed 挂 body(卡片 overflow:hidden 会裁掉菜单), + JS 按按钮位置定位并做视口翻转/夹取。 */ + .card-menu { + position: fixed; + z-index: 80; + width: 264px; + max-width: calc(100vw - 16px); + padding: 6px; + border: 1px solid #0f3460; + border-radius: 8px; + background: #16213e; + box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5); + } + .card-menu-item { + display: flex; + align-items: flex-start; + gap: 10px; + width: 100%; + padding: 8px; + border: none; + border-radius: 6px; + background: transparent; + color: #ddd; + text-align: left; + cursor: pointer; + } + .card-menu-item:hover, .card-menu-item:focus-visible { background: rgba(255,255,255,0.07); } + .card-menu-item:active { background: rgba(255,255,255,0.12); } + .card-menu-icon { + flex: 0 0 auto; + display: flex; + align-items: center; + justify-content: center; + width: 18px; + height: 18px; + margin-top: 1px; + } + .card-menu-item.term .card-menu-icon { color: #4caf50; } + .card-menu-item.bind .card-menu-icon { color: #e67e22; } + .card-menu-item.transfer .card-menu-icon { color: #d68910; } + .card-menu-item.del .card-menu-icon { color: #e74c3c; } + .card-menu-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; } + .card-menu-label { font-size: 13px; font-weight: 500; color: #eee; } + .card-menu-item.del .card-menu-label { color: #e74c3c; } + .card-menu-desc { font-size: 11px; color: #8a93a8; line-height: 1.35; } /* ====== 终端页面 ====== */ #term-page { @@ -824,7 +861,7 @@ display: flex; align-items: center; padding: 12px 16px; - padding-right: 100px; /* 给垂直居中的操作图标列让位 */ + padding-right: 56px; /* 给垂直居中的「…」按钮让位 */ gap: 20px; } .device-grid.list-view .device-card::before { display: none; } @@ -5071,7 +5108,130 @@ } } + // ---- 卡片「…」操作菜单 ---- + // 无论有几个操作,卡片上只显示一个「…」;点开弹出的菜单里才是终端/绑定/ + // 转移/删除,每项带一句功能说明。菜单项在点击时按设备实时生成,权限和 + // 在线状态不会因为列表渲染后变化而过期。 + let cardMenuEl = null; + let cardMenuBtn = null; + const cardMenuSvg = { + term: '', + bind: '', + transfer: '', + del: '' + }; + + function hasCardActions(d) { + if (d.online !== false) return true; // 在线设备至少有终端 + return canBindDevices() || canDeleteDevices(); + } + + function cardMenuEntries(d) { + const offline = d.online === false; + const out = []; + if (!offline) { + out.push({ kind: 'term', label: 'Terminal', desc: 'Open a remote shell', + run: () => openTerminal(d.id) }); + } + if (canBindDevices()) { + out.push({ kind: 'bind', label: 'Bind owner', desc: 'Assign this host to a user', + run: () => openBindModal(d.id) }); + } + if (canTransferDevices() && !offline && !d.transferTo) { + out.push({ kind: 'transfer', label: 'Transfer host', desc: 'Move the host to another master', + run: () => openTransferModal(d.id) }); + } + if (canDeleteDevices()) { + out.push({ + kind: 'del', + label: offline ? 'Delete record' : 'Uninstall host', + desc: offline ? 'Remove this offline record' : 'Remove the client from this host', + run: () => askDeleteDevice(d.id) + }); + } + return out; + } + + function closeCardMenu() { + if (cardMenuEl) { + cardMenuEl.remove(); + cardMenuEl = null; + } + if (cardMenuBtn) { + cardMenuBtn.setAttribute('aria-expanded', 'false'); + cardMenuBtn = null; + } + } + + function toggleCardMenu(btn, id) { + if (cardMenuBtn === btn) { // 再点一次同一个按钮 = 收起 + closeCardMenu(); + return; + } + const d = devices.find(x => String(x.id) === String(id)); + const entries = d ? cardMenuEntries(d) : []; + closeCardMenu(); + if (!entries.length) return; + + const menu = document.createElement('div'); + menu.className = 'card-menu'; + menu.setAttribute('role', 'menu'); + entries.forEach(en => { + const item = document.createElement('button'); + item.type = 'button'; + item.className = 'card-menu-item ' + en.kind; + item.setAttribute('role', 'menuitem'); + item.innerHTML = + '' + + ''; + item.addEventListener('click', (e) => { + e.stopPropagation(); + closeCardMenu(); + en.run(); + }); + menu.appendChild(item); + }); + document.body.appendChild(menu); + + // 右对齐按钮,菜单默认向下;贴底时向上翻,左右夹在视口内。 + const r = btn.getBoundingClientRect(); + const mw = menu.offsetWidth; + const mh = menu.offsetHeight; + let left = r.right - mw; + let top = r.bottom + 6; + if (top + mh > window.innerHeight - 8) top = r.top - mh - 6; + if (top < 8) top = 8; + left = Math.max(8, Math.min(left, window.innerWidth - mw - 8)); + menu.style.left = left + 'px'; + menu.style.top = top + 'px'; + + cardMenuEl = menu; + cardMenuBtn = btn; + btn.setAttribute('aria-expanded', 'true'); + } + + document.addEventListener('click', (e) => { + if (!cardMenuEl) return; + if (cardMenuEl.contains(e.target)) return; + if (e.target.closest && e.target.closest('.card-more-btn')) return; // 切换由按钮自己处理 + closeCardMenu(); + }); + document.addEventListener('keydown', (e) => { + if (e.key === 'Escape') closeCardMenu(); + }); + window.addEventListener('scroll', closeCardMenu, true); // 滚动后 fixed 菜单会跟丢锚点 + window.addEventListener('resize', closeCardMenu); + function renderDeviceList() { + closeCardMenu(); renderGroupFilter(); const filtered = getFilteredDevices(); const ps = getPageSize(); @@ -5100,56 +5260,20 @@ const rtt = d.rtt || '-'; const ver = d.version || '-'; const activeWin = d.activeWindow || ''; - // 操作图标:在线卡片有终端;删除对所有卡片开放(离线=删记录, - // 在线=卸载主机),仅管理员可用。Wall 模式不提供删除。 - const actions = []; - if (!offline) { - actions.push( - ''); - } - if (canBindDevices()) { - actions.push( - ''); - } - if (canTransferDevices() && !offline && !d.transferTo) { - actions.push( - ''); - } - if (canDeleteDevices()) { - actions.push( - ''); - } - const actionsHtml = actions.length - ? '