69 lines
1.7 KiB
JavaScript
69 lines
1.7 KiB
JavaScript
|
|
import { injectPage } from '@jdmini/api'
|
||
|
|
const { BEGINNER_PATH, CATEGORIES, DAILY_RECOMMEND, ALL_COURSES } = require('../../utils/data.js')
|
||
|
|
const storage = require('../../utils/storage.js')
|
||
|
|
|
||
|
|
Page(injectPage()({
|
||
|
|
data: {
|
||
|
|
beginnerPath: BEGINNER_PATH,
|
||
|
|
categories: CATEGORIES,
|
||
|
|
dailyRecommend: DAILY_RECOMMEND,
|
||
|
|
recentHistory: [],
|
||
|
|
searchKeyword: ''
|
||
|
|
},
|
||
|
|
|
||
|
|
onLoad() {
|
||
|
|
this.loadRecentHistory()
|
||
|
|
},
|
||
|
|
|
||
|
|
onShow() {
|
||
|
|
this.loadRecentHistory()
|
||
|
|
},
|
||
|
|
|
||
|
|
loadRecentHistory() {
|
||
|
|
const history = storage.getRecentHistory()
|
||
|
|
this.setData({ recentHistory: history.slice(0, 4) })
|
||
|
|
},
|
||
|
|
|
||
|
|
onSearchInput(e) {
|
||
|
|
this.setData({ searchKeyword: e.detail.value })
|
||
|
|
},
|
||
|
|
|
||
|
|
onSearchConfirm() {
|
||
|
|
const kw = this.data.searchKeyword.trim()
|
||
|
|
if (!kw) return
|
||
|
|
wx.navigateTo({
|
||
|
|
url: `/pages/category/category?keyword=${encodeURIComponent(kw)}`
|
||
|
|
})
|
||
|
|
},
|
||
|
|
|
||
|
|
onPathCardTap(e) {
|
||
|
|
const { courseId } = e.currentTarget.dataset
|
||
|
|
wx.navigateTo({ url: `/pages/course-detail/course-detail?courseId=${courseId}` })
|
||
|
|
},
|
||
|
|
|
||
|
|
onCategoryTap(e) {
|
||
|
|
const { category } = e.currentTarget.dataset
|
||
|
|
wx.navigateTo({ url: `/pages/category/category?category=${encodeURIComponent(category)}` })
|
||
|
|
},
|
||
|
|
|
||
|
|
onRecommendTap(e) {
|
||
|
|
const { courseId } = e.currentTarget.dataset
|
||
|
|
wx.navigateTo({ url: `/pages/course-detail/course-detail?courseId=${courseId}` })
|
||
|
|
},
|
||
|
|
|
||
|
|
onHistoryTap(e) {
|
||
|
|
const { courseId } = e.currentTarget.dataset
|
||
|
|
const progress = storage.getCourseProgress(courseId)
|
||
|
|
wx.navigateTo({
|
||
|
|
url: `/pages/study-step/study-step?courseId=${courseId}&stepIndex=${progress.currentStep}`
|
||
|
|
})
|
||
|
|
},
|
||
|
|
|
||
|
|
onShareAppMessage() {
|
||
|
|
return {
|
||
|
|
title: '画画怎么画 — 零基础绘画学习',
|
||
|
|
path: '/pages/home/home'
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}))
|