Browse Source

启动页优化

master
zhaoyongnian 5 years ago
parent
commit
8b7eca441b
  1. 11
      api/index.js
  2. 58
      pages/start/start.js
  3. 2
      pages/start/start.wxml

11
api/index.js

@ -1,7 +1,14 @@
const request = require('../utils/request') const request = require('../utils/request')
/** /**
* 获取欢迎页信息 * 获取欢迎页信息
*/ */
export function getStartupPage () { export function getStartupPage() {
return request.get('startup/getStartupPage') return request.get('startup/getStartupPage')
} }
/**
* 获取欢迎页信息 v2
*/
export function getStartupPageV2() {
return request.get('startup/v2/getStartupPage')
}

58
pages/start/start.js

@ -1,5 +1,7 @@
const app = getApp() const app = getApp()
import { getStartupPage } from '../../api/index' import {
getStartupPageV2
} from '../../api/index'
Page({ Page({
data: { data: {
@ -7,9 +9,13 @@ Page({
countdownNum: 0, countdownNum: 0,
bgImage: '', bgImage: '',
timer: '', timer: '',
scene: '' scene: '',
imgList: [],
datanum: 0, //第几个数组
datalength: 0, //数组长度
allTime:0,//总时间
}, },
onLoad (options) { onLoad(options) {
if (options.scene) { if (options.scene) {
this.data.scene = options.scene this.data.scene = options.scene
} }
@ -19,15 +25,25 @@ Page({
this.getStartupPage() this.getStartupPage()
}, },
// 倒计时进入 // 倒计时进入
countDown () { countDown() {
this.data.timer = setInterval(() => { this.data.timer = setInterval(() => {
if (this.data.countdownNum > 1) { if (this.data.countdownNum > 1) {
this.data.allTime--
this.data.countdownNum-- this.data.countdownNum--
this.setData({ this.setData({
countdownNum: this.data.countdownNum countdownNum: this.data.countdownNum,
allTime: this.data.allTime
}) })
} else { } else {
this.data.allTime--
this.setData({
datanum: this.data.datanum + 1,
allTime: this.data.allTime
})
clearInterval(this.data.timer) clearInterval(this.data.timer)
if (this.data.datalength != this.data.datanum) {
this.getloop()
} else {
if (this.data.scene) { if (this.data.scene) {
wx.reLaunch({ wx.reLaunch({
url: `/pages/indexNew/indexNew?scene=${this.data.scene}` url: `/pages/indexNew/indexNew?scene=${this.data.scene}`
@ -38,10 +54,11 @@ Page({
}) })
} }
} }
}
}, 1000) }, 1000)
}, },
// 立即进入 // 立即进入
immeEnter () { immeEnter() {
clearInterval(this.data.timer) clearInterval(this.data.timer)
if (this.data.scene) { if (this.data.scene) {
wx.reLaunch({ wx.reLaunch({
@ -54,19 +71,26 @@ Page({
} }
}, },
// 获取启动页信息 // 获取启动页信息
getStartupPage () { getStartupPage() {
wx.showLoading({ wx.showLoading({
title: '获取中...' title: '获取中...'
}) })
getStartupPage().then(res => { getStartupPageV2().then(res => {
wx.hideLoading() wx.hideLoading()
console.log('获取启动页信息', res) 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({ this.setData({
bgImage: res.data.imgUrl, allTime: this.data.allTime + item.duration
countdownNum: res.data.duration
}) })
this.countDown() })
this.setData({
datalength: res.data.length,
imgList: res.data
})
this.getloop()
} else { } else {
this.immeEnter() this.immeEnter()
} }
@ -74,5 +98,15 @@ Page({
wx.hideLoading() wx.hideLoading()
this.immeEnter() 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()
}
} }
}) })

2
pages/start/start.wxml

@ -5,7 +5,7 @@
<view class="content" style="height: calc(100vh - {{deviceHeight}}px - 100rpx); top: calc({{deviceHeight}}px + 100rpx)"> <view class="content" style="height: calc(100vh - {{deviceHeight}}px - 100rpx); top: calc({{deviceHeight}}px + 100rpx)">
<view class="countdown" wx:if="countdownNum > 0"> <view class="countdown" wx:if="countdownNum > 0">
<view bindtap="immeEnter" hover-class="hover-skip" class="time">{{countdownNum}}s | 跳过</view> <view bindtap="immeEnter" hover-class="hover-skip" class="time">{{allTime}}s | 跳过</view>
</view> </view>
<!-- <view class="imme-enter"> <!-- <view class="imme-enter">

Loading…
Cancel
Save