744 lines
25 KiB
Vue
744 lines
25 KiB
Vue
<script setup lang="ts">
|
||
import { ref, computed, onMounted, onUnmounted, nextTick, watch } from 'vue'
|
||
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
|
||
import { getCurrentWindow } from '@tauri-apps/api/window'
|
||
import { EVENTS, STORAGE_KEYS } from '@/lib/constants'
|
||
import { applyStoredAccent } from '@/lib/theme'
|
||
import { Effect, EffectState } from '@tauri-apps/api/window'
|
||
// Rust 端通过 tauri-specta 生成的命令绑定(bindings.ts)
|
||
import { commands } from '@/lib/bindings'
|
||
import {
|
||
ClipboardList, Pin, PinOff, Trash2, Search, Image as ImageIcon,
|
||
FileText, Files,
|
||
} from '@lucide/vue'
|
||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||
import { Input } from '@/components/ui/input'
|
||
import { Button } from '@/components/ui/button'
|
||
import {
|
||
Select, SelectContent, SelectItem, SelectTrigger, SelectValue,
|
||
} from '@/components/ui/select'
|
||
import {
|
||
Pagination, PaginationContent, PaginationItem, PaginationEllipsis,
|
||
} from '@/components/ui/pagination'
|
||
import { Skeleton } from '@/components/ui/skeleton'
|
||
|
||
// ===== 与 Rust 端对应的数据结构(bindings 提供,camelCase) =====
|
||
// kind 为 bindings 生成的 string,前端按字符串比较即可
|
||
import type { ClipboardItem, HistoryPage } from '@/lib/bindings'
|
||
|
||
// ===== 状态 =====
|
||
const items = ref<ClipboardItem[]>([])
|
||
const total = ref(0)
|
||
const currentPage = ref(1)
|
||
const PAGE_SIZE = 50
|
||
const searchQuery = ref('')
|
||
/** 类型筛选:全部/文本/图片/文件 */
|
||
const kindFilter = ref<'all' | 'text' | 'image' | 'files'>('all')
|
||
const selectedIndex = ref(0)
|
||
const loading = ref(false)
|
||
const searchInputRef = ref<HTMLInputElement | null>(null)
|
||
const unlistenFns: UnlistenFn[] = []
|
||
let searchTimer: ReturnType<typeof setTimeout> | null = null
|
||
|
||
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / PAGE_SIZE)))
|
||
|
||
// ===== 数据加载 =====
|
||
/** 加载请求序号:翻页/搜索快速操作时丢弃过期请求结果,避免旧请求覆盖新结果 */
|
||
let loadSeq = 0
|
||
/** 列表视图:history = 全部历史(后端分页);pinned = 仅钉住条目(前端筛选+分页) */
|
||
const viewMode = ref<'history' | 'pinned'>('history')
|
||
async function loadData() {
|
||
const seq = ++loadSeq
|
||
loading.value = true
|
||
try {
|
||
if (viewMode.value === 'pinned') {
|
||
// 钉住视图:一次性取回,前端按类型/搜索筛选并分页
|
||
const all = await commands.clipboardGetPinned()
|
||
if (seq !== loadSeq) return
|
||
const q = searchQuery.value.trim().toLowerCase()
|
||
const kind = kindFilter.value
|
||
let filtered = all
|
||
if (kind !== 'all') filtered = filtered.filter(i => i.kind === kind)
|
||
if (q) filtered = filtered.filter(i => i.preview.toLowerCase().includes(q))
|
||
total.value = filtered.length
|
||
const start = (currentPage.value - 1) * PAGE_SIZE
|
||
items.value = filtered.slice(start, start + PAGE_SIZE)
|
||
} else {
|
||
const q = searchQuery.value.trim()
|
||
const offset = (currentPage.value - 1) * PAGE_SIZE
|
||
let res: HistoryPage
|
||
if (q) {
|
||
res = await commands.clipboardSearch(q, PAGE_SIZE, offset)
|
||
} else {
|
||
res = await commands.clipboardGetHistory(PAGE_SIZE, offset, kindFilter.value)
|
||
}
|
||
if (seq !== loadSeq) return // 过期请求丢弃
|
||
items.value = res.items
|
||
total.value = res.total
|
||
}
|
||
selectedIndex.value = 0
|
||
} catch (e) {
|
||
if (seq !== loadSeq) return
|
||
console.error('[clipboard-popup] 加载失败:', e)
|
||
} finally {
|
||
// 仅最新请求可结束 loading,避免旧请求提前清除新请求的加载态
|
||
if (seq === loadSeq) loading.value = false
|
||
}
|
||
if (seq === loadSeq) {
|
||
await nextTick()
|
||
scrollSelectedIntoView()
|
||
}
|
||
}
|
||
|
||
/** 切换历史/钉住视图 */
|
||
async function toggleViewMode() {
|
||
viewMode.value = viewMode.value === 'history' ? 'pinned' : 'history'
|
||
currentPage.value = 1
|
||
await loadData()
|
||
}
|
||
|
||
async function gotoPage(p: number) {
|
||
currentPage.value = Math.min(Math.max(1, p), totalPages.value)
|
||
await loadData()
|
||
}
|
||
|
||
// 防抖搜索/筛选
|
||
watch([searchQuery, kindFilter], () => {
|
||
currentPage.value = 1
|
||
if (searchTimer) clearTimeout(searchTimer)
|
||
searchTimer = setTimeout(loadData, 200)
|
||
})
|
||
|
||
// ===== 选择与粘贴 =====
|
||
/// 选中条目 → 写回剪贴板 → 隐藏窗口 → 模拟 Ctrl+V 粘贴到原窗口
|
||
async function selectAndPaste(item: ClipboardItem) {
|
||
try {
|
||
await commands.clipboardCopyBack(item.id)
|
||
// paste_to_target 会先隐藏窗口,再延迟模拟 Ctrl+V
|
||
await commands.clipboardPasteToTarget()
|
||
} catch (e) {
|
||
console.error('[clipboard-popup] 粘贴失败:', e)
|
||
// 失败时至少隐藏窗口
|
||
await hideWindow()
|
||
}
|
||
}
|
||
|
||
async function togglePin(item: ClipboardItem, ev: Event) {
|
||
ev.stopPropagation()
|
||
try {
|
||
await commands.clipboardSetPinned(item.id, !item.pinned)
|
||
await loadData()
|
||
} catch (e) {
|
||
console.error('[clipboard-popup] 固定失败:', e)
|
||
}
|
||
}
|
||
|
||
async function deleteItem(item: ClipboardItem, ev: Event) {
|
||
ev.stopPropagation()
|
||
try {
|
||
await commands.clipboardDelete(item.id)
|
||
// 本地先移除保持即时反馈,再整页刷新(total/分页数与后端保持一致;
|
||
// 钉住视图下数据源也需重建)
|
||
items.value = items.value.filter((i) => i.id !== item.id)
|
||
// 当前页删空且不在第一页:回退一页,避免停留在空页
|
||
if (items.value.length === 0 && currentPage.value > 1) {
|
||
currentPage.value -= 1
|
||
}
|
||
await loadData()
|
||
} catch (e) {
|
||
console.error('[clipboard-popup] 删除失败:', e)
|
||
}
|
||
}
|
||
|
||
async function hideWindow() {
|
||
try {
|
||
await commands.clipboardHidePopup()
|
||
} catch {
|
||
/* 忽略 */
|
||
}
|
||
}
|
||
|
||
// ===== 独立预览窗口 =====
|
||
async function showPreview(item: ClipboardItem) {
|
||
try {
|
||
await commands.clipboardShowPreview(item.id)
|
||
} catch {
|
||
/* 忽略 */
|
||
}
|
||
}
|
||
|
||
async function hidePreview() {
|
||
try {
|
||
await commands.clipboardHidePreview()
|
||
} catch {
|
||
/* 忽略 */
|
||
}
|
||
}
|
||
|
||
/** 存储条目预览文本元素,用于检测是否被截断(仅截断的文本才显示预览) */
|
||
const previewEls = new Map<number, HTMLElement>()
|
||
function setPreviewEl(id: number, el: unknown) {
|
||
if (el instanceof HTMLElement) previewEls.set(id, el)
|
||
else previewEls.delete(id)
|
||
}
|
||
|
||
/** line-clamp-1 截断检测:内容高度超过单行即视为截断 */
|
||
function isTextTruncated(id: number): boolean {
|
||
const el = previewEls.get(id)
|
||
if (!el) return true // 无法测量时保守显示
|
||
return el.scrollHeight > el.clientHeight
|
||
}
|
||
|
||
/** 当前条目是否需要预览:图片始终预览;文本仅被截断时预览 */
|
||
function needsPreview(item: ClipboardItem): boolean {
|
||
if (item.kind === 'image') return true
|
||
if (item.kind === 'text') return isTextTruncated(item.id)
|
||
return false
|
||
}
|
||
|
||
let hoverTimer: ReturnType<typeof setTimeout> | null = null
|
||
/** 鼠标是否位于独立预览窗内:为 true 时离开条目不隐藏预览,便于点击复制/放大 */
|
||
const mouseInPreview = ref(false)
|
||
|
||
/** 键盘选中:立即显示/隐藏预览(不等待悬停延迟) */
|
||
function showSelectedPreview() {
|
||
cancelHoverTimer()
|
||
mouseInPreview.value = false
|
||
const item = items.value[selectedIndex.value]
|
||
if (item && needsPreview(item)) {
|
||
void showPreview(item)
|
||
} else {
|
||
void hidePreview()
|
||
}
|
||
}
|
||
|
||
function onItemHover(idx: number, item: ClipboardItem) {
|
||
selectedIndex.value = idx
|
||
// 先取消之前的定时器
|
||
cancelHoverTimer()
|
||
mouseInPreview.value = false
|
||
// 不需要预览的条目:立即隐藏预览(避免前一条目的预览残留)
|
||
if (!needsPreview(item)) {
|
||
void hidePreview()
|
||
return
|
||
}
|
||
// 100ms 后显示(快速响应悬停意图,同时避免鼠标快速划过时频繁开关)
|
||
hoverTimer = setTimeout(() => {
|
||
void showPreview(item)
|
||
}, 100)
|
||
}
|
||
|
||
function onItemLeave() {
|
||
// 延迟隐藏:避免鼠标在条目间快速移动时预览闪烁。
|
||
// 若鼠标已移入预览窗(点击复制/放大),由 preview-enter 事件取消该定时器。
|
||
cancelHoverTimer()
|
||
if (mouseInPreview.value) return
|
||
hoverTimer = setTimeout(() => {
|
||
void hidePreview()
|
||
}, 250)
|
||
}
|
||
|
||
function cancelHoverTimer() {
|
||
if (hoverTimer) {
|
||
clearTimeout(hoverTimer)
|
||
hoverTimer = null
|
||
}
|
||
}
|
||
|
||
// ===== 键盘导航 =====
|
||
// 类型筛选 Select 的展开状态:展开时 ↑↓/Enter/Esc 由 Select 自行处理,
|
||
// 不触发列表导航/粘贴/关闭弹窗
|
||
const selectOpen = ref(false)
|
||
|
||
function onKeydown(e: KeyboardEvent) {
|
||
if (selectOpen.value) return
|
||
if (e.key === 'ArrowDown') {
|
||
e.preventDefault()
|
||
selectedIndex.value = Math.min(selectedIndex.value + 1, items.value.length - 1)
|
||
showSelectedPreview()
|
||
scrollSelectedIntoView()
|
||
} else if (e.key === 'ArrowUp') {
|
||
e.preventDefault()
|
||
selectedIndex.value = Math.max(selectedIndex.value - 1, 0)
|
||
showSelectedPreview()
|
||
scrollSelectedIntoView()
|
||
} else if (e.key === 'Enter') {
|
||
e.preventDefault()
|
||
const item = items.value[selectedIndex.value]
|
||
if (item) selectAndPaste(item)
|
||
} else if (e.key === 'Escape') {
|
||
e.preventDefault()
|
||
cancelHoverTimer()
|
||
void hidePreview()
|
||
hideWindow()
|
||
}
|
||
}
|
||
|
||
function scrollSelectedIntoView() {
|
||
nextTick(() => {
|
||
const el = document.querySelector('.popup-item-selected') as HTMLElement | null
|
||
el?.scrollIntoView({ block: 'nearest' })
|
||
})
|
||
}
|
||
|
||
// ===== 显示辅助(kind 为 bindings 生成的 string,按字符串比较) =====
|
||
const kindIcon = (k: string) => {
|
||
if (k === 'text') return FileText
|
||
if (k === 'image') return ImageIcon
|
||
return Files
|
||
}
|
||
const kindLabel = (k: string) => (k === 'text' ? '文本' : k === 'image' ? '图片' : '文件')
|
||
const kindBadgeClass = (k: string) =>
|
||
k === 'text'
|
||
? 'badge-text'
|
||
: k === 'image'
|
||
? 'badge-image'
|
||
: 'badge-files'
|
||
const formatTime = (ms: number) => {
|
||
const diff = Date.now() - ms
|
||
if (diff < 60_000) return '刚刚'
|
||
if (diff < 3600_000) return `${Math.floor(diff / 60_000)}分钟前`
|
||
if (diff < 86_400_000) return `${Math.floor(diff / 3600_000)}小时前`
|
||
const d = new Date(ms)
|
||
return `${d.getMonth() + 1}/${d.getDate()}`
|
||
}
|
||
|
||
const hasItems = computed(() => items.value.length > 0)
|
||
|
||
// ===== 主题应用(与主应用同步) =====
|
||
/** 从 localStorage 读取主应用的主题设置 */
|
||
function readMainTheme(): { theme: string; effect: string } {
|
||
try {
|
||
const raw = localStorage.getItem(STORAGE_KEYS.appSettings)
|
||
if (raw) {
|
||
const s = JSON.parse(raw)
|
||
return {
|
||
theme: s.theme ?? 'system',
|
||
effect: s.effect ?? 'mica',
|
||
}
|
||
}
|
||
} catch {
|
||
/* 忽略 */
|
||
}
|
||
return { theme: 'system', effect: 'mica' }
|
||
}
|
||
|
||
/** 判断当前是否应为深色主题。
|
||
* 弹窗是独立窗口,主应用的 setTheme 不影响弹窗的 matchMedia,
|
||
* 因此 system 模式下用 matchMedia 是可靠的。 */
|
||
function resolveIsDark(theme: string): boolean {
|
||
if (theme === 'dark') return true
|
||
if (theme === 'light') return false
|
||
return window.matchMedia('(prefers-color-scheme: dark)').matches
|
||
}
|
||
|
||
/** 应用主题和窗口效果(与主应用同步)。
|
||
* 关键:先 setTheme 让窗口主题正确,再用通用 Effect.Mica(自动跟随窗口主题深浅)。 */
|
||
async function applyTheme() {
|
||
const root = document.documentElement
|
||
const { theme, effect } = readMainTheme()
|
||
|
||
// 1. 先设置窗口原生主题(system → null 跟随系统)
|
||
try {
|
||
const tauriWin = getCurrentWindow()
|
||
if (theme === 'system') {
|
||
await tauriWin.setTheme(null)
|
||
} else {
|
||
await tauriWin.setTheme(theme as 'dark' | 'light')
|
||
}
|
||
} catch {
|
||
/* 非 Tauri 环境忽略 */
|
||
}
|
||
|
||
// 2. 窗口主题已正确,用 matchMedia 判断深浅(弹窗自身不受主应用污染)
|
||
const isDark = resolveIsDark(theme)
|
||
|
||
// 3. 设置 DOM class
|
||
root.classList.remove('dark', 'effect-mica', 'effect-acrylic', 'effect-normal')
|
||
root.classList.add(`effect-${effect}`)
|
||
if (isDark) root.classList.add('dark')
|
||
// 主题色:与主窗口共用同一份设置
|
||
applyStoredAccent(root, isDark ? 'dark' : 'light', STORAGE_KEYS.appSettings)
|
||
|
||
// 4. 设置窗口效果与背景色
|
||
// 弹窗窗口创建时 transparent=true,透明窗口下原生背景色不显示,
|
||
// 需在实际可见的 DOM 元素(.popup-root)上设置背景色。
|
||
// 用 CSS 变量 --popup-bg 控制,mica/acrylic 模式下保持透明。
|
||
try {
|
||
const tauriWin = getCurrentWindow()
|
||
await tauriWin.clearEffects()
|
||
if (effect === 'mica') {
|
||
await tauriWin.setEffects({
|
||
effects: [Effect.Mica],
|
||
state: EffectState.FollowsWindowActiveState,
|
||
color: isDark ? [30, 41, 59, 0] : [248, 250, 252, 0],
|
||
})
|
||
await tauriWin.setBackgroundColor('#00000000')
|
||
root.style.setProperty('--popup-bg', 'transparent')
|
||
} else if (effect === 'acrylic') {
|
||
await tauriWin.setEffects({
|
||
effects: [Effect.Acrylic],
|
||
state: EffectState.FollowsWindowActiveState,
|
||
color: isDark ? [30, 41, 59, 0] : [248, 250, 252, 0],
|
||
})
|
||
await tauriWin.setBackgroundColor('#00000000')
|
||
root.style.setProperty('--popup-bg', 'transparent')
|
||
} else {
|
||
// 普通模式:透明窗口下原生背景不显示,由 DOM 提供背景色
|
||
await tauriWin.setBackgroundColor(isDark ? '#0f172a' : '#ffffff')
|
||
root.style.setProperty('--popup-bg', isDark ? '#0f172a' : '#ffffff')
|
||
}
|
||
} catch {
|
||
/* 非 Tauri 环境忽略 */
|
||
}
|
||
}
|
||
|
||
onMounted(async () => {
|
||
// 先应用主题(含窗口效果)
|
||
await applyTheme()
|
||
|
||
// 监听系统主题变化(仅在 system 模式下有意义)
|
||
const mq = window.matchMedia('(prefers-color-scheme: dark)')
|
||
const onThemeChange = () => applyTheme()
|
||
mq.addEventListener('change', onThemeChange)
|
||
unlistenFns.push(() => mq.removeEventListener('change', onThemeChange))
|
||
|
||
// 监听弹窗显示事件:每次显示时重新同步主题 + 刷新数据
|
||
unlistenFns.push(await listen(EVENTS.clipboardPopupShow, async () => {
|
||
// 主应用可能切换了主题,每次显示前重新应用
|
||
await applyTheme()
|
||
searchQuery.value = ''
|
||
currentPage.value = 1
|
||
// 隐藏独立预览窗口(弹窗重新显示时清除上次预览)
|
||
cancelHoverTimer()
|
||
mouseInPreview.value = false
|
||
void hidePreview()
|
||
await loadData()
|
||
await nextTick()
|
||
searchInputRef.value?.focus()
|
||
}))
|
||
|
||
// 监听弹窗隐藏事件:取消悬停定时器并隐藏预览,避免弹窗隐藏后残留定时器重新弹出预览窗
|
||
unlistenFns.push(await listen(EVENTS.clipboardPopupHide, () => {
|
||
cancelHoverTimer()
|
||
mouseInPreview.value = false
|
||
void hidePreview()
|
||
}))
|
||
|
||
// 鼠标进入预览窗:取消条目离开触发的隐藏定时器,允许在预览窗内停留并点击复制/放大
|
||
unlistenFns.push(await listen(EVENTS.clipboardPreviewEnter, () => {
|
||
mouseInPreview.value = true
|
||
cancelHoverTimer()
|
||
}))
|
||
|
||
// 鼠标离开预览窗:恢复可隐藏状态并延迟隐藏;鼠标移回条目时由 onItemHover 重新显示
|
||
unlistenFns.push(await listen(EVENTS.clipboardPreviewLeave, () => {
|
||
mouseInPreview.value = false
|
||
cancelHoverTimer()
|
||
hoverTimer = setTimeout(() => {
|
||
void hidePreview()
|
||
}, 250)
|
||
}))
|
||
|
||
// 加载初始数据
|
||
await loadData()
|
||
await nextTick()
|
||
searchInputRef.value?.focus()
|
||
|
||
// 主题和数据都就绪后,调用 Rust 端显示窗口
|
||
try {
|
||
await commands.clipboardShowWindow()
|
||
} catch {
|
||
/* 忽略 */
|
||
}
|
||
})
|
||
|
||
onUnmounted(() => {
|
||
cancelHoverTimer()
|
||
unlistenFns.forEach((fn) => fn())
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<div class="popup-root flex flex-col h-screen w-screen" @keydown="onKeydown">
|
||
<!-- 搜索栏(与剪切板主页统一样式)+ 类型筛选 -->
|
||
<div class="flex items-center gap-2 px-3 py-2 border-b border-border shrink-0">
|
||
<div class="relative flex-1 min-w-0">
|
||
<Search class="absolute left-2.5 top-1/2 -translate-y-1/2 size-4 text-muted-foreground" />
|
||
<Input
|
||
ref="searchInputRef"
|
||
v-model="searchQuery"
|
||
placeholder="搜索剪贴板历史..."
|
||
class="pl-8 text-sm"
|
||
spellcheck="false"
|
||
/>
|
||
</div>
|
||
<Select v-model="kindFilter" :open="selectOpen" @update:open="selectOpen = $event">
|
||
<SelectTrigger size="sm" class="w-[76px] shrink-0 text-xs" title="按类型筛选">
|
||
<SelectValue />
|
||
</SelectTrigger>
|
||
<!-- 内容宽度与 trigger 等宽:覆盖默认 min-w-[8rem](128px),紧凑弹窗内不显过宽 -->
|
||
<SelectContent class="w-(--reka-select-trigger-width) min-w-0">
|
||
<SelectItem value="all">全部</SelectItem>
|
||
<SelectItem value="text">文本</SelectItem>
|
||
<SelectItem value="image">图片</SelectItem>
|
||
<SelectItem value="files">文件</SelectItem>
|
||
</SelectContent>
|
||
</Select>
|
||
</div>
|
||
|
||
<!-- 列表 -->
|
||
<ScrollArea class="popup-list flex-1 min-h-0">
|
||
<div class="space-y-1.5 p-2">
|
||
<div v-if="loading && !hasItems" class="space-y-1.5">
|
||
<div
|
||
v-for="n in 8"
|
||
:key="n"
|
||
class="flex items-start gap-3 rounded-lg border px-3 py-2"
|
||
>
|
||
<Skeleton class="size-4 shrink-0 mt-0.5" />
|
||
<div class="flex-1 space-y-1.5">
|
||
<Skeleton class="h-3.5 w-3/4" />
|
||
<Skeleton class="h-2.5 w-1/4" />
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div v-else-if="!hasItems" class="flex flex-col items-center justify-center py-12 text-muted-foreground">
|
||
<ClipboardList class="size-10 mb-2 opacity-40" />
|
||
<p class="text-sm">
|
||
{{ searchQuery ? '无匹配结果' : '暂无历史记录' }}
|
||
</p>
|
||
</div>
|
||
<div
|
||
v-for="(item, idx) in items"
|
||
:key="item.id"
|
||
class="popup-item group"
|
||
:class="{ 'popup-item-selected': idx === selectedIndex }"
|
||
@click="selectAndPaste(item)"
|
||
@mouseenter="onItemHover(idx, item)"
|
||
@mouseleave="onItemLeave"
|
||
>
|
||
<component :is="kindIcon(item.kind)" class="size-4 text-muted-foreground shrink-0 mt-0.5" />
|
||
<div class="flex-1 min-w-0">
|
||
<p
|
||
class="text-sm break-all line-clamp-1"
|
||
:ref="el => setPreviewEl(item.id, el)"
|
||
>{{ item.preview }}</p>
|
||
<div class="flex items-center gap-2 mt-0.5 text-xs text-muted-foreground flex-wrap">
|
||
<span class="popup-item-kind px-1.5 py-0 text-[10px] border rounded-sm" :class="kindBadgeClass(item.kind)">{{ kindLabel(item.kind) }}</span>
|
||
<span>{{ formatTime(item.createdAt) }}</span>
|
||
</div>
|
||
</div>
|
||
<div class="popup-item-actions shrink-0">
|
||
<button class="popup-action-btn size-7" :title="item.pinned ? '取消固定' : '固定'" @click="togglePin(item, $event)">
|
||
<component :is="item.pinned ? PinOff : Pin" class="h-3.5 w-3.5" />
|
||
</button>
|
||
<button class="popup-action-btn size-7 hover:text-destructive" title="删除" @click="deleteItem(item, $event)">
|
||
<Trash2 class="h-3.5 w-3.5" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</ScrollArea>
|
||
|
||
<!-- 底部:总数 + 分页 + 视图切换(grid 两侧 1fr 等宽,分页严格居中) -->
|
||
<div class="grid grid-cols-[1fr_auto_1fr] items-center gap-2 px-3 py-1 border-t border-border shrink-0">
|
||
<span class="text-xs text-muted-foreground whitespace-nowrap justify-self-start">{{ total }} 条</span>
|
||
<div v-if="totalPages > 1" class="justify-self-center">
|
||
<Pagination
|
||
v-slot="{ page }"
|
||
:page="currentPage"
|
||
:total="total"
|
||
:items-per-page="PAGE_SIZE"
|
||
:sibling-count="1"
|
||
show-edges
|
||
@update:page="gotoPage"
|
||
>
|
||
<PaginationContent v-slot="{ items: pageItems }" class="gap-1">
|
||
<template v-for="(item, index) in pageItems" :key="index">
|
||
<PaginationItem
|
||
v-if="item.type === 'page'"
|
||
:value="item.value"
|
||
:is-active="item.value === page"
|
||
size="icon"
|
||
class="size-7 text-xs"
|
||
>
|
||
{{ item.value }}
|
||
</PaginationItem>
|
||
<PaginationEllipsis v-else class="size-7" />
|
||
</template>
|
||
</PaginationContent>
|
||
</Pagination>
|
||
</div>
|
||
<!-- col-start-3:无分页时中间轨道宽为 0,若不固定列位置按钮会被自动放置
|
||
到第 2 轨道(视觉居中),显式固定第 3 轨道保证始终贴右 -->
|
||
<div class="justify-self-end col-start-3">
|
||
<Button
|
||
:variant="viewMode === 'pinned' ? 'default' : 'outline'"
|
||
size="sm"
|
||
class="h-7 px-2 text-xs gap-1"
|
||
:title="viewMode === 'pinned' ? '当前:仅钉住条目,点击查看全部历史' : '当前:全部历史,点击仅查看钉住条目'"
|
||
@click="toggleViewMode"
|
||
>
|
||
<!-- 图标与文字同义(Pin=钉住视图 / ClipboardList=历史视图),高亮表示当前视图 -->
|
||
<component :is="viewMode === 'pinned' ? Pin : ClipboardList" class="size-3.5" />
|
||
{{ viewMode === 'pinned' ? '钉住' : '历史' }}
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 底部提示 -->
|
||
<div class="popup-footer shrink-0">
|
||
<span><kbd>↑</kbd><kbd>↓</kbd> 导航</span>
|
||
<span><kbd>Enter</kbd>/<kbd>左键</kbd> 粘贴</span>
|
||
<span><kbd>Esc</kbd> 关闭</span>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<style scoped>
|
||
/* 弹窗根容器:背景色由 --popup-bg 控制(mica/acrylic 透明,普通模式不透明) */
|
||
.popup-root {
|
||
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', 'PingFang SC', sans-serif;
|
||
background: var(--popup-bg, transparent);
|
||
color: var(--foreground);
|
||
border-radius: 8px;
|
||
overflow: hidden;
|
||
position: relative;
|
||
}
|
||
|
||
/* 列表 */
|
||
.popup-list {
|
||
padding: 0;
|
||
}
|
||
|
||
/* reka-ui ScrollAreaViewport 内部会出现一个 div,需保证高度撑满 */
|
||
.popup-list :deep([data-slot="scroll-area-viewport"] > div) {
|
||
min-height: 100%;
|
||
}
|
||
|
||
/* 条目卡片样式(与主界面 Card 统一) */
|
||
.popup-item {
|
||
display: flex;
|
||
align-items: flex-start;
|
||
gap: 12px;
|
||
padding: 8px 12px;
|
||
border-radius: var(--radius);
|
||
cursor: pointer;
|
||
border: 1px solid var(--border);
|
||
background: var(--card);
|
||
transition: box-shadow 0.2s, background-color 0.1s;
|
||
}
|
||
|
||
/* 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);
|
||
}
|
||
|
||
/* 选中态强度必须盖过 hover::hover 的特异性(0,2,0)高于单类(0,1,0),
|
||
不显式补 :hover 的话,悬停已选中项会退回更弱的行 hover 底 */
|
||
.popup-item-selected,
|
||
.popup-item-selected:hover {
|
||
background: var(--row-selected);
|
||
}
|
||
|
||
/* 类型 badge 配色(与主界面一致) */
|
||
.popup-item-kind.badge-text {
|
||
background: rgba(59, 130, 246, 0.12);
|
||
color: rgb(37, 99, 235);
|
||
border-color: rgba(59, 130, 246, 0.4);
|
||
}
|
||
.popup-item-kind.badge-image {
|
||
background: rgba(16, 185, 129, 0.12);
|
||
color: rgb(5, 150, 105);
|
||
border-color: rgba(16, 185, 129, 0.4);
|
||
}
|
||
.popup-item-kind.badge-files {
|
||
background: rgba(245, 158, 11, 0.12);
|
||
color: rgb(217, 119, 6);
|
||
border-color: rgba(245, 158, 11, 0.4);
|
||
}
|
||
|
||
/* 深色主题下调整 badge 文字色 */
|
||
.dark .popup-item-kind.badge-text {
|
||
color: rgb(96, 165, 250);
|
||
}
|
||
.dark .popup-item-kind.badge-image {
|
||
color: rgb(52, 211, 153);
|
||
}
|
||
.dark .popup-item-kind.badge-files {
|
||
color: rgb(251, 191, 36);
|
||
}
|
||
|
||
.popup-item-actions {
|
||
display: flex;
|
||
gap: 2px;
|
||
opacity: 0;
|
||
transition: opacity 0.1s;
|
||
}
|
||
|
||
/* 选中项和悬停项都显示操作按钮 */
|
||
.popup-item:hover .popup-item-actions,
|
||
.popup-item-selected .popup-item-actions {
|
||
opacity: 1;
|
||
}
|
||
|
||
.popup-action-btn {
|
||
background: transparent;
|
||
border: none;
|
||
cursor: pointer;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
border-radius: var(--radius-sm);
|
||
color: var(--muted-foreground);
|
||
transition: background-color 0.1s, color 0.1s;
|
||
}
|
||
|
||
.popup-action-btn:hover {
|
||
background: var(--muted);
|
||
color: var(--foreground);
|
||
}
|
||
|
||
/* 空状态(使用 Tailwind 类,无需额外 CSS) */
|
||
|
||
/* 底部 */
|
||
.popup-footer {
|
||
display: flex;
|
||
justify-content: center;
|
||
gap: 16px;
|
||
padding: 6px 12px;
|
||
border-top: 1px solid var(--border);
|
||
font-size: 11px;
|
||
color: var(--muted-foreground);
|
||
}
|
||
|
||
.popup-footer kbd {
|
||
background: var(--muted);
|
||
color: var(--foreground);
|
||
padding: 1px 5px;
|
||
border-radius: 3px;
|
||
font-size: 10px;
|
||
margin-right: 2px;
|
||
font-family: inherit;
|
||
}
|
||
|
||
/* 滚动条 */
|
||
.popup-list::-webkit-scrollbar {
|
||
width: 6px;
|
||
}
|
||
|
||
.popup-list::-webkit-scrollbar-thumb {
|
||
background: var(--muted-foreground);
|
||
opacity: 0.3;
|
||
border-radius: 3px;
|
||
}
|
||
|
||
.popup-list::-webkit-scrollbar-track {
|
||
background: transparent;
|
||
}
|
||
</style>
|