update at 2026-02-07 14:10:02

This commit is contained in:
douboer
2026-02-07 14:10:02 +08:00
parent 593027578a
commit dcaac46f65
6 changed files with 265 additions and 27 deletions

View File

@@ -23,6 +23,10 @@ export const useFontStore = defineStore('font', () => {
}
}
function filterSetByValidIds(source: Set<string>, validIds: Set<string>): Set<string> {
return new Set(Array.from(source).filter(id => validIds.has(id)))
}
// 状态
const fonts = ref<FontInfo[]>([])
const selectedFontIds = ref<Set<string>>(new Set())
@@ -54,6 +58,23 @@ export const useFontStore = defineStore('font', () => {
fonts.value.push(fontInfo)
}
function replaceFonts(nextFonts: FontInfo[]) {
const validIds = new Set(nextFonts.map(font => font.id))
selectedFontIds.value = filterSetByValidIds(selectedFontIds.value, validIds)
favoriteFontIds.value = filterSetByValidIds(favoriteFontIds.value, validIds)
previewFontIds.value = filterSetByValidIds(previewFontIds.value, validIds)
writeSet('font.favoriteFontIds', favoriteFontIds.value)
writeSet('font.previewFontIds', previewFontIds.value)
fonts.value = nextFonts.map(font => ({
...font,
isFavorite: favoriteFontIds.value.has(font.id),
}))
updateFontTree()
}
function removeFont(fontId: string) {
const index = fonts.value.findIndex(f => f.id === fontId)
if (index !== -1) {
@@ -229,6 +250,7 @@ export const useFontStore = defineStore('font', () => {
// 方法
addFont,
replaceFonts,
removeFont,
selectFont,
unselectFont,