Commit 6d0f319f by 陈玉桐

fix 首页定时器清除

parent 9a724568
...@@ -379,12 +379,14 @@ Page({ ...@@ -379,12 +379,14 @@ Page({
trainSortList:[], trainSortList:[],
userRanking: '', userRanking: '',
resultSortList:[], resultSortList:[],
timerId: '',// 定时器id
checkImg: '../../assets/indexDefault.png', checkImg: '../../assets/indexDefault.png',
trainingStatus: 2,//训练状态 1正在训练 0:未训练 trainingStatus: 2,//训练状态 1正在训练 0:未训练
trainingTime: 0,//当前训练时间 trainingTime: 0,//当前训练时间
watchImgText: '加载中',//当前训练时间 watchImgText: '加载中',//当前训练时间
indexTimer: '',
refreshTimer: '',
mustUpdate: true, mustUpdate: true,
status: 1, status: 1,
...@@ -415,7 +417,15 @@ Page({ ...@@ -415,7 +417,15 @@ Page({
}, },
onShow() { onShow() {
let me = this; let me = this;
if(me.data.indexTimer){
clearInterval(me.data.indexTimer)
}
if(me.data.refreshTimer){
clearInterval(me.data.refreshTimer)
}
me.setData({
watchImgText: '加载中',
})
app.getToken().then(function (res) { app.getToken().then(function (res) {
if (res.status == 200){ if (res.status == 200){
// 请求前加Loading // 请求前加Loading
...@@ -506,7 +516,7 @@ Page({ ...@@ -506,7 +516,7 @@ Page({
checkImg: '../../assets/indexDefault.png' checkImg: '../../assets/indexDefault.png'
}) })
let times = 1 let times = 1
let timer = setInterval(function(){ let indexTimer = setInterval(function(){
// console.log(timestamp) // console.log(timestamp)
times++ times++
console.log(times) console.log(times)
...@@ -520,7 +530,7 @@ Page({ ...@@ -520,7 +530,7 @@ Page({
}) })
} }
if(times>16){ if(times>16){
clearInterval(timer) clearInterval(indexTimer)
// 获取失败 // 获取失败
me.setData({ me.setData({
trainingStatus: 4,//1正在训练 0:未训练 2加载中 3未在线 4获取失败 trainingStatus: 4,//1正在训练 0:未训练 2加载中 3未在线 4获取失败
...@@ -547,7 +557,7 @@ Page({ ...@@ -547,7 +557,7 @@ Page({
checkImg: res.data.data.thumb, checkImg: res.data.data.thumb,
trainingTime: res.data.data.nowTrainingDuration trainingTime: res.data.data.nowTrainingDuration
}) })
clearInterval(timer) clearInterval(indexTimer)
} }
}else{ }else{
// wx.showModal({ // wx.showModal({
...@@ -560,11 +570,14 @@ Page({ ...@@ -560,11 +570,14 @@ Page({
trainingStatus: 3,//训练状态 1正在训练 0:未训练 trainingStatus: 3,//训练状态 1正在训练 0:未训练
checkImg: '../../assets/indexDefault.png' checkImg: '../../assets/indexDefault.png'
}) })
clearInterval(timer) clearInterval(indexTimer)
} }
} }
}) })
},1000) },1000)
me.setData({
indexTimer: indexTimer
})
} }
}else{ }else{
// wx.showModal({ // wx.showModal({
...@@ -817,7 +830,7 @@ Page({ ...@@ -817,7 +830,7 @@ Page({
}) })
}else{ }else{
let times = 1 let times = 1
let timer = setInterval(function(){ var refreshTimer = setInterval(function(){
// console.log(timestamp) // console.log(timestamp)
times++ times++
console.log(times) console.log(times)
...@@ -831,7 +844,7 @@ Page({ ...@@ -831,7 +844,7 @@ Page({
}) })
} }
if(times>16){ if(times>16){
clearInterval(timer) clearInterval(refreshTimer)
// 获取失败 // 获取失败
me.setData({ me.setData({
trainingStatus: 4,//1正在训练 0:未训练 2加载中 3未在线 4获取失败 trainingStatus: 4,//1正在训练 0:未训练 2加载中 3未在线 4获取失败
...@@ -858,7 +871,7 @@ Page({ ...@@ -858,7 +871,7 @@ Page({
checkImg: res.data.data.thumb, checkImg: res.data.data.thumb,
trainingTime: res.data.data.nowTrainingDuration trainingTime: res.data.data.nowTrainingDuration
}) })
clearInterval(timer) clearInterval(refreshTimer)
} }
}else{ }else{
// wx.showModal({ // wx.showModal({
...@@ -871,11 +884,14 @@ Page({ ...@@ -871,11 +884,14 @@ Page({
trainingStatus: 3,//训练状态 1正在训练 0:未训练 trainingStatus: 3,//训练状态 1正在训练 0:未训练
checkImg: '../../assets/indexDefault.png' checkImg: '../../assets/indexDefault.png'
}) })
clearInterval(timer) clearInterval(refreshTimer)
} }
} }
}) })
},1000) },1000)
me.setData({
refreshTimer: refreshTimer
})
} }
}else{ }else{
// wx.showModal({ // wx.showModal({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment