调整
This commit is contained in:
1 parent
79bded1cd2
commit
9e6d73e191
73 files changed
+6229
-1427
No files matched your search
@@ -415,7 +415,7 @@ onUnmounted(() => {
|
||||
<Card
|
||||
v-for="item in historyList"
|
||||
:key="item.id"
|
||||
class="group hover:shadow-md transition-shadow py-0"
|
||||
class="group transition-[background-color,box-shadow] py-0 hover:bg-row-hover hover:shadow-md"
|
||||
>
|
||||
<CardContent class="flex items-center gap-3 px-3 py-2">
|
||||
<component :is="kindIcon(item.kind)" class="size-4 text-muted-foreground shrink-0" />
|
||||
@@ -465,7 +465,7 @@ onUnmounted(() => {
|
||||
</Empty>
|
||||
|
||||
<div v-else class="space-y-1.5 px-3 pb-2">
|
||||
<Card v-for="item in pinnedList" :key="item.id" class="group hover:shadow-md transition-shadow py-0">
|
||||
<Card v-for="item in pinnedList" :key="item.id" class="group transition-[background-color,box-shadow] py-0 hover:bg-row-hover hover:shadow-md">
|
||||
<CardContent class="flex items-center gap-3 px-3 py-2">
|
||||
<component :is="kindIcon(item.kind)" class="size-4 text-primary shrink-0" />
|
||||
<div class="flex-1 min-w-0 cursor-pointer" @click="openDetail(item)">
|
||||
|
||||
@@ -630,13 +630,19 @@ onUnmounted(() => {
|
||||
transition: box-shadow 0.2s, background-color 0.1s;
|
||||
}
|
||||
|
||||
/* hover 使用 shadow(同主界面 hover:shadow-md),键盘选中保留轻微高亮 */
|
||||
/* hover 用「主题色弱底 + 阴影」;键盘选中用 primary-soft 强底。
|
||||
底色取 --row-hover(不透明)而不是半透明叠色 —— 弹窗根容器在 mica 下是透明的,
|
||||
半透明色会和桌面壁纸混色。 */
|
||||
.popup-item:hover {
|
||||
background: var(--row-hover);
|
||||
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
|
||||
}
|
||||
|
||||
.popup-item-selected {
|
||||
background: var(--accent);
|
||||
/* 选中态强度必须盖过 hover::hover 的特异性(0,2,0)高于单类(0,1,0),
|
||||
不显式补 :hover 的话,悬停已选中项会退回更弱的行 hover 底 */
|
||||
.popup-item-selected,
|
||||
.popup-item-selected:hover {
|
||||
background: var(--row-selected);
|
||||
}
|
||||
|
||||
/* 类型 badge 配色(与主界面一致) */
|
||||
|
||||
@@ -1713,7 +1713,7 @@ const toggleSortOrder = () => {
|
||||
<label
|
||||
v-for="f in btSelectTask.btFiles"
|
||||
:key="f.index"
|
||||
class="flex items-center gap-2 text-xs rounded px-1.5 py-1 hover:bg-muted cursor-pointer"
|
||||
class="flex items-center gap-2 text-xs rounded px-1.5 py-1 hover:bg-row-hover cursor-pointer"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
|
||||
@@ -1828,7 +1828,7 @@ watch(() => store.status?.ready, (ready, prev) => {
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-md border p-2.5 text-left transition-colors"
|
||||
:class="osdConfig.layout === 'single' ? 'border-primary bg-primary/5' : 'hover:bg-muted'"
|
||||
:class="osdConfig.layout === 'single' ? 'border-primary bg-primary/5' : 'hover:bg-row-hover'"
|
||||
@click="updateOsdConfig('layout', 'single')"
|
||||
>
|
||||
<div class="text-xs font-medium">单行</div>
|
||||
@@ -1837,7 +1837,7 @@ watch(() => store.status?.ready, (ready, prev) => {
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-md border p-2.5 text-left transition-colors"
|
||||
:class="osdConfig.layout === 'group' ? 'border-primary bg-primary/5' : 'hover:bg-muted'"
|
||||
:class="osdConfig.layout === 'group' ? 'border-primary bg-primary/5' : 'hover:bg-row-hover'"
|
||||
@click="updateOsdConfig('layout', 'group')"
|
||||
>
|
||||
<div class="text-xs font-medium">分组横排</div>
|
||||
@@ -1849,7 +1849,7 @@ watch(() => store.status?.ready, (ready, prev) => {
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-md border p-2.5 text-left transition-colors"
|
||||
:class="osdConfig.layout === 'multiline' ? 'border-primary bg-primary/5' : 'hover:bg-muted'"
|
||||
:class="osdConfig.layout === 'multiline' ? 'border-primary bg-primary/5' : 'hover:bg-row-hover'"
|
||||
@click="updateOsdConfig('layout', 'multiline')"
|
||||
>
|
||||
<div class="text-xs font-medium">多行</div>
|
||||
@@ -2473,7 +2473,7 @@ watch(() => store.status?.ready, (ready, prev) => {
|
||||
<div
|
||||
v-for="hw in store.hardwareConfig?.availableHardware ?? []"
|
||||
:key="hw.key"
|
||||
class="flex items-center justify-between gap-2 rounded-md px-2 py-1.5 hover:bg-muted/50"
|
||||
class="flex items-center justify-between gap-2 rounded-md px-2 py-1.5 hover:bg-row-hover"
|
||||
>
|
||||
<div class="flex items-center gap-2 min-w-0">
|
||||
<Checkbox
|
||||
@@ -2500,7 +2500,7 @@ watch(() => store.status?.ready, (ready, prev) => {
|
||||
<div
|
||||
v-for="st in store.hardwareConfig?.availableSensorTypes ?? []"
|
||||
:key="st.key"
|
||||
class="flex items-center gap-2 rounded-md px-2 py-1.5 hover:bg-muted/50"
|
||||
class="flex items-center gap-2 rounded-md px-2 py-1.5 hover:bg-row-hover"
|
||||
>
|
||||
<Checkbox
|
||||
:id="'st-' + st.key"
|
||||
@@ -2577,7 +2577,7 @@ watch(() => store.status?.ready, (ready, prev) => {
|
||||
<div
|
||||
v-for="s in grp.common"
|
||||
:key="s.key"
|
||||
class="flex items-center gap-2 rounded-md px-2 py-1.5 hover:bg-muted/50"
|
||||
class="flex items-center gap-2 rounded-md px-2 py-1.5 hover:bg-row-hover"
|
||||
>
|
||||
<Checkbox
|
||||
:id="'osd-' + s.key"
|
||||
@@ -2609,7 +2609,7 @@ watch(() => store.status?.ready, (ready, prev) => {
|
||||
<div
|
||||
v-for="s in grp.detailed"
|
||||
:key="s.key"
|
||||
class="flex items-center gap-2 rounded-md px-2 py-1.5 hover:bg-muted/50"
|
||||
class="flex items-center gap-2 rounded-md px-2 py-1.5 hover:bg-row-hover"
|
||||
>
|
||||
<Checkbox
|
||||
:id="'osd-' + s.key"
|
||||
|
||||
@@ -834,7 +834,7 @@ const RESULT_GRID = { gridTemplateColumns: '24px 36px minmax(0,1fr) 108px 52px 9
|
||||
v-for="h in filteredHistory"
|
||||
:key="h"
|
||||
type="button"
|
||||
class="flex w-full items-center gap-2 truncate rounded-md px-2 py-1.5 text-left text-[13px] hover:bg-accent/60"
|
||||
class="flex w-full items-center gap-2 truncate rounded-md px-2 py-1.5 text-left text-[13px] hover:bg-row-hover"
|
||||
@click="pickHistory(h)"
|
||||
>
|
||||
<History class="size-3.5 shrink-0 text-muted-foreground" />
|
||||
@@ -914,7 +914,7 @@ const RESULT_GRID = { gridTemplateColumns: '24px 36px minmax(0,1fr) 108px 52px 9
|
||||
<li
|
||||
v-for="task in store.tasks"
|
||||
:key="task.taskId"
|
||||
class="flex flex-col gap-1.5 rounded-md px-2 py-2 transition-colors hover:bg-accent/50"
|
||||
class="flex flex-col gap-1.5 rounded-md px-2 py-2 transition-colors hover:bg-row-hover"
|
||||
>
|
||||
<div class="flex min-w-0 items-center gap-2">
|
||||
<Badge
|
||||
@@ -1124,7 +1124,7 @@ const RESULT_GRID = { gridTemplateColumns: '24px 36px minmax(0,1fr) 108px 52px 9
|
||||
<!-- 歌曲行 -->
|
||||
<div
|
||||
v-else
|
||||
class="group grid h-11 items-center gap-3 rounded-md px-2 transition-colors hover:bg-accent/40"
|
||||
class="group grid h-11 items-center gap-3 rounded-md px-2 transition-colors hover:bg-row-hover"
|
||||
:style="RESULT_GRID"
|
||||
>
|
||||
<Checkbox
|
||||
@@ -1811,7 +1811,7 @@ const RESULT_GRID = { gridTemplateColumns: '24px 36px minmax(0,1fr) 108px 52px 9
|
||||
:class="
|
||||
chosenQuality === opt
|
||||
? 'border-primary bg-primary/10 text-foreground'
|
||||
: 'border-border hover:bg-accent/50'
|
||||
: 'border-border hover:bg-row-hover'
|
||||
"
|
||||
@click="chosenQuality = opt"
|
||||
>
|
||||
|
||||
@@ -72,7 +72,7 @@ const label = computed(() => {
|
||||
<label
|
||||
v-for="code in options"
|
||||
:key="code"
|
||||
class="flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 hover:bg-accent/60"
|
||||
class="flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 hover:bg-row-hover"
|
||||
>
|
||||
<Checkbox :model-value="checked.has(code)" @update:model-value="toggle(code)" />
|
||||
<Label class="cursor-pointer truncate text-[13px]">{{ sourceName(code) }}</Label>
|
||||
|
||||
@@ -378,7 +378,7 @@ const listEmptyHint = computed(() => {
|
||||
:class="
|
||||
activePlaylistId === p.id
|
||||
? 'bg-background font-medium text-foreground shadow-sm ring-1 ring-border'
|
||||
: 'text-muted-foreground hover:bg-accent/60 hover:text-foreground'
|
||||
: 'text-muted-foreground hover:bg-row-hover hover:text-foreground'
|
||||
"
|
||||
@click="activePlaylistId = p.id"
|
||||
>
|
||||
@@ -389,7 +389,7 @@ const listEmptyHint = computed(() => {
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="flex h-7 items-center gap-1.5 rounded-md px-2 text-[12.5px] text-muted-foreground transition-colors duration-150 hover:bg-accent/60 hover:text-foreground"
|
||||
class="flex h-7 items-center gap-1.5 rounded-md px-2 text-[12.5px] text-muted-foreground transition-colors duration-150 hover:bg-row-hover hover:text-foreground"
|
||||
@click="createOpen = true"
|
||||
>
|
||||
<Plus class="size-3.5 shrink-0" />
|
||||
|
||||
@@ -271,7 +271,7 @@ const durationText = (ms?: number) => (ms ? store.fmtDuration(ms / 1000) : '')
|
||||
class="flex h-11 items-center gap-3 rounded-md px-2 text-left transition-colors"
|
||||
:class="
|
||||
isSelectable(item)
|
||||
? 'hover:bg-accent/50'
|
||||
? 'hover:bg-row-hover'
|
||||
: 'cursor-not-allowed opacity-55'
|
||||
"
|
||||
:disabled="!isSelectable(item)"
|
||||
@@ -353,7 +353,7 @@ const durationText = (ms?: number) => (ms ? store.fmtDuration(ms / 1000) : '')
|
||||
v-for="item in visibleList"
|
||||
:key="itemKey(item)"
|
||||
type="button"
|
||||
class="flex h-11 items-center gap-3 rounded-md px-2 text-left transition-colors hover:bg-accent/50"
|
||||
class="flex h-11 items-center gap-3 rounded-md px-2 text-left transition-colors hover:bg-row-hover"
|
||||
@click="toggle(itemKey(item))"
|
||||
>
|
||||
<span
|
||||
|
||||
@@ -111,7 +111,7 @@ async function uploadToFeiniu() {
|
||||
showAlbum
|
||||
? 'grid-cols-[28px_36px_minmax(0,1fr)_minmax(0,0.75fr)_74px_28px]'
|
||||
: 'grid-cols-[28px_36px_minmax(0,1fr)_74px_28px]',
|
||||
isCurrent ? 'bg-accent/60' : 'hover:bg-accent/40'
|
||||
isCurrent ? 'bg-row-selected' : 'hover:bg-row-hover'
|
||||
]"
|
||||
@dblclick="play"
|
||||
>
|
||||
@@ -151,7 +151,7 @@ async function uploadToFeiniu() {
|
||||
<!-- 标题 + 元信息 -->
|
||||
<div class="min-w-0">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<span class="truncate text-[13px]" :class="isCurrent ? 'font-medium text-foreground' : ''">
|
||||
<span class="truncate text-[13px]" :class="isCurrent ? 'font-medium text-primary-soft-text' : ''">
|
||||
{{ item.title }}
|
||||
</span>
|
||||
<span
|
||||
|
||||
@@ -1725,11 +1725,12 @@ onUnmounted(() => {
|
||||
}
|
||||
|
||||
.qp-fa-item:hover {
|
||||
background: var(--accent);
|
||||
background: var(--row-hover-veil);
|
||||
}
|
||||
|
||||
.qp-fa-checked {
|
||||
background: var(--accent);
|
||||
.qp-fa-checked,
|
||||
.qp-fa-checked:hover {
|
||||
background: var(--row-selected-veil);
|
||||
}
|
||||
|
||||
.qp-fa-checkbox {
|
||||
@@ -1998,11 +1999,16 @@ onUnmounted(() => {
|
||||
}
|
||||
|
||||
.qp-item:hover {
|
||||
background: var(--muted);
|
||||
background: var(--row-hover-veil);
|
||||
}
|
||||
|
||||
/* 键盘光标 / 鼠标悬停项 = 选中态。
|
||||
注意 @mouseenter 会把 selectedIndex 移到鼠标所在项,所以用户感知到的"hover"
|
||||
实际渲染的是这条选中样式。
|
||||
本弹窗根容器在 mica 下无底色,行直接画在系统糊化层上,因此用蒙层值
|
||||
(半透明)而不是不透明行底色,详见 style.css 的 --row-hover-veil */
|
||||
.qp-item-selected {
|
||||
background: var(--accent);
|
||||
background: var(--row-selected-veil);
|
||||
}
|
||||
|
||||
/* 历史折叠分组 */
|
||||
@@ -2016,8 +2022,9 @@ onUnmounted(() => {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* 选中态强度必须盖过 hover::hover 的特异性高于单类,不显式补 :hover 会掉成行 hover 底 */
|
||||
.qp-item-selected:hover {
|
||||
background: var(--accent);
|
||||
background: var(--row-selected-veil);
|
||||
}
|
||||
|
||||
.qp-group-badge {
|
||||
@@ -2050,11 +2057,12 @@ onUnmounted(() => {
|
||||
}
|
||||
|
||||
.qp-sub-item:hover {
|
||||
background: var(--accent);
|
||||
background: var(--row-hover-veil);
|
||||
}
|
||||
|
||||
.qp-sub-selected {
|
||||
background: var(--accent);
|
||||
.qp-sub-selected,
|
||||
.qp-sub-selected:hover {
|
||||
background: var(--row-selected-veil);
|
||||
}
|
||||
|
||||
.qp-sub-num {
|
||||
|
||||
@@ -503,7 +503,7 @@ onUnmounted(() => {
|
||||
<div
|
||||
v-for="item in pagedRecent"
|
||||
:key="item.id"
|
||||
class="group relative rounded-lg border bg-muted/30 overflow-hidden"
|
||||
class="group relative rounded-lg border bg-muted/30 overflow-hidden transition-colors hover:border-primary/40 hover:bg-row-hover"
|
||||
>
|
||||
<!--
|
||||
缩略图底座:用语义色 bg-muted(随深浅主题切换),而不是写死的
|
||||
|
||||
@@ -2608,13 +2608,18 @@ onUnmounted(() => {
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.tb-icon:hover:not(:disabled):not(.active) { background: var(--accent); color: var(--accent-foreground); }
|
||||
/* 必须显式排除 .primary:本选择器算 4 个 class/伪类,
|
||||
特异性高于 .tb-icon.primary:hover(3 个),不排除的话悬停「完成」会把实心主题色底
|
||||
盖成浅底;同理排除 .active,否则悬停当前工具会掉色 */
|
||||
.tb-icon:hover:not(:disabled):not(.active):not(.primary) { background: var(--primary-soft); color: var(--primary-soft-text); }
|
||||
.tb-icon.active { background: var(--primary); color: var(--primary-foreground); }
|
||||
.tb-icon.primary {
|
||||
background: var(--primary);
|
||||
color: var(--primary-foreground);
|
||||
}
|
||||
.tb-icon.primary:hover { filter: brightness(0.95); }
|
||||
/* 主按钮 hover 用 --primary-hover 变深/变亮,而不是 filter: brightness(0.95)
|
||||
—— 后者在深色主题下方向是反的(设计系统 4.2 交互反馈) */
|
||||
.tb-icon.primary:hover { background: var(--primary-hover); }
|
||||
.tb-icon:disabled { opacity: 0.35; cursor: default; }
|
||||
.tb-svg { width: 15px; height: 15px; }
|
||||
|
||||
@@ -2682,7 +2687,7 @@ onUnmounted(() => {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.width-badge:hover:not(:disabled) { background: var(--accent); color: var(--accent-foreground); }
|
||||
.width-badge:hover:not(:disabled) { background: var(--primary-soft); color: var(--primary-soft-text); }
|
||||
.width-badge.disabled,
|
||||
.width-badge:disabled { opacity: 0.35; cursor: default; pointer-events: none; }
|
||||
|
||||
@@ -2716,7 +2721,7 @@ onUnmounted(() => {
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.tb-num:hover:not(.active) { background: var(--accent); color: var(--accent-foreground); }
|
||||
.tb-num:hover:not(.active) { background: var(--primary-soft); color: var(--primary-soft-text); }
|
||||
.tb-num.active { background: var(--primary); color: var(--primary-foreground); }
|
||||
.tb-size {
|
||||
font-size: 12px;
|
||||
|
||||
@@ -0,0 +1,633 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 主设置 → AI 服务卡片。
|
||||
*
|
||||
* 对齐主流桌面 Agent 的「模型/连接」设置:只管引擎本身
|
||||
* (Base URL / 模型 / 密钥 / 最大输出 / 最大上下文等)。
|
||||
* 优先级、超时、翻译提示词等场景参数在各模块自己的设置里。
|
||||
*/
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { toast } from 'vue-sonner'
|
||||
import {
|
||||
CircleAlert,
|
||||
CircleCheck,
|
||||
Eraser,
|
||||
KeyRound,
|
||||
LoaderCircle,
|
||||
Plus,
|
||||
RefreshCw,
|
||||
Sparkles,
|
||||
Trash2,
|
||||
Zap
|
||||
} from '@lucide/vue'
|
||||
import { useAiStore } from '@/stores/aiStore'
|
||||
import {
|
||||
AI_PRESETS,
|
||||
DEFAULT_MAX_CONTEXT,
|
||||
DEFAULT_MAX_OUTPUT,
|
||||
MAX_CONTEXT_OPTIONS,
|
||||
MAX_OUTPUT_OPTIONS,
|
||||
formatTokens,
|
||||
type AiErrorKind,
|
||||
type AiProviderConfig,
|
||||
type AiProviderView,
|
||||
type AiTestResult
|
||||
} from '@/types/ai'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue
|
||||
} from '@/components/ui/select'
|
||||
|
||||
const store = useAiStore()
|
||||
|
||||
/** 展开编辑的供应商 id(空表示全部收起) */
|
||||
const editingId = ref('')
|
||||
const presetKey = ref(AI_PRESETS[0].key)
|
||||
const newProviderName = ref('')
|
||||
|
||||
/** 当前展开编辑的草稿 */
|
||||
const draft = ref<AiProviderConfig | null>(null)
|
||||
const apiKey = ref('')
|
||||
const models = ref<string[]>([])
|
||||
const testResult = ref<AiTestResult | null>(null)
|
||||
const busy = ref<'' | 'save' | 'key' | 'models' | 'delete'>('')
|
||||
const confirmingDelete = ref(false)
|
||||
/** 正在执行「检查」的供应商 id(行级与编辑区共用,避免重复点击) */
|
||||
const checkingId = ref('')
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
await store.init()
|
||||
} catch (e) {
|
||||
toast.error(`读取 AI 设置失败:${String(e)}`)
|
||||
}
|
||||
})
|
||||
|
||||
const selectedPreset = computed(() => AI_PRESETS.find(p => p.key === presetKey.value))
|
||||
|
||||
/** 生成不与现有实例冲突的 id(id 会进入凭据键,必须唯一且字符集受限) */
|
||||
function nextProviderId(base: string): string {
|
||||
const used = new Set(store.providers.map(p => p.config.id))
|
||||
if (!used.has(base)) return base
|
||||
let i = 2
|
||||
while (used.has(`${base}-${i}`)) i += 1
|
||||
return `${base}-${i}`
|
||||
}
|
||||
|
||||
async function addProvider() {
|
||||
const preset = selectedPreset.value
|
||||
if (!preset) return
|
||||
const name = newProviderName.value.trim() || preset.label
|
||||
const config: AiProviderConfig = {
|
||||
id: nextProviderId(preset.key),
|
||||
name,
|
||||
preset: preset.key,
|
||||
enabled: true,
|
||||
baseUrl: '',
|
||||
model: '',
|
||||
temperature: 0.3,
|
||||
maxTokens: DEFAULT_MAX_OUTPUT,
|
||||
maxContext: DEFAULT_MAX_CONTEXT,
|
||||
extraBody: null,
|
||||
...preset.template,
|
||||
// 显式兜底:preset.template 是 Partial,缺省必须落成 false
|
||||
supportsVision: preset.template.supportsVision ?? false
|
||||
}
|
||||
try {
|
||||
await store.saveProvider(config)
|
||||
newProviderName.value = ''
|
||||
openEditor(config.id)
|
||||
toast.success(`已新增「${name}」,请填写 API Key`)
|
||||
} catch (e) {
|
||||
toast.error(String(e))
|
||||
}
|
||||
}
|
||||
|
||||
function openEditor(id: string) {
|
||||
if (editingId.value === id) {
|
||||
closeEditor()
|
||||
return
|
||||
}
|
||||
const view = store.providers.find(p => p.config.id === id)
|
||||
if (!view) return
|
||||
editingId.value = id
|
||||
draft.value = { ...view.config }
|
||||
apiKey.value = ''
|
||||
models.value = []
|
||||
testResult.value = null
|
||||
confirmingDelete.value = false
|
||||
}
|
||||
|
||||
function closeEditor() {
|
||||
editingId.value = ''
|
||||
draft.value = null
|
||||
apiKey.value = ''
|
||||
models.value = []
|
||||
testResult.value = null
|
||||
confirmingDelete.value = false
|
||||
}
|
||||
|
||||
const dirty = computed(() => {
|
||||
if (!draft.value) return false
|
||||
const view = store.providers.find(p => p.config.id === draft.value!.id)
|
||||
if (!view) return true
|
||||
return JSON.stringify(draft.value) !== JSON.stringify(view.config)
|
||||
})
|
||||
|
||||
const currentView = computed<AiProviderView | undefined>(() =>
|
||||
store.providers.find(p => p.config.id === editingId.value)
|
||||
)
|
||||
|
||||
const canFetchModels = computed(() => currentView.value?.hasApiKey === true)
|
||||
|
||||
/** 数值输入的收敛:NaN 一律退回默认值,避免把空输入写进配置 */
|
||||
function toNumber(raw: string | number, fallback: number, min: number, max: number): number {
|
||||
const n = typeof raw === 'number' ? raw : Number.parseFloat(raw)
|
||||
if (!Number.isFinite(n)) return fallback
|
||||
return Math.min(max, Math.max(min, n))
|
||||
}
|
||||
|
||||
/** 更新草稿字段。模板事件处理器里 draft 的 null 收窄不可靠,统一走这里。 */
|
||||
function patchDraft(patch: Partial<AiProviderConfig>) {
|
||||
if (!draft.value) return
|
||||
Object.assign(draft.value, patch)
|
||||
}
|
||||
|
||||
async function withBusy(kind: NonNullable<typeof busy.value>, fn: () => Promise<void>) {
|
||||
busy.value = kind
|
||||
try {
|
||||
await fn()
|
||||
} catch (e) {
|
||||
toast.error(String(e))
|
||||
} finally {
|
||||
busy.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const save = () =>
|
||||
withBusy('save', async () => {
|
||||
if (!draft.value) return
|
||||
const extra = draft.value.extraBody?.trim()
|
||||
if (extra) {
|
||||
try {
|
||||
const parsed = JSON.parse(extra)
|
||||
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
||||
toast.error('额外请求体必须是 JSON 对象,例如 {"thinking":{"type":"disabled"}}')
|
||||
return
|
||||
}
|
||||
} catch {
|
||||
toast.error('额外请求体不是合法 JSON')
|
||||
return
|
||||
}
|
||||
}
|
||||
await store.saveProvider({ ...draft.value, extraBody: extra || null })
|
||||
toast.success('已保存')
|
||||
})
|
||||
|
||||
const saveKey = () =>
|
||||
withBusy('key', async () => {
|
||||
if (!draft.value) return
|
||||
if (!apiKey.value.trim()) {
|
||||
toast.error('请输入 API Key')
|
||||
return
|
||||
}
|
||||
await store.setSecret(draft.value.id, apiKey.value.trim())
|
||||
apiKey.value = ''
|
||||
toast.success('密钥已写入系统凭据管理器')
|
||||
})
|
||||
|
||||
const clearKey = () =>
|
||||
withBusy('key', async () => {
|
||||
if (!draft.value) return
|
||||
await store.clearSecret(draft.value.id)
|
||||
toast.success('密钥已清除')
|
||||
})
|
||||
|
||||
/**
|
||||
* 「检查」:发一条极短请求验证连通性。
|
||||
*
|
||||
* 关键点:**编辑区展开时用草稿**(含刚填、还没保存的 Base URL / 模型 / API Key),
|
||||
* 这样「边填边测」成立,不必先保存一轮;收起时用已保存的配置。
|
||||
* 编辑区开着就把结果显示在编辑区里,收起着就用 toast——同一事件不重复提示。
|
||||
*/
|
||||
const checkProvider = (view: AiProviderView) =>
|
||||
withBusyCheck(view, async () => {
|
||||
const editing = editingId.value === view.config.id && draft.value !== null
|
||||
const cfg = editing ? { ...draft.value! } : { ...view.config }
|
||||
const r = await store.testProvider(cfg, editing ? apiKey.value : undefined)
|
||||
if (editing) {
|
||||
testResult.value = r
|
||||
// 用的是「还没保存」的临时密钥:通了也要提醒落库,否则关掉编辑区就白填了
|
||||
if (r.ok && apiKey.value.trim() && !currentView.value?.hasApiKey) {
|
||||
toast.info('检查通过;点「保存」才会把密钥写入凭据管理器')
|
||||
}
|
||||
} else if (r.ok) {
|
||||
toast.success(r.message)
|
||||
} else {
|
||||
toast.error(r.message)
|
||||
}
|
||||
})
|
||||
|
||||
/** 检查的忙碌态单独管理:它不占用编辑区的保存/密钥按钮禁用状态 */
|
||||
async function withBusyCheck(view: AiProviderView, fn: () => Promise<void>) {
|
||||
if (checkingId.value) return
|
||||
checkingId.value = view.config.id
|
||||
try {
|
||||
await fn()
|
||||
} catch (e) {
|
||||
toast.error(`检查失败:${String(e)}`)
|
||||
} finally {
|
||||
checkingId.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
/** 检查失败时的下一步动作提示(与翻译模块同一套说法) */
|
||||
const KIND_HINTS: Record<AiErrorKind, string> = {
|
||||
config: '检查 Base URL 与模型名是否填写正确',
|
||||
auth: '检查 API Key 是否正确、账户是否有该模型权限或余额',
|
||||
rateLimit: '上游限流,稍后重试即可',
|
||||
network: '网络不可达:检查网络;若该服务在境外,请打开上方「AI 请求走代理」',
|
||||
timeout: '请求超时:检查网络,或稍后重试',
|
||||
parse: '上游返回格式异常,可能是接口变更',
|
||||
empty: '上游返回了空内容,换个模型或稍后重试',
|
||||
unknown: '未知错误,详见下方原始响应'
|
||||
}
|
||||
|
||||
const fetchModels = () =>
|
||||
withBusy('models', async () => {
|
||||
if (!draft.value) return
|
||||
models.value = await store.fetchModels(draft.value.id)
|
||||
if (models.value.length === 0) toast.info('上游未返回任何模型')
|
||||
else toast.success(`拉取到 ${models.value.length} 个模型`)
|
||||
})
|
||||
|
||||
const remove = () =>
|
||||
withBusy('delete', async () => {
|
||||
if (!draft.value) return
|
||||
if (!confirmingDelete.value) {
|
||||
confirmingDelete.value = true
|
||||
return
|
||||
}
|
||||
await store.deleteProvider(draft.value.id)
|
||||
toast.success('供应商已删除')
|
||||
closeEditor()
|
||||
})
|
||||
|
||||
async function toggleEnabled(view: AiProviderView, enabled: boolean) {
|
||||
try {
|
||||
await store.saveProvider({ ...view.config, enabled })
|
||||
} catch (e) {
|
||||
toast.error(String(e))
|
||||
}
|
||||
}
|
||||
|
||||
async function patchUseProxy(v: boolean) {
|
||||
try {
|
||||
await store.patchSettings({ useProxy: v })
|
||||
} catch (e) {
|
||||
toast.error(String(e))
|
||||
}
|
||||
}
|
||||
|
||||
// 草稿与外部刷新保持同步(保存成功后 store 重载)
|
||||
watch(
|
||||
() => currentView.value,
|
||||
v => {
|
||||
if (v && editingId.value === v.config.id && !dirty.value) {
|
||||
draft.value = { ...v.config }
|
||||
}
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card id="settings-card-ai">
|
||||
<CardHeader class="pb-3">
|
||||
<CardTitle class="flex items-center gap-2">
|
||||
<Sparkles class="size-5 text-primary" />
|
||||
AI 服务
|
||||
</CardTitle>
|
||||
<p class="text-[12px] text-muted-foreground">
|
||||
管理可用的 AI 引擎(连接与生成参数)。翻译、终端助手等模块共用这一份配置;
|
||||
各模块自己的参数(优先级、超时、是否参与翻译候选等)在对应模块设置中调整。
|
||||
翻译模块需要在「翻译 → 设置 → AI 引擎 → 从 AI 服务添加」里显式加入某个供应商。
|
||||
</p>
|
||||
</CardHeader>
|
||||
<CardContent class="space-y-3">
|
||||
<!-- 代理开关 -->
|
||||
<div class="flex items-center justify-between rounded-lg border border-border/50 px-3 py-2">
|
||||
<div class="space-y-0.5">
|
||||
<Label class="text-[13px]">AI 请求走代理</Label>
|
||||
<p class="text-[11px] text-muted-foreground">
|
||||
仅境外服务需要;DeepSeek / 通义等境内可直连时保持关闭。
|
||||
终端助手、连通性测试与翻译里的 AI 引擎都遵循这个开关
|
||||
</p>
|
||||
</div>
|
||||
<Switch :model-value="store.settings?.useProxy ?? false" @update:model-value="patchUseProxy" />
|
||||
</div>
|
||||
|
||||
<!-- 供应商列表 -->
|
||||
<div
|
||||
v-for="view in store.providers"
|
||||
:key="view.config.id"
|
||||
class="rounded-lg border p-3"
|
||||
:class="{ 'opacity-70': !view.config.enabled }"
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-[13px] font-medium">{{ view.config.name }}</span>
|
||||
<Badge variant="outline" class="text-[11px]">AI · OpenAI 兼容</Badge>
|
||||
<Badge v-if="view.ready" variant="secondary" class="text-[11px]">就绪</Badge>
|
||||
|
||||
<div class="flex-1" />
|
||||
|
||||
<span class="text-[11px] text-muted-foreground">{{ view.config.model || '未选模型' }}</span>
|
||||
<Switch
|
||||
:model-value="view.config.enabled"
|
||||
@update:model-value="(v: boolean) => toggleEnabled(view, Boolean(v))"
|
||||
/>
|
||||
<!-- 行级「检查」:收起时也能随时验证;编辑区展开时用的是草稿(含未保存的 Key) -->
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:disabled="checkingId === view.config.id"
|
||||
:title="
|
||||
editingId === view.config.id
|
||||
? '检查当前草稿(含尚未保存的 Base URL / 模型 / API Key)'
|
||||
: '检查已保存配置的连通性'
|
||||
"
|
||||
@click="checkProvider(view)"
|
||||
>
|
||||
<LoaderCircle v-if="checkingId === view.config.id" class="animate-spin" />
|
||||
<Zap v-else />
|
||||
检查
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" @click="openEditor(view.config.id)">
|
||||
{{ editingId === view.config.id ? '收起' : '编辑' }}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<p v-if="view.issue" class="mt-1.5 flex items-center gap-1.5 text-[12px] text-warning-text">
|
||||
<CircleAlert class="size-3.5 shrink-0" />
|
||||
{{ view.issue }}
|
||||
</p>
|
||||
|
||||
<!-- 编辑器:对齐主流 Agent 的模型/连接设置 -->
|
||||
<div v-if="editingId === view.config.id && draft" class="mt-3 space-y-3 rounded-md border bg-muted/20 p-3">
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-[12px]">名称</Label>
|
||||
<Input v-model="draft.name" class="h-8 text-[13px]" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-[12px]">温度(0~2)</Label>
|
||||
<Input
|
||||
:model-value="draft.temperature"
|
||||
type="number"
|
||||
step="0.1"
|
||||
class="h-8 text-[13px]"
|
||||
@update:model-value="v => patchDraft({ temperature: toNumber(v, 0.3, 0, 2) })"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-2 space-y-1.5">
|
||||
<Label class="text-[12px]">Base URL</Label>
|
||||
<Input
|
||||
v-model="draft.baseUrl"
|
||||
placeholder="https://api.deepseek.com"
|
||||
class="h-8 text-[13px]"
|
||||
/>
|
||||
<p class="text-[11px] text-muted-foreground">
|
||||
填到 /v1 为止即可;若粘入了完整端点(…/chat/completions)后端会自动剥掉。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-[12px]">模型</Label>
|
||||
<Input v-model="draft.model" placeholder="模型标识,如 deepseek-flash" class="h-8 text-[13px]" />
|
||||
</div>
|
||||
<div class="space-y-1.5" />
|
||||
</div>
|
||||
|
||||
<!-- 最大输出 / 最大上下文:档位选择,对齐桌面 Agent -->
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-[12px]">最大输出</Label>
|
||||
<Select
|
||||
:model-value="String(draft.maxTokens)"
|
||||
@update:model-value="v => patchDraft({ maxTokens: Number(v) })"
|
||||
>
|
||||
<SelectTrigger class="h-8 text-[12px]">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="n in MAX_OUTPUT_OPTIONS" :key="n" :value="String(n)">
|
||||
{{ formatTokens(n) }} tokens
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<p class="text-[11px] text-muted-foreground">单次回答的输出上限</p>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-[12px]">最大上下文</Label>
|
||||
<Select
|
||||
:model-value="String(draft.maxContext)"
|
||||
@update:model-value="v => patchDraft({ maxContext: Number(v) })"
|
||||
>
|
||||
<SelectTrigger class="h-8 text-[12px]">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="n in MAX_CONTEXT_OPTIONS" :key="n" :value="String(n)">
|
||||
{{ formatTokens(n) }} tokens
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<p class="text-[11px] text-muted-foreground">模型可接收的输入+输出规模</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 视觉能力 -->
|
||||
<div class="flex items-start gap-3 rounded-md border bg-background p-2.5">
|
||||
<Switch
|
||||
:model-value="draft.supportsVision"
|
||||
@update:model-value="(v: boolean) => patchDraft({ supportsVision: v })"
|
||||
/>
|
||||
<div class="min-w-0 flex-1">
|
||||
<Label class="text-[12px]">图像输入(多模态)</Label>
|
||||
<p class="mt-0.5 text-[11px] text-muted-foreground">
|
||||
声明该模型可接收图片。开启后,需要「看图」的功能(如翻译的截图直传)才会把图像发给此模型;
|
||||
仅对多模态模型开启(如 gpt-4o、Qwen-VL、GLM-4V)。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- API Key -->
|
||||
<div class="space-y-1.5 rounded-md border bg-background p-2.5">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<KeyRound class="size-3.5 text-muted-foreground" />
|
||||
<Label class="text-[12px]">API Key</Label>
|
||||
<span class="text-[11px] text-muted-foreground">
|
||||
存入 Windows 凭据管理器,不写入配置文件、不回传前端明文;填好后可直接点「检查」验证,无需先保存
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<Input
|
||||
v-model="apiKey"
|
||||
type="password"
|
||||
autocomplete="off"
|
||||
class="h-8 text-[13px] flex-1"
|
||||
:placeholder="currentView?.hasApiKey ? `已配置:${currentView.apiKeyMasked}` : '尚未配置'"
|
||||
/>
|
||||
<Button size="sm" :disabled="busy === 'key' || !apiKey.trim()" @click="saveKey">
|
||||
<LoaderCircle v-if="busy === 'key'" class="animate-spin" />
|
||||
保存
|
||||
</Button>
|
||||
<Button
|
||||
v-if="currentView?.hasApiKey"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:disabled="busy === 'key'"
|
||||
@click="clearKey"
|
||||
>
|
||||
<Eraser />
|
||||
清除
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 高级 -->
|
||||
<details class="rounded-md border bg-background p-2.5">
|
||||
<summary class="cursor-pointer select-none text-[12px] font-medium">
|
||||
高级:额外请求体
|
||||
</summary>
|
||||
<div class="mt-2 space-y-1.5">
|
||||
<Label class="text-[12px]">额外请求体(JSON 对象)</Label>
|
||||
<Textarea
|
||||
:model-value="draft.extraBody ?? ''"
|
||||
class="min-h-16 font-mono text-[12px]"
|
||||
placeholder='例如 {"thinking":{"type":"disabled"}}'
|
||||
@update:model-value="v => patchDraft({ extraBody: String(v) || null })"
|
||||
/>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<!-- 模型列表 -->
|
||||
<div v-if="models.length > 0" class="space-y-1.5 rounded-md border bg-background p-2.5">
|
||||
<Label class="text-[12px]">从上游拉取到的模型(选择即填入上方「模型」)</Label>
|
||||
<Select :model-value="draft.model" @update:model-value="v => patchDraft({ model: String(v) })">
|
||||
<SelectTrigger class="h-8 text-[12px]"><SelectValue placeholder="选择模型" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="m in models" :key="m" :value="m">{{ m }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<!-- 测试结果 -->
|
||||
<div
|
||||
v-if="testResult"
|
||||
class="space-y-1 rounded-md border p-2.5 text-[12px]"
|
||||
:class="testResult.ok ? 'bg-success-soft' : 'bg-danger-soft'"
|
||||
>
|
||||
<div class="flex items-start gap-2">
|
||||
<CircleCheck v-if="testResult.ok" class="mt-0.5 size-3.5 shrink-0" />
|
||||
<CircleAlert v-else class="mt-0.5 size-3.5 shrink-0" />
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="break-words">{{ testResult.message }}</p>
|
||||
<p v-if="!testResult.ok && testResult.errorKind" class="mt-0.5 text-muted-foreground">
|
||||
{{ KIND_HINTS[testResult.errorKind] }}
|
||||
</p>
|
||||
<pre
|
||||
v-if="testResult.detail"
|
||||
class="mt-1 whitespace-pre-wrap break-all rounded bg-background/60 p-1.5 text-[11px]"
|
||||
>{{ testResult.detail }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<Button size="sm" :disabled="busy === 'save' || !dirty" @click="save">
|
||||
<LoaderCircle v-if="busy === 'save'" class="animate-spin" />
|
||||
保存配置
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:disabled="checkingId === view.config.id"
|
||||
@click="checkProvider(view)"
|
||||
>
|
||||
<LoaderCircle v-if="checkingId === view.config.id" class="animate-spin" />
|
||||
<Zap v-else />
|
||||
检查
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:disabled="busy === 'models' || !canFetchModels"
|
||||
:title="canFetchModels ? '从上游拉取模型列表' : '需先配置 API Key'"
|
||||
@click="fetchModels"
|
||||
>
|
||||
<LoaderCircle v-if="busy === 'models'" class="animate-spin" />
|
||||
<RefreshCw v-else />
|
||||
拉取模型
|
||||
</Button>
|
||||
|
||||
<div class="flex-1" />
|
||||
|
||||
<Badge v-if="dirty" variant="outline" class="text-[11px]">有未保存的改动</Badge>
|
||||
<Button
|
||||
:variant="confirmingDelete ? 'destructive' : 'outline'"
|
||||
size="sm"
|
||||
:disabled="busy === 'delete'"
|
||||
@click="remove"
|
||||
>
|
||||
<Trash2 />
|
||||
{{ confirmingDelete ? '确认删除?' : '删除' }}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p v-if="!store.loading && store.providers.length === 0" class="text-[12px] text-muted-foreground">
|
||||
还没有 AI 供应商,下面选一个预设新增。
|
||||
</p>
|
||||
|
||||
<!-- 新增 -->
|
||||
<div class="space-y-2 border-t border-border/50 pt-3">
|
||||
<Label class="text-[12px]">新增引擎</Label>
|
||||
<div class="flex gap-2">
|
||||
<Select v-model="presetKey">
|
||||
<SelectTrigger class="h-8 w-48 text-[12px]"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="p in AI_PRESETS" :key="p.key" :value="p.key">
|
||||
{{ p.label }}
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input
|
||||
v-model="newProviderName"
|
||||
class="h-8 flex-1 text-[13px]"
|
||||
:placeholder="selectedPreset?.label ?? '引擎名称'"
|
||||
/>
|
||||
<Button size="sm" @click="addProvider">
|
||||
<Plus />
|
||||
新增
|
||||
</Button>
|
||||
</div>
|
||||
<p v-if="selectedPreset" class="text-[11px] text-muted-foreground">
|
||||
{{ selectedPreset.description }}
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
@@ -13,6 +13,7 @@ import { useProcessStore } from '@/stores/processStore'
|
||||
import { useDownloaderStore } from '@/stores/downloaderStore'
|
||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog'
|
||||
import { getModuleIcon } from '@/modules/icons'
|
||||
import AiSettings from './AiSettings.vue'
|
||||
import { commands, type UpdateCheckResult } from '@/lib/bindings'
|
||||
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
@@ -394,6 +395,8 @@ onMounted(() => {
|
||||
searchStore.registerAction('settings', 11, () => scrollToCard('settings-card-quit'))
|
||||
// 主题色:追加在 searchItems 末尾(index 12),避免给前面 0–11 重新编号
|
||||
searchStore.registerAction('settings', 12, () => scrollToCard('settings-card-accent'))
|
||||
// AI 服务卡片(index 13)
|
||||
searchStore.registerAction('settings', 13, () => scrollToCard('settings-card-ai'))
|
||||
// 主动刷新所有进程状态,确保内核 badge 显示当前真实状态(而非过期缓存)
|
||||
processStore.refreshAll().catch(() => { /* 忽略:后端可能未就绪 */ })
|
||||
})
|
||||
@@ -778,6 +781,8 @@ const onDragEnd = () => {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<AiSettings />
|
||||
|
||||
<Card id="settings-card-modules">
|
||||
<CardHeader>
|
||||
<CardTitle class="flex items-center gap-2">
|
||||
|
||||
@@ -68,6 +68,11 @@ const searchItems: SearchIndexItem[] = [
|
||||
title: '主题色',
|
||||
description: '自定义应用强调色(预设色板 / 自定义颜色)',
|
||||
keywords: ['主题色', '强调色', '配色', '颜色', 'accent', 'color', 'theme']
|
||||
},
|
||||
{
|
||||
title: 'AI 服务',
|
||||
description: '配置全局 AI 供应商(翻译、终端助手共用)',
|
||||
keywords: ['AI', '人工智能', '模型', 'API Key', 'DeepSeek', 'OpenAI', '供应商', '大模型', 'LLM', 'ai']
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 文件管理器独立窗口。
|
||||
*
|
||||
* # 与终端独立窗口的关系(一个刻意的不对称)
|
||||
*
|
||||
* 终端窗口**绑定一个会话**(一个会话一个窗口,见 Rust 侧 `terminal/window.rs`),
|
||||
* 本窗口不绑任何会话:它的粒度是「两台机器之间的关系」,左右两栏各自选连接,
|
||||
* 因此它**是单例** —— 开第二个只会显示同一份状态。label 固定为 `file-window`。
|
||||
*
|
||||
* 界面骨架与 `TerminalWindow` 相同:无系统边框,窗口内自绘控制栏(左端是拖拽区),
|
||||
* 右下角三个窗口按钮;内容区直接复用 tab 页的 `FileManager`(`standalone` 模式:
|
||||
* 不渲染 `PageToolbar`)。
|
||||
*
|
||||
* # 为什么必须自己初始化 store
|
||||
*
|
||||
* 这是另一个 WebView 入口(`main.ts` 按 hash 路由),自带 Pinia,与主窗口的
|
||||
* store 实例互不可见,而**后端状态是共享的**。因此这里 `store.init()` 一次,
|
||||
* 才能拿到会话列表(连接选择器与两栏的 SFTP 通道都依赖它)。
|
||||
* 同理必须自己注册事件监听 —— 传输进度是窗口广播事件。
|
||||
*
|
||||
* # 主题:与同模块其它独立窗口同一套
|
||||
*
|
||||
* 各自读同一份 `localStorage` 设置 → 切 `dark` class + 应用主题色 → 监听 `storage`
|
||||
* 事件跟随主窗口改动;窗口由 Rust **隐藏创建**(见 `terminal/window.rs`),
|
||||
* 因此这里除了切 class 还要设**窗口底色**,否则显示瞬间是白底。
|
||||
*/
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { getCurrentWindow } from '@tauri-apps/api/window'
|
||||
import { FolderTree, Loader2, Minus, Square, X } from '@lucide/vue'
|
||||
import { toast } from 'vue-sonner'
|
||||
import { useTerminalStore } from '@/stores/terminalStore'
|
||||
import { createLogger } from '@/lib/logger'
|
||||
import { applyStoredAccent } from '@/lib/theme'
|
||||
import { appIsDark } from '@/lib/terminalThemes'
|
||||
import { STORAGE_KEYS } from '@/lib/constants'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Toaster } from '@/components/ui/sonner'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import FileManager from './components/FileManager.vue'
|
||||
|
||||
const logger = createLogger('terminal')
|
||||
const store = useTerminalStore()
|
||||
const win = getCurrentWindow()
|
||||
|
||||
// ===== 主题(与 TerminalWindow / NewTerminalWindow 同款) =====
|
||||
|
||||
/** 与 style.css 的 `--background` 对齐:浅色 #ffffff / 深色 #16161a */
|
||||
const WINDOW_BG = { light: '#ffffff', dark: '#16161a' }
|
||||
|
||||
function readMainTheme(): string {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEYS.appSettings)
|
||||
if (raw) return (JSON.parse(raw) as { theme?: string }).theme ?? 'system'
|
||||
} catch {
|
||||
/* 设置不可读时按跟随系统处理 */
|
||||
}
|
||||
return 'system'
|
||||
}
|
||||
|
||||
function resolveIsDark(theme: string): boolean {
|
||||
if (theme === 'dark') return true
|
||||
if (theme === 'light') return false
|
||||
return window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
}
|
||||
|
||||
async function applyTheme() {
|
||||
const root = document.documentElement
|
||||
const theme = readMainTheme()
|
||||
const isDark = resolveIsDark(theme)
|
||||
try {
|
||||
await win.setTheme(theme === 'system' ? null : (theme as 'dark' | 'light'))
|
||||
} catch {
|
||||
/* 平台不支持时忽略 */
|
||||
}
|
||||
try {
|
||||
// 底色单独 try:setTheme 失败不该连带跳过底色,否则仍会白底闪一下
|
||||
await win.setBackgroundColor(isDark ? WINDOW_BG.dark : WINDOW_BG.light)
|
||||
} catch {
|
||||
/* 忽略 */
|
||||
}
|
||||
root.classList.toggle('dark', isDark)
|
||||
appIsDark.value = isDark
|
||||
applyStoredAccent(root, isDark ? 'dark' : 'light', STORAGE_KEYS.appSettings)
|
||||
}
|
||||
|
||||
const darkMedia = window.matchMedia('(prefers-color-scheme: dark)')
|
||||
const onThemeChange = () => void applyTheme()
|
||||
const onStorageChange = (e: StorageEvent) => {
|
||||
if (e.key === STORAGE_KEYS.appSettings) void applyTheme()
|
||||
}
|
||||
|
||||
// ===== 生命周期 =====
|
||||
|
||||
const ready = ref(false)
|
||||
|
||||
onMounted(async () => {
|
||||
darkMedia.addEventListener('change', onThemeChange)
|
||||
window.addEventListener('storage', onStorageChange)
|
||||
|
||||
// 主题 → 显示:窗口是隐藏创建的,这一步之后用户才第一次看到它
|
||||
await applyTheme()
|
||||
try {
|
||||
await win.show()
|
||||
await win.setFocus()
|
||||
} catch (e) {
|
||||
logger.warn(`显示文件窗口失败:${String(e)}`)
|
||||
}
|
||||
|
||||
try {
|
||||
await store.init()
|
||||
} catch (e) {
|
||||
logger.error(`文件窗口初始化失败:${String(e)}`)
|
||||
toast.error(`读取会话列表失败:${String(e)}`)
|
||||
} finally {
|
||||
// `ready` 之前不挂载 FileManager:它的默认分栏要把「第一个已连接会话」
|
||||
// 放进右栏,而那份会话列表正是这里刚拿到的
|
||||
ready.value = true
|
||||
}
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
darkMedia.removeEventListener('change', onThemeChange)
|
||||
window.removeEventListener('storage', onStorageChange)
|
||||
// 不需要像 TerminalWindow 那样重置会话标记:本窗口不绑会话(见文件头)
|
||||
})
|
||||
|
||||
// ===== 无边框窗口的窗口按钮 =====
|
||||
|
||||
async function minimize() {
|
||||
await win.minimize()
|
||||
}
|
||||
async function toggleMaximize() {
|
||||
await win.toggleMaximize()
|
||||
}
|
||||
async function closeWindow() {
|
||||
await win.close()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!--
|
||||
独立窗口是另一个 WebView 入口(main.ts 按 hash 路由),不经过 App.vue,
|
||||
因此这里必须自带 TooltipProvider —— 否则子组件的 Tooltip 取不到上下文。
|
||||
-->
|
||||
<TooltipProvider>
|
||||
<div class="flex flex-col h-screen w-screen overflow-hidden bg-background">
|
||||
<!-- 控制栏:标题(拖拽区)+ 窗口按钮 -->
|
||||
<div class="shrink-0 flex items-center gap-1 h-9 px-1.5 border-b border-border">
|
||||
<!--
|
||||
拖拽区:无边框窗口靠它移动。子元素 pointer-events-none,
|
||||
让 mousedown 的 target 始终落在这块带 data-tauri-drag-region 的容器上。
|
||||
-->
|
||||
<div class="flex h-full min-w-0 flex-1 items-center gap-1.5 px-2" data-tauri-drag-region>
|
||||
<FolderTree class="size-3.5 shrink-0 text-muted-foreground pointer-events-none" />
|
||||
<span class="truncate text-xs font-medium pointer-events-none">文件管理器</span>
|
||||
<span class="text-[11px] text-muted-foreground pointer-events-none">
|
||||
左右两栏各自选择连接
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button variant="ghost" size="icon-sm" @click="minimize">
|
||||
<Minus class="size-3.5" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">最小化</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button variant="ghost" size="icon-sm" @click="toggleMaximize">
|
||||
<Square class="size-3" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">最大化 / 还原</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
class="hover:!bg-destructive hover:!text-destructive-foreground"
|
||||
@click="closeWindow"
|
||||
>
|
||||
<X class="size-3.5" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">关闭窗口(会话与传输不受影响)</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
<!-- 内容:与 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" />
|
||||
<span class="text-xs text-muted-foreground">正在加载…</span>
|
||||
</div>
|
||||
<FileManager v-else standalone />
|
||||
</div>
|
||||
|
||||
<!-- Toaster 是窗口级的:主窗口那个管不到本窗口 -->
|
||||
<Toaster position="bottom-right" rich-colors close-button :style="{ zIndex: 99999 }" />
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 独立窗口无边框,禁止整页滚动与选中,贴近原生窗口行为 */
|
||||
:global(html),
|
||||
:global(body) {
|
||||
overflow: hidden;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -4,9 +4,9 @@
|
||||
*
|
||||
* # 职责边界
|
||||
*
|
||||
* 这里只做**模块级编排**:4 个 tab 的定义与切换、tab 记忆与全局搜索跳转、
|
||||
* 这里只做**模块级编排**:5 个 tab 的定义与切换、tab 记忆与全局搜索跳转、
|
||||
* 快捷键分发、模块初始化。终端页自身的界面与交互(标签栏、画布、分屏、
|
||||
* SFTP、右键菜单、搜索、模板、AI 助手、历史/片段浮层)全部在
|
||||
* 右键菜单、搜索、模板、AI 助手、历史/片段浮层)全部在
|
||||
* `TerminalWorkspace` 里 —— 拆分前它和编排逻辑混在同一个 1197 行的文件里,
|
||||
* 动一下终端页要在其中找位置。
|
||||
*
|
||||
@@ -14,7 +14,7 @@
|
||||
*
|
||||
* ```
|
||||
* ┌─────────────────────────────────────────────────────────┐
|
||||
* │ 模块 Tabs:终端 · 主机 · 密钥 · 设置 │
|
||||
* │ 模块 Tabs:终端 · 文件 · 主机 · 密钥 · 设置 │
|
||||
* ├─────────────────────────────────────────────────────────┤
|
||||
* │ 各页内容(**无外框**) │
|
||||
* └─────────────────────────────────────────────────────────┘
|
||||
@@ -54,6 +54,7 @@ import { useModuleTabs } from '@/lib/use-module-tabs'
|
||||
import { createLogger } from '@/lib/logger'
|
||||
import { Tabs, TabsContent } from '@/components/ui/tabs'
|
||||
import TerminalWorkspace from './components/TerminalWorkspace.vue'
|
||||
import FileManager from './components/FileManager.vue'
|
||||
import HostKeyPromptDialog from './components/HostKeyPromptDialog.vue'
|
||||
import HostManager from './components/HostManager.vue'
|
||||
import KeyManagerPanel from './components/KeyManagerPanel.vue'
|
||||
@@ -86,6 +87,7 @@ const moduleTab = ref('terminal')
|
||||
/** tab 定义(顺序即 TabsList 顺序;label 同时供标题栏浮动切换器使用) */
|
||||
const MODULE_TABS = [
|
||||
{ value: 'terminal', label: '终端' },
|
||||
{ value: 'files', label: '文件' },
|
||||
{ value: 'hosts', label: '主机' },
|
||||
{ value: 'keys', label: '密钥' },
|
||||
{ value: 'settings', label: '设置' }
|
||||
@@ -227,7 +229,9 @@ useTerminalKeys({
|
||||
void workspaceRef.value?.handleSplit('down')
|
||||
break
|
||||
case 'toggleSftp':
|
||||
workspaceRef.value?.toggleSftp()
|
||||
// 文件管理器已改为模块级的一页:动作 id 保留(见 terminalActions 的说明),
|
||||
// 行为改成「跳到文件页」并顺手预选当前会话(openFiles 内部做)
|
||||
workspaceRef.value?.openFiles()
|
||||
break
|
||||
// ===== 状态在编排层,直接调用 =====
|
||||
case 'fontIncrease':
|
||||
@@ -323,9 +327,20 @@ onBeforeUnmount(() => {
|
||||
:stream="stream"
|
||||
:ready="ready"
|
||||
@go-hosts="moduleTab = 'hosts'"
|
||||
@open-files="moduleTab = 'files'"
|
||||
/>
|
||||
</TabsContent>
|
||||
|
||||
<!--
|
||||
文件页:双栏 + 两栏各自选连接(本地 / 已连接的 SSH)。
|
||||
不 forceMount —— **两栏选的是哪个连接**存在 store 里(切走再回来还在),
|
||||
而当前目录是组件内的状态:卸载重挂会回到该连接的落点并重新列一次目录
|
||||
(数据因此总是新的,代价是一次 read_dir)。
|
||||
-->
|
||||
<TabsContent value="files" class="flex-1 min-h-0 tab-animate">
|
||||
<FileManager />
|
||||
</TabsContent>
|
||||
|
||||
<!--
|
||||
===== 其余模块页 =====
|
||||
普通 TabsContent(卸载即重置,从 store 重新同步,无代价)。
|
||||
|
||||
@@ -325,6 +325,21 @@ function getTerminalContext(): string {
|
||||
return paneRef.value?.getSelection?.() ?? ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开(或唤出)文件管理器窗口。
|
||||
*
|
||||
* 本窗口没有模块 tab 可切,因此控制栏的文件按钮在这里的语义是「开那个独立窗口」
|
||||
* (后端单例幂等)——与终端页的「跳到文件 tab」共用同一个按钮,见
|
||||
* `TerminalToolbar` 的 `open-files` 事件说明。
|
||||
*/
|
||||
async function openFileWindow() {
|
||||
try {
|
||||
await store.openFileWindow()
|
||||
} catch (e) {
|
||||
toast.error(`打开文件窗口失败:${String(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
/** 会话日志 */
|
||||
async function toggleLogging() {
|
||||
const sess = session.value
|
||||
@@ -531,7 +546,6 @@ async function closeWindow() {
|
||||
:searching="searching"
|
||||
:search-hint="searchHint"
|
||||
:is-ssh="isSsh"
|
||||
:sftp-visible="false"
|
||||
:logging="session?.logging ?? false"
|
||||
:font-size="effectiveAppearance?.fontSize ?? 14"
|
||||
@toggle-search="toggleSearch"
|
||||
@@ -543,6 +557,7 @@ async function closeWindow() {
|
||||
@clear="handleClear"
|
||||
@rename="openRename"
|
||||
@open-ai="aiOpen = true"
|
||||
@open-files="openFileWindow"
|
||||
@toggle-logging="toggleLogging"
|
||||
@open-log-dir="openLogDir"
|
||||
/>
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
*
|
||||
* # 引擎来源
|
||||
*
|
||||
* 复用**翻译模块**的 AI 引擎配置(Base URL / 模型 / 密钥)——用户配置一份 API
|
||||
* 即可在两处使用。没有可用引擎时展示引导文案而不是让用户点了「生成」才报错。
|
||||
* 复用**主设置 → AI 服务**的全局供应商配置(Base URL / 模型 / 密钥)——
|
||||
* 用户配置一份 API 即可在翻译、终端等多处使用。
|
||||
* 没有可用引擎时展示引导文案而不是让用户点了「生成」才报错。
|
||||
*
|
||||
* # 交互与片段库同一套安全语义
|
||||
*
|
||||
@@ -142,7 +143,7 @@ function engineLabel(e: AiEngineOption): string {
|
||||
<Sparkles class="size-4" />AI 命令助手
|
||||
</DialogTitle>
|
||||
<DialogDescription class="text-xs">
|
||||
复用翻译设置里的 AI 引擎。建议默认只填入命令行,由你确认后执行。
|
||||
使用主设置里的 AI 供应商。建议默认只填入命令行,由你确认后执行。
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
@@ -164,7 +165,7 @@ function engineLabel(e: AiEngineOption): string {
|
||||
</template>
|
||||
<p v-else class="text-xs text-muted-foreground">
|
||||
还没有可用的 AI 引擎。请到
|
||||
<span class="text-foreground font-medium">翻译模块 → 设置 → 引擎</span>
|
||||
<span class="text-foreground font-medium">常规设置 → AI 服务</span>
|
||||
配置一个(DeepSeek / OpenAI / Ollama 等 OpenAI 兼容服务均可),配置后回到这里刷新。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,398 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 文件管理器:双栏(左 / 右各自选择连接)+ 方向式传输 + 传输进度。
|
||||
*
|
||||
* # 为什么是「双栏 + 两栏各自选连接」而不是「终端卡片里的会话面板」
|
||||
*
|
||||
* 面板原本长在终端卡片里、绑定当前会话,于是「本地 ↔ 远端」是唯一可能的组合,
|
||||
* 而每次看文件都得先切到那个会话的标签。改成独立页面后,双栏的语义变成
|
||||
* 「两台机器之间的关系」:本地 ↔ ssh1、ssh1 ↔ ssh2、ssh1 ↔ ssh1(同机跨目录)——
|
||||
* 这些都是同一类动作,用同一套 UI 表达。
|
||||
*
|
||||
* # 为什么传输由这一层编排(而不是各栏自己传)
|
||||
*
|
||||
* 一次传输需要**两栏**的信息:源栏的选中项与 cwd、目标栏的 cwd 与连接。
|
||||
* 单栏组件只看得到自己,若让它们各自发命令,就得让每一栏都持有一份「对面是什么」
|
||||
* 的镜像状态 —— 那是两份会漂移的真相。因此:单栏负责「选中了什么」,
|
||||
* 这一层负责「从谁传到哪里」。
|
||||
*
|
||||
* # 传输方向由连接组合决定,文案随之变化
|
||||
*
|
||||
* | 源 → 目标 | 命令 | 按钮文案 |
|
||||
* |---|---|---|
|
||||
* | 本地 → ssh | `terminal_sftp_upload` | 上传到远端 |
|
||||
* | ssh → 本地 | `terminal_sftp_download` | 下载到本地 |
|
||||
* | ssh → ssh | `terminal_sftp_relay`(流式中继,不经本地磁盘) | 中继到远端 |
|
||||
* | 本地 → 本地 | —— | 禁用(没有传输语义) |
|
||||
*
|
||||
* 「本地↔本地」被**禁用而不是隐藏**:两栏都是本地时用户仍可能想复制文件,
|
||||
* 灰掉的按钮配上说明(`transferBlocked`)比一个消失的按钮更容易理解。
|
||||
* 同时两栏的选择器互相排他,避免走进这个组合 —— 见 `allowLocal` 的计算。
|
||||
*/
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import {
|
||||
ArrowDownToLine,
|
||||
ArrowLeftRight,
|
||||
ArrowUpFromLine,
|
||||
FolderTree,
|
||||
SquareArrowOutUpRight,
|
||||
X
|
||||
} from '@lucide/vue'
|
||||
import { toast } from 'vue-sonner'
|
||||
import { useTerminalStore } from '@/stores/terminalStore'
|
||||
import { createLogger } from '@/lib/logger'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card } from '@/components/ui/card'
|
||||
import PageToolbar from '@/components/layout/PageToolbar.vue'
|
||||
import FilePane from './FilePane.vue'
|
||||
import { baseName, humanSize, joinLocal, joinRemote, transferKind } from '../fileUtils'
|
||||
import type { ActionOutcome, FileSource, SessionInfo } from '@/types/terminal'
|
||||
|
||||
defineProps<{
|
||||
/**
|
||||
* 独立窗口模式(`FileWindow` 复用本组件时置真)。
|
||||
*
|
||||
* 只有一件事不同:不渲染 `PageToolbar`(窗口自带控制栏,标题已在其中),
|
||||
* 改为由本组件自带四周留白。两栏与传输逻辑完全共用 —— 与终端页 / 终端独立窗口
|
||||
* 复用同一套组件的取舍一致。
|
||||
*/
|
||||
standalone?: boolean
|
||||
}>()
|
||||
|
||||
const store = useTerminalStore()
|
||||
const logger = createLogger('terminal')
|
||||
|
||||
const leftRef = ref<InstanceType<typeof FilePane> | null>(null)
|
||||
const rightRef = ref<InstanceType<typeof FilePane> | null>(null)
|
||||
/** 分栏容器:拖动分界线时按它的实际宽度换算百分比 */
|
||||
const splitRowRef = ref<HTMLElement | null>(null)
|
||||
|
||||
// ===== 拖动分界线调整两栏宽度 =====
|
||||
|
||||
/**
|
||||
* 拖动分界线。
|
||||
*
|
||||
* 事件挂在 **document** 而不是分界线自己:鼠标一旦快速划出那条 5px 的命中区,
|
||||
* 挂在元素上的 `mousemove` 就断了(拖动会「粘住」或半路失效)。
|
||||
* 同时用 `document.body` 上的 `user-select: none` 防止拖出选区(一份文本被选中后
|
||||
* 半透明蓝底会盖住整个列表)。
|
||||
*/
|
||||
function startResize(e: MouseEvent) {
|
||||
e.preventDefault()
|
||||
const row = splitRowRef.value
|
||||
if (!row) return
|
||||
const rect = row.getBoundingClientRect()
|
||||
if (rect.width <= 0) return
|
||||
|
||||
const prevSelect = document.body.style.userSelect
|
||||
document.body.style.userSelect = 'none'
|
||||
|
||||
const onMove = (ev: MouseEvent) => {
|
||||
store.setFilePaneSplit(((ev.clientX - rect.left) / rect.width) * 100)
|
||||
}
|
||||
const onUp = () => {
|
||||
document.body.style.userSelect = prevSelect
|
||||
document.removeEventListener('mousemove', onMove)
|
||||
document.removeEventListener('mouseup', onUp)
|
||||
}
|
||||
document.addEventListener('mousemove', onMove)
|
||||
document.addEventListener('mouseup', onUp)
|
||||
}
|
||||
|
||||
const sources = computed(() => store.filePaneSources)
|
||||
|
||||
/**
|
||||
* 可作为一栏来源的 SSH 会话。
|
||||
*
|
||||
* 只要**已建立**或**连接不稳定**的:连接中/认证中的会话还没有 SFTP 子系统可开,
|
||||
* 已断开/失败的会话只会让列目录报错。「看得见但用不了」比「看不见」更让人困惑。
|
||||
*/
|
||||
const sessions = computed<SessionInfo[]>(() =>
|
||||
store.sessions.filter(
|
||||
s => s.kind === 'ssh' && (s.state === 'established' || s.state === 'degraded')
|
||||
)
|
||||
)
|
||||
|
||||
/** 本地↔本地没有传输语义,故两栏的「本地」互斥(谁的默认值先占上就留着) */
|
||||
const allowLocalLeft = computed(() => sources.value.right?.kind !== 'local')
|
||||
const allowLocalRight = computed(() => sources.value.left?.kind !== 'local')
|
||||
|
||||
function setSource(side: 'left' | 'right', v: FileSource | null) {
|
||||
store.setFilePaneSource(side, v)
|
||||
}
|
||||
|
||||
// ===== 传输 =====
|
||||
|
||||
const transferring = ref(false)
|
||||
|
||||
function kindOf(from: 'left' | 'right') {
|
||||
const to = from === 'left' ? sources.value.right : sources.value.left
|
||||
return transferKind(sources.value[from], to)
|
||||
}
|
||||
|
||||
function labelOf(from: 'left' | 'right'): string {
|
||||
switch (kindOf(from)) {
|
||||
case 'upload':
|
||||
return '上传到远端'
|
||||
case 'download':
|
||||
return '下载到本地'
|
||||
case 'relay':
|
||||
return '中继到远端'
|
||||
default:
|
||||
return '无法传送'
|
||||
}
|
||||
}
|
||||
|
||||
function blockedOf(from: 'left' | 'right'): string {
|
||||
if (kindOf(from)) return ''
|
||||
const self = sources.value[from]
|
||||
const other = from === 'left' ? sources.value.right : sources.value.left
|
||||
if (!self) return '本栏还没有选择连接'
|
||||
if (!other) return '另一栏还没有选择连接(点上方按钮选择)'
|
||||
if (self.kind === 'local' && other.kind === 'local')
|
||||
return '两栏都是本地时无法直接传送;把其中一栏切到 SSH 会话即可'
|
||||
return '当前两栏的组合不支持传送'
|
||||
}
|
||||
|
||||
/** 进行中的传输(不再按会话过滤:一屏内能看到自己发起的全部传输) */
|
||||
const activeTransfers = computed(() => store.transfers)
|
||||
|
||||
async function transfer(from: 'left' | 'right') {
|
||||
const src = sources.value[from]
|
||||
const dst = from === 'left' ? sources.value.right : sources.value.left
|
||||
const kind = kindOf(from)
|
||||
if (!src || !dst || !kind) {
|
||||
toast.info(blockedOf(from))
|
||||
return
|
||||
}
|
||||
const paneFrom = from === 'left' ? leftRef.value : rightRef.value
|
||||
const paneTo = from === 'left' ? rightRef.value : leftRef.value
|
||||
const files = (paneFrom?.getSelection() ?? []).filter(e => !e.isDir)
|
||||
if (files.length === 0) {
|
||||
toast.info('请先选择要传送的文件(目录递归传输属 P2)')
|
||||
return
|
||||
}
|
||||
const toCwd = paneTo?.getCwd() ?? ''
|
||||
if (!toCwd) {
|
||||
toast.info('目标栏还没有打开目录')
|
||||
return
|
||||
}
|
||||
|
||||
// 组合由 `transferKind` 判定,这里把两栏的会话 id 取出来;任一侧缺失说明
|
||||
// 连接在点击与执行之间变了(会话刚断开),直接提示重试而不是发一条注定失败的命令
|
||||
const srcSsh = src.kind === 'ssh' ? src.sessionId : ''
|
||||
const dstSsh = dst.kind === 'ssh' ? dst.sessionId : ''
|
||||
const missing =
|
||||
(kind === 'upload' && !dstSsh) ||
|
||||
(kind === 'download' && !srcSsh) ||
|
||||
(kind === 'relay' && (!srcSsh || !dstSsh))
|
||||
if (missing) {
|
||||
toast.error('连接状态已变化,请重新选择后再试')
|
||||
return
|
||||
}
|
||||
|
||||
transferring.value = true
|
||||
let ok = 0
|
||||
const failed: string[] = []
|
||||
// 串行:受控并发的闸门(4 路)被占满时,文件名顺序错乱的进度条比
|
||||
// 「一个一个来」更难读(与旧的单文件上传同一取舍)
|
||||
for (const f of files) {
|
||||
try {
|
||||
let r: ActionOutcome
|
||||
if (kind === 'upload') {
|
||||
r = await store.sftpUpload(dstSsh, f.path, joinRemote(toCwd, f.name))
|
||||
} else if (kind === 'download') {
|
||||
r = await store.sftpDownload(srcSsh, f.path, joinLocal(toCwd, f.name))
|
||||
} else {
|
||||
r = await store.sftpRelay(srcSsh, f.path, dstSsh, joinRemote(toCwd, f.name))
|
||||
}
|
||||
if (r.ok) ok += 1
|
||||
else failed.push(`${f.name}:${r.message}`)
|
||||
} catch (e) {
|
||||
failed.push(`${f.name}:${String(e)}`)
|
||||
}
|
||||
}
|
||||
transferring.value = false
|
||||
// 刷新目标栏:刚传过去的文件要立刻出现在眼前,否则用户会以为没成功
|
||||
await paneTo?.reload()
|
||||
|
||||
const verb = kind === 'upload' ? '上传' : kind === 'download' ? '下载' : '中继'
|
||||
if (failed.length === 0) toast.success(`已${verb} ${ok} 个文件`)
|
||||
else if (ok > 0) toast.warning(`${verb}完成 ${ok} 个,失败 ${failed.length} 个:${failed.join(';')}`)
|
||||
else toast.error(`${verb}失败:${failed.join(';')}`)
|
||||
}
|
||||
|
||||
// ===== 独立窗口 =====
|
||||
|
||||
async function openWindow() {
|
||||
try {
|
||||
await store.openFileWindow()
|
||||
} catch (e) {
|
||||
logger.error(`打开文件窗口失败:${String(e)}`)
|
||||
toast.error(`打开文件窗口失败:${String(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 初始化 =====
|
||||
|
||||
/**
|
||||
* 默认分栏。
|
||||
*
|
||||
* 左栏固定落本地(「我自己的机器」是绝大多数传输的起点),右栏取**第一个**已连接的
|
||||
* SSH 会话。取「第一个」而不是「终端页当前激活的那个」:激活会话属于
|
||||
* `useTerminalStream` 的窗口级局部状态(见 TerminalModule 的说明),这里读不到;
|
||||
* 而从终端页跳过来的那条路径由 `TerminalWorkspace` 先把激活会话写进
|
||||
* `filePaneSources.right`,效果等价。
|
||||
*
|
||||
* 每次挂载都跑一次:tab 切走会卸载本组件(连接选择存在 store 里,不丢),
|
||||
* 但期间可能有关掉的会话 —— 失效的连接在这里被收敛掉。
|
||||
*/
|
||||
function initSources() {
|
||||
const s = sources.value
|
||||
const alive = (v: FileSource | null) =>
|
||||
v?.kind === 'ssh' && sessions.value.some(x => x.id === v.sessionId)
|
||||
|
||||
if (s.left?.kind === 'ssh' && !alive(s.left)) setSource('left', { kind: 'local' })
|
||||
// 只收敛「指向已消失会话」的右栏:右栏若被用户设成本地(左栏是 ssh),
|
||||
// 它同样不是 ssh 来源,**不能**当成失效处理
|
||||
if (s.right?.kind === 'ssh' && !alive(s.right)) setSource('right', null)
|
||||
|
||||
// 左栏若是空的(理论上不会:本地永远可用),补成本地
|
||||
if (!sources.value.left) setSource('left', { kind: 'local' })
|
||||
|
||||
if (!sources.value.right) {
|
||||
const first = sessions.value[0]
|
||||
// 左栏已是本地时右栏不能也是本地 —— 所以没有 SSH 会话就保持空态
|
||||
if (first) setSource('right', { kind: 'ssh', sessionId: first.id })
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
initSources()
|
||||
})
|
||||
|
||||
// 会话列表变化(连上/断开):失效的连接及时收敛,新连上的会话自动补上右栏
|
||||
// ——后者只在右栏还是空态时发生,不覆盖用户已有的选择
|
||||
watch(
|
||||
() => sessions.value.map(s => s.id).join(','),
|
||||
() => initSources()
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!--
|
||||
独立窗口模式自带四周留白(窗口控制栏之下没有模块级的 p-5);
|
||||
tab 模式由终端模块根节点的 p-5 提供边距。
|
||||
-->
|
||||
<div class="flex flex-col h-full overflow-hidden" :class="standalone ? 'p-3' : ''">
|
||||
<PageToolbar
|
||||
v-if="!standalone"
|
||||
:icon="FolderTree"
|
||||
title="文件管理器"
|
||||
:meta="sessions.length > 0 ? `可切换 ${sessions.length} 个 SSH 会话` : '暂无已连接的 SSH 会话'"
|
||||
>
|
||||
<Button variant="outline" size="sm" :disabled="transferring" @click="openWindow">
|
||||
<SquareArrowOutUpRight class="size-3.5" />独立窗口
|
||||
</Button>
|
||||
</PageToolbar>
|
||||
|
||||
<!--
|
||||
两栏装在**同一个容器**里,中间一条可拖动的分界线。
|
||||
分成两张卡片(`gap-3`)会让它读作「两个窗口并排」,而这里要做的是
|
||||
「一个窗口的两半」—— 分界线可拖,与资源管理器的双栏一致。
|
||||
-->
|
||||
<Card class="flex-1 min-h-0 !py-0 !gap-0 overflow-hidden">
|
||||
<div ref="splitRowRef" class="h-full min-h-0 flex">
|
||||
<!-- 左栏:宽度用百分比(拖动的结果在窗口缩放后仍然成立) -->
|
||||
<div class="min-w-0 flex flex-col" :style="{ width: `${store.filePaneSplit}%` }">
|
||||
<FilePane
|
||||
ref="leftRef"
|
||||
side="left"
|
||||
:connection="sources.left"
|
||||
:sessions="sessions"
|
||||
:allow-local="allowLocalLeft"
|
||||
:transfer-label="labelOf('left')"
|
||||
:transfer-blocked="blockedOf('left')"
|
||||
@update:connection="setSource('left', $event)"
|
||||
@transfer="transfer('left')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
分界线:视觉上是 1px 的线,命中区宽 5px(`w-[5px]` 容器 + 居中的线)。
|
||||
只给 1px 的命中区几乎点不中,而把线画成 5px 又太粗。
|
||||
-->
|
||||
<div
|
||||
class="group w-[5px] shrink-0 cursor-col-resize relative"
|
||||
title="拖动调整两栏宽度"
|
||||
@mousedown="startResize"
|
||||
>
|
||||
<div
|
||||
class="absolute inset-y-0 left-1/2 -translate-x-1/2 w-px bg-border
|
||||
transition-colors group-hover:bg-primary/60"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 min-w-0 flex flex-col">
|
||||
<FilePane
|
||||
ref="rightRef"
|
||||
side="right"
|
||||
:connection="sources.right"
|
||||
:sessions="sessions"
|
||||
:allow-local="allowLocalRight"
|
||||
:transfer-label="labelOf('right')"
|
||||
:transfer-blocked="blockedOf('right')"
|
||||
@update:connection="setSource('right', $event)"
|
||||
@transfer="transfer('right')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<!-- ===== 传输进度 ===== -->
|
||||
<div v-if="activeTransfers.length > 0" class="shrink-0 mt-3 max-h-28 overflow-auto">
|
||||
<div
|
||||
v-for="t in activeTransfers"
|
||||
:key="t.id"
|
||||
class="px-2.5 py-1.5 flex items-center gap-2 text-xs border-b border-border/50 last:border-b-0"
|
||||
>
|
||||
<component
|
||||
:is="
|
||||
t.direction === 'upload'
|
||||
? ArrowUpFromLine
|
||||
: t.direction === 'download'
|
||||
? ArrowDownToLine
|
||||
: ArrowLeftRight
|
||||
"
|
||||
class="size-3.5 shrink-0"
|
||||
:class="t.state === 'failed' ? 'text-destructive' : 'text-muted-foreground'"
|
||||
/>
|
||||
<span class="truncate flex-1" :title="`${t.source} → ${t.target}`">
|
||||
{{ baseName(t.source) }}
|
||||
<span class="text-muted-foreground/60">→ {{ baseName(t.target) }}</span>
|
||||
</span>
|
||||
<div v-if="t.state === 'running'" class="w-24 h-1 rounded-full bg-muted overflow-hidden shrink-0">
|
||||
<div
|
||||
class="h-full bg-primary transition-[width] duration-200"
|
||||
:style="{ width: t.total > 0 ? `${Math.min(100, (t.transferred / t.total) * 100)}%` : '0%' }"
|
||||
/>
|
||||
</div>
|
||||
<span class="text-muted-foreground tabular-nums shrink-0 w-28 text-right whitespace-nowrap">
|
||||
<template v-if="t.state === 'running'">
|
||||
{{ t.total > 0 ? `${humanSize(t.transferred)} / ${humanSize(t.total)}` : humanSize(t.transferred) }}
|
||||
</template>
|
||||
<span v-else-if="t.state === 'done'" class="text-success">完成</span>
|
||||
<span v-else-if="t.state === 'failed'" class="text-destructive" :title="t.error ?? ''">失败</span>
|
||||
<span v-else>{{ t.state }}</span>
|
||||
</span>
|
||||
<button
|
||||
class="text-muted-foreground hover:text-foreground shrink-0"
|
||||
title="从列表移除"
|
||||
@click="store.dismissTransfer(t.id)"
|
||||
>
|
||||
<X class="size-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,779 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 文件管理器的**一栏**(本地,或某个 SSH 会话)。
|
||||
*
|
||||
* # 为什么本地与远端合成一个组件
|
||||
*
|
||||
* 改造前是「本地栏」与「远端栏」两套代码(`SftpPanel` 里一个只做选取、一个做完整
|
||||
* 文件管理)。现在两栏可以各自被切到任意连接(本地 / ssh1 / ssh2…),组合有四种,
|
||||
* 若按组合写分支就是四套 UI。合成一个组件后,「这一栏做什么」只取决于
|
||||
* `props.connection.kind` —— 差异被压到三处:**调用哪条命令**、**路径怎么拼**、
|
||||
* **删除是什么语义**(本地进回收站,远端直接删)。模板完全共用。
|
||||
*
|
||||
* # 这一栏不知道对面是什么
|
||||
*
|
||||
* 传输按钮的文案与可用性由父组件(`FileManager`)算好传进来:它同时看得到两栏的
|
||||
* 连接,而本组件只看得到自己。这也是传输动作由父组件编排的原因 —— 见
|
||||
* `FileManager` 的说明。
|
||||
*
|
||||
* # 与旧实现的差异(都是有意的)
|
||||
*
|
||||
* | 项 | 旧 | 新 |
|
||||
* |---|---|---|
|
||||
* | 符号链接 | 本地按目标类型、远端是独立 kind | 归一成 `isDir` + `isLink`,模板只认这两个 |
|
||||
* | 跟随 cd | 跟随「当前激活会话」(面板绑会话) | 跟随**本栏所选会话**的 cwd |
|
||||
* | 新增目录校验 | 分别禁止 `/` 或 `\` | 两种分隔符都禁止(本地路径也认 `/`) |
|
||||
*/
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { open as openDialog } from '@tauri-apps/plugin-dialog'
|
||||
import {
|
||||
ArrowLeft,
|
||||
ArrowRight,
|
||||
ChevronDown,
|
||||
CornerUpLeft,
|
||||
ExternalLink,
|
||||
File as FileIcon,
|
||||
Folder,
|
||||
FolderOpen,
|
||||
FolderPlus,
|
||||
HardDrive,
|
||||
House,
|
||||
Link2,
|
||||
Loader2,
|
||||
RefreshCw,
|
||||
Server,
|
||||
SquarePen,
|
||||
Trash2
|
||||
} from '@lucide/vue'
|
||||
import { toast } from 'vue-sonner'
|
||||
import { useTerminalStore } from '@/stores/terminalStore'
|
||||
import { createLogger } from '@/lib/logger'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { fmtEntryTime, fmtFullTime, humanSize, joinLocal, joinRemote, parentOf } from '../fileUtils'
|
||||
import type { FileSource, SessionInfo } from '@/types/terminal'
|
||||
|
||||
/**
|
||||
* 一栏里的一行(本地与远端**归一化**后的公共形态)。
|
||||
*
|
||||
* 归一掉的是两侧模型里那些「只对其中一侧成立」的字段:远端的 `permissions`、
|
||||
* 两种路径的分隔符、以及符号链接的表达方式(远端是独立 kind,本地是目标类型 +
|
||||
* `linkTarget`)。归一之后模板与传输逻辑只需要问 `isDir` / `isLink`。
|
||||
*/
|
||||
interface PaneEntry {
|
||||
name: string
|
||||
path: string
|
||||
isDir: boolean
|
||||
isLink: boolean
|
||||
linkTarget: string | null
|
||||
size: number
|
||||
modifiedAt?: number | null
|
||||
/** 仅远端有(权限位八进制展示) */
|
||||
permissions?: string
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
/** 本栏的连接来源;`null` = 空态(还没有可选连接) */
|
||||
connection: FileSource | null
|
||||
/** 可选的 SSH 会话(父组件已过滤:仅已建立的 ssh 会话) */
|
||||
sessions: SessionInfo[]
|
||||
/** 是否允许选「本地」:另一栏已是本地时为 false(本地↔本地没有传输语义) */
|
||||
allowLocal: boolean
|
||||
/** 传送到另一栏的按钮文案(父组件按两侧类型算好,如「上传到远端」) */
|
||||
transferLabel: string
|
||||
/** 不能传送时的原因(空串 = 可传送) */
|
||||
transferBlocked: string
|
||||
/** 本栏位置(决定传送按钮的箭头方向:箭头指向另一栏) */
|
||||
side: 'left' | 'right'
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:connection', v: FileSource | null): void
|
||||
/** 请求把选中项传送到另一栏(真正的传输由父组件编排) */
|
||||
(e: 'transfer'): void
|
||||
}>()
|
||||
|
||||
const store = useTerminalStore()
|
||||
const logger = createLogger('terminal')
|
||||
|
||||
// ===== 状态 =====
|
||||
|
||||
const cwd = ref('')
|
||||
/** 父目录;根为 null(「上一级」据此禁用) */
|
||||
const parent = ref<string | null>(null)
|
||||
const entries = ref<PaneEntry[]>([])
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const filter = ref('')
|
||||
/** 路径输入框内容(回车跳转;ESC 回填当前目录) */
|
||||
const pathInput = ref('')
|
||||
/** 选中项(多选;删除/传送作用于全部,重命名只对单项开放) */
|
||||
const selected = ref<PaneEntry[]>([])
|
||||
/** shift 范围选择的锚点。不进响应式:只在下一次点击时读一次 */
|
||||
let anchor = 0
|
||||
/**
|
||||
* 待跳转路径(一次性)。
|
||||
*
|
||||
* 只为一件事存在:`pickDir` 在「当前是 ssh 栏」时会先把本栏切成本地,
|
||||
* 而连接切换的 watch 会把目录拉回落点(主目录)——用户选的那个目录就丢了。
|
||||
* 把路径交给下一次连接切换消费,可以避免「先 load(picked) 再被 watch 覆盖」
|
||||
* 这种时序竞争。
|
||||
*/
|
||||
let pendingJump: string | null = null
|
||||
|
||||
const showNewDir = ref(false)
|
||||
const newDirName = ref('')
|
||||
const renaming = ref(false)
|
||||
const renameValue = ref('')
|
||||
|
||||
/** 是否跟随该栏所选会话的终端 cwd(仅 ssh 栏有意义) */
|
||||
const following = ref(false)
|
||||
|
||||
const isSsh = computed(() => props.connection?.kind === 'ssh')
|
||||
const sessionId = computed(() => (props.connection?.kind === 'ssh' ? props.connection.sessionId : ''))
|
||||
|
||||
const session = computed(() => (sessionId.value ? store.sessionById(sessionId.value) : undefined))
|
||||
|
||||
/** 会话已不在列表里(被关掉 / 应用重连后失效)—— 只在确实拿到过列表时才判定 */
|
||||
const staleSession = computed(
|
||||
() => isSsh.value && !!sessionId.value && store.sessions.length > 0 && !session.value
|
||||
)
|
||||
|
||||
const sourceLabel = computed(() => (isSsh.value ? store.sessionLabel(session.value) : '本地'))
|
||||
const sourceSub = computed(() => {
|
||||
if (!isSsh.value) return ''
|
||||
return store.sessionTarget(session.value)
|
||||
})
|
||||
|
||||
const filtered = computed(() => {
|
||||
const kw = filter.value.trim().toLowerCase()
|
||||
if (!kw) return entries.value
|
||||
return entries.value.filter(e => e.name.toLowerCase().includes(kw))
|
||||
})
|
||||
|
||||
const filesSelected = computed(() => selected.value.filter(e => !e.isDir))
|
||||
|
||||
/** 传送按钮的悬停说明:连接组合 > 选中内容 > 默认 */
|
||||
const transferHint = computed(() => {
|
||||
if (props.transferBlocked) return props.transferBlocked
|
||||
if (selected.value.length > 0 && filesSelected.value.length === 0)
|
||||
return '选中的是目录;目录递归传输属 P2,请进入目录后选择其中的文件'
|
||||
return `把选中的 ${filesSelected.value.length} 个文件传送到另一栏`
|
||||
})
|
||||
|
||||
// ===== 加载 =====
|
||||
|
||||
/** 一栏打开时的落点:本地用主目录,ssh 用该会话的终端 cwd(拿不到就交给服务端 `canonicalize('.')`) */
|
||||
function initialPath(): string {
|
||||
if (props.connection?.kind === 'ssh') return store.sessionById(props.connection.sessionId)?.cwd || '.'
|
||||
return ''
|
||||
}
|
||||
|
||||
async function load(path: string) {
|
||||
const c = props.connection
|
||||
if (!c) return
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
if (c.kind === 'local') {
|
||||
const dir = await store.localList(path)
|
||||
cwd.value = dir.cwd
|
||||
parent.value = dir.parent ?? null
|
||||
entries.value = dir.entries.map(e => ({
|
||||
name: e.name,
|
||||
path: e.path,
|
||||
isDir: e.kind === 'dir',
|
||||
// 本地的链接是「目标类型 + linkTarget」,见 Rust 侧 local_fs 的说明
|
||||
isLink: !!e.linkTarget,
|
||||
linkTarget: e.linkTarget ?? null,
|
||||
size: e.size,
|
||||
modifiedAt: e.modifiedAt
|
||||
}))
|
||||
} else {
|
||||
// 通道按需打开(幂等);不在这里关 —— 见 store 里通道生命周期的说明
|
||||
await store.sftpOpen(c.sessionId)
|
||||
const dir = await store.sftpList(c.sessionId, path || '.')
|
||||
// 用服务端返回的 cwd 而不是请求的 path:符号链接目录下两者不同,
|
||||
// 显示真实位置才能解释「为什么我看的内容和路径不像」
|
||||
const real = dir.cwd || path
|
||||
cwd.value = real
|
||||
parent.value = real === '/' ? null : await store.sftpParent(real)
|
||||
entries.value = dir.entries.map(e => ({
|
||||
name: e.name,
|
||||
path: e.path,
|
||||
// 远端符号链接的 kind 是独立的 'symlink'(SFTP 的 attrs 不带目标类型)
|
||||
isDir: e.kind === 'dir',
|
||||
isLink: e.kind === 'symlink',
|
||||
linkTarget: e.linkTarget || null,
|
||||
size: e.size,
|
||||
modifiedAt: e.modifiedAt,
|
||||
permissions: e.permissions
|
||||
}))
|
||||
}
|
||||
pathInput.value = cwd.value
|
||||
selected.value = []
|
||||
} catch (e) {
|
||||
error.value = String(e)
|
||||
logger.error(`列举目录 ${path} 失败(${c.kind}):${String(e)}`)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 连接变化 = 换了一台机器/一个语义,所有局部状态作废 */
|
||||
watch(
|
||||
() => props.connection,
|
||||
c => {
|
||||
renaming.value = false
|
||||
showNewDir.value = false
|
||||
filter.value = ''
|
||||
selected.value = []
|
||||
if (!c) {
|
||||
cwd.value = ''
|
||||
parent.value = null
|
||||
entries.value = []
|
||||
error.value = ''
|
||||
pathInput.value = ''
|
||||
return
|
||||
}
|
||||
following.value = false
|
||||
// 待跳转路径:对话框选完目录可能顺带把本栏从 ssh 切到本地,
|
||||
// 那种情况下真正要去的是用户选的那个目录,而不是落点(见 `pickDir`)
|
||||
const next = pendingJump ?? initialPath()
|
||||
pendingJump = null
|
||||
void load(next)
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
// 跟随 cd:只在用户勾选、且该栏所选会话的 cwd 真的变了时同步
|
||||
watch(
|
||||
() => session.value?.cwd,
|
||||
next => {
|
||||
if (following.value && next) void load(next)
|
||||
}
|
||||
)
|
||||
|
||||
/** 会话异常结束时收起跟随,避免一直朝一个不存在的通道发请求 */
|
||||
watch(staleSession, gone => {
|
||||
if (gone) following.value = false
|
||||
})
|
||||
|
||||
// ===== 连接选择 =====
|
||||
|
||||
function pick(source: FileSource) {
|
||||
if (source.kind === 'ssh' && source.sessionId === sessionId.value) return
|
||||
if (source.kind === 'local' && !isSsh.value) return
|
||||
emit('update:connection', source)
|
||||
}
|
||||
|
||||
// ===== 导航 =====
|
||||
|
||||
async function goUp() {
|
||||
if (parent.value) await load(parent.value)
|
||||
}
|
||||
|
||||
/** 双击:目录进去;远端符号链接先试一次列举(可能指向目录) */
|
||||
async function enter(entry: PaneEntry) {
|
||||
if (entry.isDir) {
|
||||
await load(entry.path)
|
||||
return
|
||||
}
|
||||
if (entry.isLink && isSsh.value) {
|
||||
try {
|
||||
await store.sftpList(sessionId.value, entry.path)
|
||||
await load(entry.path)
|
||||
} catch {
|
||||
toast.info(`符号链接指向 ${entry.linkTarget ?? '未知目标'}(不是目录或不可访问)`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 路径输入框回车:跳到手输的目录(两栏统一的可编辑地址栏) */
|
||||
async function jump() {
|
||||
const target = pathInput.value.trim()
|
||||
if (!target || target === cwd.value) {
|
||||
pathInput.value = cwd.value
|
||||
return
|
||||
}
|
||||
await load(target)
|
||||
}
|
||||
|
||||
/** 系统对话框定位目录 */
|
||||
async function pickDir() {
|
||||
try {
|
||||
const picked = await openDialog({ directory: true, multiple: false })
|
||||
if (typeof picked !== 'string') return
|
||||
if (isSsh.value) {
|
||||
// 对话框选的是**本机**路径,因此本栏必须先切回本地语义;
|
||||
// 具体跳转交给随后的连接切换(见 `pendingJump` 的说明)
|
||||
pendingJump = picked
|
||||
emit('update:connection', { kind: 'local' })
|
||||
return
|
||||
}
|
||||
await load(picked)
|
||||
} catch (e) {
|
||||
toast.error(`选择目录失败:${String(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 选择 =====
|
||||
|
||||
function isSelected(entry: PaneEntry): boolean {
|
||||
return selected.value.some(e => e.path === entry.path)
|
||||
}
|
||||
|
||||
/**
|
||||
* 行的点击选择。
|
||||
*
|
||||
* 多选是必须的:传送是本页最高频的动作,逐个点要 2N 次操作。
|
||||
* `Ctrl` 逐个加减、`Shift` 从锚点取范围,与资源管理器一致。
|
||||
*/
|
||||
function clickEntry(entry: PaneEntry, ev: MouseEvent) {
|
||||
const list = filtered.value
|
||||
const idx = list.findIndex(e => e.path === entry.path)
|
||||
if (idx < 0) return
|
||||
if (ev.shiftKey) {
|
||||
const from = Math.min(anchor, idx)
|
||||
const to = Math.max(anchor, idx)
|
||||
selected.value = list.slice(from, to + 1)
|
||||
return
|
||||
}
|
||||
if (ev.ctrlKey || ev.metaKey) {
|
||||
selected.value = isSelected(entry)
|
||||
? selected.value.filter(e => e.path !== entry.path)
|
||||
: [...selected.value, entry]
|
||||
anchor = idx
|
||||
return
|
||||
}
|
||||
selected.value = [entry]
|
||||
anchor = idx
|
||||
}
|
||||
|
||||
// ===== 增删改 =====
|
||||
|
||||
function hasSeparator(name: string): boolean {
|
||||
return name.includes('/') || name.includes('\\')
|
||||
}
|
||||
|
||||
async function createFolder() {
|
||||
const name = newDirName.value.trim()
|
||||
if (!name) {
|
||||
toast.error('目录名不能为空')
|
||||
return
|
||||
}
|
||||
if (hasSeparator(name)) {
|
||||
toast.error('目录名不能包含路径分隔符')
|
||||
return
|
||||
}
|
||||
try {
|
||||
if (isSsh.value) await store.sftpMkdir(sessionId.value, joinRemote(cwd.value, name))
|
||||
else await store.localMkdir(joinLocal(cwd.value, name))
|
||||
showNewDir.value = false
|
||||
newDirName.value = ''
|
||||
await load(cwd.value)
|
||||
toast.success(`已创建 ${name}`)
|
||||
} catch (e) {
|
||||
toast.error(`创建目录失败:${String(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
function startRename() {
|
||||
const e = selected.value[0]
|
||||
if (!e) return
|
||||
renameValue.value = e.name
|
||||
renaming.value = true
|
||||
}
|
||||
|
||||
async function submitRename() {
|
||||
const e = selected.value[0]
|
||||
if (!e) return
|
||||
const name = renameValue.value.trim()
|
||||
if (!name || name === e.name) {
|
||||
renaming.value = false
|
||||
return
|
||||
}
|
||||
if (hasSeparator(name)) {
|
||||
toast.error('名称不能包含路径分隔符')
|
||||
return
|
||||
}
|
||||
try {
|
||||
// 目标路径由「条目自己的父目录」拼出而不是用 cwd:列表可能来自旧快照
|
||||
const base = parentOf(e.path)
|
||||
if (isSsh.value) await store.sftpRename(sessionId.value, e.path, joinRemote(base, name))
|
||||
else await store.localRename(e.path, joinLocal(base, name))
|
||||
renaming.value = false
|
||||
await load(cwd.value)
|
||||
} catch (err) {
|
||||
toast.error(`重命名失败:${String(err)}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除。
|
||||
*
|
||||
* 两种语义**必须**在确认框里说清:本地是移入回收站(可恢复),远端是服务端删除
|
||||
* (不可恢复)。文案混用会让用户在远端误以为还能捞回来。
|
||||
*/
|
||||
async function removeSelected() {
|
||||
const items = selected.value
|
||||
if (items.length === 0) return
|
||||
const names = items.map(e => e.name).join('、')
|
||||
const ssh = isSsh.value
|
||||
const hint = items.some(e => e.isDir) ? '及其全部内容' : ''
|
||||
const question = ssh
|
||||
? `确定删除「${names}」${hint}?远端删除不可恢复。`
|
||||
: `确定把「${names}」${hint}移入回收站?`
|
||||
if (!window.confirm(question)) return
|
||||
|
||||
try {
|
||||
if (ssh) {
|
||||
let ok = 0
|
||||
const failed: string[] = []
|
||||
for (const e of items) {
|
||||
try {
|
||||
await store.sftpDelete(sessionId.value, e.path, e.isDir)
|
||||
ok += 1
|
||||
} catch (err) {
|
||||
failed.push(`${e.name}:${String(err)}`)
|
||||
}
|
||||
}
|
||||
if (failed.length === 0) toast.success(`已删除 ${ok} 项`)
|
||||
else if (ok > 0) toast.warning(`已删除 ${ok} 项,失败 ${failed.length} 项:${failed.join(';')}`)
|
||||
else toast.error(`删除失败:${failed.join(';')}`)
|
||||
} else {
|
||||
const r = await store.localDelete(items.map(e => e.path))
|
||||
// 部分成功也算 ok=false(见后端注释),按 ok 分流提示级别,
|
||||
// 否则「9 个成功 1 个失败」会被报成全部成功
|
||||
if (r.ok) toast.success(r.message)
|
||||
else toast.warning(r.message)
|
||||
}
|
||||
await load(cwd.value)
|
||||
} catch (e) {
|
||||
toast.error(`删除失败:${String(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
/** 用默认程序打开 / 在资源管理器中定位(只对本地行有意义 —— 远端路径本机没有) */
|
||||
function openLocalPath(path: string) {
|
||||
void store.openLocalPath(path).catch(e => toast.error(`打开失败:${String(e)}`))
|
||||
}
|
||||
|
||||
function revealLocalPath(path: string) {
|
||||
void store.revealLocalPath(path).catch(e => toast.error(`定位失败:${String(e)}`))
|
||||
}
|
||||
|
||||
// ===== 对外接口(父组件编排传输时读这两样) =====
|
||||
|
||||
defineExpose({
|
||||
/** 当前目录(父组件用它拼目标路径) */
|
||||
getCwd: () => cwd.value,
|
||||
/** 选中项(父组件据此逐个传输) */
|
||||
getSelection: () => selected.value,
|
||||
/** 传输完成后刷新列表(目标栏要立刻看到新文件) */
|
||||
reload: () => load(cwd.value)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col h-full min-h-0 bg-background">
|
||||
<!-- ===== 连接选择 =====
|
||||
放在最上面的固定一行:它是「这一栏是什么」的唯一表达,
|
||||
切连接与切目录是两种不同层级的动作,不该混在同一行里。 -->
|
||||
<div class="shrink-0 h-8 px-2 flex items-center gap-1.5 border-b border-border bg-muted/40">
|
||||
<component :is="isSsh ? Server : HardDrive" class="size-3.5 text-muted-foreground shrink-0 pointer-events-none" />
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger as-child>
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-1 min-w-0 h-7 px-2 rounded-md text-xs
|
||||
transition-colors hover:bg-primary-soft hover:text-primary-soft-text"
|
||||
>
|
||||
<span class="truncate max-w-[150px] font-medium text-[13px]">{{ sourceLabel }}</span>
|
||||
<span v-if="sourceSub" class="text-[11px] text-muted-foreground truncate max-w-[110px]">
|
||||
{{ sourceSub }}
|
||||
</span>
|
||||
<ChevronDown class="size-3 opacity-70 shrink-0" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" class="w-60">
|
||||
<DropdownMenuLabel>选择这一栏的连接</DropdownMenuLabel>
|
||||
<DropdownMenuItem :disabled="!allowLocal" @click="pick({ kind: 'local' })">
|
||||
<HardDrive class="size-4" />
|
||||
<span>本地</span>
|
||||
<span v-if="!allowLocal" class="ml-auto text-[10px] text-muted-foreground">另一栏已是本地</span>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator v-if="sessions.length > 0" />
|
||||
<DropdownMenuItem
|
||||
v-for="s in sessions"
|
||||
:key="s.id"
|
||||
@click="pick({ kind: 'ssh', sessionId: s.id })"
|
||||
>
|
||||
<Server class="size-4" />
|
||||
<span class="truncate">{{ store.sessionLabel(s) }}</span>
|
||||
<span class="ml-auto text-[11px] text-muted-foreground shrink-0">
|
||||
{{ store.sessionTarget(s) }}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
<p v-if="sessions.length === 0" class="px-2 py-1.5 text-xs leading-relaxed text-muted-foreground">
|
||||
还没有已连接的 SSH 会话。在「终端」页连上主机后,这里就能选它。
|
||||
</p>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
<div class="flex-1" />
|
||||
|
||||
<span v-if="staleSession" class="text-[11px] text-warning shrink-0">会话已断开</span>
|
||||
<label
|
||||
v-if="isSsh && !staleSession"
|
||||
class="flex items-center gap-1 text-[11px] text-muted-foreground cursor-pointer select-none shrink-0"
|
||||
>
|
||||
<input v-model="following" type="checkbox" class="size-3.5 accent-primary" />
|
||||
跟随 cd
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- ===== 空态:还没有连接 ===== -->
|
||||
<div v-if="!connection" class="flex-1 min-h-0 flex items-center justify-center p-6">
|
||||
<div class="flex flex-col items-center gap-2 text-center max-w-[300px]">
|
||||
<FolderOpen class="size-8 text-muted-foreground/40" />
|
||||
<p class="text-[13px] font-medium">未选择连接</p>
|
||||
<p class="text-xs leading-relaxed text-muted-foreground">
|
||||
{{
|
||||
sessions.length === 0
|
||||
? '上面选择「本地」即可浏览本机文件;连上 SSH 主机后还能把这一栏切到远端。'
|
||||
: '点上面的按钮选择要浏览的连接。'
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<!-- ===== 工具条(两栏同一套顺序,减少来回看时的定位成本) ===== -->
|
||||
<div class="shrink-0 px-2 py-1.5 flex items-center gap-1 border-b border-border">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="h-7 w-7 p-0"
|
||||
title="上一级"
|
||||
:disabled="!parent"
|
||||
@click="goUp"
|
||||
>
|
||||
<CornerUpLeft class="size-3.5" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" class="h-7 w-7 p-0" title="刷新" @click="load(cwd)">
|
||||
<RefreshCw class="size-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="h-7 w-7 p-0"
|
||||
title="新建目录"
|
||||
@click="showNewDir = !showNewDir"
|
||||
>
|
||||
<FolderPlus class="size-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="h-7 w-7 p-0"
|
||||
title="重命名"
|
||||
:disabled="selected.length !== 1"
|
||||
@click="startRename"
|
||||
>
|
||||
<SquarePen class="size-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="h-7 w-7 p-0 text-destructive"
|
||||
:title="isSsh ? '删除(远端,不可恢复)' : '删除(移入回收站)'"
|
||||
:disabled="selected.length === 0"
|
||||
@click="removeSelected"
|
||||
>
|
||||
<Trash2 class="size-3.5" />
|
||||
</Button>
|
||||
<div class="flex-1" />
|
||||
<Input v-model="filter" placeholder="筛选…" class="h-7 w-28 text-xs" />
|
||||
</div>
|
||||
|
||||
<!-- 新建目录输入 -->
|
||||
<div v-if="showNewDir" class="shrink-0 px-2 py-1.5 flex items-center gap-1.5 border-b border-border">
|
||||
<Input
|
||||
v-model="newDirName"
|
||||
placeholder="新目录名"
|
||||
class="h-7 flex-1 text-xs"
|
||||
@keydown.enter="createFolder"
|
||||
@keydown.esc="showNewDir = false"
|
||||
/>
|
||||
<Button size="sm" class="h-7 text-xs" @click="createFolder">创建</Button>
|
||||
</div>
|
||||
|
||||
<!-- 路径行:可编辑地址栏(回车跳转)。远端不再有面包屑,
|
||||
两栏共用同一个心智模型「这里是地址」,见 FileManager 的取舍说明。 -->
|
||||
<div class="shrink-0 px-2 py-1 flex items-center gap-1 border-b border-border">
|
||||
<Input
|
||||
v-model="pathInput"
|
||||
class="h-7 flex-1 text-xs font-mono"
|
||||
title="输入路径后回车跳转(ESC 还原)"
|
||||
@keydown.enter="jump"
|
||||
@keydown.esc="pathInput = cwd"
|
||||
/>
|
||||
<Button
|
||||
v-if="!isSsh"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="h-7 w-7 p-0 shrink-0"
|
||||
title="跳到主目录"
|
||||
@click="load('')"
|
||||
>
|
||||
<House class="size-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
v-if="!isSsh || allowLocal"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="h-7 w-7 p-0 shrink-0"
|
||||
title="用系统对话框选择本地目录"
|
||||
@click="pickDir"
|
||||
>
|
||||
<FolderOpen class="size-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- ===== 列表 =====
|
||||
表头固定在滚动区**外面**:它不随内容滚动(免去 sticky 在 reka-ui viewport
|
||||
里的定位不确定性),也不会与行一起横向抖动。
|
||||
|
||||
列宽是**写死的 flex 行**而不是 <table>:表格的 auto 布局按内容协商列宽,
|
||||
文件名一长,名称列反而被压成 0 宽、大小/时间列被挤到换行(改版前那一版
|
||||
的真实表现)。定宽列 + `min-w-0 truncate` 的名称列没有协商空间,
|
||||
长名字只会截断,其余列永不变形。 -->
|
||||
<div
|
||||
v-if="!loading && !error && filtered.length > 0"
|
||||
class="shrink-0 h-7 px-2 flex items-center gap-2 border-b border-border
|
||||
text-[11px] text-muted-foreground select-none"
|
||||
>
|
||||
<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 v-if="isSsh" class="w-11 shrink-0 text-right">权限</span>
|
||||
</div>
|
||||
|
||||
<ScrollArea class="flex-1 min-h-0">
|
||||
<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>
|
||||
</div>
|
||||
<div v-else-if="error" class="p-4">
|
||||
<p class="text-xs text-destructive break-all">{{ error }}</p>
|
||||
</div>
|
||||
<div v-else-if="filtered.length === 0" class="p-4 text-center">
|
||||
<p class="text-xs text-muted-foreground/70">
|
||||
{{ entries.length === 0 ? '空目录' : '无匹配项' }}
|
||||
</p>
|
||||
</div>
|
||||
<template v-else>
|
||||
<div
|
||||
v-for="e in filtered"
|
||||
:key="e.path"
|
||||
class="group h-8 px-2 flex items-center gap-2 text-xs cursor-default select-none
|
||||
border-b border-border/40"
|
||||
:class="isSelected(e) ? 'bg-row-selected' : 'hover:bg-row-hover'"
|
||||
@click="clickEntry(e, $event)"
|
||||
@dblclick="enter(e)"
|
||||
>
|
||||
<!-- 名称列:唯一可伸缩的一列(min-w-0 + truncate 是截断生效的充要条件) -->
|
||||
<div class="flex-1 min-w-0 flex items-center gap-1.5">
|
||||
<!-- 图标:目录用警示色(唯一需要一眼区分的信息是「能进去 vs 能传」) -->
|
||||
<component
|
||||
:is="e.isLink ? Link2 : e.isDir ? Folder : FileIcon"
|
||||
class="size-3.5 shrink-0"
|
||||
:class="e.isDir ? 'text-warning' : 'text-muted-foreground'"
|
||||
/>
|
||||
<template v-if="renaming && selected[0]?.path === e.path">
|
||||
<input
|
||||
v-model="renameValue"
|
||||
class="flex-1 min-w-0 h-6 px-1 text-xs rounded border border-primary/60 bg-transparent outline-none"
|
||||
@click.stop
|
||||
@keydown.enter="submitRename"
|
||||
@keydown.esc="renaming = false"
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="truncate" :title="e.linkTarget ? `${e.path} → ${e.linkTarget}` : e.path">
|
||||
{{ e.name }}
|
||||
</span>
|
||||
<span
|
||||
v-if="e.linkTarget"
|
||||
class="text-muted-foreground/60 truncate shrink-0 max-w-[40%]"
|
||||
>
|
||||
→ {{ e.linkTarget }}
|
||||
</span>
|
||||
<!-- 行内操作只对本地行给出:远端路径在本机上没有「打开」的语义 -->
|
||||
<template v-if="!isSsh">
|
||||
<button
|
||||
class="opacity-0 group-hover:opacity-100 shrink-0 text-muted-foreground hover:text-foreground"
|
||||
title="用默认程序打开"
|
||||
@click.stop="openLocalPath(e.path)"
|
||||
>
|
||||
<ExternalLink class="size-3.5" />
|
||||
</button>
|
||||
<button
|
||||
class="opacity-0 group-hover:opacity-100 shrink-0 text-muted-foreground hover:text-foreground"
|
||||
title="在资源管理器中显示"
|
||||
@click.stop="revealLocalPath(e.path)"
|
||||
>
|
||||
<FolderOpen class="size-3.5" />
|
||||
</button>
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
<!-- 其余列定宽 + 不换行:宽度不足时只会挤名称列,列本身永不变形 -->
|
||||
<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>
|
||||
<span
|
||||
v-if="isSsh"
|
||||
class="w-11 shrink-0 text-right text-muted-foreground font-mono whitespace-nowrap"
|
||||
>
|
||||
{{ e.permissions || '—' }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</ScrollArea>
|
||||
|
||||
<!-- ===== 底部:传送方向按钮(文案由父组件按两侧连接算出) ===== -->
|
||||
<div class="shrink-0 p-2 border-t border-border flex items-center gap-2">
|
||||
<span class="text-[11px] text-muted-foreground whitespace-nowrap truncate hidden sm:block">
|
||||
{{ selected.length > 0 ? `已选 ${selected.length} 项` : `共 ${filtered.length} 项` }}
|
||||
</span>
|
||||
<Button
|
||||
size="sm"
|
||||
class="flex-1 h-8 text-xs gap-1.5"
|
||||
:disabled="transferBlocked !== '' || filesSelected.length === 0"
|
||||
:title="transferHint"
|
||||
@click="emit('transfer')"
|
||||
>
|
||||
<component :is="side === 'left' ? ArrowRight : ArrowLeft" class="size-3.5" />
|
||||
{{ transferLabel }}{{ filesSelected.length > 1 ? ` (${filesSelected.length})` : '' }}
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -347,7 +347,7 @@ const isFiltered = computed(() => !!keyword.value || !!hostFilter.value || favor
|
||||
v-for="item in items"
|
||||
:key="item.id"
|
||||
class="group flex items-start gap-1.5 px-2.5 py-1.5 cursor-pointer transition-colors"
|
||||
:class="selectedId === item.id ? 'bg-primary-soft' : 'hover:bg-hover'"
|
||||
:class="selectedId === item.id ? 'bg-row-selected' : 'hover:bg-row-hover'"
|
||||
@click="selectedId = item.id"
|
||||
@dblclick="useCommand(item, false)"
|
||||
>
|
||||
|
||||
@@ -414,7 +414,7 @@ function moveHop(i: number, dir: -1 | 1) {
|
||||
<div
|
||||
v-for="v in store.hosts"
|
||||
:key="v.config.id"
|
||||
class="group flex items-center gap-3 rounded-md border border-border p-3 transition-colors hover:bg-hover"
|
||||
class="group flex items-center gap-3 rounded-md border border-border p-3 transition-colors hover:bg-row-hover"
|
||||
>
|
||||
<button
|
||||
class="shrink-0 size-7 rounded flex items-center justify-center transition-colors"
|
||||
|
||||
@@ -445,7 +445,7 @@ function formatDate(rfc3339: string): string {
|
||||
<div
|
||||
v-for="k in store.keys"
|
||||
:key="k.meta.id"
|
||||
class="group rounded-md border border-border p-3 transition-colors hover:bg-hover"
|
||||
class="group rounded-md border border-border p-3 transition-colors hover:bg-row-hover"
|
||||
>
|
||||
<div class="flex items-start gap-3">
|
||||
<div class="shrink-0 mt-0.5">
|
||||
|
||||
@@ -1,817 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* SFTP 双栏文件管理面板。
|
||||
*
|
||||
* # 为什么是双栏而不是单栏 + 上传/下载按钮
|
||||
*
|
||||
* 传输任务的本质是「把 A 处的这个东西放到 B 处」。单栏形态下用户必须:
|
||||
* 先在远端浏览到目标目录 → 记住路径 → 打开本地文件对话框 → 逐级点到源文件。
|
||||
* 双栏把这个心智模型直接画出来:左边本地、右边远端,拖过去就行。
|
||||
*
|
||||
* # 左右栏的分工是有意不对称的
|
||||
*
|
||||
* 远端栏是**完整实现**(浏览、新建、删除、重命名、符号链接解析、跟随终端 cwd);
|
||||
* 本地栏只做「定位与选取」——它有真实的系统文件管理器在旁边,
|
||||
* 在 WebView 里重造一个更差的资源管理器(缩略图、右键菜单、拖放剪贴板互操作)
|
||||
* 是纯粹的浪费。因此本地栏刻意只给:路径输入 + 快捷位置 + 系统对话框选择。
|
||||
*
|
||||
* # 一次只服务一个会话
|
||||
*
|
||||
* 面板绑定 `sessionId`,不自己持有 SFTP 通道句柄——通道由 store 按会话管理
|
||||
* (见 `SftpRegistry`)。会话断开时面板自动收起,不留一个指向死通道的空壳。
|
||||
*/
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
||||
import { open as openDialog, save as saveDialog } from '@tauri-apps/plugin-dialog'
|
||||
import {
|
||||
ArrowDownToLine,
|
||||
ArrowUpFromLine,
|
||||
ChevronRight,
|
||||
CornerUpLeft,
|
||||
ExternalLink,
|
||||
File as FileIcon,
|
||||
Folder,
|
||||
FolderOpen,
|
||||
FolderPlus,
|
||||
HardDrive,
|
||||
Link2,
|
||||
Loader2,
|
||||
RefreshCw,
|
||||
Server,
|
||||
Trash2,
|
||||
X
|
||||
} from '@lucide/vue'
|
||||
import { toast } from 'vue-sonner'
|
||||
import { useTerminalStore } from '@/stores/terminalStore'
|
||||
import { createLogger } from '@/lib/logger'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import type { RemoteEntry } from '@/types/terminal'
|
||||
|
||||
const props = defineProps<{
|
||||
sessionId: string
|
||||
/** 会话显示名(面板标题用,避免面板自己再查一次 store) */
|
||||
sessionLabel: string
|
||||
/** 终端当前工作目录,用于「跟随终端目录」 */
|
||||
terminalCwd: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'close'): void
|
||||
}>()
|
||||
|
||||
const logger = createLogger('terminal')
|
||||
|
||||
const store = useTerminalStore()
|
||||
|
||||
// ===== 远端栏状态 =====
|
||||
|
||||
const remoteCwd = ref('')
|
||||
const remoteEntries = ref<RemoteEntry[]>([])
|
||||
const remoteLoading = ref(false)
|
||||
const remoteError = ref('')
|
||||
|
||||
/** 选中项(单选用它;多选留给 P2 的批量操作) */
|
||||
const selectedRemote = ref<RemoteEntry | null>(null)
|
||||
|
||||
const remoteFilter = ref('')
|
||||
|
||||
const filteredRemote = computed(() => {
|
||||
const kw = remoteFilter.value.trim().toLowerCase()
|
||||
if (!kw) return remoteEntries.value
|
||||
return remoteEntries.value.filter(e => e.name.toLowerCase().includes(kw))
|
||||
})
|
||||
|
||||
/** 面包屑:把 `/a/b/c` 拆成可点击的逐级路径 */
|
||||
const crumbs = computed(() => {
|
||||
const p = remoteCwd.value
|
||||
if (!p) return []
|
||||
const parts = p.split('/').filter(Boolean)
|
||||
const out: Array<{ name: string; path: string }> = []
|
||||
let acc = ''
|
||||
for (const part of parts) {
|
||||
acc += `/${part}`
|
||||
out.push({ name: part, path: acc })
|
||||
}
|
||||
return out
|
||||
})
|
||||
|
||||
async function loadRemote(path: string) {
|
||||
if (!path) return
|
||||
remoteLoading.value = true
|
||||
remoteError.value = ''
|
||||
try {
|
||||
const dir = await store.sftpList(props.sessionId, path)
|
||||
// 用服务端返回的 cwd 而不是请求的 path:符号链接目录下两者不同,
|
||||
// 显示真实位置才能解释「为什么我看的内容和路径不像」
|
||||
remoteCwd.value = dir.cwd || path
|
||||
remoteEntries.value = dir.entries
|
||||
selectedRemote.value = null
|
||||
} catch (e) {
|
||||
remoteError.value = String(e)
|
||||
logger.error(`列举远端目录 ${path} 失败:${String(e)}`)
|
||||
} finally {
|
||||
remoteLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function goUp() {
|
||||
try {
|
||||
const parent = await store.sftpParent(remoteCwd.value)
|
||||
if (parent === remoteCwd.value) return
|
||||
await loadRemote(parent)
|
||||
} catch (e) {
|
||||
toast.error(`无法返回上一级:${String(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
async function enterRemote(entry: RemoteEntry) {
|
||||
if (entry.kind === 'dir') {
|
||||
await loadRemote(entry.path)
|
||||
return
|
||||
}
|
||||
if (entry.kind === 'symlink') {
|
||||
// 符号链接指向目录时应该「进去」而不是报错。判断方式:读目标再试一次列举。
|
||||
try {
|
||||
const dir = await store.sftpList(props.sessionId, entry.path)
|
||||
remoteCwd.value = dir.cwd || entry.path
|
||||
remoteEntries.value = dir.entries
|
||||
selectedRemote.value = null
|
||||
return
|
||||
} catch {
|
||||
// 不是目录(或链接已失效)——退回「选中」,让用户自己决定下一步
|
||||
selectedRemote.value = entry
|
||||
toast.info(`符号链接指向 ${entry.linkTarget}(不是目录或不可访问)`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 跟随终端当前目录 */
|
||||
async function followTerminalCwd() {
|
||||
if (!props.terminalCwd) {
|
||||
toast.info('终端尚未上报工作目录(该 shell 可能不支持 OSC 7)')
|
||||
return
|
||||
}
|
||||
await loadRemote(props.terminalCwd)
|
||||
}
|
||||
|
||||
// ===== 远端编辑操作 =====
|
||||
|
||||
const newDirName = ref('')
|
||||
const showNewDir = ref(false)
|
||||
|
||||
async function createFolder() {
|
||||
const name = newDirName.value.trim()
|
||||
if (!name || name.includes('/')) {
|
||||
toast.error('目录名不能为空,且不能包含 /')
|
||||
return
|
||||
}
|
||||
try {
|
||||
// 用 store.sftpParent 拼接而不是前端拼 `/`:远端是 POSIX 语义,
|
||||
// 根目录下的拼接结果与 Windows 侧的习惯不同(避免出现 `//new`)
|
||||
await store.sftpMkdir(props.sessionId, joinRemote(remoteCwd.value, name))
|
||||
showNewDir.value = false
|
||||
newDirName.value = ''
|
||||
await loadRemote(remoteCwd.value)
|
||||
toast.success(`已创建 ${name}`)
|
||||
} catch (e) {
|
||||
toast.error(`创建目录失败:${String(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 远端路径拼接。
|
||||
*
|
||||
* 与 Rust 侧 `join_remote` 同一套规则。前端这边**只在展示与提交时**用,
|
||||
* 真实解析仍以服务端 `cwd` 为准——若两边规则有出入,服务端是权威。
|
||||
*/
|
||||
function joinRemote(base: string, name: string): string {
|
||||
if (!base) return `/${name}`
|
||||
if (base === '/') return `/${name}`
|
||||
return `${base.replace(/\/+$/, '')}/${name}`
|
||||
}
|
||||
|
||||
async function removeRemote() {
|
||||
const e = selectedRemote.value
|
||||
if (!e) return
|
||||
const isDir = e.kind === 'dir'
|
||||
const hint = isDir ? '及其全部内容' : ''
|
||||
if (!window.confirm(`确定删除「${e.name}」${hint}?此操作不可恢复。`)) return
|
||||
try {
|
||||
const r = await store.sftpDelete(props.sessionId, e.path, isDir)
|
||||
toast.success(r.message)
|
||||
await loadRemote(remoteCwd.value)
|
||||
} catch (err) {
|
||||
toast.error(`删除失败:${String(err)}`)
|
||||
}
|
||||
}
|
||||
|
||||
const renaming = ref(false)
|
||||
const renameValue = ref('')
|
||||
|
||||
function startRename() {
|
||||
const e = selectedRemote.value
|
||||
if (!e) return
|
||||
renameValue.value = e.name
|
||||
renaming.value = true
|
||||
}
|
||||
|
||||
async function submitRename() {
|
||||
const e = selectedRemote.value
|
||||
if (!e) return
|
||||
const name = renameValue.value.trim()
|
||||
if (!name || name === e.name) {
|
||||
renaming.value = false
|
||||
return
|
||||
}
|
||||
if (name.includes('/')) {
|
||||
toast.error('名称不能包含 /')
|
||||
return
|
||||
}
|
||||
try {
|
||||
await store.sftpRename(props.sessionId, e.path, joinRemote(remoteCwd.value, name))
|
||||
renaming.value = false
|
||||
await loadRemote(remoteCwd.value)
|
||||
} catch (err) {
|
||||
toast.error(`重命名失败:${String(err)}`)
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 本地栏状态 =====
|
||||
|
||||
/**
|
||||
* 本地目录**不由前端列举**。
|
||||
*
|
||||
* 理由:WebView 里没有可靠的方式读本地目录(FS Access API 在 Tauri 的
|
||||
* http://tauri.localhost 源下支持情况不稳定,而为了列目录去引一个
|
||||
* fs 插件权限太重)。本机已经有资源管理器,因此本地栏的定位入口是
|
||||
* **系统文件对话框** ——用户本来就更习惯用它。
|
||||
*/
|
||||
const localDir = ref('')
|
||||
const localFiles = ref<string[]>([])
|
||||
|
||||
async function pickLocalDir() {
|
||||
try {
|
||||
const picked = await openDialog({ directory: true, multiple: false })
|
||||
if (typeof picked !== 'string') return
|
||||
localDir.value = picked
|
||||
localFiles.value = []
|
||||
} catch (e) {
|
||||
toast.error(`选择目录失败:${String(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
async function pickLocalFiles() {
|
||||
try {
|
||||
const picked = await openDialog({ multiple: true, directory: false })
|
||||
if (!picked) return
|
||||
const list = Array.isArray(picked) ? picked : [picked]
|
||||
localFiles.value = list
|
||||
// 把目录同步成首个文件的所在目录,让「上传」的目标路径有参照
|
||||
if (list.length > 0) {
|
||||
const first = list[0].replace(/\\/g, '/')
|
||||
localDir.value = first.slice(0, first.lastIndexOf('/')) || localDir.value
|
||||
}
|
||||
} catch (e) {
|
||||
toast.error(`选择文件失败:${String(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
function clearLocalFiles() {
|
||||
localFiles.value = []
|
||||
}
|
||||
|
||||
/** 本地文件名的展示形态(去掉目录部分) */
|
||||
function baseName(path: string): string {
|
||||
const p = path.replace(/\\/g, '/')
|
||||
return p.slice(p.lastIndexOf('/') + 1)
|
||||
}
|
||||
|
||||
// ===== 传输 =====
|
||||
|
||||
const uploading = ref(false)
|
||||
const downloading = ref(false)
|
||||
|
||||
/** 进行中的传输(按 id 去重后展示进度条) */
|
||||
const activeTransfers = computed(() =>
|
||||
store.transfers.filter(t => t.sessionId === props.sessionId)
|
||||
)
|
||||
|
||||
async function uploadSelected() {
|
||||
if (localFiles.value.length === 0) {
|
||||
toast.info('请先选择要上传的本地文件')
|
||||
return
|
||||
}
|
||||
uploading.value = true
|
||||
let ok = 0
|
||||
const failed: string[] = []
|
||||
// 串行上传:并发多个大文件会把受控并发的闸门(4)占满,
|
||||
// 而文件名顺序错乱的进度条比「一个一个来」更难读
|
||||
for (const file of localFiles.value) {
|
||||
try {
|
||||
const r = await store.sftpUpload(
|
||||
props.sessionId,
|
||||
file,
|
||||
joinRemote(remoteCwd.value, baseName(file))
|
||||
)
|
||||
if (r.ok) ok += 1
|
||||
else failed.push(`${baseName(file)}:${r.message}`)
|
||||
} catch (e) {
|
||||
failed.push(`${baseName(file)}:${String(e)}`)
|
||||
}
|
||||
}
|
||||
uploading.value = false
|
||||
await loadRemote(remoteCwd.value)
|
||||
|
||||
if (failed.length === 0) {
|
||||
toast.success(`已上传 ${ok} 个文件`)
|
||||
} else if (ok > 0) {
|
||||
toast.warning(`上传完成 ${ok} 个,失败 ${failed.length} 个:${failed.join(';')}`)
|
||||
} else {
|
||||
toast.error(`上传失败:${failed.join(';')}`)
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadSelected() {
|
||||
const e = selectedRemote.value
|
||||
if (!e) {
|
||||
toast.info('请先选择要下载的远端文件')
|
||||
return
|
||||
}
|
||||
if (e.kind === 'dir') {
|
||||
toast.info('目录下载属 P2;请进入目录后逐个下载文件')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const suggested = localDir.value
|
||||
? `${localDir.value.replace(/\\/g, '/').replace(/\/+$/, '')}/${e.name}`
|
||||
: e.name
|
||||
const target = await saveDialog({ defaultPath: suggested })
|
||||
if (!target) return
|
||||
downloading.value = true
|
||||
const r = await store.sftpDownload(props.sessionId, e.path, target)
|
||||
toast.success(r.message)
|
||||
} catch (err) {
|
||||
toast.error(`下载失败:${String(err)}`)
|
||||
} finally {
|
||||
downloading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 下载到本地目录(不弹保存框,直接用当前本地目录 + 原文件名) */
|
||||
async function downloadToLocalDir() {
|
||||
const e = selectedRemote.value
|
||||
if (!e) {
|
||||
toast.info('请先选择要下载的远端文件')
|
||||
return
|
||||
}
|
||||
if (!localDir.value) {
|
||||
toast.info('请先选择本地目录')
|
||||
return
|
||||
}
|
||||
if (e.kind === 'dir') {
|
||||
toast.info('目录下载属 P2')
|
||||
return
|
||||
}
|
||||
try {
|
||||
downloading.value = true
|
||||
const sep = localDir.value.includes('\\') ? '\\' : '/'
|
||||
const target = `${localDir.value.replace(/[\\/]+$/, '')}${sep}${e.name}`
|
||||
const r = await store.sftpDownload(props.sessionId, e.path, target)
|
||||
toast.success(r.message)
|
||||
} catch (err) {
|
||||
toast.error(`下载失败:${String(err)}`)
|
||||
} finally {
|
||||
downloading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function openLocal(path: string) {
|
||||
void store.openLocalPath(path).catch(e => toast.error(`打开失败:${String(e)}`))
|
||||
}
|
||||
|
||||
function revealLocal(path: string) {
|
||||
void store.revealLocalPath(path).catch(e => toast.error(`定位失败:${String(e)}`))
|
||||
}
|
||||
|
||||
// ===== 展示辅助 =====
|
||||
|
||||
/** 字节数的人类可读形态 */
|
||||
function humanSize(n: number): string {
|
||||
if (n < 1024) return `${n} B`
|
||||
const units = ['KB', 'MB', 'GB', 'TB']
|
||||
let v = n / 1024
|
||||
let i = 0
|
||||
while (v >= 1024 && i < units.length - 1) {
|
||||
v /= 1024
|
||||
i += 1
|
||||
}
|
||||
return `${v < 10 ? v.toFixed(1) : Math.round(v)} ${units[i]}`
|
||||
}
|
||||
|
||||
function fmtTime(ms?: number | null): string {
|
||||
if (!ms) return ''
|
||||
const d = new Date(ms)
|
||||
const pad = (x: number) => String(x).padStart(2, '0')
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||||
}
|
||||
|
||||
function entryIcon(e: RemoteEntry) {
|
||||
if (e.kind === 'dir') return Folder
|
||||
if (e.kind === 'symlink') return Link2
|
||||
return FileIcon
|
||||
}
|
||||
|
||||
// ===== 生命周期 =====
|
||||
|
||||
let disposed = false
|
||||
|
||||
watch(
|
||||
() => props.sessionId,
|
||||
async id => {
|
||||
if (!id || disposed) return
|
||||
try {
|
||||
await store.sftpOpen(id)
|
||||
// 初始目录:优先会话的 remoteCwd / 终端 cwd,都由调用方通过 props 给到
|
||||
await loadRemote(props.terminalCwd || '.')
|
||||
} catch (e) {
|
||||
remoteError.value = String(e)
|
||||
toast.error(`打开文件管理器失败:${String(e)}`)
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
// 终端 cd 之后,若用户开着「跟随」就自动同步
|
||||
const following = ref(false)
|
||||
watch(
|
||||
() => props.terminalCwd,
|
||||
cwd => {
|
||||
if (following.value && cwd) void loadRemote(cwd)
|
||||
}
|
||||
)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true
|
||||
// 显式关通道:让服务端立刻回收句柄,而不是等 TCP 超时。
|
||||
// 不 await —— 卸载路径上等异步会让面板关闭出现可见延迟。
|
||||
void store.sftpClose(props.sessionId).catch(() => {
|
||||
/* 会话可能已断开,忽略 */
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col h-full min-h-0 bg-background">
|
||||
<!--
|
||||
===== 头部 =====
|
||||
高度与终端页上下两条栏(控制栏 / 状态栏,均 h-9)保持一致:本面板落在
|
||||
终端卡片内部,头部与它们同属一块屏幕的横向分隔线,等高才不显得突兀
|
||||
(2026-09-21 控制栏从 h-11 收进卡片并降到 h-9 后同步调整;
|
||||
更早的约定是「与卡片外的工具条行 h-11 连成一条线」,那层已不存在)。
|
||||
-->
|
||||
<div class="shrink-0 flex items-center gap-2 px-3 h-9 border-b border-border">
|
||||
<HardDrive class="size-4 text-muted-foreground shrink-0" />
|
||||
<span class="text-xs font-medium truncate" :title="sessionLabel">{{ sessionLabel }}</span>
|
||||
<span class="text-[10px] text-muted-foreground font-mono truncate">
|
||||
{{ remoteCwd || '—' }}
|
||||
</span>
|
||||
<div class="flex-1" />
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="h-7 px-1.5 text-[11px]"
|
||||
:disabled="!terminalCwd"
|
||||
title="定位到终端当前目录"
|
||||
@click="followTerminalCwd"
|
||||
>
|
||||
跟随终端
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" class="h-7 w-7 p-0" title="关闭面板" @click="emit('close')">
|
||||
<X class="size-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- ===== 主体:左右双栏 ===== -->
|
||||
<div class="flex-1 min-h-0 flex">
|
||||
<!-- ---------- 本地栏 ---------- -->
|
||||
<section class="w-[38%] min-w-[220px] flex flex-col border-r border-border">
|
||||
<div class="shrink-0 h-7 px-2 flex items-center gap-1.5 border-b border-border bg-muted/40">
|
||||
<HardDrive class="size-3 text-muted-foreground" />
|
||||
<span class="text-[11px] font-medium">本地</span>
|
||||
</div>
|
||||
|
||||
<div class="shrink-0 p-2 space-y-1.5 border-b border-border">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="w-full h-7 text-[11px] justify-start gap-1.5"
|
||||
@click="pickLocalDir"
|
||||
>
|
||||
<FolderOpen class="size-3" />选择目录
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="w-full h-7 text-[11px] justify-start gap-1.5"
|
||||
@click="pickLocalFiles"
|
||||
>
|
||||
<FileIcon class="size-3" />选择文件…
|
||||
</Button>
|
||||
<div v-if="localDir" class="text-[10px] text-muted-foreground truncate font-mono px-0.5" :title="localDir">
|
||||
{{ localDir }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 min-h-0 overflow-auto">
|
||||
<div v-if="localFiles.length === 0" class="p-3 text-center">
|
||||
<p class="text-[11px] text-muted-foreground/70 leading-relaxed">
|
||||
选择本地文件后点「上传」。<br />
|
||||
本地目录浏览请用系统资源管理器 —— 在 WebView 里重造一个更差的资源管理器没有意义。
|
||||
</p>
|
||||
</div>
|
||||
<ul v-else class="py-1">
|
||||
<li
|
||||
v-for="f in localFiles"
|
||||
:key="f"
|
||||
class="group px-2 py-1 flex items-center gap-1.5 text-[11px] hover:bg-accent cursor-default"
|
||||
:title="f"
|
||||
>
|
||||
<FileIcon class="size-3 shrink-0 text-muted-foreground" />
|
||||
<span class="truncate flex-1">{{ baseName(f) }}</span>
|
||||
<button
|
||||
class="opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-foreground"
|
||||
title="用默认程序打开"
|
||||
@click="openLocal(f)"
|
||||
>
|
||||
<ExternalLink class="size-3" />
|
||||
</button>
|
||||
<button
|
||||
class="opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-foreground"
|
||||
title="在资源管理器中显示"
|
||||
@click="revealLocal(f)"
|
||||
>
|
||||
<FolderOpen class="size-3" />
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="shrink-0 p-2 border-t border-border flex items-center gap-1.5">
|
||||
<Button
|
||||
size="sm"
|
||||
class="flex-1 h-7 text-[11px] gap-1.5"
|
||||
:disabled="uploading || localFiles.length === 0"
|
||||
@click="uploadSelected"
|
||||
>
|
||||
<Loader2 v-if="uploading" class="size-3 animate-spin" />
|
||||
<ArrowUpFromLine v-else class="size-3" />
|
||||
上传{{ localFiles.length > 1 ? ` (${localFiles.length})` : '' }}
|
||||
</Button>
|
||||
<Button
|
||||
v-if="localFiles.length > 0"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="h-7 px-1.5 text-[11px]"
|
||||
@click="clearLocalFiles"
|
||||
>
|
||||
清空
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- ---------- 远端栏 ---------- -->
|
||||
<section class="flex-1 min-w-0 flex flex-col">
|
||||
<div class="shrink-0 h-7 px-2 flex items-center gap-1.5 border-b border-border bg-muted/40">
|
||||
<Server class="size-3 text-muted-foreground" />
|
||||
<span class="text-[11px] font-medium">远端</span>
|
||||
<div class="flex-1" />
|
||||
<label class="flex items-center gap-1 text-[10px] text-muted-foreground cursor-pointer select-none">
|
||||
<input v-model="following" type="checkbox" class="size-3 accent-primary" />
|
||||
跟随 cd
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- 工具条 -->
|
||||
<div class="shrink-0 px-2 py-1.5 flex items-center gap-1 border-b border-border">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="h-6 w-6 p-0"
|
||||
title="上一级"
|
||||
:disabled="remoteCwd === '/' || !remoteCwd"
|
||||
@click="goUp"
|
||||
>
|
||||
<CornerUpLeft class="size-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="h-6 w-6 p-0"
|
||||
title="刷新"
|
||||
@click="loadRemote(remoteCwd)"
|
||||
>
|
||||
<RefreshCw class="size-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="h-6 w-6 p-0"
|
||||
title="新建目录"
|
||||
@click="showNewDir = !showNewDir"
|
||||
>
|
||||
<FolderPlus class="size-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="h-6 w-6 p-0"
|
||||
title="重命名"
|
||||
:disabled="!selectedRemote"
|
||||
@click="startRename"
|
||||
>
|
||||
<FileIcon class="size-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="h-6 w-6 p-0 text-destructive"
|
||||
title="删除"
|
||||
:disabled="!selectedRemote"
|
||||
@click="removeRemote"
|
||||
>
|
||||
<Trash2 class="size-3.5" />
|
||||
</Button>
|
||||
<div class="flex-1" />
|
||||
<Input
|
||||
v-model="remoteFilter"
|
||||
placeholder="筛选…"
|
||||
class="h-6 w-32 text-[11px]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 新建目录输入 -->
|
||||
<div v-if="showNewDir" class="shrink-0 px-2 py-1.5 flex items-center gap-1.5 border-b border-border">
|
||||
<Input
|
||||
v-model="newDirName"
|
||||
placeholder="新目录名"
|
||||
class="h-6 flex-1 text-[11px]"
|
||||
@keydown.enter="createFolder"
|
||||
@keydown.esc="showNewDir = false"
|
||||
/>
|
||||
<Button size="sm" class="h-6 text-[11px]" @click="createFolder">创建</Button>
|
||||
</div>
|
||||
|
||||
<!-- 面包屑 -->
|
||||
<div class="shrink-0 px-2 py-1 flex items-center gap-0.5 text-[11px] border-b border-border overflow-x-auto whitespace-nowrap">
|
||||
<button class="hover:text-primary shrink-0" @click="loadRemote('/')">/</button>
|
||||
<template v-for="c in crumbs" :key="c.path">
|
||||
<ChevronRight class="size-3 shrink-0 text-muted-foreground/50" />
|
||||
<button class="hover:text-primary shrink-0" @click="loadRemote(c.path)">{{ c.name }}</button>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- 列表 -->
|
||||
<div class="flex-1 min-h-0 overflow-auto">
|
||||
<div v-if="remoteLoading" class="p-4 flex items-center justify-center gap-2">
|
||||
<Loader2 class="size-3.5 animate-spin text-muted-foreground" />
|
||||
<span class="text-[11px] text-muted-foreground">正在读取…</span>
|
||||
</div>
|
||||
<div v-else-if="remoteError" class="p-4">
|
||||
<p class="text-[11px] text-destructive break-all">{{ remoteError }}</p>
|
||||
</div>
|
||||
<div v-else-if="filteredRemote.length === 0" class="p-4 text-center">
|
||||
<p class="text-[11px] text-muted-foreground/70">
|
||||
{{ remoteEntries.length === 0 ? '空目录' : '无匹配项' }}
|
||||
</p>
|
||||
</div>
|
||||
<table v-else class="w-full text-[11px] border-collapse">
|
||||
<thead class="sticky top-0 bg-background z-10">
|
||||
<tr class="text-muted-foreground text-left">
|
||||
<th class="font-normal px-2 py-1 border-b border-border">名称</th>
|
||||
<th class="font-normal px-2 py-1 border-b border-border w-20 text-right">大小</th>
|
||||
<th class="font-normal px-2 py-1 border-b border-border w-28 hidden md:table-cell">修改时间</th>
|
||||
<th class="font-normal px-2 py-1 border-b border-border w-14 text-right">权限</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="e in filteredRemote"
|
||||
:key="e.path"
|
||||
class="hover:bg-accent cursor-default select-none"
|
||||
:class="selectedRemote?.path === e.path ? 'bg-accent' : ''"
|
||||
@click="selectedRemote = e"
|
||||
@dblclick="enterRemote(e)"
|
||||
>
|
||||
<td class="px-2 py-1">
|
||||
<div class="flex items-center gap-1.5 min-w-0">
|
||||
<component
|
||||
:is="entryIcon(e)"
|
||||
class="size-3 shrink-0"
|
||||
:class="e.kind === 'dir' ? 'text-warning' : 'text-muted-foreground'"
|
||||
/>
|
||||
<template v-if="renaming && selectedRemote?.path === e.path">
|
||||
<input
|
||||
v-model="renameValue"
|
||||
class="flex-1 h-5 px-1 text-[11px] rounded border border-primary/60 bg-transparent outline-none"
|
||||
@click.stop
|
||||
@keydown.enter="submitRename"
|
||||
@keydown.esc="renaming = false"
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="truncate" :title="e.kind === 'symlink' ? `${e.path} → ${e.linkTarget}` : e.path">
|
||||
{{ e.name }}
|
||||
</span>
|
||||
<span
|
||||
v-if="e.kind === 'symlink' && e.linkTarget"
|
||||
class="text-muted-foreground/60 truncate shrink-0 max-w-[40%]"
|
||||
>
|
||||
→ {{ e.linkTarget }}
|
||||
</span>
|
||||
</template>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-2 py-1 text-right text-muted-foreground tabular-nums">
|
||||
{{ e.kind === 'dir' ? '—' : humanSize(e.size) }}
|
||||
</td>
|
||||
<td class="px-2 py-1 text-muted-foreground hidden md:table-cell tabular-nums">
|
||||
{{ fmtTime(e.modifiedAt) }}
|
||||
</td>
|
||||
<td class="px-2 py-1 text-right text-muted-foreground font-mono">
|
||||
{{ e.permissions || '—' }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 远端操作条 -->
|
||||
<div class="shrink-0 p-2 border-t border-border flex items-center gap-1.5">
|
||||
<span class="text-[10px] text-muted-foreground truncate flex-1" :title="selectedRemote?.path">
|
||||
{{ selectedRemote ? selectedRemote.path : `共 ${filteredRemote.length} 项` }}
|
||||
</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="h-7 text-[11px] gap-1.5"
|
||||
:disabled="downloading || !selectedRemote || selectedRemote.kind === 'dir'"
|
||||
@click="downloadSelected"
|
||||
>
|
||||
<Loader2 v-if="downloading" class="size-3 animate-spin" />
|
||||
<ArrowDownToLine v-else class="size-3" />
|
||||
另存为…
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
class="h-7 text-[11px] gap-1.5"
|
||||
:disabled="downloading || !selectedRemote || selectedRemote.kind === 'dir' || !localDir"
|
||||
@click="downloadToLocalDir"
|
||||
>
|
||||
<ArrowDownToLine class="size-3" />
|
||||
下载到本地目录
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- ===== 传输进度 ===== -->
|
||||
<div v-if="activeTransfers.length > 0" class="shrink-0 border-t border-border max-h-28 overflow-auto">
|
||||
<div
|
||||
v-for="t in activeTransfers"
|
||||
:key="t.id"
|
||||
class="px-2.5 py-1.5 flex items-center gap-2 text-[11px] border-b border-border/50 last:border-b-0"
|
||||
>
|
||||
<component
|
||||
:is="t.direction === 'upload' ? ArrowUpFromLine : ArrowDownToLine"
|
||||
class="size-3 shrink-0"
|
||||
:class="t.state === 'failed' ? 'text-destructive' : 'text-muted-foreground'"
|
||||
/>
|
||||
<span class="truncate flex-1" :title="`${t.source} → ${t.target}`">
|
||||
{{ baseName(t.source) }}
|
||||
<span class="text-muted-foreground/60">→ {{ baseName(t.target) }}</span>
|
||||
</span>
|
||||
<div v-if="t.state === 'running'" class="w-24 h-1 rounded-full bg-muted overflow-hidden shrink-0">
|
||||
<div
|
||||
class="h-full bg-primary transition-[width] duration-200"
|
||||
:style="{ width: t.total > 0 ? `${Math.min(100, (t.transferred / t.total) * 100)}%` : '0%' }"
|
||||
/>
|
||||
</div>
|
||||
<span class="text-muted-foreground tabular-nums shrink-0 w-24 text-right">
|
||||
<template v-if="t.state === 'running'">
|
||||
{{ t.total > 0 ? `${humanSize(t.transferred)} / ${humanSize(t.total)}` : humanSize(t.transferred) }}
|
||||
</template>
|
||||
<span v-else-if="t.state === 'done'" class="text-success">完成</span>
|
||||
<span v-else-if="t.state === 'failed'" class="text-destructive" :title="t.error ?? ''">失败</span>
|
||||
<span v-else>{{ t.state }}</span>
|
||||
</span>
|
||||
<button
|
||||
class="text-muted-foreground hover:text-foreground shrink-0"
|
||||
title="从列表移除"
|
||||
@click="store.dismissTransfer(t.id)"
|
||||
>
|
||||
<X class="size-3" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -344,7 +344,7 @@ const hint = computed(() =>
|
||||
<button
|
||||
v-for="s in list"
|
||||
:key="s.id"
|
||||
class="w-full text-left px-2.5 py-1.5 hover:bg-accent border-l-2 border-transparent transition-colors"
|
||||
class="w-full text-left px-2.5 py-1.5 hover:bg-row-hover border-l-2 border-transparent transition-colors"
|
||||
@click="select(s)"
|
||||
>
|
||||
<div class="flex items-center gap-1.5">
|
||||
|
||||
@@ -673,7 +673,7 @@ const fontFamilyValue = computed({
|
||||
<div
|
||||
v-for="s in store.shells"
|
||||
:key="s.id"
|
||||
class="group flex items-start gap-3 rounded-md border border-border p-3 transition-colors hover:bg-hover"
|
||||
class="group flex items-start gap-3 rounded-md border border-border p-3 transition-colors hover:bg-row-hover"
|
||||
>
|
||||
<Monitor class="size-4 shrink-0 mt-0.5 text-muted-foreground" />
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*
|
||||
* # 为什么用「更多」菜单而不是全部铺成图标
|
||||
*
|
||||
* 会话级动作有十来个(端口转发、文件面板、会话日志、日志位置、模板、AI 助手…)。
|
||||
* 会话级动作有十来个(端口转发、文件管理器、会话日志、日志位置、模板、AI 助手…)。
|
||||
* 全铺成图标会占掉半行宽度,把左侧的会话标签挤到只剩一两个可见 ——
|
||||
* 而标签是终端页最主要的导航。取舍与主机/密钥页一致:**高频动作外露,
|
||||
* 低频配置性动作入菜单**。
|
||||
@@ -103,8 +103,6 @@ const props = defineProps<{
|
||||
searchHint?: string
|
||||
/** 当前会话是否为 SSH(决定是否显示 SSH 专属动作) */
|
||||
isSsh: boolean
|
||||
/** 文件面板是否展开 */
|
||||
sftpVisible: boolean
|
||||
/** 当前会话是否正在记录日志 */
|
||||
logging: boolean
|
||||
/** 当前生效字号(含视图级临时覆盖,popover 里作为滑块初值) */
|
||||
@@ -112,10 +110,15 @@ const props = defineProps<{
|
||||
/**
|
||||
* 独立窗口模式(TerminalWindow 复用本组件时置真)。
|
||||
*
|
||||
* 隐藏三类只对「主窗口的终端页」成立的动作:
|
||||
* 隐藏两类只对「主窗口的终端页」成立的动作:
|
||||
* - 「在独立窗口中打开」——自己就是那个窗口;
|
||||
* - 文件面板 / 端口转发 / 会话模板 —— 它们开的是终端页里的面板与分屏布局,
|
||||
* 独立窗口没有那套容器。
|
||||
* - 端口转发 / 会话模板 —— 它们开的是终端页里的对话框与分屏布局,
|
||||
* 独立窗口没有那套容器。
|
||||
*
|
||||
* **文件按钮在两种模式下都保留**(2026-09-24):文件管理器已从「终端卡片里的
|
||||
* 面板」改为独立的 tab / 独立窗口,因此独立窗口里的同一个按钮改成「打开文件
|
||||
* 窗口」,语义由宿主实现(见 `open-files` 事件说明)。
|
||||
*
|
||||
* 保留的动作(搜索 / 字体 / 清屏 / 重命名 / AI 助手 / 会话日志)都只依赖 store
|
||||
* 与当前会话,在两种形态下语义一致。
|
||||
*/
|
||||
@@ -134,7 +137,14 @@ const emit = defineEmits<{
|
||||
(e: 'clear'): void
|
||||
(e: 'detach'): void
|
||||
(e: 'rename'): void
|
||||
(e: 'toggle-sftp'): void
|
||||
/**
|
||||
* 打开文件管理器。
|
||||
*
|
||||
* 两种宿主语义不同,由它们各自实现:
|
||||
* - 终端页:切到「文件」tab,并把当前 SSH 会话放进右栏;
|
||||
* - 终端独立窗口:打开(或唤出)文件管理器独立窗口 —— 这个窗口里没有 tab 可切。
|
||||
*/
|
||||
(e: 'open-files'): void
|
||||
/** 打开端口转发对话框(仅 SSH 会话显示菜单项) */
|
||||
(e: 'open-forwards'): void
|
||||
/** 开关当前会话的日志记录 */
|
||||
@@ -315,6 +325,17 @@ function onFontSlide(v: number[] | undefined) {
|
||||
<TooltipContent side="bottom">清屏</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button variant="ghost" size="icon-sm" @click="emit('open-files')">
|
||||
<FolderTree class="size-3.5" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">
|
||||
{{ standalone ? '打开文件管理器窗口' : '文件管理器' }}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip v-if="!standalone">
|
||||
<TooltipTrigger as-child>
|
||||
<Button variant="ghost" size="icon-sm" :disabled="!sessionId" @click="emit('detach')">
|
||||
@@ -367,16 +388,13 @@ function onFontSlide(v: number[] | undefined) {
|
||||
<!--
|
||||
SSH 专属动作:本地会话不给菜单项,而不是给了再报错。
|
||||
「看得见但点不动」比「看不见」更让人困惑。
|
||||
独立窗口里不给(面板与分屏属于终端页),见 standalone 的说明。
|
||||
独立窗口里不给(端口转发属于终端页的分屏容器),见 standalone 的说明。
|
||||
-->
|
||||
<template v-if="isSsh && !standalone">
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem :disabled="!sessionId" @click="emit('open-forwards')">
|
||||
<Network class="size-4" />端口转发(-L / -R)
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem :disabled="!sessionId" @click="emit('toggle-sftp')">
|
||||
<FolderTree class="size-4" />{{ sftpVisible ? '隐藏文件面板' : '显示文件面板' }}
|
||||
</DropdownMenuItem>
|
||||
</template>
|
||||
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* 拆分前 TerminalModule.vue 有 1197 行,同时承担两件性质完全不同的事:
|
||||
* (a) 模块级编排 —— 5 个 tab、tab 记忆、快捷键分发;
|
||||
* (b) 终端页的全部交互 —— 搜索、右键菜单、分屏、SFTP、清屏、重命名、
|
||||
* (b) 终端页的全部交互 —— 搜索、右键菜单、分屏、清屏、重命名、
|
||||
* 模板拉起、AI 助手、会话日志、独立窗口。
|
||||
*
|
||||
* 后者是终端模块里体量最大、改动最频繁的部分,与前者混在一个文件里,
|
||||
@@ -20,13 +20,16 @@
|
||||
* │ ╭───────────────────────────────────────────╮ │
|
||||
* │ │ [会话标签…] │ 历史 片段 搜索 字体 清屏 ⋯ │ │ ← 控制栏(h-9,带下边框)
|
||||
* │ ├───────────────────────────────────────────┤ │
|
||||
* │ │ 画布(xterm) [SFTP 面板] │ │
|
||||
* │ │ 画布(xterm) │ │
|
||||
* │ ├───────────────────────────────────────────┤ │
|
||||
* │ │ 状态栏:会话 · 目标 · 编码 · cwd · 尺寸 │ │ ← 与控制栏同高(h-9)
|
||||
* │ ╰───────────────────────────────────────────╯ │
|
||||
* └───────────────────────────────────────────────┘
|
||||
* ```
|
||||
*
|
||||
* 文件管理器**不在**卡片里(2026-09-24):它是模块级的一页(`FileManager`,
|
||||
* 双栏 + 两栏各自选连接)与一个独立窗口。控制栏的文件按钮只负责跳过去。
|
||||
*
|
||||
* 控制栏最左的两个图标(历史 / 片段)各带一个浮层,见 `TerminalToolbar` 的文件头。
|
||||
*
|
||||
* 上一版把「会话标签 + 操作组」放在卡片**外面**当作页面级工具条。结果是卡片里
|
||||
@@ -63,7 +66,6 @@ import TerminalTabs from './TerminalTabs.vue'
|
||||
import TerminalToolbar from './TerminalToolbar.vue'
|
||||
import TerminalStatusBar from './TerminalStatusBar.vue'
|
||||
import TerminalContextMenu from './TerminalContextMenu.vue'
|
||||
import SftpPanel from './SftpPanel.vue'
|
||||
import ForwardPanel from './ForwardPanel.vue'
|
||||
import TemplatePanel from './TemplatePanel.vue'
|
||||
import AiPanel from './AiPanel.vue'
|
||||
@@ -88,6 +90,8 @@ const props = defineProps<{
|
||||
const emit = defineEmits<{
|
||||
/** 请求切换到模块的「主机」tab(空态与标签栏的「管理主机」入口) */
|
||||
(e: 'go-hosts'): void
|
||||
/** 请求切换到模块的「文件」tab(控制栏的文件按钮,见 `openFiles`) */
|
||||
(e: 'open-files'): void
|
||||
}>()
|
||||
|
||||
const store = useTerminalStore()
|
||||
@@ -142,53 +146,29 @@ watch(
|
||||
}
|
||||
)
|
||||
|
||||
// ===== SFTP 文件面板 =====
|
||||
// ===== 文件管理器(已从终端卡片里的面板改为独立 tab / 独立窗口) =====
|
||||
//
|
||||
// 2026-09-24:原先这里挂着一个绑定当前会话的 SFTP 面板(含拖拽调宽)。
|
||||
// 它有两个绕不开的限制:一次只能服务一个会话(本地↔远端是唯一组合),
|
||||
// 且每次看文件都得先切到对应会话的标签。现在文件管理器是模块级的一页
|
||||
// (双栏 + 两栏各自选连接),本组件只负责把它「叫出来」并预选当前会话。
|
||||
|
||||
/**
|
||||
* 文件面板是**按会话**的开合状态(不全局开关)。
|
||||
* 从控制栏的文件按钮跳到「文件」页。
|
||||
*
|
||||
* 理由:面板显示的是「某个会话对应主机上的目录」,切到本地会话标签时
|
||||
* 继续显示上一个 SSH 主机的文件会让人误以为在看本机 —— 那是个危险的误会。
|
||||
* 因此面板只在 activeSession 是 SSH 时可用,且对每个会话独立记忆。
|
||||
* 把激活会话写进右栏是**关键的一步**:文件页自己读不到「终端页当前在看哪个会话」
|
||||
* (`activeSessionId` 是 `useTerminalStream` 的窗口级局部状态,见文件头),
|
||||
* 所以由这里顺手带过去。非 SSH 会话不带(本地会话没有远端目录可浏览)。
|
||||
*/
|
||||
const sftpVisible = ref(false)
|
||||
const sftpWidth = ref(420)
|
||||
|
||||
const canShowSftp = computed(() => activeSession.value?.kind === 'ssh')
|
||||
|
||||
/** 面板标题用的会话名(store 的派生方法需要看到 hosts,故在这层取) */
|
||||
const sftpSessionLabel = computed(() => store.sessionLabel(activeSession.value))
|
||||
|
||||
// 切到非 SSH 会话时收起面板:见上面关于「误以为是本机」的说明
|
||||
watch(activeSessionId, () => {
|
||||
if (!canShowSftp.value) sftpVisible.value = false
|
||||
})
|
||||
|
||||
function toggleSftp() {
|
||||
if (!canShowSftp.value) {
|
||||
toast.info('文件管理器只对 SSH 会话可用(本地会话请用系统资源管理器)')
|
||||
return
|
||||
function openFiles() {
|
||||
if (activeSession.value?.kind === 'ssh') {
|
||||
store.setFilePaneSource('right', { kind: 'ssh', sessionId: activeSession.value.id })
|
||||
}
|
||||
sftpVisible.value = !sftpVisible.value
|
||||
emit('open-files')
|
||||
}
|
||||
|
||||
/** 面板左边缘的拖拽调宽 */
|
||||
function startResizeSftp(e: MouseEvent) {
|
||||
e.preventDefault()
|
||||
const startX = e.clientX
|
||||
const startW = sftpWidth.value
|
||||
const onMove = (ev: MouseEvent) => {
|
||||
// 向左拖是变宽:面板贴右边缘,宽度 = 起点到鼠标的距离
|
||||
const next = startW + (startX - ev.clientX)
|
||||
sftpWidth.value = Math.min(Math.max(280, next), window.innerWidth - 360)
|
||||
}
|
||||
const onUp = () => {
|
||||
document.removeEventListener('mousemove', onMove)
|
||||
document.removeEventListener('mouseup', onUp)
|
||||
}
|
||||
document.addEventListener('mousemove', onMove)
|
||||
document.addEventListener('mouseup', onUp)
|
||||
}
|
||||
/** 激活会话的显示名(端口转发对话框的标题用;store 的派生方法需要看到 hosts,故在这层取) */
|
||||
const activeSessionLabel = computed(() => store.sessionLabel(activeSession.value))
|
||||
|
||||
// ===== 端口转发 / 会话模板 / AI 助手(低频配置,用 Dialog) =====
|
||||
|
||||
@@ -645,7 +625,7 @@ defineExpose({
|
||||
handleNewLocal,
|
||||
handleSplit,
|
||||
handleDetach,
|
||||
toggleSftp,
|
||||
openFiles,
|
||||
openRename,
|
||||
focusActivePane
|
||||
})
|
||||
@@ -689,10 +669,9 @@ defineExpose({
|
||||
:searching="searching"
|
||||
:search-hint="searchHint"
|
||||
:is-ssh="activeSession?.kind === 'ssh'"
|
||||
:sftp-visible="sftpVisible"
|
||||
:logging="activeSession?.logging ?? false"
|
||||
:font-size="effectiveAppearance?.fontSize ?? 14"
|
||||
@toggle-sftp="toggleSftp"
|
||||
@open-files="openFiles"
|
||||
@open-forwards="forwardsOpen = true"
|
||||
@toggle-logging="toggleLogging"
|
||||
@open-log-dir="openLogDir"
|
||||
@@ -802,26 +781,7 @@ defineExpose({
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- ===== SFTP 文件面板(仅 SSH 会话) ===== -->
|
||||
<template v-if="sftpVisible && canShowSftp && activeSessionId">
|
||||
<!-- 拖拽条:面板贴右边缘,向左拖变宽 -->
|
||||
<div
|
||||
class="shrink-0 w-1 cursor-col-resize hover:bg-primary/40 transition-colors"
|
||||
title="拖动调整宽度"
|
||||
@mousedown="startResizeSftp"
|
||||
/>
|
||||
<aside class="shrink-0 border-l border-border" :style="{ width: `${sftpWidth}px` }">
|
||||
<SftpPanel
|
||||
:key="activeSessionId"
|
||||
:session-id="activeSessionId"
|
||||
:session-label="sftpSessionLabel"
|
||||
:terminal-cwd="activeSession?.cwd ?? ''"
|
||||
@close="sftpVisible = false"
|
||||
/>
|
||||
</aside>
|
||||
</template>
|
||||
|
||||
<!-- 独立窗口的会话提示条:该会话在主窗口不可交互 -->
|
||||
<!-- ===== 独立窗口的会话提示条:该会话在主窗口不可交互 ===== -->
|
||||
<div
|
||||
v-if="activeSession?.detached"
|
||||
class="shrink-0 w-8 border-l border-border flex items-start justify-center pt-3"
|
||||
@@ -864,7 +824,7 @@ defineExpose({
|
||||
<ForwardPanel
|
||||
v-model:open="forwardsOpen"
|
||||
:session-id="activeSessionId"
|
||||
:session-label="sftpSessionLabel"
|
||||
:session-label="activeSessionLabel"
|
||||
/>
|
||||
|
||||
<!-- ===== 会话模板(P2) ===== -->
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* 文件管理器的路径与展示工具。
|
||||
*
|
||||
* # 为什么单独抽一个文件
|
||||
*
|
||||
* 拆成「双栏 + 独立窗口」之后,同一批纯函数要被三处用:`FilePane`(拼接新建/重命名
|
||||
* 的目标路径)、`FileManager`(拼接传输的目标路径)、`FileWindow`(不需要,但边界
|
||||
* 一致)。留在某个组件里靠 props/emit 传出去,只会让三处各自抄一份 ——
|
||||
* 而**路径拼接抄错是静默错误**:拼出 `C:\dir\/name` 或 `/a//b` 时列表照样显示,
|
||||
* 只有在服务端报 `No such file` 时才暴露。
|
||||
*
|
||||
* # 本地与远端是两套语义,因此有两个 join
|
||||
*
|
||||
* - 远端固定 POSIX:分隔符只有 `/`,且不能出现 `//`(部分 sftp-server 会把 `//`
|
||||
* 当成 UNC 风格路径处理);
|
||||
* - 本地跟随当前目录的分隔符(Windows `\`,其它平台 `/`),且盘符根
|
||||
* (`C:\`)去掉尾部分隔符会退化成 `C:`(相对当前盘目录!),必须补回来。
|
||||
*
|
||||
* 二者的规则都不复杂,但都不能靠「反正 Windows 也认 `/`」蒙混 —— 本地路径会被
|
||||
* 回传给 `ShellExecuteW`、系统对话框与 SFTP 上传命令,任一处对 `/` 的容忍度不同。
|
||||
*/
|
||||
|
||||
import type { FileSource } from '@/types/terminal'
|
||||
|
||||
/** 远端路径拼接(POSIX 语义,避免 `//`)。与 Rust 侧 `join_remote` 同一套规则 */
|
||||
export function joinRemote(base: string, name: string): string {
|
||||
if (!base || base === '.') return name
|
||||
if (name.startsWith('/')) return name
|
||||
return base.endsWith('/') ? `${base}${name}` : `${base}/${name}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 本地路径拼接。
|
||||
*
|
||||
* 分隔符取「当前路径里已经用过的那个」:Windows 下 `C:\a\b` 得到 `\`,
|
||||
* POSIX 下得到 `/`。盘符根 `C:\` 先去尾部分隔符再拼,避免 `C:\/name`。
|
||||
*/
|
||||
export function joinLocal(base: string, name: string): string {
|
||||
if (!base) return name
|
||||
const sep = base.includes('\\') ? '\\' : '/'
|
||||
return `${base.replace(/[\\/]+$/, '')}${sep}${name}`
|
||||
}
|
||||
|
||||
/** 取路径的所在目录(本地/远端通用:两种分隔符都认) */
|
||||
export function parentOf(path: string): string {
|
||||
const idx = Math.max(path.lastIndexOf('\\'), path.lastIndexOf('/'))
|
||||
// idx <= 0 时没有可用的父目录(相对文件名 / 根目录),交回原值由调用方兜底
|
||||
return idx > 0 ? path.slice(0, idx) : path
|
||||
}
|
||||
|
||||
/** 文件名(去掉目录部分),展示用 */
|
||||
export function baseName(path: string): string {
|
||||
const p = path.replace(/\\/g, '/')
|
||||
return p.slice(p.lastIndexOf('/') + 1)
|
||||
}
|
||||
|
||||
/** 字节数的人类可读形态 */
|
||||
export function humanSize(n: number): string {
|
||||
if (n < 1024) return `${n} B`
|
||||
const units = ['KB', 'MB', 'GB', 'TB']
|
||||
let v = n / 1024
|
||||
let i = 0
|
||||
while (v >= 1024 && i < units.length - 1) {
|
||||
v /= 1024
|
||||
i += 1
|
||||
}
|
||||
return `${v < 10 ? v.toFixed(1) : Math.round(v)} ${units[i]}`
|
||||
}
|
||||
|
||||
/** 完整时间戳 `YYYY-MM-DD HH:mm`(行的悬停提示用) */
|
||||
export function fmtFullTime(ms?: number | null): string {
|
||||
if (!ms) return ''
|
||||
const d = new Date(ms)
|
||||
const pad = (x: number) => String(x).padStart(2, '0')
|
||||
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,
|
||||
to: FileSource | null
|
||||
): 'upload' | 'download' | 'relay' | null {
|
||||
if (!from || !to) return null
|
||||
if (from.kind === 'local' && to.kind === 'ssh') return 'upload'
|
||||
if (from.kind === 'ssh' && to.kind === 'local') return 'download'
|
||||
if (from.kind === 'ssh' && to.kind === 'ssh') return 'relay'
|
||||
return null
|
||||
}
|
||||
@@ -7,12 +7,15 @@ import type { SearchIndexItem } from '@/stores/searchIndex'
|
||||
* # `tab` 只能表达「哪个 tab」(现存取舍)
|
||||
*
|
||||
* 模块 Tabs 于 2026-09-20 由 7 项收敛为 5 项,2026-09-22 又收敛为 4 项
|
||||
* (终端 / 主机 / 密钥 / 设置):
|
||||
* (终端 / 主机 / 密钥 / 设置);2026-09-24 因文件管理器从「终端卡片里的面板」
|
||||
* 升级为独立页而加回「文件」,现为 5 项(终端 / 文件 / 主机 / 密钥 / 设置):
|
||||
*
|
||||
* - 「已知主机」不再是一个 tab,而是主机页里的**信任徽标**(点开看指纹与
|
||||
* 变更历史)与列表末尾的**孤儿记录区块**,因此它指向 `hosts`;
|
||||
* - 「命令历史」「命令片段」变成终端页控制栏上的两个 popover,因此指向
|
||||
* `terminal`。
|
||||
* `terminal`;
|
||||
* - 「文件管理器」现在确实是一页,因此指向 `files`(此前它只是终端卡片里的
|
||||
* 面板,搜索项无从表达)。
|
||||
*
|
||||
* **已知的取舍**:`SearchIndexItem.tab` 只能表达「哪个 tab」,无法表达
|
||||
* 「tab 里的哪一个 popover / 哪台主机」,所以搜「命令片段」会落在终端页、
|
||||
@@ -32,6 +35,24 @@ const searchItems: SearchIndexItem[] = [
|
||||
keywords: ['新建', '本地', 'powershell', 'pwsh', 'cmd', 'git bash', 'wsl', '会话', '标签'],
|
||||
tab: 'terminal'
|
||||
},
|
||||
{
|
||||
title: '文件管理器',
|
||||
description: '双栏文件浏览与传输:两栏各自选择本地或已连接的 SSH 会话,支持上传 / 下载 / 远端间中继',
|
||||
keywords: [
|
||||
'文件',
|
||||
'文件管理器',
|
||||
'sftp',
|
||||
'传输',
|
||||
'上传',
|
||||
'下载',
|
||||
'中继',
|
||||
'双栏',
|
||||
'本地',
|
||||
'file',
|
||||
'manager'
|
||||
],
|
||||
tab: 'files'
|
||||
},
|
||||
{
|
||||
title: 'SSH 主机',
|
||||
description: '管理 SSH 主机连接(含跳板机、主机密钥信任状态与自动登录)',
|
||||
|
||||
@@ -793,7 +793,7 @@ onUnmounted(() => {
|
||||
v-for="(c, i) in candidates"
|
||||
:key="i"
|
||||
class="flex w-full items-center gap-2 rounded px-1.5 py-1 text-left transition-colors"
|
||||
:class="i === activeCandidate ? 'bg-primary/10 ring-1 ring-primary/40' : 'hover:bg-accent/60'"
|
||||
:class="i === activeCandidate ? 'bg-primary/10 ring-1 ring-primary/40' : 'hover:bg-row-hover'"
|
||||
@mousemove="activeCandidate = i"
|
||||
@click="adoptCandidate(c)"
|
||||
>
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { toast } from 'vue-sonner'
|
||||
import { CircleAlert, CircleCheck, Eraser, KeyRound, LoaderCircle, RefreshCw, Trash2, Zap } from '@lucide/vue'
|
||||
import { CircleAlert, CircleCheck, Eraser, KeyRound, LoaderCircle, Trash2, Zap } from '@lucide/vue'
|
||||
import { useTranslateStore } from '@/stores/translateStore'
|
||||
import { ERROR_HINTS, type EngineTestResult, type EngineView, type TranslateEngineConfig } from '@/types/translate'
|
||||
import {
|
||||
DEFAULT_TRANSLATE_AI_PARAMS,
|
||||
ERROR_HINTS,
|
||||
type EngineTestResult,
|
||||
type EngineView,
|
||||
type TranslateAiParams,
|
||||
type TranslateEngineConfig
|
||||
} from '@/types/translate'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue
|
||||
} from '@/components/ui/select'
|
||||
|
||||
const props = defineProps<{ view: EngineView }>()
|
||||
const emit = defineEmits<{
|
||||
@@ -23,15 +23,19 @@ const emit = defineEmits<{
|
||||
}>()
|
||||
|
||||
const store = useTranslateStore()
|
||||
const isAi = computed(() => props.view.config.kind === 'ai')
|
||||
|
||||
/** 编辑草稿。保存前的改动只在这里,不影响已生效配置 */
|
||||
const draft = ref<TranslateEngineConfig>({ ...props.view.config })
|
||||
const apiKey = ref('')
|
||||
const models = ref<string[]>([])
|
||||
const testResult = ref<EngineTestResult | null>(null)
|
||||
const busy = ref<'' | 'save' | 'key' | 'test' | 'models'>('')
|
||||
const busy = ref<'' | 'save' | 'key' | 'test'>('')
|
||||
const confirmingDelete = ref(false)
|
||||
|
||||
/** AI 引擎:只编辑翻译场景参数(连接配置在主设置 → AI 服务) */
|
||||
const aiDraft = ref<TranslateAiParams>({ providerId: props.view.config.id, ...DEFAULT_TRANSLATE_AI_PARAMS })
|
||||
const aiBusy = ref(false)
|
||||
|
||||
// 外部刷新(保存成功、密钥变更后 store.reload)时重置草稿
|
||||
watch(
|
||||
() => props.view,
|
||||
@@ -39,17 +43,37 @@ watch(
|
||||
draft.value = { ...v.config }
|
||||
apiKey.value = ''
|
||||
testResult.value = null
|
||||
}
|
||||
if (v.config.kind === 'ai') {
|
||||
// 再展开一次:草稿必须是独立的编辑副本,写回时不碰 store 里的原对象
|
||||
aiDraft.value = { ...store.aiParamsFor(v.config.id) }
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
const aiDirty = computed(() => {
|
||||
const current = store.aiParamsFor(props.view.config.id)
|
||||
return JSON.stringify(aiDraft.value) !== JSON.stringify(current)
|
||||
})
|
||||
|
||||
async function saveAiParams() {
|
||||
aiBusy.value = true
|
||||
try {
|
||||
await store.saveAiParams({ ...aiDraft.value, providerId: props.view.config.id })
|
||||
toast.success('翻译参数已保存')
|
||||
} catch (e) {
|
||||
toast.error(String(e))
|
||||
} finally {
|
||||
aiBusy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const dirty = computed(() => {
|
||||
const a = JSON.stringify(draft.value)
|
||||
const b = JSON.stringify(props.view.config)
|
||||
return a !== b
|
||||
})
|
||||
|
||||
const canFetchModels = computed(() => props.view.hasApiKey && props.view.config.kind === 'ai')
|
||||
|
||||
/** 数值输入的收敛:NaN 一律退回默认值,避免把空输入写进配置 */
|
||||
function toNumber(raw: string | number, fallback: number, min: number, max: number): number {
|
||||
const n = typeof raw === 'number' ? raw : Number.parseFloat(raw)
|
||||
@@ -115,13 +139,6 @@ const test = () =>
|
||||
else toast.error(testResult.value.message)
|
||||
})
|
||||
|
||||
const fetchModels = () =>
|
||||
withBusy('models', async () => {
|
||||
models.value = await store.fetchModels(props.view.config.id)
|
||||
if (models.value.length === 0) toast.info('上游未返回任何模型')
|
||||
else toast.success(`拉取到 ${models.value.length} 个模型`)
|
||||
})
|
||||
|
||||
const remove = () =>
|
||||
withBusy('save', async () => {
|
||||
if (!confirmingDelete.value) {
|
||||
@@ -135,7 +152,63 @@ const remove = () =>
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-3 rounded-lg border bg-muted/20 p-3">
|
||||
<!-- ===== AI 引擎:只编辑翻译场景参数(连接配置在主设置 → AI 服务) ===== -->
|
||||
<div v-if="isAi" class="space-y-3 rounded-lg border bg-muted/20 p-3">
|
||||
<p class="text-[11px] text-muted-foreground">
|
||||
连接、模型与密钥在
|
||||
<span class="text-foreground font-medium">常规设置 → AI 服务</span>
|
||||
中修改;这里只调整该供应商在翻译里的优先级、超时与提示词
|
||||
(启用开关在引擎列表行上)。
|
||||
</p>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-[12px]">优先级(越小越先尝试)</Label>
|
||||
<Input
|
||||
:model-value="aiDraft.priority"
|
||||
type="number"
|
||||
class="h-8 text-[13px]"
|
||||
@update:model-value="
|
||||
v => {
|
||||
const n = Number(v)
|
||||
aiDraft.priority = Number.isFinite(n) ? Math.min(9999, Math.max(0, Math.round(n))) : 100
|
||||
}
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-[12px]">超时(毫秒)</Label>
|
||||
<Input
|
||||
:model-value="aiDraft.timeoutMs"
|
||||
type="number"
|
||||
class="h-8 text-[13px]"
|
||||
@update:model-value="
|
||||
v => {
|
||||
const n = Number(v)
|
||||
aiDraft.timeoutMs = Number.isFinite(n) ? Math.min(600000, Math.max(1000, Math.round(n))) : 30000
|
||||
}
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-[12px]">自定义 System Prompt(可选)</Label>
|
||||
<Textarea
|
||||
v-model="aiDraft.systemPrompt"
|
||||
class="min-h-20 text-[12px]"
|
||||
placeholder="留空则使用「设置 → 提示词模板」中的模板;{target} 会替换为目标语言"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<Button size="sm" :disabled="aiBusy || !aiDirty" @click="saveAiParams">
|
||||
<LoaderCircle v-if="aiBusy" class="animate-spin" />
|
||||
保存翻译参数
|
||||
</Button>
|
||||
<Badge v-if="aiDirty" variant="outline" class="text-[11px]">有未保存的改动</Badge>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ===== free / cloud 引擎:完整编辑 ===== -->
|
||||
<div v-else class="space-y-3 rounded-lg border bg-muted/20 p-3">
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-[12px]">名称</Label>
|
||||
@@ -151,29 +224,17 @@ const remove = () =>
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="draft.kind === 'ai' || draft.preset === 'libretranslate'"
|
||||
class="col-span-2 space-y-1.5"
|
||||
>
|
||||
<div v-if="draft.preset === 'libretranslate'" class="col-span-2 space-y-1.5">
|
||||
<Label class="text-[12px]">Base URL</Label>
|
||||
<Input
|
||||
v-model="draft.baseUrl"
|
||||
:placeholder="draft.preset === 'libretranslate' ? 'https://translate.example.com' : 'https://api.deepseek.com'"
|
||||
placeholder="https://translate.example.com"
|
||||
class="h-8 text-[13px]"
|
||||
/>
|
||||
<p class="text-[11px] text-muted-foreground">
|
||||
<template v-if="draft.kind === 'ai'">
|
||||
填到 /v1 为止即可;若粘入了完整端点(…/chat/completions)后端会自动剥掉。
|
||||
</template>
|
||||
<template v-else>
|
||||
填 LibreTranslate 服务根地址;若粘入了 /translate 结尾后端会自动剥掉。
|
||||
</template>
|
||||
填 LibreTranslate 服务根地址;若粘入了 /translate 结尾后端会自动剥掉。
|
||||
</p>
|
||||
</div>
|
||||
<div v-if="draft.kind === 'ai'" class="space-y-1.5">
|
||||
<Label class="text-[12px]">模型</Label>
|
||||
<Input v-model="draft.model" placeholder="deepseek-flash" class="h-8 text-[13px]" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-[12px]">超时(毫秒)</Label>
|
||||
<Input
|
||||
@@ -184,30 +245,7 @@ const remove = () =>
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="draft.kind === 'ai'" class="space-y-1.5">
|
||||
<Label class="text-[12px]">温度(0~2)</Label>
|
||||
<Input
|
||||
:model-value="draft.temperature"
|
||||
type="number"
|
||||
step="0.1"
|
||||
class="h-8 text-[13px]"
|
||||
@update:model-value="v => (draft.temperature = toNumber(v, 0.3, 0, 2))"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="draft.kind === 'ai'" class="space-y-1.5">
|
||||
<Label class="text-[12px]">最大输出 tokens</Label>
|
||||
<Input
|
||||
:model-value="draft.maxTokens"
|
||||
type="number"
|
||||
class="h-8 text-[13px]"
|
||||
@update:model-value="v => (draft.maxTokens = toNumber(v, 4096, 64, 384000))"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="draft.kind !== 'ai'"
|
||||
class="col-span-2 space-y-1 rounded-md border bg-background p-2.5 text-[11px] text-muted-foreground"
|
||||
>
|
||||
<div class="col-span-2 space-y-1 rounded-md border bg-background p-2.5 text-[11px] text-muted-foreground">
|
||||
<p v-if="draft.preset === 'libretranslate'">
|
||||
LibreTranslate:文本发往你自己的服务器。API Key 可选——部署启用密钥校验时才必须填写。
|
||||
</p>
|
||||
@@ -218,29 +256,13 @@ const remove = () =>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="draft.kind === 'ai'" class="flex items-start gap-3 rounded-md border bg-background p-2.5">
|
||||
<Switch
|
||||
:model-value="draft.supportsVision"
|
||||
@update:model-value="(v: boolean) => (draft.supportsVision = v)"
|
||||
/>
|
||||
<div class="min-w-0 flex-1">
|
||||
<Label class="text-[12px]">支持图像输入</Label>
|
||||
<p class="mt-0.5 text-[11px] text-muted-foreground">
|
||||
勾选后「截图翻译」可用视觉直译模式:把截图直接发给该模型,识别与翻译一步完成。
|
||||
仅对支持图像输入的模型勾选(如 GLM-4V、Qwen-VL、gpt-4o 等)。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="draft.kind === 'ai' || draft.preset === 'libretranslate'"
|
||||
v-if="draft.preset === 'libretranslate'"
|
||||
class="space-y-1.5 rounded-md border bg-background p-2.5"
|
||||
>
|
||||
<div class="flex items-center gap-1.5">
|
||||
<KeyRound class="size-3.5 text-muted-foreground" />
|
||||
<Label class="text-[12px]">
|
||||
{{ draft.preset === 'libretranslate' ? 'API Key(可选)' : 'API Key' }}
|
||||
</Label>
|
||||
<Label class="text-[12px]">API Key(可选)</Label>
|
||||
<span class="text-[11px] text-muted-foreground">
|
||||
存入 Windows 凭据管理器,不写入配置文件、不回传前端明文
|
||||
</span>
|
||||
@@ -298,16 +320,6 @@ const remove = () =>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<div v-if="models.length > 0" class="space-y-1.5 rounded-md border bg-background p-2.5">
|
||||
<Label class="text-[12px]">从上游拉取到的模型(选择即填入上方「模型」)</Label>
|
||||
<Select :model-value="draft.model" @update:model-value="v => (draft.model = String(v))">
|
||||
<SelectTrigger class="h-8 text-[12px]"><SelectValue placeholder="选择模型" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="m in models" :key="m" :value="m">{{ m }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="testResult"
|
||||
class="space-y-1 rounded-md border p-2.5 text-[12px]"
|
||||
@@ -339,18 +351,6 @@ const remove = () =>
|
||||
<Zap v-else />
|
||||
测试连通性
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:disabled="busy === 'models' || !canFetchModels"
|
||||
:title="canFetchModels ? '从上游拉取模型列表' : '需先配置 API Key'"
|
||||
@click="fetchModels"
|
||||
>
|
||||
<LoaderCircle v-if="busy === 'models'" class="animate-spin" />
|
||||
<RefreshCw v-else />
|
||||
拉取模型
|
||||
</Button>
|
||||
|
||||
<div class="flex-1" />
|
||||
|
||||
<Badge v-if="dirty" variant="outline" class="text-[11px]">有未保存的改动</Badge>
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { toast } from 'vue-sonner'
|
||||
import { CircleAlert, LoaderCircle, Plus, Save, ScanText, Sparkles } from '@lucide/vue'
|
||||
import { CircleAlert, LoaderCircle, Plus, Save, ScanText, Sparkles, Trash2 } from '@lucide/vue'
|
||||
import { useTranslateStore } from '@/stores/translateStore'
|
||||
import { orderedLanguages } from '@/lib/translate/languages'
|
||||
import type { AiProviderView } from '@/types/ai'
|
||||
import {
|
||||
ENGINE_PRESETS,
|
||||
type EngineView,
|
||||
type HistorySettings,
|
||||
type PromptTemplates,
|
||||
type SelectionSettings,
|
||||
@@ -54,6 +56,8 @@ onMounted(async () => {
|
||||
} catch (e) {
|
||||
toast.error(`读取设置失败:${String(e)}`)
|
||||
}
|
||||
// 候选名单单独取:失败不该连累设置页整体不可用
|
||||
await store.loadAiProviderOptions()
|
||||
})
|
||||
|
||||
const targetLanguages = computed(() => orderedLanguages(false))
|
||||
@@ -81,7 +85,7 @@ async function addEngine() {
|
||||
const config: TranslateEngineConfig = {
|
||||
id: nextEngineId(preset.key),
|
||||
name,
|
||||
kind: 'ai',
|
||||
kind: 'free',
|
||||
preset: preset.key,
|
||||
enabled: true,
|
||||
priority: 100,
|
||||
@@ -114,6 +118,66 @@ async function patch(patch: Partial<TranslateSettings>) {
|
||||
}
|
||||
}
|
||||
|
||||
// ===== AI 引擎:从 AI 服务加入 / 移出翻译候选 =====
|
||||
// 供应商本身只在 AI 服务里维护(连接、模型、密钥);翻译侧只决定「哪几个上场」+ 场景参数。
|
||||
|
||||
/** 「从 AI 服务添加」列表是否展开 */
|
||||
const addingAi = ref(false)
|
||||
/** 正在添加 / 移出的供应商 id(按行禁用按钮,避免重复点击) */
|
||||
const aiBusyId = ref('')
|
||||
|
||||
/** 已加入翻译候选的供应商 id(`aiParams` 有记录即已加入) */
|
||||
const addedAiIds = computed(
|
||||
() => new Set((store.settings?.aiParams ?? []).map(p => p.providerId))
|
||||
)
|
||||
|
||||
/** 主设置里已配置、但还没加入翻译候选的供应商 */
|
||||
const addableAiProviders = computed(() =>
|
||||
store.aiProviderOptions.filter(p => !addedAiIds.value.has(p.config.id))
|
||||
)
|
||||
|
||||
/**
|
||||
* 已加入的 AI 引擎数量。
|
||||
*
|
||||
* 取实际候选(`store.engines`)而不是 `aiParams.length`:供应商在 AI 服务里被删掉后,
|
||||
* 翻译侧的场景参数会留成孤儿记录,按后者数会多报。
|
||||
*/
|
||||
const aiEngineCount = computed(() => store.engines.filter(e => e.config.kind === 'ai').length)
|
||||
|
||||
async function addAiEngine(view: AiProviderView) {
|
||||
aiBusyId.value = view.config.id
|
||||
try {
|
||||
await store.addAiEngine(view.config.id)
|
||||
toast.success(`已把「${view.config.name}」加入翻译候选`)
|
||||
} catch (e) {
|
||||
toast.error(String(e))
|
||||
} finally {
|
||||
aiBusyId.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
async function removeAiEngine(view: EngineView) {
|
||||
aiBusyId.value = view.config.id
|
||||
try {
|
||||
await store.removeAiEngine(view.config.id)
|
||||
if (editingId.value === view.config.id) editingId.value = ''
|
||||
toast.success(`已把「${view.config.name}」移出翻译候选`)
|
||||
} catch (e) {
|
||||
toast.error(String(e))
|
||||
} finally {
|
||||
aiBusyId.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
/** 翻译侧启用开关:只改 aiParams,不动 AI 服务里的供应商配置 */
|
||||
async function toggleAiEnabled(view: EngineView, enabled: boolean) {
|
||||
try {
|
||||
await store.saveAiParams({ ...store.aiParamsFor(view.config.id), enabled })
|
||||
} catch (e) {
|
||||
toast.error(String(e))
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 翻译面板:快捷键与黑名单需要显式保存 =====
|
||||
// 快捷键是文本输入,逐键保存会在「Ctrl」这种半成品状态下反复注册/注销并报错;
|
||||
// 黑名单同理(一行一个进程名,输入到一半不该落盘)。这两项因此走草稿 + 保存按钮,
|
||||
@@ -262,7 +326,9 @@ function templateWarning(text: string): string {
|
||||
翻译引擎
|
||||
</CardTitle>
|
||||
<p class="text-[12px] text-muted-foreground">
|
||||
同一类引擎可配置多个实例(如官方 API 与本地 Ollama 并存)。「自动」模式会按优先级依次尝试。
|
||||
同一类引擎可配置多个实例。「自动」模式会按优先级依次尝试。
|
||||
<span class="text-foreground/80">AI 引擎的连接与模型在「常规设置 → AI 服务」维护</span>,
|
||||
想让哪个供应商参与翻译,就在下方「从 AI 服务添加」里加入它。
|
||||
</p>
|
||||
</CardHeader>
|
||||
<CardContent class="space-y-3">
|
||||
@@ -270,11 +336,12 @@ function templateWarning(text: string): string {
|
||||
v-for="view in store.engines"
|
||||
:key="view.config.id"
|
||||
class="rounded-lg border p-3"
|
||||
:class="{ 'opacity-90': view.config.kind === 'ai' && !view.config.enabled }"
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-[13px] font-medium">{{ view.config.name }}</span>
|
||||
<Badge variant="outline" class="text-[11px]">
|
||||
{{ view.config.kind === 'ai' ? 'AI · OpenAI 兼容' : view.config.kind }}
|
||||
{{ view.config.kind === 'ai' ? 'AI · 连接在主设置' : view.config.kind }}
|
||||
</Badge>
|
||||
<Badge variant="secondary" class="text-[11px] tabular-nums">
|
||||
P{{ view.config.priority }}
|
||||
@@ -284,7 +351,15 @@ function templateWarning(text: string): string {
|
||||
<div class="flex-1" />
|
||||
|
||||
<span class="text-[11px] text-muted-foreground">{{ view.config.model }}</span>
|
||||
<!-- AI 引擎:开关写翻译侧参数(总开关在 AI 服务);free/cloud 直接写引擎配置 -->
|
||||
<Switch
|
||||
v-if="view.config.kind === 'ai'"
|
||||
:model-value="store.aiParamsFor(view.config.id).enabled"
|
||||
title="翻译侧开关;是否允许使用该供应商由主设置 → AI 服务决定"
|
||||
@update:model-value="v => toggleAiEnabled(view, Boolean(v))"
|
||||
/>
|
||||
<Switch
|
||||
v-else
|
||||
:model-value="view.config.enabled"
|
||||
@update:model-value="
|
||||
v =>
|
||||
@@ -298,7 +373,18 @@ function templateWarning(text: string): string {
|
||||
size="sm"
|
||||
@click="editingId = editingId === view.config.id ? '' : view.config.id"
|
||||
>
|
||||
{{ editingId === view.config.id ? '收起' : '编辑' }}
|
||||
{{ editingId === view.config.id ? '收起' : view.config.kind === 'ai' ? '翻译参数' : '编辑' }}
|
||||
</Button>
|
||||
<Button
|
||||
v-if="view.config.kind === 'ai'"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:disabled="aiBusyId === view.config.id"
|
||||
title="移出翻译候选(不影响 AI 服务里的配置与密钥)"
|
||||
@click="removeAiEngine(view)"
|
||||
>
|
||||
<Trash2 />
|
||||
移出
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -339,6 +425,55 @@ function templateWarning(text: string): string {
|
||||
{{ selectedPreset.description }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
|
||||
<!-- ===== AI 引擎:从 AI 服务加入(可多个供应商) ===== -->
|
||||
<div class="space-y-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<Label class="text-[12px]">AI 引擎</Label>
|
||||
<Button variant="outline" size="sm" @click="addingAi = !addingAi">
|
||||
{{ addingAi ? '收起' : '从 AI 服务添加' }}
|
||||
</Button>
|
||||
<span class="text-[11px] text-muted-foreground">
|
||||
已加入 {{ aiEngineCount }} 个;同一供应商只加入一次
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div v-if="addingAi" class="space-y-1.5 rounded-md border bg-muted/20 p-2.5">
|
||||
<p v-if="store.aiProviderOptionsLoading" class="text-[11px] text-muted-foreground">
|
||||
正在读取 AI 供应商…
|
||||
</p>
|
||||
<p v-else-if="store.aiProviderOptions.length === 0" class="text-[11px] text-muted-foreground">
|
||||
AI 服务里还没有供应商。请先到
|
||||
<span class="text-foreground font-medium">常规设置 → AI 服务</span>
|
||||
新增一个(DeepSeek / OpenAI / Ollama 等 OpenAI 兼容服务均可),再回到这里添加。
|
||||
</p>
|
||||
<p v-else-if="addableAiProviders.length === 0" class="text-[11px] text-muted-foreground">
|
||||
AI 服务里的供应商都已加入翻译候选。
|
||||
</p>
|
||||
<template v-else>
|
||||
<div
|
||||
v-for="p in addableAiProviders"
|
||||
:key="p.config.id"
|
||||
class="flex items-center gap-2 rounded-md border bg-background px-2.5 py-1.5"
|
||||
>
|
||||
<span class="text-[12px] font-medium">{{ p.config.name }}</span>
|
||||
<Badge variant="outline" class="text-[11px]">{{ p.config.model || '未选模型' }}</Badge>
|
||||
<Badge v-if="!p.config.enabled" variant="secondary" class="text-[11px]">
|
||||
已在 AI 服务中停用
|
||||
</Badge>
|
||||
<Badge v-else-if="p.ready" variant="secondary" class="text-[11px]">就绪</Badge>
|
||||
<span v-if="p.issue" class="text-[11px] text-warning-text">{{ p.issue }}</span>
|
||||
<div class="flex-1" />
|
||||
<Button size="sm" :disabled="aiBusyId === p.config.id" @click="addAiEngine(p)">
|
||||
<Plus />
|
||||
添加
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -406,7 +541,9 @@ function templateWarning(text: string): string {
|
||||
/>
|
||||
<p class="mt-1 text-[11px] text-muted-foreground">
|
||||
默认关闭。自建 LibreTranslate 在境内、MyMemory 与 DeepSeek 均可直连;
|
||||
仅当翻译服务部署在境外或直连被拦截时打开。
|
||||
仅当翻译服务部署在境外或直连被拦截时打开。<br />
|
||||
只作用于本模块的免密钥 / 云引擎;<span class="text-foreground">
|
||||
AI 引擎按「常规设置 → AI 服务」里的同名开关判定</span>。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -33,10 +33,13 @@ const store = useTranslateStore()
|
||||
const sourceLanguages = computed(() => orderedLanguages(true))
|
||||
const targetLanguages = computed(() => orderedLanguages(false))
|
||||
|
||||
/** 无可用引擎时的引导(比让用户点下去才报错要好) */
|
||||
const showEngineWarning = computed(
|
||||
() => !store.loading && store.engines.length > 0 && store.usableEngines.length === 0
|
||||
)
|
||||
/**
|
||||
* 无可用引擎时的引导(比让用户点下去才报错要好)。
|
||||
*
|
||||
* 不要求 `engines.length > 0`:全新安装时一个候选都没有(AI 供应商要显式加入翻译,
|
||||
* 主设置里配好也不自动上场),这个空列表同样需要给出下一步动作。
|
||||
*/
|
||||
const showEngineWarning = computed(() => !store.loading && store.usableEngines.length === 0)
|
||||
|
||||
/** 对比面板:与右侧单引擎结果并存(左列 = 输入 + 对比,右列 = 当前引擎译文) */
|
||||
const showCompare = ref(false)
|
||||
@@ -300,7 +303,8 @@ function onTargetScroll(e: Event) {
|
||||
<div class="flex items-start gap-2">
|
||||
<CircleAlert class="mt-0.5 size-3.5 shrink-0" />
|
||||
<span>
|
||||
还没有可用的翻译引擎。请到「设置」页填写引擎的 API Key,或新增一个引擎实例。
|
||||
还没有可用的翻译引擎。到「常规设置 → AI 服务」配置供应商并填好 API Key,
|
||||
再回翻译设置用「从 AI 服务添加」把它加入翻译候选;也可以新增一个免密钥 / 云引擎。
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,8 +10,8 @@ const searchItems: SearchIndexItem[] = [
|
||||
},
|
||||
{
|
||||
title: '翻译引擎设置',
|
||||
description: '配置 AI 引擎、Base URL、模型与 API Key',
|
||||
keywords: ['引擎', '模型', 'api key', '密钥', 'deepseek', 'openai', 'ollama', '中转'],
|
||||
description: '配置免密钥/云翻译引擎,或从 AI 服务添加 AI 引擎',
|
||||
keywords: ['引擎', '模型', 'api key', '密钥', 'deepl', 'libretranslate', '中转'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
|
||||
@@ -689,12 +689,15 @@ onUnmounted(() => {
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
/* 托盘菜单根容器在 mica 下无底色(--menu-bg: transparent),行直接画在系统糊化层上,
|
||||
所以用蒙层值(半透明)而不是不透明行底色 —— 不透明浅底会变成一块贴上去的白块。
|
||||
按下用更深的一档,保证"按下比悬停沉"。详见 style.css 的 --row-hover-veil */
|
||||
.tray-item:hover:not(:disabled) {
|
||||
background: var(--accent);
|
||||
background: var(--row-hover-veil);
|
||||
}
|
||||
|
||||
.tray-item:active:not(:disabled) {
|
||||
background: var(--secondary);
|
||||
background: var(--row-selected-veil);
|
||||
}
|
||||
|
||||
.tray-item:disabled {
|
||||
|
||||
Reference in new issue
Block a user