89 lines
2.7 KiB
TypeScript
89 lines
2.7 KiB
TypeScript
import { ALL_WORKSHEETS, getWorksheetsByCategory, getWorksheetPath } from '../../core/data/worksheets';
|
|
import { CATEGORIES } from '../../core/data/categories';
|
|
import { WorksheetType } from '../../core/models/worksheet';
|
|
|
|
const CATEGORY_TABS = [
|
|
{ id: 'all', name: '全部' },
|
|
...CATEGORIES.map((c) => ({ id: c.id, name: c.name })),
|
|
];
|
|
|
|
Page({
|
|
data: {
|
|
tabs: CATEGORY_TABS,
|
|
activeTab: 'all',
|
|
sections: [] as Array<{ title: string; icon: string; category: string; items: WorksheetType[] }>,
|
|
hotItems: [] as WorksheetType[],
|
|
filteredItems: null as WorksheetType[] | null,
|
|
},
|
|
|
|
onLoad() {
|
|
const sections = CATEGORIES.filter((cat) => {
|
|
const items = getWorksheetsByCategory(cat.id);
|
|
return items.length > 0;
|
|
}).map((cat) => ({
|
|
title: cat.name,
|
|
icon: cat.icon,
|
|
category: cat.id,
|
|
items: getWorksheetsByCategory(cat.id).slice(0, 3),
|
|
}));
|
|
|
|
const hotItems = ALL_WORKSHEETS.filter((w) => w.page).slice(0, 4);
|
|
|
|
this.setData({ sections, hotItems });
|
|
},
|
|
|
|
onTabChange(e: WechatMiniprogram.CustomEvent) {
|
|
const activeTab = e.detail.id;
|
|
if (activeTab === 'all') {
|
|
this.setData({ activeTab, filteredItems: null });
|
|
} else {
|
|
const filteredItems = getWorksheetsByCategory(activeTab);
|
|
this.setData({ activeTab, filteredItems });
|
|
}
|
|
},
|
|
|
|
onCardTap(e: WechatMiniprogram.TouchEvent) {
|
|
const id = e.currentTarget.dataset.id as string | undefined;
|
|
if (!id) return;
|
|
const item = ALL_WORKSHEETS.find((w) => w.id === id);
|
|
if (!item) return;
|
|
const path = getWorksheetPath(item);
|
|
if (path) {
|
|
wx.navigateTo({ url: path });
|
|
}
|
|
},
|
|
|
|
onHotCardTap(e: WechatMiniprogram.TouchEvent) {
|
|
const id = e.currentTarget.dataset.id as string | undefined;
|
|
if (!id) return;
|
|
const item = ALL_WORKSHEETS.find((w) => w.id === id);
|
|
if (!item) return;
|
|
const path = getWorksheetPath(item);
|
|
if (path) {
|
|
wx.navigateTo({ url: path });
|
|
}
|
|
},
|
|
|
|
onSeeMore(e: WechatMiniprogram.TouchEvent) {
|
|
const { category } = e.currentTarget.dataset;
|
|
wx.navigateTo({
|
|
url: `/pages/category/category?category=${category}`,
|
|
});
|
|
},
|
|
|
|
onShareAppMessage() {
|
|
return {
|
|
title: '涂鸦丫 - 快来生成宝宝的专属学习卡',
|
|
path: '/pages/home/home',
|
|
imageUrl: 'https://cdn.joeyone.cn/doodle/share-img/index-share-v2.png',
|
|
};
|
|
},
|
|
|
|
onShareTimeline() {
|
|
return {
|
|
title: '涂鸦丫 - 快来生成宝宝的专属学习卡',
|
|
query: '',
|
|
};
|
|
},
|
|
});
|