import { injectPage } from '@jdmini/api' const { getCourseById } = require('../../utils/data.js') const storage = require('../../utils/storage.js') Page(injectPage()({ data: { course: null, myWorkPath: '', viewMode: 'example', // 'example' | 'mywork' | 'compare' saved: false }, onLoad(options) { const courseId = options.courseId const course = getCourseById(courseId) this.setData({ course: course || null }) }, onSwitchView(e) { const { mode } = e.currentTarget.dataset this.setData({ viewMode: mode }) }, onChooseWork() { wx.chooseMedia({ count: 1, mediaType: ['image'], sourceType: ['album', 'camera'], success: (res) => { const filePath = res.tempFiles[0].tempFilePath this.setData({ myWorkPath: filePath, viewMode: 'compare', saved: false }) } }) }, onSaveRecord() { const { course, myWorkPath } = this.data if (!myWorkPath) { wx.showToast({ title: '请先上传你的作品', icon: 'none' }) return } storage.addWorkRecord({ courseId: course ? course.id : '', courseTitle: course ? course.title : '', imagePath: myWorkPath }) this.setData({ saved: true }) wx.showToast({ title: '保存成功!', icon: 'success' }) }, onContinueLearning() { wx.navigateBack({ delta: 2 }) }, onBackToHome() { wx.switchTab({ url: '/pages/home/home' }) }, onShareAppMessage() { return { title: '我完成了一节绘画课!', path: '/pages/home/home' } } }))