update at 2026-02-09 09:48:44

This commit is contained in:
douboer
2026-02-09 09:48:44 +08:00
parent 77a0c7b741
commit 49c70efed0
4 changed files with 244 additions and 38 deletions

View File

@@ -30,10 +30,13 @@ const LOCAL_ICON_PATHS = {
fontIcon: '/assets/icons/font-icon.svg', // 字体item图标
expandIcon: '/assets/icons/expand.svg', // 展开分类图标
collapseIcon: '/assets/icons/expand.svg', // 折叠使用同一图标,通过旋转实现
favoriteIcon: '/assets/icons/favorite.svg', // 收藏图标(未收藏白色底,收藏红色底
checkbox: '/assets/icons/checkbox.svg', // 复选框(未选中
checkboxChecked: '/assets/icons/checkbox-no.svg', // 复选框(选中)
favoriteIcon: '/assets/icons/favorite.svg', // 收藏图标(未收藏)
favoriteRedIcon: '/assets/icons/favorite-red.svg', // 已收藏图标(红色
checkbox: '/assets/icons/checkbox-no.svg', // 复选框(选中)
checkboxChecked: '/assets/icons/checkbox.svg', // 复选框(已选中)
search: '/assets/icons/search.svg', // 搜索图标
selectAll: '/assets/icons/selectall.svg', // 全选图标
unselectAll: '/assets/icons/unselectall.svg', // 取消全选图标
}
function toSvgDataUri(svg) {
@@ -156,7 +159,7 @@ Page({
icons: LOCAL_ICON_PATHS,
// 搜索功能
searchKeyword: '',
showSearch: false,
showSearch: true,
},
async onLoad() {
@@ -233,6 +236,8 @@ Page({
}))
this.setData({ selectedFonts })
// 更新字体树以反映选中状态
this.updateFontTrees()
await this.generateAllPreviews()
}
} catch (error) {
@@ -284,6 +289,7 @@ Page({
? true
: (typeof expandedFromState === 'boolean' ? expandedFromState : false),
fonts: [],
allSelected: false,
})
}
categoryMap.get(category).fonts.push({
@@ -303,6 +309,15 @@ Page({
})
const fontCategories = Array.from(categoryMap.values()).sort((a, b) => a.category.localeCompare(b.category))
// 计算每个分类的allSelected状态
fontCategories.forEach(cat => {
if (cat.fonts.length > 0) {
cat.allSelected = cat.fonts.every(f => f.selected)
} else {
cat.allSelected = false
}
})
favoriteFonts.sort((a, b) => {
const categoryCompare = String(a.category || '').localeCompare(String(b.category || ''))
if (categoryCompare !== 0) return categoryCompare
@@ -414,6 +429,56 @@ Page({
}
},
// 切换分类全选/取消全选
onToggleSelectAllInCategory(e) {
const category = e.currentTarget.dataset.category
if (!category) return
const categoryFonts = this.data.fontCategories.find(c => c.category === category)
if (!categoryFonts || categoryFonts.fonts.length === 0) return
const allSelected = categoryFonts.allSelected
const selectedFonts = [...this.data.selectedFonts]
const selectedIdSet = new Set(selectedFonts.map(f => f.id))
if (allSelected) {
// 取消全选:移除该分类下的所有字体
categoryFonts.fonts.forEach(font => {
selectedIdSet.delete(font.id)
})
} else {
// 全选:添加该分类下的所有字体
categoryFonts.fonts.forEach(font => {
selectedIdSet.add(font.id)
})
}
const newSelectedFonts = []
this.fontMap.forEach(font => {
if (selectedIdSet.has(font.id)) {
newSelectedFonts.push({
id: font.id,
name: font.name,
category: font.category,
showInPreview: true,
previewSrc: '',
})
}
})
this.setData({ selectedFonts: newSelectedFonts })
this.updateFontTrees()
this.scheduleGenerate()
saveAppState({
inputText: this.data.inputText,
selectedFontIds: newSelectedFonts.map(f => f.id),
fontSize: Number(this.data.fontSize),
letterSpacing: Number(this.data.letterSpacingInput || 0),
textColor: this.data.textColor,
})
},
// 生成单个字体的预览
async generatePreviewForFont(fontId) {
const text = String(this.data.inputText || '')