// pages/Videodetails/Videodetails.js const MyApi = require('../../Api/api.js'); Page({ /** * 页面的初始数据 */ data: { BaseURL:getApp().globalData.BaseURL, JustChapter:"", zhangjieTitle:"", VideoImageURL:"", VideoTitle:"", RealeaseTime:"", shichangTime:"", playdata:[], VideoPlayerSrc:null, coursedata:null, top:0, HiddenVideoControl:true, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { //只有当登录才有效 if (wx.getStorageSync('UserInfoCache').IsLogin) { //获取接收到的视频序号 var receivedIndex = options.number ?? null; if (receivedIndex){ MyApi.ApiGetFreeCourseData(receivedIndex) .then(result => { this.setData({ VideoTitle:result.PlayData[0].课程名称, playdata:result.PlayData, VideoImageURL:this.data.BaseURL+"/Course/"+result.课程id+".png", coursedata:result, }); }) .catch(err => { this.setData({ playdata:[], }); console.error("请求失败:"+err); }); } else { wx.switchTab({ url: '/pages/index/index', }) } } else { setTimeout(function() { wx.switchTab({ url: '/pages/index/index', }) },50); } }, OnTapVideoList(e){ //只有当登录才有效 if (wx.getStorageSync('UserInfoCache').IsLogin) { // 获取当前点击的索引 const courseindex = e.currentTarget.dataset.courseindex; this.setData({ VideoPlayerSrc:this.data.BaseURL+'/'+this.data.coursedata.PlayData[courseindex].视频m3u8, HiddenVideoControl:false, top:420, }); } else { setTimeout(function() { wx.switchTab({ url: '/pages/index/index', }) },50); } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { if (!wx.getStorageSync('UserInfoCache').IsLogin) { setTimeout(function() { wx.switchTab({ url: '/pages/index/index', }) },50); } }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { } })