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

98 lines
1.9 KiB
JavaScript

// pages/kecheng/kecheng.js
Page({
/**
* 页面的初始数据
*/
data: {
BaseURL:getApp().globalData.BaseURL,
hasCourse: false,
OwnedCourse: null,
intervalId: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
//每10ms获取一次数据,直到获取到个人信息数据为止
// 使用箭头函数确保正确的作用域
var longtime=0;
this.intervalId = setInterval(() => {
//不间断刷新页面
this.onShow();
if (this.data.OwnedCourse){
clearInterval(this.intervalId);
return;
};
//计时500次,即5s后如果没有任何获取到已经登录的标志,依然断开计时器
if (longtime>=500){
clearInterval(this.intervalId);
console.log('暂无已购课程!');
};
longtime=longtime+1;
}, 10);
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
if ((wx.getStorageSync('UserInfoCache').OwnedCourse)&&(wx.getStorageSync('UserInfoCache').IsLogin)) {
this.setData({
hasCourse: true,
OwnedCourse: wx.getStorageSync('UserInfoCache').OwnedCourse
});
} else {
this.setData({
hasCourse: false,
OwnedCourse: null
});
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
NavigatorToVideoDetails(e) {
var index=e.currentTarget.dataset.index;
wx.navigateTo({
url: '/pages/VideoDetails/VideoDetails?index='+index,
})
}
})