UI/细节调整
This commit is contained in:
1 parent
b018abd922
commit
bccd21fde5
135 files changed
+11393
-5104
No files matched your search
@@ -0,0 +1,226 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 已知主机记录的维护入口(主机页工具条右侧的下拉菜单)。
|
||||
*
|
||||
* # 为什么这些动作挂在主机页而不是独立分区
|
||||
*
|
||||
* 「导入 / 导出 / 清空」都是**低频的维护性动作**,作用于整份 known_hosts 文件,
|
||||
* 与「某台主机是否可信」这条主线无关(后者已经落到主机行的信任徽标与详情
|
||||
* popover 上)。它们此前和列表一起占着「凭据」页的一个分区,代价是让
|
||||
* 「看一眼主机信任状态」变成一个跨 tab 的动作。
|
||||
*
|
||||
* 现在收进主机页工具条的下拉里:页面主线是主机,维护动作在旁边待命。
|
||||
* 这与主机/密钥页既有的「高频外露、低频入菜单」取舍一致。
|
||||
*
|
||||
* # 为什么清空要输入确认词
|
||||
*
|
||||
* 清空之后所有主机密钥校验都要重新人工核对,而**在核对之前连接不会报错**
|
||||
* ——用户会以为一切正常。这是「静默降低安全性」的操作,必须让手指慢下来。
|
||||
*/
|
||||
import { ref } from 'vue'
|
||||
import {
|
||||
ChevronDown,
|
||||
ClipboardPaste,
|
||||
Check,
|
||||
Download,
|
||||
Loader2,
|
||||
ShieldCheck,
|
||||
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 { Textarea } from '@/components/ui/textarea'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle
|
||||
} from '@/components/ui/dialog'
|
||||
|
||||
const logger = createLogger('terminal')
|
||||
const store = useTerminalStore()
|
||||
|
||||
// ===== 导入 / 导出 =====
|
||||
|
||||
/** 刚复制过的短暂反馈(按钮文案变成「已导出」,给出「确实生效了」的确认) */
|
||||
const copied = ref(false)
|
||||
let copiedTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
async function copyAll() {
|
||||
try {
|
||||
const text = await store.exportKnownHosts()
|
||||
if (!text.trim()) {
|
||||
toast.info('没有可导出的记录')
|
||||
return
|
||||
}
|
||||
await navigator.clipboard.writeText(text)
|
||||
copied.value = true
|
||||
if (copiedTimer) clearTimeout(copiedTimer)
|
||||
copiedTimer = setTimeout(() => (copied.value = false), 1800)
|
||||
toast.success('已复制到剪贴板')
|
||||
} catch (e) {
|
||||
toast.error(`导出失败:${String(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
const importOpen = ref(false)
|
||||
const importText = ref('')
|
||||
const importBusy = ref(false)
|
||||
|
||||
function openImport() {
|
||||
importText.value = ''
|
||||
importOpen.value = true
|
||||
}
|
||||
|
||||
async function submitImport() {
|
||||
const text = importText.value.trim()
|
||||
if (!text) {
|
||||
toast.error('请粘贴 known_hosts 内容')
|
||||
return
|
||||
}
|
||||
importBusy.value = true
|
||||
try {
|
||||
const r = await store.importKnownHosts(text)
|
||||
if (r.ok) {
|
||||
toast.success(r.message)
|
||||
importOpen.value = false
|
||||
} else {
|
||||
toast.error(r.message)
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error(`导入 known_hosts 失败:${String(e)}`)
|
||||
toast.error(`导入失败:${String(e)}`)
|
||||
} finally {
|
||||
importBusy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 清空 =====
|
||||
|
||||
const clearOpen = ref(false)
|
||||
const clearBusy = ref(false)
|
||||
const clearConfirmText = ref('')
|
||||
const CLEAR_KEYWORD = '清空'
|
||||
|
||||
async function submitClear() {
|
||||
if (clearConfirmText.value.trim() !== CLEAR_KEYWORD) return
|
||||
clearBusy.value = true
|
||||
try {
|
||||
await store.clearKnownHosts()
|
||||
toast.success('已清空全部已知主机')
|
||||
clearOpen.value = false
|
||||
clearConfirmText.value = ''
|
||||
} catch (e) {
|
||||
toast.error(`清空失败:${String(e)}`)
|
||||
} finally {
|
||||
clearBusy.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger as-child>
|
||||
<Button variant="outline" size="sm" class="gap-1.5">
|
||||
<ShieldCheck class="size-3.5" />已知主机<ChevronDown class="size-3" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" class="w-56">
|
||||
<DropdownMenuItem @click="openImport">
|
||||
<ClipboardPaste class="size-4" />导入 known_hosts…
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem :disabled="store.knownHosts.length === 0" @click="copyAll">
|
||||
<Check v-if="copied" class="size-4 text-success" />
|
||||
<Download v-else class="size-4" />
|
||||
{{ copied ? '已复制到剪贴板' : '导出到剪贴板' }}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
class="text-destructive"
|
||||
:disabled="store.knownHosts.length === 0"
|
||||
@click="clearOpen = true"
|
||||
>
|
||||
<Trash2 class="size-4" />清空全部已知主机
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
<!-- ===== 导入(粘贴 known_hosts 文本) ===== -->
|
||||
<Dialog v-model:open="importOpen">
|
||||
<DialogContent class="max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>导入 known_hosts</DialogTitle>
|
||||
<DialogDescription class="text-xs">
|
||||
粘贴 <span class="font-mono">~/.ssh/known_hosts</span> 的内容,或从其它设备导出的记录。
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Textarea
|
||||
v-model="importText"
|
||||
placeholder="example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA…"
|
||||
class="font-mono text-xs min-h-[180px] resize-y"
|
||||
/>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" size="sm" @click="importOpen = false">取消</Button>
|
||||
<Button size="sm" :disabled="importBusy" @click="submitImport">
|
||||
<Loader2 v-if="importBusy" class="size-3.5 mr-1.5 animate-spin" />
|
||||
导入
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<!-- ===== 清空全部(需输入确认词) ===== -->
|
||||
<Dialog v-model:open="clearOpen">
|
||||
<DialogContent class="max-w-sm" :show-close-button="false">
|
||||
<DialogHeader>
|
||||
<DialogTitle class="text-base text-destructive">清空全部已知主机</DialogTitle>
|
||||
<DialogDescription class="text-xs">
|
||||
将删除全部 {{ store.knownHosts.length }} 条记录。
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div class="rounded-md border border-destructive/40 bg-destructive/5 p-2.5">
|
||||
<p class="text-[11px] text-destructive font-medium mb-1">这会降低连接安全性</p>
|
||||
<p class="text-[11px] text-muted-foreground">
|
||||
清空后,所有主机的密钥校验都需要重新人工核对。在核对前,
|
||||
连接可能被中间人攻击劫持而您不会收到提示。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-1.5">
|
||||
<p class="text-xs text-muted-foreground">
|
||||
请输入 <span class="font-mono font-semibold text-foreground">{{ CLEAR_KEYWORD }}</span> 以确认
|
||||
</p>
|
||||
<input
|
||||
v-model="clearConfirmText"
|
||||
class="w-full h-8 px-2.5 rounded-md border border-border bg-transparent
|
||||
text-sm outline-none focus:border-destructive/60"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button variant="outline" size="sm" @click="clearOpen = false">取消</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
:disabled="clearBusy || clearConfirmText.trim() !== CLEAR_KEYWORD"
|
||||
@click="submitClear"
|
||||
>
|
||||
<Loader2 v-if="clearBusy" class="size-3.5 mr-1.5 animate-spin" />
|
||||
清空全部
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
Reference in new issue
Block a user