dsh模块、快捷键调整

This commit is contained in:
zhongluofeng committed 2026-09-28 18:05:29 +08:00
1 parent ff1d5cd517
commit 7e65825d3e
54 files changed
+7082 -109

No files matched your search

+170
View File
@@ -0,0 +1,170 @@
<script setup lang="ts">
/**
* dsh 模块主页面(DeepSeek Harness 外壳)。
*
* 页面只承载「状态 + 配置 + 日志」,**不内嵌** dsh 的 Web UI:
* dsh 界面通过「独立窗口」(Tauri WebviewWindow 直接加载 http://127.0.0.1:<端口>)
* 或「浏览器打开」(系统默认浏览器)访问。
*
* 布局遵循项目规范:模块根 `min-h-full p-5`(滚动归属主滚动区),
* Tab 行不渲染(注册给 TitleBar 常驻切换器)。
*/
import { onMounted, onUnmounted, ref } from 'vue'
import {
ExternalLink,
Loader2,
Play,
RotateCw,
Square,
AppWindow,
FolderOpen
} from '@lucide/vue'
import { Tabs, TabsContent } from '@/components/ui/tabs'
import { Button } from '@/components/ui/button'
import { Card, CardContent } from '@/components/ui/card'
import { useModuleTabs } from '@/lib/use-module-tabs'
import { useDshStore } from '@/stores/dshStore'
import SetupStepper from './components/SetupStepper.vue'
import DshSettingsPanel from './components/DshSettingsPanel.vue'
import DshLogPanel from './components/DshLogPanel.vue'
const store = useDshStore()
const activeTab = ref('setup')
useModuleTabs(
'dsh',
activeTab,
[
{ value: 'setup', label: '状态' },
{ value: 'settings', label: '设置' },
{ value: 'logs', label: '日志' }
],
{ alwaysVisible: true }
)
onMounted(async () => {
await store.init()
})
onUnmounted(() => {
store.stopListeners()
})
</script>
<template>
<div class="min-h-full p-5">
<Tabs v-model="activeTab" class="flex min-h-full w-full flex-col">
<TabsContent value="setup" class="tab-animate">
<div class="flex flex-col gap-4">
<!-- 状态横幅:状态区 → 指标区 → 操作区(UI_DESIGN_SYSTEM §3.4) -->
<Card class="!py-0 !gap-0">
<CardContent class="flex flex-wrap items-center gap-x-6 gap-y-3 px-4 py-4">
<div class="flex items-center gap-2.5">
<span
v-if="!store.initialized"
class="flex items-center gap-1.5 text-[13px] text-muted-foreground"
>
<Loader2 class="size-3.5 animate-spin" />加载中
</span>
<template v-else>
<span
v-if="store.running"
class="flex items-center gap-1.5 text-[13px] text-success"
>
<span class="size-2 rounded-full bg-success status-dot-pulse" />运行中
</span>
<span
v-else
class="flex items-center gap-1.5 text-[13px] text-muted-foreground"
>
<span class="size-2 rounded-full bg-muted-foreground" />已停止
</span>
</template>
<span class="text-[13px] text-fg-secondary">DeepSeek Harness</span>
</div>
<div class="flex min-w-24 flex-col gap-0.5">
<span class="text-[11px] text-muted-foreground">dsh</span>
<span
class="text-lg font-semibold tabular-nums"
:class="store.installed ? 'text-foreground' : 'text-danger'"
>{{ store.install?.version ?? '未安装' }}</span>
</div>
<div class="flex min-w-24 flex-col gap-0.5">
<span class="text-[11px] text-muted-foreground">Node</span>
<span
class="text-lg font-semibold tabular-nums"
:class="store.nodeReady ? 'text-foreground' : 'text-danger'"
>{{ store.node?.version ?? '未检测到' }}</span>
</div>
<div class="flex min-w-40 flex-col gap-0.5">
<span class="text-[11px] text-muted-foreground">服务地址</span>
<span class="truncate font-mono text-[13px] text-fg-secondary">{{ store.displayUrl }}</span>
</div>
<div class="ml-auto flex flex-wrap gap-2">
<Button
v-if="!store.running"
size="sm"
:disabled="!store.envReady || store.starting"
@click="store.start()"
>
<Loader2 v-if="store.starting" class="size-3.5 animate-spin" />
<Play v-else class="size-3.5" />启动
</Button>
<template v-else>
<Button size="sm" variant="outline" :disabled="store.starting" @click="store.restart()">
<Loader2 v-if="store.starting" class="size-3.5 animate-spin" />
<RotateCw v-else class="size-3.5" />重启
</Button>
<Button size="sm" variant="destructive" :disabled="store.stopping" @click="store.stop()">
<Loader2 v-if="store.stopping" class="size-3.5 animate-spin" />
<Square v-else class="size-3.5" />停止
</Button>
</template>
<Button size="sm" variant="outline" :disabled="!store.canOpen" @click="store.openWebWindow()">
<AppWindow class="size-3.5" />独立窗口
</Button>
<Button size="sm" variant="outline" :disabled="!store.canOpen" @click="store.openInBrowser()">
<ExternalLink class="size-3.5" />浏览器打开
</Button>
</div>
</CardContent>
</Card>
<!-- 服务启动失败的可见原因(否则只有日志里能看到) -->
<Card v-if="store.server?.error" class="!py-0 !gap-0">
<CardContent class="flex items-start gap-2 px-4 py-3">
<span class="text-[13px] text-danger">{{ store.server.error }}</span>
<Button class="ml-auto shrink-0" size="xs" variant="outline" @click="store.openDir()">
<FolderOpen class="size-3" />打开目录
</Button>
</CardContent>
</Card>
<!-- 已监听但还没打印带令牌的启动地址:此时打开界面只会拿到 401,故先等待 -->
<Card v-else-if="store.ready && !store.canOpen" class="!py-0 !gap-0">
<CardContent class="flex items-center gap-2 px-4 py-3">
<Loader2 class="size-3.5 shrink-0 animate-spin text-muted-foreground" />
<span class="text-[13px] text-fg-secondary">
等待 dsh 输出访问地址(浏览器鉴权令牌需要它换 cookie,稍候即可打开)
</span>
</CardContent>
</Card>
<SetupStepper />
</div>
</TabsContent>
<TabsContent value="settings" class="tab-animate">
<DshSettingsPanel />
</TabsContent>
<TabsContent value="logs" class="tab-animate">
<DshLogPanel />
</TabsContent>
</Tabs>
</div>
</template>
@@ -0,0 +1,54 @@
<script setup lang="ts">
/**
* dsh 服务日志面板:读取服务进程 stdout/stderr 的尾部输出。
*
* 日志在 Rust 侧同时写入 `{app_data}/dsh/logs/web.log` 与内存环形缓冲
* (最多 500 行),因此这里读到的是最近一段,不随运行时长无限增长。
* 读取时已过滤疑似密钥(`sk-` 形态)的行内片段。
*/
import { onMounted } from 'vue'
import { FolderOpen, RefreshCw, Trash2 } from '@lucide/vue'
import { Button } from '@/components/ui/button'
import { Card, CardContent } from '@/components/ui/card'
import { useDshStore } from '@/stores/dshStore'
const store = useDshStore()
onMounted(() => {
void store.loadLogs()
})
</script>
<template>
<div class="flex flex-col gap-3">
<div class="flex flex-wrap items-center gap-2">
<span class="text-[13px] font-medium text-foreground">服务日志</span>
<span class="text-xs text-muted-foreground">
{{ store.progress ? store.progress.message : '最近 300 行' }}
</span>
<div class="ml-auto flex gap-2">
<Button size="sm" variant="outline" :disabled="store.loadingLogs" @click="store.loadLogs()">
<RefreshCw class="size-3.5" :class="store.loadingLogs && 'animate-spin'" />刷新
</Button>
<Button size="sm" variant="outline" @click="store.openDir()">
<FolderOpen class="size-3.5" />打开目录
</Button>
<Button size="sm" variant="ghost" @click="store.clearLogs()">
<Trash2 class="size-3.5" />清空
</Button>
</div>
</div>
<Card class="!py-0 !gap-0">
<CardContent class="px-4 py-3">
<pre
v-if="store.logs.trim()"
class="max-h-[420px] overflow-auto whitespace-pre-wrap break-all font-mono text-[11px] leading-relaxed text-fg-secondary"
>{{ store.logs }}</pre>
<p v-else class="py-6 text-center text-xs text-muted-foreground">
暂无日志。启动服务后这里会显示 dsh 的输出。
</p>
</CardContent>
</Card>
</div>
</template>
@@ -0,0 +1,363 @@
<script setup lang="ts">
/**
* dsh 模块设置页。
*
* 版式与音乐模块设置页一致:**标题放在卡片内部**(Card → CardHeader/CardTitle +
* CardContent),卡片之间 `gap-4`;卡片内的一行行设置项复用业务组件 `SettingRow`
* (左标签+说明、右控件),用 1px 分隔线隔开。
*
* 约定:设置项改动**立即生效**(无保存按钮),端口与工作区在下次启动服务时生效。
* 成功提示省略,仅错误经 store 内的 `toast.error` 提示。
*/
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
import { toast } from 'vue-sonner'
import { Cpu, FolderOpen, Keyboard, RefreshCw, Server, Sparkles, Zap } from '@lucide/vue'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Input } from '@/components/ui/input'
import { Switch } from '@/components/ui/switch'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
import { SettingRow } from '@/components/common'
import { useDshStore } from '@/stores/dshStore'
import { useAiStore } from '@/stores/aiStore'
const store = useDshStore()
const aiStore = useAiStore()
const enabledProviders = computed(() => aiStore.providers.filter(p => p.config.enabled))
onMounted(async () => {
if (!store.initialized) await store.refresh()
await aiStore.init()
await store.loadAiPreview()
})
function onPortChange(e: Event) {
const raw = Number((e.target as HTMLInputElement).value)
if (!Number.isFinite(raw) || raw <= 0 || raw > 65535) {
store.refresh()
return
}
if (raw !== store.settings?.port) store.saveSettings({ port: Math.trunc(raw) })
}
function onTextChange(key: 'nodeMirror' | 'npmRegistry' | 'workspace' | 'installDir', e: Event) {
const value = (e.target as HTMLInputElement).value.trim()
store.saveSettings({ [key]: value })
}
// ===== 快捷键录入器(与 QuickPanelModule / ClipboardModule 同一模式) =====
const recording = ref(false)
const recorderRef = ref<HTMLDivElement | null>(null)
function displayShortcut(s: string): string {
if (!s) return ''
return s
.split('+')
.map(p => {
const t = p.trim()
if (!t) return ''
if (t.length === 1) return t.toUpperCase()
return t.charAt(0).toUpperCase() + t.slice(1)
})
.join(' + ')
}
function eventToShortcut(e: KeyboardEvent): string | null {
const mods: string[] = []
if (e.ctrlKey) mods.push('ctrl')
if (e.altKey) mods.push('alt')
if (e.shiftKey) mods.push('shift')
if (e.metaKey) mods.push('super')
let main = ''
const code = e.code || ''
if (/^Key[A-Z]$/.test(code)) main = code.slice(3).toLowerCase()
else if (/^Digit[0-9]$/.test(code)) main = code.slice(5)
else if (/^F([1-9]|1[0-2])$/.test(code)) main = code.toLowerCase()
else if (code === 'Space') main = 'space'
else if (code === 'PrintScreen') main = 'printscreen'
else if (code.startsWith('Numpad')) main = code.slice(6).toLowerCase()
else return null
const isFunctionKey = /^f([1-9]|1[0-2])$/.test(main) || main === 'printscreen'
if (mods.length === 0 && !isFunctionKey) return null
return [...mods, main].join('+')
}
function onRecordKey(e: KeyboardEvent) {
if (!recording.value) return
e.preventDefault()
e.stopPropagation()
if (e.key === 'Escape') {
recording.value = false
return
}
if (['Control', 'Alt', 'Shift', 'Meta'].includes(e.key)) return
const combo = eventToShortcut(e)
if (!combo) {
toast.warning('不支持的按键组合,请使用字母/数字/功能键 + 修饰键')
return
}
recording.value = false
// saveSettings 会顺带重新注册(注册失败时由 store 弹错误提示,如组合键被占用)
void store.saveSettings({ shortcut: combo }).then(() => {
if (store.settings?.shortcut === combo) {
toast.success(`快捷键已更新为 ${displayShortcut(combo)}`)
}
})
}
async function startRecord() {
recording.value = true
await nextTick()
recorderRef.value?.focus()
}
watch(recording, on => {
if (on) window.addEventListener('keydown', onRecordKey, true)
else window.removeEventListener('keydown', onRecordKey, true)
})
async function clearShortcut() {
await store.saveSettings({ shortcut: '' })
}
onUnmounted(() => {
window.removeEventListener('keydown', onRecordKey, true)
})
</script>
<template>
<div class="flex flex-col gap-4 pb-4">
<!-- 基础设置 -->
<Card class="!gap-2 !py-4">
<CardHeader class="!px-4">
<CardTitle class="flex items-center gap-2 text-base">
<Zap class="size-4 text-primary" />
基础设置
</CardTitle>
</CardHeader>
<CardContent class="!px-4">
<div class="flex flex-col divide-y divide-divider">
<SettingRow label="随应用启动" description="应用启动且 dsh 已安装时自动拉起 Web 服务">
<Switch
:model-value="store.settings?.autoStart ?? false"
@update:model-value="v => store.saveSettings({ autoStart: v === true })"
/>
</SettingRow>
<SettingRow
label="打开独立窗口"
description="全局快捷键,在任意模块下都能唤出 dsh 界面;需至少一个修饰键 + 字母/数字/功能键"
>
<div class="flex items-center gap-2">
<div
ref="recorderRef"
class="hotkey-recorder"
:class="{ recording }"
tabindex="0"
@click="startRecord"
>
<template v-if="recording">按下快捷键…(Esc 取消)</template>
<template v-else-if="store.settings?.shortcut">
{{ displayShortcut(store.settings.shortcut) }}
</template>
<template v-else>未设置(点击录入)</template>
</div>
<Button
v-if="store.settings?.shortcut"
variant="ghost"
size="sm"
class="h-8 text-muted-foreground"
@click="clearShortcut"
>清除</Button>
</div>
</SettingRow>
</div>
</CardContent>
</Card>
<!-- 运行环境 -->
<Card class="!gap-2 !py-4">
<CardHeader class="!px-4">
<CardTitle class="flex items-center gap-2 text-base">
<Cpu class="size-4 text-primary" />
运行环境
</CardTitle>
</CardHeader>
<CardContent class="!px-4">
<p class="pb-2 text-xs text-muted-foreground">
Node 的来源、镜像源与下载链路(dsh 要求 Node ^22.19 或 &gt;=24)
</p>
<div class="flex flex-col divide-y divide-divider">
<SettingRow
label="Node 来源"
description="自动 = 系统 Node 满足要求就复用,否则回落托管版本"
control-width="wide"
>
<Select
:model-value="store.settings?.nodeSource ?? 'auto'"
@update:model-value="v => store.saveSettings({ nodeSource: String(v) })"
>
<SelectTrigger class="w-full"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem value="auto">自动(系统优先)</SelectItem>
<SelectItem value="system">仅使用系统 Node</SelectItem>
<SelectItem value="managed">仅使用托管便携 Node</SelectItem>
</SelectContent>
</Select>
</SettingRow>
<SettingRow
label="Node 镜像源"
description="留空使用 nodejs.org;国内可填 https://npmmirror.com/mirrors/node"
control-width="wide"
>
<Input
:model-value="store.settings?.nodeMirror ?? ''"
placeholder="https://nodejs.org/dist"
@change="(e: Event) => onTextChange('nodeMirror', e)"
/>
</SettingRow>
<SettingRow
label="npm 源"
description="留空 = 跟随 npm 自身配置(环境变量 → 安装目录 .npmrc → 用户 ~/.npmrc),系统 Node 已设的镜像会被沿用;国内镜像可在安装引导页用下拉快速选择"
control-width="wide"
>
<Input
:model-value="store.settings?.npmRegistry ?? ''"
placeholder="留空 = 跟随 npm 配置"
@change="(e: Event) => onTextChange('npmRegistry', e)"
/>
</SettingRow>
<SettingRow label="下载走代理" description="使用代理模块(mihomo)的混合端口;内核未运行时自动直连">
<Switch
:model-value="store.settings?.useProxy ?? true"
@update:model-value="v => store.saveSettings({ useProxy: v === true })"
/>
</SettingRow>
</div>
</CardContent>
</Card>
<!-- 服务 -->
<Card class="!gap-2 !py-4">
<CardHeader class="!px-4">
<CardTitle class="flex items-center gap-2 text-base">
<Server class="size-4 text-primary" />
服务
</CardTitle>
</CardHeader>
<CardContent class="!px-4">
<p class="pb-2 text-xs text-muted-foreground">
监听端口、安装位置与工作区(端口与工作区改动在下次启动服务时生效)
</p>
<div class="flex flex-col divide-y divide-divider">
<SettingRow label="端口" description="dsh 的 --port 参数;被占用时启动会直接报错" control-width="wide">
<Input
type="number"
min="1"
max="65535"
:model-value="store.settings?.port ?? 3080"
@change="onPortChange"
/>
</SettingRow>
<SettingRow
label="dsh 安装目录"
description="npm 安装目标(node_modules 所在位置),必须是绝对路径;留空 = 模块目录。改到新目录后需重新安装,原目录不会自动清理"
control-width="wide"
>
<Input
:model-value="store.settings?.installDir ?? ''"
placeholder="留空 = 应用数据目录下的 dsh"
@change="(e: Event) => onTextChange('installDir', e)"
/>
</SettingRow>
<SettingRow label="工作区" description="dsh 进程的启动目录,也是默认 workspace;留空使用模块目录下的 workspace" control-width="wide">
<Input
:model-value="store.settings?.workspace ?? ''"
placeholder="留空 = 模块目录下的 workspace"
@change="(e: Event) => onTextChange('workspace', e)"
/>
</SettingRow>
</div>
</CardContent>
</Card>
<!-- AI 装载 -->
<Card class="!gap-2 !py-4">
<CardHeader class="!px-4">
<CardTitle class="flex items-center gap-2 text-base">
<Sparkles class="size-4 text-primary" />
AI 装载
</CardTitle>
</CardHeader>
<CardContent class="!px-4">
<p class="pb-2 text-xs text-muted-foreground">
把主设置「AI 服务」里的供应商映射进 dsh;密钥不落盘,改为启动时以环境变量注入
</p>
<div class="flex flex-col divide-y divide-divider">
<SettingRow
label="dsh 主目录"
description="托管 = 模块目录(卸载即清理);用户目录 = ~/.dsh(与命令行 dsh 共享会话)"
control-width="wide"
>
<Select
:model-value="store.settings?.dshHomeMode ?? 'managed'"
@update:model-value="v => store.saveSettings({ dshHomeMode: String(v) })"
>
<SelectTrigger class="w-full"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem value="managed">模块独立目录</SelectItem>
<SelectItem value="user">用户目录(~/.dsh)</SelectItem>
</SelectContent>
</Select>
</SettingRow>
<SettingRow label="默认供应商" description="写入 agent-default-model,作为 dsh 的默认模型来源" control-width="wide">
<Select
:model-value="store.settings?.providerId ?? ''"
@update:model-value="v => store.saveSettings({ providerId: String(v) })"
>
<SelectTrigger class="w-full"><SelectValue placeholder="选择供应商" /></SelectTrigger>
<SelectContent>
<SelectItem v-for="p in enabledProviders" :key="p.config.id" :value="p.config.id">
{{ p.config.name || p.config.id }}
</SelectItem>
</SelectContent>
</Select>
</SettingRow>
<SettingRow label="默认模型" description="来自所选供应商的模型标识" control-width="wide">
<span class="block truncate text-right font-mono text-xs text-fg-secondary">
{{ store.preview?.defaultModel ?? '—' }}
</span>
</SettingRow>
<SettingRow label="启动前自动同步" description="每次启动服务前合并写入 settings.yaml(写前备份 .bak)">
<Switch
:model-value="store.settings?.aiSync ?? true"
@update:model-value="v => store.saveSettings({ aiSync: v === true })"
/>
</SettingRow>
</div>
</CardContent>
</Card>
<div class="flex flex-wrap items-center gap-2">
<Button size="sm" variant="outline" @click="store.openDir()">
<FolderOpen class="size-3.5" />打开模块目录
</Button>
<Button size="sm" variant="ghost" @click="store.refresh()">
<RefreshCw class="size-3.5" />刷新状态
</Button>
<span class="flex items-center gap-1.5 text-xs text-muted-foreground">
<Keyboard class="size-3" />
settings.yaml:{{ store.preview?.settingsPath ?? '—' }}
</span>
</div>
</div>
</template>
+491
View File
@@ -0,0 +1,491 @@
<script setup lang="ts">
/**
* 安装引导步骤条:Node 运行环境 → dsh 本体 → AI 通道。
*
* 步骤条用项目已有的 `ui/stepper`(reka-ui 封装,此前无模块使用)。
* 进度条用 `ui/progress`,**必须传 `:model-value`**(reka-ui ProgressRoot 没有
* `:value`,传错不报错但指示条永远停在 0)。
*
* npm 安装阶段没有百分比(npm 不输出),此时 `percent === 0`,用不确定态动画条
* 表达「正在进行」,不伪造百分比。
*/
import { computed, onMounted, ref, watch } from 'vue'
import {
Check,
Download,
FolderOpen,
Loader2,
RefreshCw,
Play,
Sparkles,
Terminal,
X
} from '@lucide/vue'
import { open as openDialog } from '@tauri-apps/plugin-dialog'
import {
Stepper,
StepperDescription,
StepperIndicator,
StepperItem,
StepperSeparator,
StepperTitle,
StepperTrigger
} from '@/components/ui/stepper'
import { Button } from '@/components/ui/button'
import { Progress } from '@/components/ui/progress'
import { Switch } from '@/components/ui/switch'
import { Badge } from '@/components/ui/badge'
import { Input } from '@/components/ui/input'
import { ScrollArea } from '@/components/ui/scroll-area'
import { Card, CardContent } from '@/components/ui/card'
import { SettingGroup, SettingRow } from '@/components/common'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
import { createLogger } from '@/lib/logger'
import { useDshStore } from '@/stores/dshStore'
import { useAiStore } from '@/stores/aiStore'
const logger = createLogger('dsh')
const store = useDshStore()
const aiStore = useAiStore()
const steps = [
{ value: 'node', title: 'Node 运行环境', description: 'dsh 要求 ^22.19 或 >=24' },
{ value: 'dsh', title: 'dsh 本体', description: '本地安装,可锁版本与更新' },
{ value: 'ai', title: 'AI 通道', description: '复用设置里的供应商与密钥' }
]
/** 当前步骤跟随环境状态自动推进(已完成的步骤不再回退) */
const step = ref(0)
const maxStepReached = ref(0)
watch(
() => store.setupStep,
value => {
if (value > maxStepReached.value) {
maxStepReached.value = value
step.value = value
}
},
{ immediate: true }
)
const installProgressText = computed(() => store.progress?.message ?? '')
/** 不确定进度(npm 无百分比输出) */
const indeterminate = computed(() => !!store.progress && store.progress.percent === 0)
const progressPercent = computed(() => store.progress?.percent ?? 0)
/**
* 安装输出面板的显示开关。
*
* 日志只在内存里(Rust 缓冲 + 本页展示,不进应用日志),因此这里也做成
* 「临时」的:一次安装结束后仍留在页面上供排查,用户可手动隐藏;
* 发起新安装时重新展开。
*/
const logHidden = ref(false)
const hasInstallLog = computed(() => store.installLog.trim().length > 0)
const showInstallLog = computed(() => hasInstallLog.value && !logHidden.value)
watch(
() => store.installing,
value => {
if (value) logHidden.value = false
}
)
/**
* npm 源下拉选项(地址均为实测可用)。
*
* 「跟随 npm 配置」对应存储值空串 = 不传 `--registry`,让 npm 走自己的配置链
* (环境变量 > 安装目录 .npmrc > 用户 ~/.npmrc > 内置)——「系统 Node 以前配过的
* 镜像」正是靠这一项被沿用。
*
* 注意:reka-ui 的 SelectItem **不允许空字符串 value**(会 throw),
* 因此这里用哨兵值 `__npm__` 代表「跟随」,读写设置时再与空串互换。
*/
const FOLLOW_NPM = '__npm__'
const REGISTRY_PRESETS = [
{ label: '跟随 npm 配置(推荐,沿用系统 Node 已设的镜像)', value: FOLLOW_NPM },
{ label: 'npm 官方源(registry.npmjs.org)', value: 'https://registry.npmjs.org' },
{ label: 'npmmirror(阿里)', value: 'https://registry.npmmirror.com' },
{ label: '腾讯云', value: 'https://mirrors.cloud.tencent.com/npm' },
{ label: '华为云', value: 'https://mirrors.huaweicloud.com/repository/npm' }
]
/** 当前存的若是自定义地址,补一条选项,避免下拉显示空白 */
const registryOptions = computed(() => {
const current = store.settings?.npmRegistry ?? ''
if (!current || REGISTRY_PRESETS.some(p => p.value === current)) return REGISTRY_PRESETS
return [...REGISTRY_PRESETS, { label: `自定义:${current}`, value: current }]
})
const registrySelectValue = computed(() => store.settings?.npmRegistry || FOLLOW_NPM)
function onRegistryChange(v: unknown) {
const value = String(v)
store.saveSettings({ npmRegistry: value === FOLLOW_NPM ? '' : value })
}
/** 来源说明(让用户一眼看出到底走的哪个源) */
const registrySourceText = computed(() => {
const info = store.registryInfo
if (!info) return ''
if (info.source === 'setting') return '模块设置指定'
if (info.source === 'npm') return 'npm 配置链(含系统 Node 的 ~/.npmrc)'
return '默认官方源(未检测到 npm 配置)'
})
onMounted(async () => {
await aiStore.init()
await store.loadAiPreview()
})
async function handleInstallNode() {
await store.installNode()
}
/** 安装目录改动手工输入(Rust 侧校验绝对路径,非法会 toast) */
function onInstallDirChange(e: Event) {
const value = (e.target as HTMLInputElement).value.trim()
if (value === (store.settings?.installDir ?? '')) return
store.saveSettings({ installDir: value })
}
/** 目录选择器选安装目录(返回的一定是绝对路径) */
async function pickInstallDir() {
try {
const picked = await openDialog({ directory: true, multiple: false, title: '选择 dsh 安装目录' })
if (typeof picked === 'string') store.saveSettings({ installDir: picked })
} catch (e) {
logger.error('选择安装目录失败: ' + e)
}
}
</script>
<template>
<div class="flex flex-col gap-4">
<Stepper
:model-value="step"
class="w-full flex-col gap-3 sm:flex-row sm:items-center"
@update:model-value="v => (step = Number(v))"
>
<StepperItem
v-for="(item, index) in steps"
:key="item.value"
:step="index"
class="flex w-full items-center gap-2"
>
<StepperTrigger class="flex-row items-center gap-2.5 rounded-md p-1">
<StepperIndicator class="size-7 bg-muted text-xs">
<Check v-if="index < step" class="size-3.5" />
<span v-else>{{ index + 1 }}</span>
</StepperIndicator>
<div class="flex flex-col items-start text-left">
<StepperTitle class="text-[13px]">{{ item.title }}</StepperTitle>
<StepperDescription>{{ item.description }}</StepperDescription>
</div>
</StepperTrigger>
<StepperSeparator
v-if="index < steps.length - 1"
class="mx-1 h-px flex-1 shrink-0"
/>
</StepperItem>
</Stepper>
<!-- 步骤 1:Node -->
<Card v-if="step === 0" class="!py-0 !gap-0">
<CardContent class="flex flex-col gap-3 px-4 py-4">
<div class="flex items-start justify-between gap-4">
<div class="flex min-w-0 flex-col gap-1">
<span class="text-[13px] font-medium text-foreground">Node 运行环境</span>
<span class="text-xs text-muted-foreground">
当前策略:{{ store.settings?.nodeSource === 'managed' ? '始终使用托管便携 Node' : store.settings?.nodeSource === 'system' ? '仅使用系统 Node' : '优先复用系统 Node,缺失才下载' }}
</span>
</div>
<Badge v-if="store.nodeReady" variant="outline" class="shrink-0">已满足</Badge>
<Badge v-else variant="destructive" class="shrink-0">不满足</Badge>
</div>
<dl class="flex flex-col gap-1 text-xs">
<div class="flex gap-2">
<dt class="w-20 shrink-0 text-muted-foreground">来源</dt>
<dd class="text-foreground">
{{ store.node?.source === 'managed' ? '模块托管' : store.node?.source === 'system' ? '系统 PATH' : '未找到' }}
</dd>
</div>
<div class="flex gap-2">
<dt class="w-20 shrink-0 text-muted-foreground">版本</dt>
<dd class="font-mono text-foreground">{{ store.node?.version ?? '—' }}</dd>
</div>
<div class="flex gap-2">
<dt class="w-20 shrink-0 text-muted-foreground">要求</dt>
<dd class="font-mono text-foreground">{{ store.node?.required }}</dd>
</div>
<div v-if="store.node?.path" class="flex gap-2">
<dt class="w-20 shrink-0 text-muted-foreground">路径</dt>
<dd class="min-w-0 break-all font-mono text-fg-secondary">{{ store.node.path }}</dd>
</div>
</dl>
<div v-if="store.installing" class="flex flex-col gap-2">
<div
v-if="indeterminate"
class="relative h-2 w-full overflow-hidden rounded-full bg-primary/20"
>
<div class="progress-indeterminate bg-primary absolute inset-y-0 w-1/3 rounded-full" />
</div>
<Progress v-else :model-value="progressPercent" />
<span class="text-xs text-muted-foreground">{{ installProgressText }}</span>
</div>
<div class="flex gap-2">
<Button v-if="!store.nodeReady" size="sm" :disabled="store.installing" @click="handleInstallNode">
<Loader2 v-if="store.installing" class="size-3.5 animate-spin" />
<Download v-else class="size-3.5" />下载便携 Node
</Button>
<Button v-else size="sm" disabled>
<Check class="size-3.5" />环境就绪
</Button>
<Button v-if="store.installing" size="sm" variant="outline" @click="store.cancelInstall()">
<X class="size-3.5" />取消
</Button>
<Button size="sm" variant="ghost" :disabled="store.installing" @click="store.detectNode()">
<RefreshCw class="size-3.5" />重新检测
</Button>
</div>
</CardContent>
</Card>
<!-- 步骤 2:dsh -->
<Card v-else-if="step === 1" class="!py-0 !gap-0">
<CardContent class="flex flex-col gap-3 px-4 py-4">
<div class="flex items-start justify-between gap-4">
<div class="flex min-w-0 flex-col gap-1">
<span class="text-[13px] font-medium text-foreground">dsh 本体</span>
<span class="text-xs text-muted-foreground">
用当前 Node 自带的 npm 安装到指定目录(默认应用数据目录),更新与卸载可回滚
</span>
</div>
<Badge v-if="store.installed" variant="outline" class="shrink-0">已安装</Badge>
<Badge v-else variant="destructive" class="shrink-0">未安装</Badge>
</div>
<dl class="flex flex-col gap-1 text-xs">
<div class="flex gap-2">
<dt class="w-20 shrink-0 text-muted-foreground">版本</dt>
<dd class="font-mono text-foreground">{{ store.install?.version ?? '—' }}</dd>
</div>
<div v-if="store.updateInfo" class="flex gap-2">
<dt class="w-20 shrink-0 text-muted-foreground">最新版本</dt>
<dd class="flex items-center gap-2 font-mono text-foreground">
{{ store.updateInfo.latest }}
<span v-if="store.updateInfo.hasUpdate" class="text-[11px] text-warning">可更新</span>
<Check v-else class="size-3 text-success" />
</dd>
</div>
</dl>
<!-- 安装目录:可直接改 + 目录选择器(设置页同一项,两处联动) -->
<div class="flex flex-col gap-2 rounded-lg border border-border p-3">
<div class="flex flex-wrap items-center gap-2">
<span class="text-xs font-medium text-foreground">安装目录</span>
<span class="text-[11px] text-muted-foreground">
dsh 本体(node_modules)装到哪,必须是绝对路径;改到新目录后需重新安装
</span>
</div>
<div class="flex w-full gap-2 sm:max-w-96">
<Input
:model-value="store.settings?.installDir ?? ''"
placeholder="留空 = 应用数据目录下的 dsh"
@change="onInstallDirChange"
/>
<Button size="sm" variant="outline" class="shrink-0" @click="pickInstallDir">
<FolderOpen class="size-3.5" />浏览
</Button>
</div>
<span class="text-[11px] text-muted-foreground">
实际使用
<span class="font-mono text-fg-secondary">{{ store.install?.dir }}</span>
<template v-if="store.settings?.installDir">(已自定义)</template>
<template v-else>(模块目录,未自定义)</template>
</span>
</div>
<!-- 下载源:看清本次安装走哪个 npm 源,并可一键切到国内镜像 -->
<div class="flex flex-col gap-1.5 rounded-lg border border-border p-3">
<div class="flex flex-wrap items-center gap-2">
<span class="text-xs font-medium text-foreground">下载源</span>
<span class="text-[11px] text-muted-foreground">npm 依赖从哪个源拉取</span>
<Select
class="w-full sm:ml-auto sm:w-80"
:model-value="registrySelectValue"
@update:model-value="onRegistryChange"
>
<SelectTrigger class="w-full"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem v-for="opt in registryOptions" :key="opt.value" :value="opt.value">
{{ opt.label }}
</SelectItem>
</SelectContent>
</Select>
</div>
<span class="text-[11px] text-muted-foreground">
本次将使用
<span class="font-mono text-fg-secondary">{{ store.registryInfo?.effective ?? '检测中...' }}</span>
<template v-if="registrySourceText">({{ registrySourceText }})</template>
</span>
<span
v-if="store.registryInfo?.npmRegistry && store.registryInfo.source === 'setting'"
class="text-[11px] text-muted-foreground"
>
系统 npm 当前配置:<span class="font-mono">{{ store.registryInfo.npmRegistry }}</span>
</span>
</div>
<div v-if="store.installing" class="flex flex-col gap-2">
<div
v-if="indeterminate"
class="relative h-2 w-full overflow-hidden rounded-full bg-primary/20"
>
<div class="progress-indeterminate bg-primary absolute inset-y-0 w-1/3 rounded-full" />
</div>
<Progress v-else :model-value="progressPercent" />
<span class="text-xs text-muted-foreground">{{ installProgressText }}</span>
</div>
<div class="flex flex-wrap gap-2">
<Button v-if="!store.installed" size="sm" :disabled="store.installing" @click="store.installDsh()">
<Loader2 v-if="store.installing" class="size-3.5 animate-spin" />
<Download v-else class="size-3.5" />安装 dsh
</Button>
<Button v-else size="sm" variant="outline" :disabled="store.installing" @click="store.updateDsh()">
<Loader2 v-if="store.installing" class="size-3.5 animate-spin" />
<Download v-else class="size-3.5" />更新到最新
</Button>
<Button size="sm" variant="ghost" :disabled="store.checkingUpdate || store.installing" @click="store.checkUpdate()">
<Loader2 v-if="store.checkingUpdate" class="size-3.5 animate-spin" />
<RefreshCw v-else class="size-3.5" />检查更新
</Button>
<Button v-if="store.installing" size="sm" variant="outline" @click="store.cancelInstall()">
<X class="size-3.5" />取消
</Button>
<Button v-if="store.installed && !store.installing" size="sm" variant="ghost" @click="store.uninstallDsh()">
卸载
</Button>
</div>
<!-- 安装输出:只在内存里,临时展示;不进应用日志 -->
<div v-if="showInstallLog" class="flex flex-col gap-2">
<div class="flex items-center gap-2">
<Terminal class="size-3.5 text-muted-foreground" />
<span class="text-xs font-medium text-foreground">安装输出</span>
<span class="text-[11px] text-muted-foreground">仅本页临时显示,不写入应用日志</span>
<Button class="ml-auto" size="xs" variant="ghost" @click="logHidden = true">
隐藏
</Button>
</div>
<ScrollArea class="h-56 rounded-lg border border-border bg-card">
<pre
class="px-3 py-2.5 whitespace-pre-wrap break-all font-mono text-[11px] leading-relaxed text-fg-secondary"
>{{ store.installLog }}</pre>
</ScrollArea>
</div>
</CardContent>
</Card>
<!-- 步骤 3:AI 通道 -->
<Card v-else class="!py-0 !gap-0">
<CardContent class="flex flex-col gap-3 px-4 py-4">
<div class="flex items-start justify-between gap-4">
<div class="flex min-w-0 flex-col gap-1">
<span class="text-[13px] font-medium text-foreground">AI 通道</span>
<span class="text-xs text-muted-foreground">
把主设置「AI 服务」里已启用的供应商写入 dsh 的 settings.yaml;
密钥不落盘,改为启动时以环境变量注入(来自系统凭据管理器)
</span>
</div>
<Badge v-if="store.preview?.providers.length" variant="outline" class="shrink-0">
{{ store.preview.providers.length }} 个供应商
</Badge>
<Badge v-else variant="destructive" class="shrink-0">无可用供应商</Badge>
</div>
<SettingGroup title="默认模型" description="选择 dsh 默认使用哪个供应商(在 dsh 内仍可切换)">
<SettingRow label="默认供应商" description="取自设置 → AI 服务中已启用的供应商" control-width="wide">
<Select
:model-value="store.settings?.providerId ?? ''"
@update:model-value="v => store.saveSettings({ providerId: String(v) })"
>
<SelectTrigger class="w-full"><SelectValue placeholder="选择供应商" /></SelectTrigger>
<SelectContent>
<SelectItem
v-for="p in aiStore.providers.filter(x => x.config.enabled)"
:key="p.config.id"
:value="p.config.id"
>
{{ p.config.name || p.config.id }}
</SelectItem>
</SelectContent>
</Select>
</SettingRow>
<SettingRow label="同步 settings.yaml" description="启动服务前自动同步一次;关闭后可手动同步">
<Switch
:model-value="store.settings?.aiSync ?? true"
@update:model-value="v => store.saveSettings({ aiSync: v === true })"
/>
</SettingRow>
</SettingGroup>
<div v-if="store.preview" class="flex flex-col gap-2">
<div class="flex flex-wrap gap-2">
<Badge
v-for="p in store.preview.providers"
:key="p.id"
:variant="p.hasKey ? 'outline' : 'destructive'"
>
{{ p.name || p.id }} · {{ p.hasKey ? '已配置密钥' : '缺密钥' }}
</Badge>
</div>
<ScrollArea class="h-56 rounded-lg border border-border bg-card">
<pre
class="px-3 py-2.5 font-mono text-[11px] leading-relaxed text-fg-secondary"
>{{ store.preview.yaml }}</pre>
</ScrollArea>
</div>
<div class="flex flex-wrap gap-2">
<Button size="sm" variant="outline" @click="store.syncAi()">
<Sparkles class="size-3.5" />同步 AI 配置
</Button>
<Button size="sm" variant="ghost" @click="store.loadAiPreview()">
<RefreshCw class="size-3.5" />刷新预览
</Button>
<Button size="sm" :disabled="!store.running" @click="store.restart()">
<Play class="size-3.5" />重启服务生效
</Button>
</div>
</CardContent>
</Card>
</div>
</template>
<style scoped>
/*
* 不确定进度条(npm 安装无百分比输出时的表达)。
* 项目没有「indeterminate Progress」组件,这里用一条循环平移的色块代替,
* 避免伪造百分比数字。
*/
.progress-indeterminate {
animation: dsh-indeterminate 1.2s ease-in-out infinite;
}
@keyframes dsh-indeterminate {
0% {
left: -33%;
}
100% {
left: 100%;
}
}
</style>
+72
View File
@@ -0,0 +1,72 @@
import type { ModuleConfig } from '@/types/module'
import type { SearchIndexItem } from '@/stores/searchIndex'
const searchItems: SearchIndexItem[] = [
{
title: 'DeepSeek Harness',
description: '安装、更新与启动 dsh,管理 Node 运行环境与 AI 通道',
keywords: ['dsh', 'deepseek', 'harness', 'agent', '智能体', '外壳', '安装'],
tab: 'setup'
},
{
title: '安装 dsh 环境',
description: '按步骤引导安装 Node 运行环境与 dsh 本体',
keywords: ['安装', 'install', 'node', '环境', '引导', 'stepper', '更新'],
tab: 'setup'
},
{
title: 'dsh 设置',
description: '端口、工作区、Node 来源、镜像源与自动启动',
keywords: ['设置', 'setting', '端口', 'port', '工作区', 'workspace', '镜像'],
tab: 'settings'
},
{
title: 'dsh AI 通道',
description: '把设置里的 AI 供应商(含 DeepSeek API Key)同步给 dsh',
keywords: ['ai', 'api key', 'deepseek', '供应商', 'provider', '模型', 'model'],
tab: 'settings'
},
{
title: 'dsh 运行日志',
description: '查看 dsh 服务的输出日志',
keywords: ['日志', 'log', '输出', '排查', 'debug'],
tab: 'logs'
}
]
export const moduleConfig: ModuleConfig = {
id: 'dsh',
name: 'DeepSeek Harness',
icon: 'dsh',
description: 'DeepSeek Harness(dsh)外壳:环境安装引导、版本更新与 Web 服务生命周期管理',
category: 'tool',
defaultEnabled: true,
loader: () => import('./DshModule.vue'),
searchItems,
lifecycle: {
// 模块启用:恢复全局快捷键(应用启动时由 main.ts 注册;这里覆盖「先禁用再启用」)
onEnable: async () => {
try {
const { useDshStore } = await import('@/stores/dshStore')
await useDshStore().registerShortcut()
} catch (e) {
console.error('[dsh] onEnable 注册快捷键失败:', e)
}
},
// 模块禁用:停服务 + 注销快捷键(服务停了快捷键也没意义,且组合键不该被占着)
onDisable: async () => {
// 动态导入避免 index.ts 直接依赖 store(会形成循环依赖,参见 terminal / music 的处理)
try {
const { useDshStore } = await import('@/stores/dshStore')
const store = useDshStore()
if (store.running) await store.stop()
await store.unregisterShortcut()
store.stopListeners()
} catch (e) {
console.error('[dsh] onDisable 停止服务失败:', e)
}
}
},
// 排在开发工具之后:音乐 / 代理 / 下载 / 终端 / 翻译 / 监控 / 截图 / 剪贴板 / 快捷面板 / 开发工具 / dsh
order: 110
}
+4 -2
View File
@@ -10,7 +10,8 @@ import {
Wrench,
Music,
Languages,
SquareTerminal
SquareTerminal,
Bot
} from '@lucide/vue'
/**
@@ -31,7 +32,8 @@ export const moduleIconMap: Record<string, Component> = {
devtools: Wrench,
music: Music,
translate: Languages,
terminal: SquareTerminal
terminal: SquareTerminal,
dsh: Bot
}
/** 获取模块图标组件,未找到时回退到 Settings 图标 */
+3 -1
View File
@@ -13,6 +13,7 @@ import { moduleConfig as settings } from './settings'
import { moduleConfig as music } from './music'
import { moduleConfig as translate } from './translate'
import { moduleConfig as terminal } from './terminal'
import { moduleConfig as dsh } from './dsh'
const allModules: ModuleConfig[] = [
proxy,
@@ -25,7 +26,8 @@ const allModules: ModuleConfig[] = [
settings,
music,
translate,
terminal
terminal,
dsh
]
// 启动时注册所有模块
@@ -63,6 +63,8 @@ const win = getCurrentWindow()
let objectUrl = ''
/** 常驻窗口:加载事件监听(store 通知加载编辑器图片槽中的新图) */
let loadUnlisten: UnlistenFn | null = null
/** 握手请求监听(见 store 的 ensureEditorReady):主窗口每次打开编辑器前 ping,本窗口应答 ready */
let pingUnlisten: UnlistenFn | null = null
/** 马赛克结果缓存:标注参数不变时跳过重复像素化(长图上拖动其他标注不再卡顿) */
let mosaicCache: { key: string; canvas: HTMLCanvasElement } | null = null
@@ -1108,6 +1110,12 @@ onMounted(async () => {
loadUnlisten = await listen(EVENTS.screenshotEditorLoad, () => {
void loadPendingImage()
})
// 握手应答:主窗口每次打开编辑器前 ping(store 的 ensureEditorReady)。本监听挂在
// 加载监听**之后** —— 只有加载监听已就绪,应答才代表「可以接收新图」。这样主窗口
// 重载后(编辑器窗口存活、不会再发首次 ready)也能重新确认就绪状态。
pingUnlisten = await listen(EVENTS.screenshotEditorPing, () => {
void emit(EVENTS.screenshotEditorReady).catch(() => {})
})
await emit(EVENTS.screenshotEditorReady)
})
@@ -1118,6 +1126,8 @@ onUnmounted(() => {
window.removeEventListener('storage', onStorageChange)
loadUnlisten?.()
loadUnlisten = null
pingUnlisten?.()
pingUnlisten = null
if (objectUrl) {
URL.revokeObjectURL(objectUrl)
objectUrl = ''
@@ -167,6 +167,8 @@ let magGridCanvas: HTMLCanvasElement | null = null
// 常驻窗口:'screenshot-begin' 事件监听(store 捕获并定位窗口后触发)
let beginUnlisten: UnlistenFn | null = null
/** 握手请求监听(见 store 的 ensureOverlayReady):主窗口每次截图前 ping,本窗口应答 ready */
let pingUnlisten: UnlistenFn | null = null
const beginUnlistenCleanups: Array<() => void> = []
/** 界面内滚动会话事件监听(scrollProgress / scrollComplete / scrollCancelled) */
let scrollProgressUnlisten: UnlistenFn | null = null
@@ -1904,6 +1906,12 @@ onMounted(async () => {
beginUnlisten = await listen<ScreenshotBeginPayload>(EVENTS.screenshotBegin, (e) => {
void beginCapture(e.payload)
})
// 握手应答:主窗口每次发起截图前 ping(store 的 ensureOverlayReady)。本监听挂在
// begin 监听**之后** —— 只有 begin 监听已就绪,应答才真正代表「可以接收截图」。
// 这样主窗口重载后(覆盖层窗口存活、不会再发首次 ready)也能重新确认就绪状态。
pingUnlisten = await listen(EVENTS.screenshotOverlayPing, () => {
void emit(EVENTS.screenshotOverlayReady).catch(() => {})
})
// 界面内滚动会话事件(仅滚动模式下有意义;会话由主窗口触发、覆盖层常驻监听)
scrollProgressUnlisten = await listen<{ width: number; height: number }>(EVENTS.scrollProgress, (e) => {
if (!scrollMode.value) return
@@ -2029,6 +2037,8 @@ onUnmounted(() => {
window.removeEventListener('storage', onStorageChange)
beginUnlisten?.()
beginUnlisten = null
pingUnlisten?.()
pingUnlisten = null
scrollProgressUnlisten?.()
scrollProgressUnlisten = null
scrollCompleteUnlisten?.()
+9
View File
@@ -27,6 +27,8 @@ const items = ref<{ filePath: string; width: number; height: number; posX?: numb
const cur = ref(0)
let showUnlisten: UnlistenFn | null = null
/** 握手请求监听(见 store 的 ensurePinReady):主窗口每次贴图前 ping,本窗口应答 ready */
let pingUnlisten: UnlistenFn | null = null
// ===== 贴图数据缓存(LRU,值为 Blob URL):命中时上一张/下一张切换零 IPC、零等待 =====
const imgCache = new Map<string, string>()
@@ -384,6 +386,11 @@ onMounted(async () => {
showUnlisten = await listen(EVENTS.screenshotPinShow, () => {
openPin()
})
// 握手应答:主窗口每次贴图前 ping(store 的 ensurePinReady)。挂在 show 监听**之后**
// —— 应答即代表 show 监听已就绪。主窗口重载后本窗口不会再发首次 ready,由应答补上。
pingUnlisten = await listen(EVENTS.screenshotPinPing, () => {
void emit(EVENTS.screenshotPinReady).catch(() => {})
})
await emit(EVENTS.screenshotPinReady)
})
@@ -391,6 +398,8 @@ onUnmounted(() => {
window.removeEventListener('keydown', onKeyDown)
window.removeEventListener('blur', onBlur)
showUnlisten?.()
pingUnlisten?.()
pingUnlisten = null
})
</script>
+1 -1
View File
@@ -190,7 +190,7 @@ async function closeWindow() {
</Tooltip>
</div>
<!-- 内容:与 tab 页完全同一个组件(standalone 模式自带四周留白) -->
<!-- 内容:与 tab 页完全同一个组件(standalone 模式占满容器、无圆角) -->
<div class="flex-1 min-h-0">
<div v-if="!ready" class="h-full flex items-center justify-center gap-2">
<Loader2 class="size-4 animate-spin text-muted-foreground" />
+1 -1
View File
@@ -14,7 +14,7 @@
*
* # 键位从设置里读
*
* 键位存在终端设置的快捷键表里(设置 → 快捷键 → 会话 → 新建独立窗口,默认 `Ctrl+3`),
* 键位存在终端设置的快捷键表里(设置 → 快捷键 → 会话 → 新建独立窗口,默认 `Alt+T`),
* 因此这里是「读设置 → 注册」而不是硬编码:改键后 watch 到变化即重新注册。
* 关掉那一行右侧的开关 = 不注册。
*
@@ -281,10 +281,10 @@ watch(
<template>
<!--
独立窗口模式自带四周留白(窗口控制栏之下没有模块级的 p-5);
独立窗口模式:窗口控制栏之下的区域由本组件占满(无边距、无圆角),
tab 模式由终端模块根节点的 p-5 提供边距。
-->
<div class="flex flex-col h-full overflow-hidden" :class="standalone ? 'p-3' : ''">
<div class="flex flex-col h-full overflow-hidden">
<PageToolbar
v-if="!standalone"
:icon="FolderTree"
@@ -301,7 +301,10 @@ watch(
分成两张卡片(`gap-3`)会让它读作「两个窗口并排」,而这里要做的是
「一个窗口的两半」—— 分界线可拖,与资源管理器的双栏一致。
-->
<Card class="flex-1 min-h-0 !py-0 !gap-0 overflow-hidden">
<Card
class="flex-1 min-h-0 !py-0 !gap-0 overflow-hidden"
:class="standalone ? 'rounded-none' : ''"
>
<div ref="splitRowRef" class="h-full min-h-0 flex">
<!-- 左栏:宽度用百分比(拖动的结果在窗口缩放后仍然成立) -->
<div class="min-w-0 flex flex-col" :style="{ width: `${store.filePaneSplit}%` }">
+184 -9
View File
@@ -24,7 +24,7 @@
* | 跟随 cd | 跟随「当前激活会话」(面板绑会话) | 跟随**本栏所选会话**的 cwd |
* | 新增目录校验 | 分别禁止 `/` 或 `\` | 两种分隔符都禁止(本地路径也认 `/`) |
*/
import { computed, ref, watch } from 'vue'
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { open as openDialog } from '@tauri-apps/plugin-dialog'
import {
ArrowLeft,
@@ -59,7 +59,7 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger
} from '@/components/ui/dropdown-menu'
import { fmtEntryTime, fmtFullTime, humanSize, joinLocal, joinRemote, parentOf } from '../fileUtils'
import { fmtFullTime, humanSize, joinLocal, joinRemote, parentOf } from '../fileUtils'
import type { FileSource, SessionInfo } from '@/types/terminal'
/**
@@ -472,6 +472,124 @@ function revealLocalPath(path: string) {
void store.revealLocalPath(path).catch(e => toast.error(`定位失败:${String(e)}`))
}
// ===== 右键菜单 =====
/**
* 行内右键菜单。
*
* 动作全部落在本栏:重命名 / 删除 / 新建 / 刷新都是本栏的局部操作,
* 只有「传送」需要父组件编排(本栏不知道对面是什么),因此仍然只是 `emit('transfer')`。
*
* 原生右键菜单被 `main.ts` 全局禁用了,所以这里是自绘菜单 —— 外观与终端右键菜单
*(`TerminalContextMenu`)同一套,不为文件列表另立一套视觉。
*/
const menuPos = ref<{ x: number; y: number } | null>(null)
/** 右键命中的行;`null` = 右键落在空白区域(只给本栏级动作) */
const menuEntry = ref<PaneEntry | null>(null)
const menuRef = ref<HTMLElement | null>(null)
function closeMenu() {
menuPos.value = null
menuEntry.value = null
}
/**
* 打开菜单并按视口边界收拢位置。
*
* 列表最后一行的右键位置几乎贴着窗口底边,不收拢的话菜单会有一半落在窗口外
*(原生菜单由系统负责这件事,自绘就得自己算)。菜单尺寸只能渲染后量出来,
* 所以收拢放在 `nextTick` 里。
*/
function openMenu(entry: PaneEntry | null, ev: MouseEvent) {
menuEntry.value = entry
menuPos.value = { x: ev.clientX, y: ev.clientY }
void nextTick(() => {
const el = menuRef.value
const pos = menuPos.value
if (!el || !pos) return
const rect = el.getBoundingClientRect()
menuPos.value = {
x: Math.max(4, Math.min(pos.x, window.innerWidth - rect.width - 4)),
y: Math.max(4, Math.min(pos.y, window.innerHeight - rect.height - 4))
}
})
}
/**
* 行上右键。
*
* 命中未选中的行时先把选择落到它身上(资源管理器的一致行为);
* 命中的行已在**多选**里则保留整组 —— 右键是「对当前选择执行动作」的入口,
* 后面的「传送」正需要整组。
*/
function onRowContextMenu(entry: PaneEntry, ev: MouseEvent) {
if (!isSelected(entry)) {
selected.value = [entry]
anchor = filtered.value.findIndex(e => e.path === entry.path)
}
openMenu(entry, ev)
}
/** 空白处右键:先取消选择,再给本栏级动作(新建目录 / 刷新) */
function onBlankContextMenu(ev: MouseEvent) {
selected.value = []
openMenu(null, ev)
}
function transferFromMenu() {
closeMenu()
emit('transfer')
}
function openFromMenu() {
const e = menuEntry.value
closeMenu()
if (e) openLocalPath(e.path)
}
function revealFromMenu() {
const e = menuEntry.value
closeMenu()
if (e) revealLocalPath(e.path)
}
function renameFromMenu() {
closeMenu()
startRename()
}
function removeFromMenu() {
closeMenu()
void removeSelected()
}
function newDirFromMenu() {
closeMenu()
showNewDir.value = true
}
function reloadFromMenu() {
closeMenu()
void load(cwd.value)
}
const onMenuKeydown = (e: KeyboardEvent) => {
if (e.key === 'Escape') closeMenu()
}
onMounted(() => {
// 点击任意处 / 按 ESC 关闭菜单(冒泡阶段:面板自身的 click 也要能关掉它)。
// 两栏各挂一份无妨:任一栏的点击都会把另一栏的菜单一起收掉 —— 一屏内
// 同时存在两个右键菜单本身就是不该出现的样子。
document.addEventListener('click', closeMenu)
document.addEventListener('keydown', onMenuKeydown)
})
onBeforeUnmount(() => {
document.removeEventListener('click', closeMenu)
document.removeEventListener('keydown', onMenuKeydown)
})
// ===== 对外接口(父组件编排传输时读这两样) =====
defineExpose({
@@ -665,11 +783,12 @@ defineExpose({
>
<span class="flex-1 min-w-0">名称</span>
<span class="w-[72px] shrink-0 text-right">大小</span>
<span class="w-[76px] shrink-0">修改时间</span>
<span class="w-[110px] shrink-0">修改时间</span>
<span v-if="isSsh" class="w-11 shrink-0 text-right">权限</span>
</div>
<ScrollArea class="flex-1 min-h-0">
<!-- 空白区域右键(本栏级动作):行的右键带 `.stop`,不会冒泡到这里 -->
<ScrollArea class="flex-1 min-h-0" @contextmenu="onBlankContextMenu">
<div v-if="loading" class="p-4 flex items-center justify-center gap-2">
<Loader2 class="size-3.5 animate-spin text-muted-foreground" />
<span class="text-xs text-muted-foreground">正在读取…</span>
@@ -691,6 +810,7 @@ defineExpose({
:class="isSelected(e) ? 'bg-row-selected' : 'hover:bg-row-hover'"
@click="clickEntry(e, $event)"
@dblclick="enter(e)"
@contextmenu.stop.prevent="onRowContextMenu(e, $event)"
>
<!-- 名称列:唯一可伸缩的一列(min-w-0 + truncate 是截断生效的充要条件) -->
<div class="flex-1 min-w-0 flex items-center gap-1.5">
@@ -742,11 +862,8 @@ defineExpose({
<span class="w-[72px] shrink-0 text-right text-muted-foreground tabular-nums whitespace-nowrap">
{{ e.isDir ? '—' : humanSize(e.size) }}
</span>
<span
class="w-[76px] shrink-0 text-muted-foreground tabular-nums whitespace-nowrap"
:title="fmtFullTime(e.modifiedAt)"
>
{{ fmtEntryTime(e.modifiedAt) }}
<span class="w-[110px] shrink-0 text-muted-foreground tabular-nums whitespace-nowrap">
{{ fmtFullTime(e.modifiedAt) }}
</span>
<span
v-if="isSsh"
@@ -775,5 +892,63 @@ defineExpose({
</Button>
</div>
</template>
<!-- ===== 右键菜单 =====
自绘菜单(`main.ts` 全局禁用了原生右键菜单),外观与终端右键菜单一致。
`fixed` + 视口坐标:不受列表滚动容器裁剪;位置已在 `openMenu` 里按视口收拢。
行上的菜单与空白处的菜单是两套条目 —— 前者作用于「选中的行」,
后者只给本栏级动作,因为右键位置本身就是用户对作用对象的声明。 -->
<div
v-if="menuPos"
ref="menuRef"
class="fixed z-50 min-w-[176px] py-1 rounded-md border border-border bg-popover shadow-lg text-xs"
:style="{ left: `${menuPos.x}px`, top: `${menuPos.y}px` }"
@click.stop
@contextmenu.stop.prevent
>
<template v-if="menuEntry">
<button
class="w-full px-3 py-1.5 text-left hover:bg-accent disabled:opacity-40 disabled:pointer-events-none"
:disabled="transferBlocked !== '' || filesSelected.length === 0"
:title="transferHint"
@click="transferFromMenu"
>
{{ transferLabel }}{{ filesSelected.length > 1 ? ` (${filesSelected.length})` : '' }}
</button>
<!-- 打开 / 定位只对本地行给出:远端路径在本机上没有这两个语义 -->
<template v-if="!isSsh">
<div class="my-1 h-px bg-border" />
<button class="w-full px-3 py-1.5 text-left hover:bg-accent" @click="openFromMenu">
用默认程序打开
</button>
<button class="w-full px-3 py-1.5 text-left hover:bg-accent" @click="revealFromMenu">
在资源管理器中显示
</button>
</template>
<div class="my-1 h-px bg-border" />
<button
class="w-full px-3 py-1.5 text-left hover:bg-accent disabled:opacity-40 disabled:pointer-events-none"
:disabled="selected.length !== 1"
@click="renameFromMenu"
>
重命名
</button>
<button
class="w-full px-3 py-1.5 text-left hover:bg-accent text-destructive"
@click="removeFromMenu"
>
删除
</button>
</template>
<template v-else>
<button class="w-full px-3 py-1.5 text-left hover:bg-accent" @click="newDirFromMenu">
新建目录
</button>
<button class="w-full px-3 py-1.5 text-left hover:bg-accent" @click="reloadFromMenu">
刷新
</button>
</template>
</div>
</div>
</template>
@@ -527,7 +527,13 @@ function moveHop(i: number, dir: -1 | 1) {
(monitor / downloader)都用 ScrollArea + max-h 的写法。
-->
<ScrollArea class="max-h-[60vh] pr-4">
<div v-if="editing" class="space-y-4">
<!--
`px-1.5` 不是装饰:ScrollArea 的 viewport 恒定 `overflow: hidden/scroll`,
输入框铺满视口时,`focus-visible:ring-3` 的焦点环(画在边框外侧 3px)
会被左右裁掉(聚焦后表现为「边被遮挡」)。内边距必须加在**滚动内容**这层,
加在 ScrollArea 根上只会把视口整体变窄,裁切线跟着输入框一起移动。
-->
<div v-if="editing" class="space-y-4 px-1.5">
<!-- 基本信息 -->
<div class="grid grid-cols-2 gap-3">
<div class="space-y-1.5">
@@ -543,9 +543,10 @@ function formatDate(rfc3339: string): string {
</DialogDescription>
</DialogHeader>
<!-- 表单较长,用 ScrollArea 滚动(见 HostManager 的编辑对话框同款说明) -->
<!-- 表单较长,用 ScrollArea 滚动(见 HostManager 的编辑对话框同款说明);
px-1.5 见同处说明:滚动内容不留内边距时输入框的聚焦环会被 viewport 裁掉 -->
<ScrollArea class="max-h-[60vh] pr-4">
<div class="space-y-3">
<div class="space-y-3 px-1.5">
<div class="space-y-1.5">
<Label class="text-xs">名称</Label>
<Input v-model="genForm.name" placeholder="例如:生产服务器" class="h-8 text-sm" />
@@ -628,9 +629,10 @@ function formatDate(rfc3339: string): string {
</DialogDescription>
</DialogHeader>
<!-- 含多行私钥文本域,容易超过视口高度,用 ScrollArea 滚动 -->
<!-- 含多行私钥文本域,容易超过视口高度,用 ScrollArea 滚动;
px-1.5 见 HostManager 编辑对话框的说明(滚动内容的聚焦环防裁切) -->
<ScrollArea class="max-h-[60vh] pr-4">
<div class="space-y-3">
<div class="space-y-3 px-1.5">
<div class="space-y-1.5">
<Label class="text-xs">名称</Label>
<Input v-model="importName" placeholder="例如:GitHub" class="h-8 text-sm" />
@@ -118,9 +118,20 @@ async function submit() {
</DialogDescription>
</DialogHeader>
<!-- 表单较长(七个字段 + 危险提示),用 ScrollArea 滚动(见 HostManager 同款说明) -->
<!--
表单较长(七个字段 + 危险提示),用 ScrollArea 滚动(见 HostManager 同款说明)。
`px-1.5` 不是装饰:reka 的 ScrollArea viewport 恒定是 `overflow: hidden/scroll`
(由 X/Y 滚动条是否启用决定,**不是**只在滚动时才裁),而 `focus-visible:ring-3`
的焦点环画在输入框边框**外侧** 3px。输入框铺满视口时,左右两侧的外环正好落在
裁切线上被切掉(表现为聚焦后「边被遮挡」)。给滚动内容留出内边距,外环落在
视口内部即可完整显示。
内边距必须加在**滚动内容**这一层:加在 ScrollArea 根上只会把视口整体变窄,
裁切线跟着输入框一起移动,环照样被切。
-->
<ScrollArea class="max-h-[60vh] pr-4">
<div v-if="draft" class="space-y-3">
<div v-if="draft" class="space-y-3 px-1.5">
<label class="block space-y-1">
<span class="text-[11px] text-muted-foreground">名称</span>
<Input v-model="draft.name" class="h-8 text-sm" placeholder="如:查找大文件" />
+6 -24
View File
@@ -67,7 +67,12 @@ export function humanSize(n: number): string {
return `${v < 10 ? v.toFixed(1) : Math.round(v)} ${units[i]}`
}
/** 完整时间戳 `YYYY-MM-DD HH:mm`(行的悬停提示用) */
/**
* 完整时间戳 `YYYY-MM-DD HH:mm`。
*
* 「修改时间」列直接显示它 —— 定宽列(`w-[110px]`)在 12px 字号下刚好放得下,
* 年月日与时刻都不再省略(此前本年内只显示 `MM-DD HH:mm`、更早的只显示日期)。
*/
export function fmtFullTime(ms?: number | null): string {
if (!ms) return ''
const d = new Date(ms)
@@ -75,29 +80,6 @@ export function fmtFullTime(ms?: number | null): string {
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
}
/**
* 列表里显示的紧凑时间。
*
* 本年内的条目省略年份(`05-19 10:01`),其余显示 `2024-05-19`。
*
* # 为什么不是「一律 `YYYY-MM-DD HH:mm`」
*
* 文件列表的「修改时间」列是**定宽**的,而完整时间戳在 12px 字号下要 100px 左右;
* 定宽列一旦装不下就会换行(这正是改版前那一版的表现:日期被折成三行)。
* 截断也不行 —— 时间的一半信息比年份缺失更糟。因此按「近期看时刻、远期看日期」
* 分档,一列 76px 两种形态都放得下;完整值仍在悬停提示里。
*/
export function fmtEntryTime(ms?: number | null): string {
if (!ms) return ''
const d = new Date(ms)
const pad = (x: number) => String(x).padStart(2, '0')
const md = `${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
if (d.getFullYear() === new Date().getFullYear()) {
return `${md} ${pad(d.getHours())}:${pad(d.getMinutes())}`
}
return `${d.getFullYear()}-${md}`
}
/** 两栏连接的组合是否支持传输(本地↔本地没有传输语义,见 FileManager 的说明) */
export function transferKind(
from: FileSource | null,
+2 -2
View File
@@ -85,8 +85,8 @@ const searchItems: SearchIndexItem[] = [
},
{
title: '终端独立窗口',
description: '把会话拖出主窗口,独立窗口承载单个会话;Ctrl+3 可直接唤起新建列表',
keywords: ['独立窗口', '分离', 'detach', '新窗口', '多屏', 'ctrl+3'],
description: '把会话拖出主窗口,独立窗口承载单个会话;Alt+T 可直接唤起新建列表',
keywords: ['独立窗口', '分离', 'detach', '新窗口', '多屏', 'alt+t'],
tab: 'settings'
},
{
+1 -1
View File
@@ -88,7 +88,7 @@ const sourceDirty = computed(() => {
return editableText.value.trim() !== lastTranslated.value.trim()
})
// ===== 面板模式(Ctrl+2 打开):候选列表 + 键盘交互 =====
// ===== 面板模式(默认 Alt+F 打开):候选列表 + 键盘交互 =====
const candidates = ref<PanelCandidate[]>([])
const listOpen = ref(false)
const activeCandidate = ref(0)
@@ -657,7 +657,7 @@ function templateWarning(text: string): string {
<Input
v-model="shortcutDraft.panelShortcut"
class="h-8 w-40 text-[13px]"
placeholder="Ctrl+2"
placeholder="Alt+F"
/>
<span class="text-[11px] text-muted-foreground">全局生效;留空禁用</span>
</div>