feat: 开发收藏和下载功能
This commit is contained in:
@@ -22,7 +22,7 @@ import {
|
||||
} from '../shared/data/fontProfiles';
|
||||
import { loadLetterFont } from '../shared/draw/drawTools';
|
||||
import type { DebugPublishMeta } from '../../utils/debugPublish';
|
||||
import { incrementWorksheetLikes } from '../../utils/worksheetStats';
|
||||
import { addFavorite, removeFavorite, batchCheckFavorited } from '../../utils/favorites';
|
||||
|
||||
/** 三字母精练分组:26 字母每 3 个一组 */
|
||||
const TRIPLE_GROUPS: { title: string; letters: string[] }[] = [];
|
||||
@@ -82,6 +82,7 @@ createPage(
|
||||
boxWidth: 0,
|
||||
drawService: null as LetterTracingDraw | null,
|
||||
fontProfile: DEFAULT_LETTER_PROFILE as FontProfile,
|
||||
_favoritedMap: {} as Record<string, boolean>,
|
||||
|
||||
data: {
|
||||
pageTitle: '字母描红',
|
||||
@@ -147,6 +148,8 @@ createPage(
|
||||
updates as Partial<PageData> & WechatMiniprogram.IAnyObject,
|
||||
);
|
||||
}
|
||||
|
||||
this.loadFavoritedMap();
|
||||
},
|
||||
|
||||
/** 用户点击模式选择器时切换 worksheet */
|
||||
@@ -275,8 +278,14 @@ createPage(
|
||||
async onPreviewFavorite() {
|
||||
const next = !this.data.isPreviewFavorite;
|
||||
this.setData({ isPreviewFavorite: next });
|
||||
if (next) {
|
||||
incrementWorksheetLikes(this.data.worksheetId);
|
||||
const id = this.data.worksheetId;
|
||||
if (id) {
|
||||
this._favoritedMap[id] = next;
|
||||
if (next) {
|
||||
addFavorite(id);
|
||||
} else {
|
||||
removeFavorite(id);
|
||||
}
|
||||
}
|
||||
wx.showToast({
|
||||
title: next ? '收藏成功' : '已取消收藏',
|
||||
@@ -284,6 +293,15 @@ createPage(
|
||||
});
|
||||
},
|
||||
|
||||
async loadFavoritedMap() {
|
||||
const ids = LETTER_TRACING_MODE_OPTIONS.map((d) => d.id);
|
||||
this._favoritedMap = await batchCheckFavorited(ids);
|
||||
const currentId = this.data.worksheetId;
|
||||
if (this._favoritedMap[currentId]) {
|
||||
this.setData({ isPreviewFavorite: true });
|
||||
}
|
||||
},
|
||||
|
||||
getPublishMeta(): DebugPublishMeta {
|
||||
const meta = getPublishMetaByMode(this.data.worksheetId);
|
||||
if (!meta) {
|
||||
@@ -358,7 +376,7 @@ createPage(
|
||||
worksheetId,
|
||||
functionId: worksheetId,
|
||||
traceMode,
|
||||
isPreviewFavorite: false,
|
||||
isPreviewFavorite: !!this._favoritedMap[worksheetId],
|
||||
selectedLetter,
|
||||
selectedLetterPair: `${selectedLetter}${selectedLetter.toLowerCase()}`,
|
||||
letterCaseLower,
|
||||
|
||||
Reference in New Issue
Block a user