61 lines
1.5 KiB
JavaScript
61 lines
1.5 KiB
JavaScript
import { injectPage } from '@jdmini/api'
|
|
const { PRACTICE_TASKS } = require('../../utils/data.js')
|
|
const storage = require('../../utils/storage.js')
|
|
|
|
Page(injectPage()({
|
|
data: {
|
|
allTasks: PRACTICE_TASKS,
|
|
filteredTasks: PRACTICE_TASKS,
|
|
activeDifficulty: '全部',
|
|
difficulties: ['全部', '入门', '初级'],
|
|
worksRecords: [],
|
|
completedCount: 0
|
|
},
|
|
|
|
onLoad() {
|
|
this.loadData()
|
|
},
|
|
|
|
onShow() {
|
|
this.loadData()
|
|
},
|
|
|
|
loadData() {
|
|
const records = storage.getWorksRecords()
|
|
const completedIds = records.map(r => r.courseId)
|
|
const tasks = this.data.allTasks.map(t => ({
|
|
...t,
|
|
done: completedIds.includes(t.courseId)
|
|
}))
|
|
this.setData({
|
|
allTasks: tasks,
|
|
filteredTasks: this.filterByDifficulty(tasks, this.data.activeDifficulty),
|
|
completedCount: completedIds.length
|
|
})
|
|
},
|
|
|
|
filterByDifficulty(tasks, diff) {
|
|
if (diff === '全部') return tasks
|
|
return tasks.filter(t => t.difficulty === diff)
|
|
},
|
|
|
|
onDifficultySwitch(e) {
|
|
const diff = e.currentTarget.dataset.diff
|
|
this.setData({
|
|
activeDifficulty: diff,
|
|
filteredTasks: this.filterByDifficulty(this.data.allTasks, diff)
|
|
})
|
|
},
|
|
|
|
onTaskTap(e) {
|
|
const { courseId, stepIndex } = e.currentTarget.dataset
|
|
wx.navigateTo({
|
|
url: `/pages/study-step/study-step?courseId=${courseId}&stepIndex=${stepIndex}`
|
|
})
|
|
},
|
|
|
|
onShareAppMessage() {
|
|
return { title: '画画怎么画 — 每日练习', path: '/pages/practice/practice' }
|
|
}
|
|
}))
|