feat: 面板顶栏添加悬浮球显示/隐藏切换按钮

This commit is contained in:
Youzini-afk
2026-03-27 14:36:49 +08:00
parent c06fff01cd
commit a5ab93e701
3 changed files with 66 additions and 0 deletions

View File

@@ -8,6 +8,14 @@
>SYSTEM_ACTIVE</span
>
</div>
<button
class="bme-fab-toggle-btn"
id="bme-fab-toggle-btn"
title="显示/隐藏悬浮球"
type="button"
>
<i class="fa-solid fa-circle-dot"></i>
</button>
<div class="bme-theme-picker">
<button
class="bme-theme-picker-btn"

View File

@@ -223,13 +223,39 @@ export async function initPanel({
_syncConfigSectionState();
_refreshRuntimeStatus();
_initFloatingBall();
_bindFabToggle();
}
// ==================== 悬浮球 ====================
const FAB_STORAGE_KEY = "bme-fab-position";
const FAB_VISIBLE_KEY = "bme-fab-visible";
let _fabEl = null;
function _getFabVisible() {
try {
const val = localStorage.getItem(FAB_VISIBLE_KEY);
return val === null ? true : val === "true";
} catch { return true; }
}
function _setFabVisible(visible) {
try { localStorage.setItem(FAB_VISIBLE_KEY, String(visible)); } catch {}
if (_fabEl) _fabEl.style.display = visible ? "flex" : "none";
const btn = panelEl?.querySelector("#bme-fab-toggle-btn");
if (btn) btn.setAttribute("data-active", String(visible));
}
function _bindFabToggle() {
const btn = panelEl?.querySelector("#bme-fab-toggle-btn");
if (!btn) return;
btn.setAttribute("data-active", String(_getFabVisible()));
btn.addEventListener("click", () => {
const next = !_getFabVisible();
_setFabVisible(next);
});
}
function _initFloatingBall() {
if (document.getElementById("bme-floating-ball")) return;
@@ -243,6 +269,9 @@ function _initFloatingBall() {
document.body.appendChild(fab);
_fabEl = fab;
// 应用可见性
if (!_getFabVisible()) fab.style.display = "none";
// 恢复位置
const saved = _loadFabPosition();
if (saved) {

View File

@@ -83,6 +83,35 @@
margin-right: 4px;
}
.bme-fab-toggle-btn {
width: 28px;
height: 28px;
display: flex;
align-items: center;
justify-content: center;
border: none;
background: transparent;
color: var(--bme-on-surface-dim);
cursor: pointer;
border-radius: 4px;
font-size: 14px;
transition: all 0.15s;
margin-right: 2px;
}
.bme-fab-toggle-btn:hover {
background: var(--bme-surface-highest);
color: var(--bme-primary);
}
.bme-fab-toggle-btn[data-active="true"] {
color: var(--bme-primary);
}
.bme-fab-toggle-btn[data-active="false"] {
opacity: 0.45;
}
.bme-theme-picker-btn {
width: 28px;
height: 28px;