update at 2026-02-07 14:54:45

This commit is contained in:
douboer
2026-02-07 14:54:45 +08:00
parent 7fcb84aed6
commit 6733ce3e9f
2 changed files with 121 additions and 26 deletions

View File

@@ -31,6 +31,7 @@ export const useFontStore = defineStore('font', () => {
const expandedCategoryNames = ref<Set<string>>(readSet('font.expandedCategories'))
const fontTree = ref<FontTreeNode[]>([])
const isLoadingFonts = ref(false)
const loadingFontTasks = new Map<string, Promise<void>>()
// 计算属性
const selectedFonts = computed(() => {
@@ -151,17 +152,31 @@ export const useFontStore = defineStore('font', () => {
return
}
try {
const font = await loadFontWithProgress(fontInfo.path, (progress) => {
fontInfo.progress = progress
})
fontInfo.font = font
fontInfo.loaded = true
fontInfo.progress = 100
} catch (error) {
console.error(`Failed to load font ${fontInfo.name}:`, error)
throw error
const existingTask = loadingFontTasks.get(fontInfo.id)
if (existingTask) {
await existingTask
return
}
const loadingTask = (async () => {
try {
const font = await loadFontWithProgress(fontInfo.path, (progress) => {
fontInfo.progress = progress
})
fontInfo.font = font
fontInfo.loaded = true
fontInfo.progress = 100
} catch (error) {
console.error(`Failed to load font ${fontInfo.name}:`, error)
throw error
} finally {
loadingFontTasks.delete(fontInfo.id)
}
})()
loadingFontTasks.set(fontInfo.id, loadingTask)
await loadingTask
}
function buildFontTree(fontList: FontInfo[]): FontTreeNode[] {