feat: 首页跳转到分类页指定分类优化
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { CATEGORY_LIST_WITH_ALL } from '../../core/data/categories';
|
||||
import { takePendingCategoryTabId } from '../../utils/index';
|
||||
import { CATEGORY_DATA, type CategoryItem } from './category.data';
|
||||
|
||||
type CategoryTab = {
|
||||
@@ -190,10 +191,10 @@ Page({
|
||||
onShow() {
|
||||
_categoryData = null;
|
||||
this.setData({ displayItems: SKELETON_ITEMS, loading: true });
|
||||
void this.loadWorksheets();
|
||||
void this.loadWorksheets(takePendingCategoryTabId() ?? undefined);
|
||||
},
|
||||
|
||||
async loadWorksheets() {
|
||||
async loadWorksheets(overrideCategoryId?: string | null) {
|
||||
try {
|
||||
const res = await wx.cloud.callFunction({
|
||||
name: 'worksheetsQuery',
|
||||
@@ -207,7 +208,11 @@ Page({
|
||||
_categoryData = CATEGORY_DATA;
|
||||
}
|
||||
|
||||
const activeId = this.data.activeCategoryId || this._defaultCategoryId;
|
||||
const activeId =
|
||||
overrideCategoryId != null &&
|
||||
String(overrideCategoryId).trim() !== ''
|
||||
? String(overrideCategoryId).trim()
|
||||
: this.data.activeCategoryId || this._defaultCategoryId;
|
||||
const items = getItemsByCategory(activeId);
|
||||
const filtered = filterByKeyword(items, this.data.searchKeyword);
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ export const HOME_PRODUCT_TARGET_DATA: HomeDisplayDataset = {
|
||||
id: 'math',
|
||||
title: '数学启蒙',
|
||||
subtitle: '数字认知、计数练习、加减运算、时钟与形状',
|
||||
morePath: '/pages/mathIndex/mathIndex',
|
||||
morePath: '/pages/category/category?id=math',
|
||||
items: [
|
||||
{
|
||||
id: 'target-math-1',
|
||||
@@ -221,7 +221,7 @@ export const HOME_PRODUCT_TARGET_DATA: HomeDisplayDataset = {
|
||||
id: 'chinese',
|
||||
title: '语文启蒙',
|
||||
subtitle: '识字、练字、拼音、表达训练',
|
||||
morePath: '/pages/index/index',
|
||||
morePath: '/pages/category/category?id=chinese',
|
||||
items: [
|
||||
{
|
||||
id: 'target-chinese-1',
|
||||
@@ -277,7 +277,7 @@ export const HOME_PRODUCT_TARGET_DATA: HomeDisplayDataset = {
|
||||
id: 'english',
|
||||
title: '英语启蒙',
|
||||
subtitle: '字母学习、闪卡、描红与自然拼读',
|
||||
morePath: '/englishPages/letterTracing/letterTracing',
|
||||
morePath: '/pages/category/category?id=english',
|
||||
items: [
|
||||
{
|
||||
id: 'target-english-1',
|
||||
@@ -321,7 +321,7 @@ export const HOME_PRODUCT_TARGET_DATA: HomeDisplayDataset = {
|
||||
id: 'puzzle',
|
||||
title: '益智游戏',
|
||||
subtitle: '迷宫、找不同、连线、数独与控笔',
|
||||
morePath: '/pages/focusIndex/focusIndex',
|
||||
morePath: '/pages/category/category?id=puzzle',
|
||||
items: [
|
||||
{
|
||||
id: 'target-puzzle-1',
|
||||
@@ -519,7 +519,7 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
id: 'math',
|
||||
title: '数感启蒙',
|
||||
subtitle: '优先展示现有高价值、高覆盖的数感与运算内容',
|
||||
morePath: '/pages/mathIndex/mathIndex',
|
||||
morePath: '/pages/category/category?id=math',
|
||||
items: [
|
||||
{
|
||||
id: 'current-math-1',
|
||||
@@ -581,7 +581,8 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
ageBand: '7-8岁',
|
||||
difficulty: '挑战',
|
||||
icon: '✖️',
|
||||
previewImg: '/assets/entrancePicture/math/multiplication-table.png',
|
||||
previewImg:
|
||||
'/assets/entrancePicture/math/multiplication-table.png',
|
||||
path: '/mathPages/mathDraw/mathDraw?id=multiplication-table',
|
||||
available: true,
|
||||
source: 'multiplicationTable',
|
||||
@@ -590,9 +591,9 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
},
|
||||
{
|
||||
id: 'chinese',
|
||||
title: '趣味识字',
|
||||
title: '识字练字',
|
||||
subtitle: '用现有识字与练字能力先覆盖核心语文场景',
|
||||
morePath: '/pages/index/index',
|
||||
morePath: '/pages/category/category?id=chinese',
|
||||
items: [
|
||||
{
|
||||
id: 'current-chinese-1',
|
||||
@@ -636,7 +637,7 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
id: 'puzzle',
|
||||
title: '益智游戏',
|
||||
subtitle: '从现有专注力模块中抽取最符合产品重设计的内容',
|
||||
morePath: '/pages/focusIndex/focusIndex',
|
||||
morePath: '/pages/category/category?id=puzzle',
|
||||
items: [
|
||||
{
|
||||
id: 'current-puzzle-1',
|
||||
@@ -659,7 +660,8 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
ageBand: '4-6岁',
|
||||
difficulty: '基础',
|
||||
icon: '🧵',
|
||||
previewImg: '/assets/entrancePicture/focus/match-connect.png',
|
||||
previewImg:
|
||||
'/assets/entrancePicture/focus/match-connect.png',
|
||||
path: '/focusPages/focusDraw/focusDraw?id=match-connect',
|
||||
available: true,
|
||||
source: 'match-connect',
|
||||
@@ -672,7 +674,8 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
ageBand: '4-6岁',
|
||||
difficulty: '基础',
|
||||
icon: '🌈',
|
||||
previewImg: '/assets/entrancePicture/focus/color-pattern.png',
|
||||
previewImg:
|
||||
'/assets/entrancePicture/focus/color-pattern.png',
|
||||
path: '/focusPages/focusDraw/focusDraw?id=color-pattern',
|
||||
available: true,
|
||||
source: 'color-pattern',
|
||||
@@ -685,7 +688,8 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
ageBand: '5-7岁',
|
||||
difficulty: '进阶',
|
||||
icon: '🧠',
|
||||
previewImg: '/assets/entrancePicture/focus/grid-reasoning.png',
|
||||
previewImg:
|
||||
'/assets/entrancePicture/focus/grid-reasoning.png',
|
||||
path: '/focusPages/focusDraw/focusDraw?id=grid-reasoning',
|
||||
available: true,
|
||||
source: 'grid-reasoning',
|
||||
@@ -698,7 +702,8 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
ageBand: '4-7岁',
|
||||
difficulty: '进阶',
|
||||
icon: '🟨',
|
||||
previewImg: '/assets/entrancePicture/focus/grid-drawing-5x5.png',
|
||||
previewImg:
|
||||
'/assets/entrancePicture/focus/grid-drawing-5x5.png',
|
||||
path: '/focusPages/focusDraw/focusDraw?id=grid-drawing',
|
||||
available: true,
|
||||
source: 'grid-drawing',
|
||||
@@ -709,7 +714,7 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
id: 'english',
|
||||
title: '英语启蒙',
|
||||
subtitle: '多种描红版式,认读与书写循序渐进',
|
||||
morePath: '/englishPages/letterTracing/letterTracing',
|
||||
morePath: '/pages/category/category?id=english',
|
||||
items: [
|
||||
{
|
||||
id: 'current-english-1',
|
||||
@@ -719,7 +724,8 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
ageBand: '4-7岁',
|
||||
difficulty: '入门',
|
||||
icon: '',
|
||||
previewImg: '/assets/entrancePicture/english/letter-tracing-single.jpg',
|
||||
previewImg:
|
||||
'/assets/entrancePicture/english/letter-tracing-single.jpg',
|
||||
path: '/englishPages/letterTracing/letterTracing?id=letter-tracing-single',
|
||||
available: true,
|
||||
source: 'letter-tracing-single',
|
||||
@@ -732,7 +738,8 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
ageBand: '4-7岁',
|
||||
difficulty: '入门',
|
||||
icon: '',
|
||||
previewImg: '/assets/entrancePicture/english/letter-tracing-upper-lower.jpg',
|
||||
previewImg:
|
||||
'/assets/entrancePicture/english/letter-tracing-upper-lower.jpg',
|
||||
path: '/englishPages/letterTracing/letterTracing?id=letter-tracing-upper-lower',
|
||||
available: true,
|
||||
source: 'letter-tracing-upper-lower',
|
||||
@@ -745,7 +752,8 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
ageBand: '4-7岁',
|
||||
difficulty: '入门',
|
||||
icon: '',
|
||||
previewImg: '/assets/entrancePicture/english/letter-tracing-case-pairing.jpg',
|
||||
previewImg:
|
||||
'/assets/entrancePicture/english/letter-tracing-case-pairing.jpg',
|
||||
path: '/englishPages/letterTracing/letterTracing?id=letter-tracing-case-pairing',
|
||||
available: true,
|
||||
source: 'letter-tracing-case-pairing',
|
||||
@@ -758,7 +766,8 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
ageBand: '4-7岁',
|
||||
difficulty: '入门',
|
||||
icon: '',
|
||||
previewImg: '/assets/entrancePicture/english/letter-tracing-two-column.jpg',
|
||||
previewImg:
|
||||
'/assets/entrancePicture/english/letter-tracing-two-column.jpg',
|
||||
path: '/englishPages/letterTracing/letterTracing?id=letter-tracing-two-column',
|
||||
available: true,
|
||||
source: 'letter-tracing-two-column',
|
||||
@@ -771,7 +780,8 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
ageBand: '4-7岁',
|
||||
difficulty: '入门',
|
||||
icon: '',
|
||||
previewImg: '/assets/entrancePicture/english/letter-tracing-half.jpg',
|
||||
previewImg:
|
||||
'/assets/entrancePicture/english/letter-tracing-half.jpg',
|
||||
path: '/englishPages/letterTracing/letterTracing?id=letter-tracing-half',
|
||||
available: true,
|
||||
source: 'letter-tracing-half',
|
||||
@@ -784,7 +794,8 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
ageBand: '4-7岁',
|
||||
difficulty: '入门',
|
||||
icon: '',
|
||||
previewImg: '/assets/entrancePicture/english/letter-tracing-three.jpg',
|
||||
previewImg:
|
||||
'/assets/entrancePicture/english/letter-tracing-three.jpg',
|
||||
path: '/englishPages/letterTracing/letterTracing?id=letter-tracing-three',
|
||||
available: true,
|
||||
source: 'letter-tracing-three',
|
||||
@@ -795,7 +806,7 @@ export const HOME_CURRENT_CAPABILITY_DATA: HomeDisplayDataset = {
|
||||
id: 'craft',
|
||||
title: '创意手工',
|
||||
subtitle: '暂用最接近创意表达的现有能力承接展示位',
|
||||
morePath: '/pages/index/index',
|
||||
morePath: '/pages/category/category?id=craft',
|
||||
items: [
|
||||
{
|
||||
id: 'current-craft-1',
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { NAV_INNER_PX } from '../../utils/navMetrics';
|
||||
import { parseMiniProgramUrl } from '../../utils/index';
|
||||
import {
|
||||
parseMiniProgramUrl,
|
||||
stashPendingCategoryTabId,
|
||||
} from '../../utils/index';
|
||||
import {
|
||||
HOME_CURRENT_CAPABILITY_DATA,
|
||||
type HomeDisplayItem,
|
||||
@@ -78,8 +81,13 @@ function navigateByPath(path?: string, fallbackTitle?: string) {
|
||||
const { path: basePath, query } = parseMiniProgramUrl(path);
|
||||
|
||||
if (TAB_BAR_PATHS.has(basePath)) {
|
||||
// tabBar 页面不支持携带 query/hash,统一跳到 basePath
|
||||
if (Object.keys(query).length > 0) {
|
||||
if (
|
||||
basePath === '/pages/category/category' &&
|
||||
query.id &&
|
||||
String(query.id).trim() !== ''
|
||||
) {
|
||||
stashPendingCategoryTabId(String(query.id).trim());
|
||||
} else if (Object.keys(query).length > 0) {
|
||||
console.warn(
|
||||
'[navigateByPath] tabBar 不支持携带参数,已忽略 query:',
|
||||
basePath,
|
||||
@@ -245,7 +253,7 @@ Page({
|
||||
},
|
||||
|
||||
onTapHotMore() {
|
||||
wx.showToast({ title: '热门内容整理中', icon: 'none' });
|
||||
navigateByPath('/pages/category/category?id=hot');
|
||||
},
|
||||
|
||||
onTapTrackMore(e: WechatMiniprogram.TouchEvent) {
|
||||
@@ -257,8 +265,7 @@ Page({
|
||||
onTapCard(e: WechatMiniprogram.CustomEvent) {
|
||||
const detail = (e.detail || {}) as { title?: string; path?: string };
|
||||
const path =
|
||||
detail.path ||
|
||||
(e.currentTarget.dataset.path as string | undefined);
|
||||
detail.path || (e.currentTarget.dataset.path as string | undefined);
|
||||
const title =
|
||||
detail.title ||
|
||||
(e.currentTarget.dataset.title as string | undefined);
|
||||
|
||||
Reference in New Issue
Block a user