性能优化
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, onUnmounted, watch, nextTick } from 'vue'
|
||||
import { ref, onUnmounted, watch, nextTick } from 'vue'
|
||||
import {
|
||||
Keyboard, Settings, FolderOpen, Camera, Copy, Save, Trash2, Timer,
|
||||
Image as ImageIcon, Loader2,
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
import { toast } from 'vue-sonner'
|
||||
import { open } from '@tauri-apps/plugin-dialog'
|
||||
import { useScreenshotStore, type RecentCapture } from '@/stores/screenshotStore'
|
||||
import { useModuleTabs } from '@/lib/useModuleTabs'
|
||||
import { useModuleTabs } from '@/lib/use-module-tabs'
|
||||
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
@@ -35,7 +35,7 @@ function formatTime(t: number): string {
|
||||
}
|
||||
|
||||
function thumbSrc(item: RecentCapture): string {
|
||||
return `data:image/png;base64,${item.pngBase64}`
|
||||
return item.thumb
|
||||
}
|
||||
|
||||
async function handleCapture() {
|
||||
@@ -51,16 +51,26 @@ async function chooseSaveDir() {
|
||||
}
|
||||
|
||||
async function handleCopy(item: RecentCapture) {
|
||||
await store.copyImage(item.pngBase64)
|
||||
try {
|
||||
// 完整图从缓存按需加载(历史内存只保留缩略图)
|
||||
const full = await store.loadFullImage(item)
|
||||
await store.copyImage(full)
|
||||
} catch (e) {
|
||||
toast.error('加载完整图失败: ' + e)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSave(item: RecentCapture) {
|
||||
await store.saveImage(item.pngBase64)
|
||||
try {
|
||||
const full = await store.loadFullImage(item)
|
||||
await store.saveImage(full)
|
||||
} catch (e) {
|
||||
toast.error('加载完整图失败: ' + e)
|
||||
}
|
||||
}
|
||||
|
||||
function handleDelete(item: RecentCapture) {
|
||||
const idx = store.recent.findIndex(r => r.id === item.id)
|
||||
if (idx >= 0) store.recent.splice(idx, 1)
|
||||
void store.removeRecent(item)
|
||||
toast.success('已从历史移除')
|
||||
}
|
||||
|
||||
@@ -149,12 +159,10 @@ async function clearShortcut() {
|
||||
toast.success('已禁用截图快捷键')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
store.initExportListener().catch(e => console.error('[screenshot] 导出监听初始化失败:', e))
|
||||
})
|
||||
// 导出监听(screenshot-exported)由应用级注册(main.ts/App.vue),随应用生命周期管理;
|
||||
// 模块卸载不得销毁该单例监听,否则离开截图模块后全局快捷键截图将不记录历史/不自动保存。
|
||||
|
||||
onUnmounted(() => {
|
||||
store.destroyExportListener()
|
||||
window.removeEventListener('keydown', onRecordKey, true)
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user