性能优化
This commit is contained in:
@@ -6,6 +6,8 @@ import { invoke } from '@tauri-apps/api/core'
|
||||
import { getCurrentWindow } from '@tauri-apps/api/window'
|
||||
import { useSearchStore, type SearchItem } from '@/stores/searchStore'
|
||||
import { useModuleTabsStore } from '@/stores/moduleTabsStore'
|
||||
// 复用快速面板匹配引擎(支持拼音/子序列模糊匹配)
|
||||
import { getTextForms, bestScore } from '@/modules/quickpanel/engine'
|
||||
|
||||
const tabsStore = useModuleTabsStore()
|
||||
|
||||
@@ -23,10 +25,12 @@ const searchStore = useSearchStore()
|
||||
|
||||
const filteredModules = computed(() => {
|
||||
if (!searchQuery.value.trim()) return []
|
||||
const query = searchQuery.value.toLowerCase()
|
||||
return props.modules.filter(m =>
|
||||
m.name.toLowerCase().includes(query) || m.id.toLowerCase().includes(query)
|
||||
)
|
||||
const query = searchQuery.value.trim()
|
||||
return props.modules
|
||||
.map(m => ({ m, score: Math.max(bestScore(query, getTextForms(m.name)), bestScore(query, getTextForms(m.id))) }))
|
||||
.filter(e => e.score > 0)
|
||||
.sort((a, b) => b.score - a.score)
|
||||
.map(e => e.m)
|
||||
})
|
||||
|
||||
const searchResults = computed(() => {
|
||||
@@ -68,6 +72,7 @@ const minimize = async () => {
|
||||
// 窗口最大化状态:切换最大化/还原图标
|
||||
const isMaximized = ref(false)
|
||||
let unlistenMaximize: (() => void) | null = null
|
||||
let unlistenFocus: (() => void) | null = null
|
||||
|
||||
const maximize = async () => {
|
||||
await tauriWindow?.toggleMaximize()
|
||||
@@ -118,7 +123,8 @@ const close = async () => {
|
||||
}
|
||||
|
||||
if (tauriWindow) {
|
||||
tauriWindow.onFocusChanged(({ payload: focused }) => {
|
||||
// 保存 unlisten,onUnmounted 时释放(onFocusChanged 返回 Promise<UnlistenFn>)
|
||||
void tauriWindow.onFocusChanged(({ payload: focused }) => {
|
||||
if (focused) {
|
||||
hoverSuppressed.value = true
|
||||
if (document.activeElement instanceof HTMLElement) {
|
||||
@@ -131,6 +137,8 @@ if (tauriWindow) {
|
||||
} else {
|
||||
hoverSuppressed.value = true
|
||||
}
|
||||
}).then(fn => {
|
||||
unlistenFocus = fn
|
||||
})
|
||||
}
|
||||
|
||||
@@ -202,6 +210,7 @@ onUnmounted(() => {
|
||||
window.removeEventListener('mousemove', handleFirstMouseMove)
|
||||
if (restoreHoverTimer) clearTimeout(restoreHoverTimer)
|
||||
if (unlistenMaximize) unlistenMaximize()
|
||||
if (unlistenFocus) unlistenFocus()
|
||||
if (scrollViewport) scrollViewport.removeEventListener('scroll', handleMainScroll)
|
||||
if (rafId !== null) cancelAnimationFrame(rafId)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user