Files
YelayMaths/pages/VideoDetails/VideoDetails.js
T
2026-01-05 18:07:57 +08:00

162 lines
3.7 KiB
JavaScript

// pages/Videodetails/Videodetails.js
const MyApi = require('../../Api/api.js');
Page({
/**
* 页面的初始数据
*/
data: {
BaseURL:getApp().globalData.BaseURL,
JustChapter:"",
zhangjieTitle:"",
VideoImageURL:"",
VideoTitle:"",
VideoDetails:"",
RealeaseTime:"",
shichangTime:"",
playdata:[],
VideoPlayerSrc:null,
coursedata:null,
top:0,
HiddenVideoControl:true
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
//只有当登录才有效
if (wx.getStorageSync('UserInfoCache').IsLogin) {
var receivedIndex = options.index ?? null;
if (receivedIndex){
//分享页面跳转至课程页面
try {
wx.getStorageSync('UserInfoCache').OwnedCourse[receivedIndex];
if (wx.getStorageSync('UserInfoCache').OwnedCourse[receivedIndex] === undefined){
wx.showToast({
title: '不可用!',
icon: 'error',
mask:true,
duration: 3000
});
setTimeout(function() {
wx.switchTab({
url: '/pages/kecheng/kecheng',
})
},3000);
}
} catch (error) {
wx.showToast({
title: '不可用!',
icon: 'error',
mask:true,
duration: 3000
});
setTimeout(function() {
wx.switchTab({
url: '/pages/kecheng/kecheng',
})
},3000);
}
var tempdata=wx.getStorageSync('UserInfoCache').OwnedCourse[receivedIndex];
MyApi.ApiGetCourseData(tempdata.OpenID,tempdata.课程id)
.then(result => {
this.setData({
VideoTitle:tempdata.课程,
playdata:result.PlayData,
VideoDetails:tempdata.课程介绍,
VideoImageURL:this.data.BaseURL+"/Course/"+tempdata.课程id+".png",
coursedata:tempdata,
});
})
.catch(err => {
this.setData({
playdata:[],
});
console.error("请求失败:"+err);
});
} else {
wx.switchTab({
url: '/pages/kecheng/kecheng',
})
}
} else {
setTimeout(function() {
wx.switchTab({
url: '/pages/kecheng/kecheng',
})
},50);
}
},
OnTapVideoList(e){
//只有当登录才有效
if (wx.getStorageSync('UserInfoCache').IsLogin) {
// 获取当前点击的索引
const currentcourseid = e.currentTarget.dataset.courseid;
const currentzhangjieid = e.currentTarget.dataset.zhangjieid;
const currentplayid = e.currentTarget.dataset.playid;
this.setData({
VideoPlayerSrc:this.data.BaseURL+"/Course/"+currentcourseid+"/"+currentzhangjieid+"/"+currentplayid+"/"+"playlist.m3u8",
HiddenVideoControl:false,
top:420
});
} else {
setTimeout(function() {
wx.switchTab({
url: '/pages/kecheng/kecheng',
})
},50);
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
if (!wx.getStorageSync('UserInfoCache').IsLogin) {
setTimeout(function() {
wx.switchTab({
url: '/pages/kecheng/kecheng',
})
},50);
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
}
})