const app = getApp() import { getStartupPage } from '../../api/index' Page({ data: { deviceHeight: 0, countdownNum: 0, bgImage: '', timer: '', scene: '' }, onLoad (options) { if (options.scene) { this.data.scene = options.scene } this.setData({ deviceHeight: app.globalData.height }) this.getStartupPage() }, // 倒计时进入 countDown () { this.data.timer = setInterval(() => { if (this.data.countdownNum > 1) { this.data.countdownNum-- this.setData({ countdownNum: this.data.countdownNum }) } else { clearInterval(this.data.timer) if (this.data.scene) { wx.reLaunch({ url: `/pages/indexNew/indexNew?scene=${this.data.scene}` }) } else { wx.reLaunch({ url: '/pages/indexNew/indexNew' }) } } }, 1000) }, // 立即进入 immeEnter () { clearInterval(this.data.timer) if (this.data.scene) { wx.reLaunch({ url: `/pages/indexNew/indexNew?scene=${this.data.scene}` }) } else { wx.reLaunch({ url: '/pages/indexNew/indexNew' }) } }, // 获取启动页信息 getStartupPage () { wx.showLoading({ title: '获取中...' }) getStartupPage().then(res => { wx.hideLoading() console.log('获取启动页信息', res) if (res.data.imgUrl) { this.setData({ bgImage: res.data.imgUrl, countdownNum: res.data.duration }) this.countDown() } else { this.immeEnter() } }).catch(err => { wx.hideLoading() this.immeEnter() }) } })