From 8b7eca441b25c976b1be0771bf56ec75d6a868c1 Mon Sep 17 00:00:00 2001 From: zhaoyongnian <541231643@qq.com> Date: Mon, 18 May 2020 17:19:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E5=8A=A8=E9=A1=B5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/index.js | 15 ++++++--- pages/start/start.js | 74 ++++++++++++++++++++++++++++++------------ pages/start/start.wxml | 2 +- 3 files changed, 66 insertions(+), 25 deletions(-) diff --git a/api/index.js b/api/index.js index 655978b..78a7894 100644 --- a/api/index.js +++ b/api/index.js @@ -1,7 +1,14 @@ const request = require('../utils/request') - /** - * 获取欢迎页信息 - */ - export function getStartupPage () { +/** + * 获取欢迎页信息 + */ +export function getStartupPage() { return request.get('startup/getStartupPage') +} + +/** + * 获取欢迎页信息 v2 + */ +export function getStartupPageV2() { + return request.get('startup/v2/getStartupPage') } \ No newline at end of file diff --git a/pages/start/start.js b/pages/start/start.js index 5441859..3c4e4ae 100644 --- a/pages/start/start.js +++ b/pages/start/start.js @@ -1,5 +1,7 @@ const app = getApp() -import { getStartupPage } from '../../api/index' +import { + getStartupPageV2 +} from '../../api/index' Page({ data: { @@ -7,9 +9,13 @@ Page({ countdownNum: 0, bgImage: '', timer: '', - scene: '' + scene: '', + imgList: [], + datanum: 0, //第几个数组 + datalength: 0, //数组长度 + allTime:0,//总时间 }, - onLoad (options) { + onLoad(options) { if (options.scene) { this.data.scene = options.scene } @@ -19,29 +25,40 @@ Page({ this.getStartupPage() }, // 倒计时进入 - countDown () { + countDown() { this.data.timer = setInterval(() => { if (this.data.countdownNum > 1) { + this.data.allTime-- this.data.countdownNum-- + this.setData({ + countdownNum: this.data.countdownNum, + allTime: this.data.allTime + }) + } else { + this.data.allTime-- this.setData({ - countdownNum: this.data.countdownNum + datanum: this.data.datanum + 1, + allTime: this.data.allTime }) - } else { clearInterval(this.data.timer) - if (this.data.scene) { - wx.reLaunch({ - url: `/pages/indexNew/indexNew?scene=${this.data.scene}` - }) + if (this.data.datalength != this.data.datanum) { + this.getloop() } else { - wx.reLaunch({ - url: '/pages/indexNew/indexNew' - }) + if (this.data.scene) { + wx.reLaunch({ + url: `/pages/indexNew/indexNew?scene=${this.data.scene}` + }) + } else { + wx.reLaunch({ + url: '/pages/indexNew/indexNew' + }) + } } } }, 1000) }, // 立即进入 - immeEnter () { + immeEnter() { clearInterval(this.data.timer) if (this.data.scene) { wx.reLaunch({ @@ -54,19 +71,26 @@ Page({ } }, // 获取启动页信息 - getStartupPage () { + getStartupPage() { wx.showLoading({ title: '获取中...' }) - getStartupPage().then(res => { + getStartupPageV2().then(res => { wx.hideLoading() console.log('获取启动页信息', res) - if (res.data.imgUrl) { + if (res.data.length > 0) { + + res.data.forEach((item, index) => { + // this.data.allTime = this.data.allTime + item.duration + this.setData({ + allTime: this.data.allTime + item.duration + }) + }) this.setData({ - bgImage: res.data.imgUrl, - countdownNum: res.data.duration + datalength: res.data.length, + imgList: res.data }) - this.countDown() + this.getloop() } else { this.immeEnter() } @@ -74,5 +98,15 @@ Page({ wx.hideLoading() this.immeEnter() }) + }, + //数组循环 + getloop() { + if (this.data.imgList[this.data.datanum].duration > 0) { + this.setData({ + bgImage: this.data.imgList[this.data.datanum].imgUrl, + countdownNum: this.data.imgList[this.data.datanum].duration + }) + this.countDown() + } } }) \ No newline at end of file diff --git a/pages/start/start.wxml b/pages/start/start.wxml index 4b085c3..601219c 100644 --- a/pages/start/start.wxml +++ b/pages/start/start.wxml @@ -5,7 +5,7 @@ - {{countdownNum}}s | 跳过 + {{allTime}}s | 跳过