feat(ui): 主题切换挪到会话头部动作区,手机端进「更多」菜单
原来放在文件树头部,只有开着文件树才看得到;切到会话页/欢迎页就没有入口。 桌面放到头部动作区「新建会话」左边(.ha-icons),手机收进「更多」下拉菜单, 与切换模型/定时任务/压缩上下文同一套 data-act 分发,点完自动收起菜单。 files-tree.js 里那份按钮和主题逻辑一并删掉,统一到 sessions.js。 手机菜单项按现有写法拆成主文案「切换主题」+ 副标题「浅色/深色」,与其他 动作项一致(主文案是动作,副标题才是当前值)。
This commit is contained in:
@@ -193,6 +193,10 @@
|
||||
桌面属性区与菜单项共用 data-act,事件统一在 sessions.js 分发。 -->
|
||||
<div class="header-actions" id="header-actions">
|
||||
<div class="ha-icons">
|
||||
<button class="icon-btn ha-btn" data-act="theme" id="theme-toggle" data-tip="主题:浅色" aria-label="切换主题">
|
||||
<svg class="ic sm" viewBox="0 0 24 24"><use href="#i-theme-light"/></svg>
|
||||
<svg class="ic sm hidden" viewBox="0 0 24 24"><use href="#i-theme-dark"/></svg>
|
||||
</button>
|
||||
<button class="icon-btn ha-btn" data-act="new" data-tip="新建会话" aria-label="新建会话">
|
||||
<svg class="ic sm" viewBox="0 0 24 24"><use href="#i-plus"/></svg>
|
||||
</button>
|
||||
@@ -213,6 +217,11 @@
|
||||
<svg class="ic sm" viewBox="0 0 24 24"><use href="#i-database"/></svg>
|
||||
<span class="ha-item-main">压缩上下文</span>
|
||||
</button>
|
||||
<button class="ha-item" role="menuitem" data-act="theme" id="theme-toggle-mobile">
|
||||
<svg class="ic sm" viewBox="0 0 24 24"><use href="#i-theme-light"/></svg>
|
||||
<svg class="ic sm hidden" viewBox="0 0 24 24"><use href="#i-theme-dark"/></svg>
|
||||
<span class="ha-item-main">切换主题</span><span class="ha-item-sub" id="theme-label-mobile">浅色</span>
|
||||
</button>
|
||||
<button class="ha-item" role="menuitem" data-act="new">
|
||||
<svg class="ic sm" viewBox="0 0 24 24"><use href="#i-plus"/></svg>
|
||||
<span class="ha-item-main">新建会话</span>
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
const SVG_EYE = '<svg class="ic sm" viewBox="0 0 24 24"><use href="#i-eye-sm"/></svg>';
|
||||
const SVG_DL = '<svg viewBox="0 0 24 24"><use href="#i-download"/></svg>';
|
||||
const SVG_DEL = '<svg viewBox="0 0 24 24"><use href="#i-trash"/></svg>';
|
||||
const SVG_THEME = '<svg class="ic sm" viewBox="0 0 24 24"><use href="#i-theme-light"/></svg>' +
|
||||
'<svg class="ic sm hidden" viewBox="0 0 24 24"><use href="#i-theme-dark"/></svg>';
|
||||
const SVG_REVEAL_SM = '<svg viewBox="0 0 24 24"><use href="#i-external-b"/></svg>';
|
||||
|
||||
let localCapable = false; // local 启动器:才显示「在 Finder/终端中打开」
|
||||
@@ -396,34 +394,6 @@
|
||||
}
|
||||
|
||||
// local 能力探测结果回来后才把「在 Finder/终端中打开」露出来(服务器形态永远隐藏)
|
||||
// ---------- 主题(auto / light / dark 三态循环)----------
|
||||
// 色板全在 style.css 的变量里,这里只负责落 data-theme 与两态图标。
|
||||
const THEME_ORDER = ['light', 'dark'];
|
||||
const THEME_LABEL = ['主题:浅色', '主题:深色'];
|
||||
function themeMode() { return document.documentElement.getAttribute('data-theme-mode') === 'dark' ? 'dark' : 'light'; }
|
||||
function applyTheme(mode) {
|
||||
const m = mode === 'dark' ? 'dark' : 'light';
|
||||
document.documentElement.setAttribute('data-theme', m);
|
||||
document.documentElement.setAttribute('data-theme-mode', m);
|
||||
try { localStorage.setItem('agent-theme', m); } catch (_) {}
|
||||
const meta = document.querySelector('meta[name="theme-color"]');
|
||||
if (meta) meta.setAttribute('content', m === 'dark' ? '#0d1117' : '#3964FE');
|
||||
syncThemeBtn();
|
||||
}
|
||||
function cycleTheme() {
|
||||
applyTheme(themeMode() === 'dark' ? 'light' : 'dark');
|
||||
}
|
||||
function syncThemeBtn() {
|
||||
const btn = $('tree-theme');
|
||||
if (!btn) return;
|
||||
const i = themeMode() === 'dark' ? 1 : 0;
|
||||
btn.title = THEME_LABEL[i];
|
||||
btn.setAttribute('aria-label', THEME_LABEL[i]);
|
||||
btn.querySelectorAll('svg').forEach(function (s, k) { s.classList.toggle('hidden', k !== i); });
|
||||
}
|
||||
window.applyTheme = applyTheme;
|
||||
window.cycleTheme = cycleTheme;
|
||||
window.syncThemeBtn = syncThemeBtn;
|
||||
|
||||
function syncLocalButtons() {
|
||||
const rv = $('tree-reveal'), tm = $('tree-terminal');
|
||||
@@ -455,7 +425,6 @@
|
||||
'<button class="icon-btn" type="button" id="tree-vcs" title="Git 改动与历史" aria-label="Git 改动与历史">' + SVG_VCS + '</button>' +
|
||||
'</span>' +
|
||||
'<span class="pv-actions tree-actions-ext">' +
|
||||
'<button class="icon-btn" type="button" id="tree-theme" title="主题:浅色" aria-label="切换主题">' + SVG_THEME + '</button>' +
|
||||
'<button class="icon-btn hidden" type="button" id="tree-reveal" title="在 Finder 中打开" aria-label="在 Finder 中打开">' + SVG_REVEAL + '</button>' +
|
||||
'<button class="icon-btn hidden" type="button" id="tree-terminal" title="在终端中打开" aria-label="在终端中打开">' + SVG_TERM + '</button>' +
|
||||
'</span>';
|
||||
@@ -477,9 +446,6 @@
|
||||
box.appendChild(body);
|
||||
box.appendChild(foot);
|
||||
|
||||
head.querySelector('#tree-theme').addEventListener('click', function () {
|
||||
if (typeof cycleTheme === 'function') cycleTheme();
|
||||
});
|
||||
head.querySelector('#tree-hidden').addEventListener('click', function () {
|
||||
showHidden = !showHidden;
|
||||
invalidate(false);
|
||||
@@ -501,7 +467,6 @@
|
||||
body.addEventListener('click', onTreeClick);
|
||||
|
||||
syncLocalButtons();
|
||||
syncThemeBtn();
|
||||
}
|
||||
|
||||
// 侧栏底部「文件树」图标 → 切到这个面板(由 files.js 的 setDrawerPane 调用)。
|
||||
|
||||
@@ -491,8 +491,37 @@
|
||||
if (act === 'model') openModelSwitch();
|
||||
else if (act === 'schedule') openScheduleModal();
|
||||
else if (act === 'compact') summarizeChat();
|
||||
else if (act === 'theme') cycleTheme();
|
||||
else if (act === 'new') newChat();
|
||||
}
|
||||
|
||||
// ---------- 主题(浅/深两态,默认浅色;色板全在 style.css 变量里)----------
|
||||
function themeMode() { return document.documentElement.getAttribute('data-theme-mode') === 'dark' ? 'dark' : 'light'; }
|
||||
function applyTheme(mode) {
|
||||
const m = mode === 'dark' ? 'dark' : 'light';
|
||||
document.documentElement.setAttribute('data-theme', m);
|
||||
document.documentElement.setAttribute('data-theme-mode', m);
|
||||
try { localStorage.setItem('agent-theme', m); } catch (_) {}
|
||||
const meta = document.querySelector('meta[name="theme-color"]');
|
||||
if (meta) meta.setAttribute('content', m === 'dark' ? '#0d1117' : '#3964FE');
|
||||
syncThemeBtns();
|
||||
}
|
||||
function cycleTheme() { applyTheme(themeMode() === 'dark' ? 'light' : 'dark'); }
|
||||
function syncThemeBtns() {
|
||||
const dark = themeMode() === 'dark';
|
||||
const lbl = dark ? '主题:深色' : '主题:浅色';
|
||||
['theme-toggle', 'theme-toggle-mobile'].forEach(function (id) {
|
||||
const b = $(id);
|
||||
if (!b) return;
|
||||
b.querySelectorAll('svg').forEach(function (s, k) { s.classList.toggle('hidden', k !== (dark ? 1 : 0)); });
|
||||
});
|
||||
const t = $('theme-toggle');
|
||||
if (t) { t.title = lbl; t.dataset.tip = lbl; }
|
||||
const lab = $('theme-label-mobile');
|
||||
if (lab) lab.textContent = dark ? '深色' : '浅色'; // 副标题只写当前值,主文案是动作
|
||||
}
|
||||
window.applyTheme = applyTheme;
|
||||
window.cycleTheme = cycleTheme;
|
||||
// 桌面属性区(模型/定时任务/压缩)与移动菜单项共用同一批 data-act,事件只在这里绑一次。
|
||||
(function bindHeaderActions() {
|
||||
document.querySelectorAll('#header-meta [data-act], #header-actions [data-act]').forEach(el => {
|
||||
@@ -505,6 +534,7 @@
|
||||
if (!e.target.closest('#header-actions')) closeHeaderMenu();
|
||||
});
|
||||
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeHeaderMenu(); });
|
||||
syncThemeBtns(); // 按钮图标/文字跟着当前主题落一次
|
||||
})();
|
||||
|
||||
// ---------- 定时任务(弹窗改频次/提示词;无任务时同一弹窗即新建) ----------
|
||||
|
||||
Reference in New Issue
Block a user