57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
// pages/IndexFreeCourseDetails/IndexFreeCourseDetails.js
|
|
const api = require('../../utils/api');
|
|
const format = require('../../utils/format');
|
|
|
|
Page({
|
|
data: {
|
|
VideoTitle: '',
|
|
playdata: [],
|
|
VideoPlayerSrc: '',
|
|
HiddenVideoControl: true,
|
|
top: 0,
|
|
},
|
|
|
|
onLoad(options) {
|
|
const seriesNo = options.seriesNo;
|
|
if (!seriesNo) {
|
|
wx.switchTab({ url: '/pages/index/index' });
|
|
return;
|
|
}
|
|
|
|
api
|
|
.getFreeLessons(Number(seriesNo))
|
|
.then((list) => {
|
|
const rows = (list || []).map((item) => ({
|
|
coverUrl: item.coverUrl,
|
|
videoTitle: item.videoTitle,
|
|
intro: item.intro,
|
|
publishedAt: format.toDateString(item.publishedAt),
|
|
duration: item.duration,
|
|
videoUrl: item.videoUrl,
|
|
}));
|
|
this.setData({
|
|
playdata: rows,
|
|
VideoTitle: rows.length ? rows[0].videoTitle || '' : '',
|
|
});
|
|
})
|
|
.catch((err) => {
|
|
console.error('[IndexFreeCourseDetails] 加载失败', err);
|
|
this.setData({ playdata: [] });
|
|
});
|
|
},
|
|
|
|
onTapLesson(e) {
|
|
const item = this.data.playdata[e.currentTarget.dataset.index];
|
|
if (!item || !item.videoUrl) {
|
|
wx.showToast({ title: '该课时暂无视频', icon: 'none' });
|
|
return;
|
|
}
|
|
this.setData({ VideoPlayerSrc: item.videoUrl, HiddenVideoControl: false, top: 420 });
|
|
},
|
|
|
|
onShareAppMessage() {
|
|
return { title: '叶雷讲数学', path: '/pages/index/index' };
|
|
},
|
|
});
|
|
|