feat: 完成分龄页开发
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import type { DebugPublishMeta } from '../../utils/debugPublish';
|
||||
import { inferGradeFromAge } from '../../utils/debugPublish';
|
||||
|
||||
interface FocusDrawDefinition {
|
||||
/** 本地 worksheet 元数据(与云库 `worksheets` 文档 `_id` 对齐) */
|
||||
interface FocusWorksheetDefinition {
|
||||
id: string;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
@@ -12,7 +13,7 @@ interface FocusDrawDefinition {
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
const FOCUS_DRAW_DEFINITIONS = [
|
||||
export const FOCUS_WORKSHEET_DEFINITIONS = [
|
||||
{
|
||||
id: 'color-shape-match',
|
||||
title: '根据颜色画图形',
|
||||
@@ -68,7 +69,7 @@ const FOCUS_DRAW_DEFINITIONS = [
|
||||
title: '线条识别',
|
||||
subtitle: '认识不同线条,画对应线条',
|
||||
ageMin: 3,
|
||||
ageMax: 5,
|
||||
ageMax: 6,
|
||||
difficulty: 1,
|
||||
tags: ['专注力', '线条', '识别', '控笔'],
|
||||
sortOrder: 206,
|
||||
@@ -97,7 +98,7 @@ const FOCUS_DRAW_DEFINITIONS = [
|
||||
id: 'dot-connect',
|
||||
title: '数字点连线',
|
||||
subtitle: '按数字顺序连点成图',
|
||||
ageMin: 3,
|
||||
ageMin: 4,
|
||||
ageMax: 6,
|
||||
difficulty: 1,
|
||||
tags: ['专注力', '数字', '连线'],
|
||||
@@ -127,19 +128,19 @@ const FOCUS_DRAW_DEFINITIONS = [
|
||||
id: 'grid-drawing-7x7',
|
||||
title: '格子仿画 7×7',
|
||||
subtitle: '大师挑战,锻炼耐心',
|
||||
ageMin: 5,
|
||||
ageMin: 6,
|
||||
ageMax: 8,
|
||||
difficulty: 3,
|
||||
tags: ['专注力', '格子仿画', '耐心'],
|
||||
sortOrder: 212,
|
||||
},
|
||||
] as const satisfies ReadonlyArray<FocusDrawDefinition>;
|
||||
] as const satisfies ReadonlyArray<FocusWorksheetDefinition>;
|
||||
|
||||
type FocusDrawDefinitionItem = (typeof FOCUS_DRAW_DEFINITIONS)[number];
|
||||
type FocusWorksheetDefinitionItem = (typeof FOCUS_WORKSHEET_DEFINITIONS)[number];
|
||||
|
||||
const FOCUS_DRAW_BY_ID = Object.fromEntries(
|
||||
FOCUS_DRAW_DEFINITIONS.map((item) => [item.id, item]),
|
||||
) as Record<string, FocusDrawDefinitionItem>;
|
||||
const FOCUS_WORKSHEET_BY_ID = Object.fromEntries(
|
||||
FOCUS_WORKSHEET_DEFINITIONS.map((item) => [item.id, item]),
|
||||
) as Record<string, FocusWorksheetDefinitionItem>;
|
||||
|
||||
function resolveFocusPublishId(
|
||||
routeId: string,
|
||||
@@ -150,7 +151,7 @@ function resolveFocusPublishId(
|
||||
return `grid-drawing-${mode || '3x3'}`;
|
||||
}
|
||||
|
||||
if (routeId in FOCUS_DRAW_BY_ID) {
|
||||
if (routeId in FOCUS_WORKSHEET_BY_ID) {
|
||||
return routeId;
|
||||
}
|
||||
|
||||
@@ -163,7 +164,7 @@ export function getPublishMetaByFocusState(
|
||||
mode?: string,
|
||||
): DebugPublishMeta | null {
|
||||
const id = resolveFocusPublishId(routeId, selectedTypeId, mode);
|
||||
const item = FOCUS_DRAW_BY_ID[id];
|
||||
const item = FOCUS_WORKSHEET_BY_ID[id];
|
||||
if (!item) return null;
|
||||
|
||||
return {
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from './registry';
|
||||
import { getPublishMetaByFocusState } from './focusDraw.config';
|
||||
import type { DebugPublishMeta } from '../../utils/debugPublish';
|
||||
import { incrementWorksheetLikes } from '../../utils/worksheetStats';
|
||||
|
||||
const TYPE_LIST = FOCUS_TYPE_CONFIGS.map((t) => ({
|
||||
id: t.id,
|
||||
@@ -120,6 +121,7 @@ createFocusPage({
|
||||
selectedTypeId: id,
|
||||
functionId: id,
|
||||
pageTitle: title,
|
||||
isPreviewFavorite: false,
|
||||
showActions: !!typeConfig.actions,
|
||||
currentActions: typeConfig.actions || [],
|
||||
actionsTitle: typeConfig.actionsTitle || '选择模式',
|
||||
@@ -156,6 +158,7 @@ createFocusPage({
|
||||
this.setData({
|
||||
currentMode: value,
|
||||
pageTitle: title,
|
||||
isPreviewFavorite: false,
|
||||
});
|
||||
|
||||
this.initPageInfo(this.data.functionId, title);
|
||||
@@ -196,15 +199,28 @@ createFocusPage({
|
||||
this.onRandom();
|
||||
},
|
||||
|
||||
onPreviewFavorite() {
|
||||
async onPreviewFavorite() {
|
||||
const next = !this.data.isPreviewFavorite;
|
||||
this.setData({ isPreviewFavorite: next });
|
||||
if (next) {
|
||||
const id = this.getWorksheetStatsId();
|
||||
if (id) incrementWorksheetLikes(id);
|
||||
}
|
||||
wx.showToast({
|
||||
title: next ? '收藏成功' : '已取消收藏',
|
||||
icon: 'none',
|
||||
});
|
||||
},
|
||||
|
||||
getWorksheetStatsId(): string {
|
||||
const meta = getPublishMetaByFocusState(
|
||||
this.data.functionId,
|
||||
this.data.selectedTypeId,
|
||||
this.data.currentMode,
|
||||
);
|
||||
return meta?.id || this.data.functionId;
|
||||
},
|
||||
|
||||
getPublishMeta(): DebugPublishMeta {
|
||||
const meta = getPublishMetaByFocusState(
|
||||
this.data.functionId,
|
||||
|
||||
Reference in New Issue
Block a user