refactor(ui): 去掉侧栏预览按钮,预览只从文件树点文件开窗

This commit is contained in:
2026-11-11 15:52:50 +08:00
parent 20824dc42e
commit c0488938ff
4 changed files with 9 additions and 39 deletions
+2 -2
View File
@@ -873,8 +873,8 @@ body.voice-active .scroll-bottom-btn { display: none; }
stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
/* 窄屏:没有右侧预览分栏(预览走全屏 #fs-viewer);文件浏览只保留输入行右侧的
旧「任务文件」面板,左栏不再出现文件树(不做两套文件 UI)。所以这两个钮都隐藏。 */
@media (max-width: 959px) { #da-preview, #da-files { display: none !important; } }
旧「任务文件」面板,左栏不再出现文件树(不做两套文件 UI)。所以文件树钮也隐藏。 */
@media (max-width: 959px) { #da-files { display: none !important; } }
.files-tree { display: none; flex: 1; min-height: 0; flex-direction: column; }
#drawer.drawer-mode-files .drawer-search,
+3 -5
View File
@@ -235,15 +235,13 @@
</div>
<div class="drawer-list" id="drawer-list"></div>
<div class="files-tree" id="files-tree"></div>
<!-- 底部图标操作栏:文件树 / 预览 / 设置(文件树按钮是「会话 ↔ 文件」的切换开关)。
窄屏两个都隐藏:预览走全屏浮层,文件只保留输入行右侧的旧面板(不做两套)。选中项高亮。 -->
<!-- 底部图标操作栏:文件树 / 设置(文件树按钮是「会话 ↔ 文件」的切换开关)。
预览不占按钮:桌面端在文件树里点文件即开预览栏,关窗走预览栏自己的关闭钮。
窄屏两个都隐藏:文件只保留输入行右侧的旧面板(不做两套)。选中项高亮。 -->
<div class="drawer-actions" id="drawer-actions">
<button class="drawer-act" id="da-files" type="button" title="文件树" aria-label="文件树">
<svg viewBox="0 0 24 24"><path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path></svg>
</button>
<button class="drawer-act" id="da-preview" type="button" title="预览" aria-label="预览">
<svg viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="16" rx="2"></rect><path d="M14 4v16"></path></svg>
</button>
<button class="drawer-act" id="da-settings" type="button" title="设置" aria-label="设置">
<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"></circle><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"></path></svg>
</button>
+1 -4
View File
@@ -1258,10 +1258,7 @@
// 窄屏只保留输入行右侧的旧「任务文件」面板,左栏不再提供文件树(按钮也已 CSS 隐藏)。
// 宽屏缩到窄屏时如果正停在文件页,先退回会话列表,避免出现两套文件 UI。
drawerMQ.addEventListener('change', (e) => { if (!e.matches) setDrawerPane(false); });
// 预览:同一个按钮开/关右侧面板
$('da-preview').addEventListener('click', () => {
if (typeof pvTogglePane === 'function') pvTogglePane();
});
// 预览没有独立按钮:桌面端只在文件树里点文件时开窗(关窗走预览栏自己的关闭钮 / Esc)。
$('da-settings').addEventListener('click', () => {
if (typeof showSettings !== 'function') return;
const page = $('settings-page');
+3 -28
View File
@@ -17,8 +17,7 @@ const PV_TEXT = /\.(md|markdown|txt|log|csv|tsv|json|jsonl|xml|yml|yaml|toml|ini
const PV_TEXT_MAX = 512 * 1024; // 文本预览截断阈值(字符),超出提示下载看全文
let pvSeq = 0; // 预览序号:快速连点时旧请求不许再动 DOM
// reload: 当前内容的"重新载入"动作(文本类无 iframe,按名重开);为 null 时回退到 reload iframe
// lastName: 最后展示过的文件路径。关窗后 pvState.name 会被清空,靠它支持"再点预览图标重开上次文件"
const pvState = { name: null, url: null, blobUrl: null, reload: null, mobilePush: false, lastName: null };
const pvState = { name: null, url: null, blobUrl: null, reload: null, mobilePush: false };
function pvDesktop() { return window.matchMedia('(min-width: 960px)').matches; }
@@ -81,7 +80,6 @@ function pvToolbar(o) {
// 每次展示内容都过一遍:标题显示相对路径(子目录可见),右上角下载钮随文件走
function pvHeader(name, sizeText) {
pvState.name = name;
if (name) pvState.lastName = name; // 记住最后一份内容,供关窗后重开
const t = document.getElementById('pv-title');
t.value = String(name || '');
t.title = sizeText ? name + ' · ' + sizeText : String(name || '');
@@ -127,7 +125,6 @@ function pvOpenPane() {
// 开预览就把侧栏切到文件树:预览就贴在它旁边,切了才能顺手换文件看。
// 已经在文件页时 setDrawerPane 内部会因「没变化」而直接返回,不会重复拉树。
if (typeof setDrawerPane === 'function') setDrawerPane(true);
pvSyncBtn();
}
function pvCloseDoc() {
@@ -136,32 +133,10 @@ function pvCloseDoc() {
if (typeof pvSetMaxUI === 'function') pvSetMaxUI(false); // 收起时复位放大钮图标(函数声明提升,定义在后亦可)
pvClearBody();
pvState.name = null; pvState.url = null;
pvSyncBtn();
}
// 侧栏底部「预览」图标:开/关预览分栏(桌面端)。图标随开合高亮。
function pvSyncBtn() {
const b = document.getElementById('da-preview');
if (b) b.classList.toggle('active', document.body.classList.contains('pv-open'));
}
// 同一个图标开/关预览:已开 → 关;未开 → 优先重开上次看过的文件,没有就开空面板给个提示。
function pvTogglePane() {
if (!pvDesktop()) return; // 移动端预览走全屏 #fs-viewer,不维护分栏
// 已开着的先允许关:新建会话后 sessionId 会变空,不能让开了的窗关不掉
if (document.body.classList.contains('pv-open')) { pvCloseDoc(); return; }
// 还没开始会话:没有任务目录可看,点了就什么都别做(不弹提示、不开空窗、不切侧栏)
if (!state.sessionId) return;
if (pvState.lastName) { openFilePreview(pvState.lastName); return; }
pvOpenPane(); pvClearBody(); pvHeader('', '');
const body = document.getElementById('pv-body');
if (body) {
const tip = document.createElement('div');
tip.className = 'pv-none';
tip.innerHTML = '<div class="hint">点击文件即可在此预览</div>';
body.appendChild(tip);
}
}
// 侧栏底部没有「预览」按钮:桌面端的预览只有一条入口——在文件树里点文件(点即开窗),
// 关窗走预览栏自己的关闭钮 / Esc / 缩到窄屏。所以这里不再维护任何按钮高亮状态。
// 移动端全屏承载:把节点塞进 #fs-viewer 并展开
// opts.bar → 文件预览沉浸模式:顶部独立操作条,内容全宽占满剩余空间