1.修改首页样式

yj-dev
杨杰 3 years ago
parent 23c3817208
commit ebf63d96b3
  1. 210
      subPages/lottery/lottery.vue

@ -3,7 +3,7 @@
<!-- head --> <!-- head -->
<image src="../static/head.jpg" mode="widthFix" class="width100"></image> <image src="../static/head.jpg" mode="widthFix" class="width100"></image>
<view class="almost-lottery__wheel"> <view class="almost-lottery__wheel">
<almost-lottery :lottery-size="lotteryConfig.lotterySize" :action-size="lotteryConfig.actionSize" <AlmostLottery :lottery-size="lotteryConfig.lotterySize" :action-size="lotteryConfig.actionSize"
:ring-count="2" :duration="3" :prize-list="prizeList" :prize-index="prizeIndex" :ring-count="2" :duration="3" :prize-list="prizeList" :prize-index="prizeIndex"
@reset-index="prizeIndex = -1" @draw-start="handleDrawStart" @draw-end="handleDrawEnd" @reset-index="prizeIndex = -1" @draw-start="handleDrawStart" @draw-end="handleDrawEnd"
@finish="handleDrawFinish" v-if="prizeList.length" /> @finish="handleDrawFinish" v-if="prizeList.length" />
@ -16,7 +16,7 @@
</view> --> </view> -->
<view class="_notice"> <view class="_notice">
<swiper class="_swiper tc" indicator-dots="false" autoplay="true" :interval="interval" circular="true" <swiper class="_swiper tc" indicator-dots="false" autoplay="true" :interval="interval" circular="true"
display-multiple-items="2" :duration="duration"> display-multiple-items="2" :duration="duration">
<swiper-item> <swiper-item>
<view class="swiper-item uni-bg-red"></view> <view class="swiper-item uni-bg-red"></view>
</swiper-item> </swiper-item>
@ -136,8 +136,8 @@
goldNum: 20, goldNum: 20,
// //
freeNumDay: 3, freeNumDay: 3,
interval:3000, interval: 3000,
duration:12000, duration: 12000,
list: ['1分钟前,无夏购买了会员', '2分钟前,无夏购买了会员', '3分钟前,无夏购买了会员'] list: ['1分钟前,无夏购买了会员', '2分钟前,无夏购买了会员', '3分钟前,无夏购买了会员']
} }
}, },
@ -162,23 +162,77 @@
}, },
// //
handleInitCanvas() { handleInitCanvas() {
this.prizeList = [] this.prizeList = []
this.getPrizeList() this.getPrizeList()
}, },
// //
async getPrizeList() { getPrizeList() {
uni.showLoading({ uni.showLoading({
title: '奖品准备中...' title: '奖品准备中...'
}) })
// //
let res = await this.requestApiGetPrizeList() // let res = await this.requestApiGetPrizeList()
if (res.ok) { // if (res.ok) {
uni.hideLoading() // uni.hideLoading()
let data = res.data // let data = res.data
if (data.length) { // if (data.length) {
this.prizeList = data this.prizeList = [{
prizeId: 1,
prizeName: '0.1元现金',
prizeStock: 10,
prizeWeight: 200,
prizeImage: '/static/img/order3.png'
},
{
prizeId: 2,
prizeName: '10元现金',
prizeStock: 0,
prizeWeight: 50,
prizeImage: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/56f085e0-bcfe-11ea-b244-a9f5e5565f30.png'
},
{
prizeId: 3,
prizeName: '5元话费',
prizeStock: 1,
prizeWeight: 80,
prizeImage: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAABCElEQVRoge3YMa4BURSH8Y8o7UAp0WgkotBZwluAfhqlZSgUGr23ENUUCpppJnTswAIUSCaTiziZJ8d9/193zdzrfMltABF5plb+oLscDoAV0Pn8OC/lwDhL0k35QT3wstcIuM61Cj0IhXiNuAvOFwr5SgrxRiHeKMSbhnHfAVgU1i1gajhnBpwK6wnQtgxkDTlmSTq/L7rLYQ9byG+WpLvCOT8YQ6K5WgrxRiHeKMQbhXijEG8U4o1CvIkmxPrDquwMrI37KlFJSJake2BUxVlW0VytaEKsV6t5+8Ohak3rRmtIH9hav/QvRHO1FOKNQrwJheQfn+I9wflCIeNHLzuQc51PRP6rC1ZeIm1I8cC5AAAAAElFTkSuQmCC'
},
{
prizeId: 4,
prizeName: '50元现金',
prizeStock: 0,
prizeWeight: 10,
prizeImage: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAB2klEQVRIia3Wv09TURjG8U+u2kQZcNENh2ok0cnJ0R+L0RB2g/EvwITEwRgnV0Zx0fAHYBh0khBD4sBAmAgDiwQNg4qwmSBDAYf7Fi+n97al9UlObnvO836f3tO355b2GsAYZrCBPRzGdSPmx8J3YtXwDDsB7TR2wl/rNmAYK13C07ES9W11E9s9BjTHdnBKVf8PAcWgehpwCssF0w/5FzqLgw7AA7zDQ/wqzC8H90jjSeFMYW0Yr8PzALfjOh7z1wve2YTzpLlQw2ay+KZ1N7vS24SziVqGexhKzB07pEJXk/dDwTetdZ9HewwZLWFNw2oyudZjQFNrCW8109pqS32GpPX1TOu586fPkLR+IEMjmbzYZ0ha34Atx/fwW58hXxPeFixo7Yg7PQbcKmEtZFgsMb/C4AkDBuUnQKpFuFZI3cZuvP6C+8g6wDP572O95C4Og49/W/YJl/G5YPqO9yV3dh4f8LMCfhjcI93Afix8xAX5SVx2YBY10yagEdxjmiwY7uISXuIFrlSEPG0TMllWcAbzYViXd0rzeXC6ImSiImA+eKU6h7mCeV/eCBMnCJkLzpHSztnFCJ7L//ZkOFv1iRLtRd1IcLpSHVP4jccVnkexPqXkmd7UX15b7tiz29ReAAAAAElFTkSuQmCC'
},
{
prizeId: 5,
prizeName: '1卷抽纸',
prizeStock: 3,
prizeWeight: 3000,
prizeImage: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAABCElEQVRoge3YMa4BURSH8Y8o7UAp0WgkotBZwluAfhqlZSgUGr23ENUUCpppJnTswAIUSCaTiziZJ8d9/193zdzrfMltABF5plb+oLscDoAV0Pn8OC/lwDhL0k35QT3wstcIuM61Cj0IhXiNuAvOFwr5SgrxRiHeKMSbhnHfAVgU1i1gajhnBpwK6wnQtgxkDTlmSTq/L7rLYQ9byG+WpLvCOT8YQ6K5WgrxRiHeKMQbhXijEG8U4o1CvIkmxPrDquwMrI37KlFJSJake2BUxVlW0VytaEKsV6t5+8Ohak3rRmtIH9hav/QvRHO1FOKNQrwJheQfn+I9wflCIeNHLzuQc51PRP6rC1ZeIm1I8cC5AAAAAElFTkSuQmCC'
},
{
prizeId: 6,
prizeName: '0.2元现金',
prizeStock: 8,
prizeWeight: 120,
prizeImage: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAABCElEQVRoge3YMa4BURSH8Y8o7UAp0WgkotBZwluAfhqlZSgUGr23ENUUCpppJnTswAIUSCaTiziZJ8d9/193zdzrfMltABF5plb+oLscDoAV0Pn8OC/lwDhL0k35QT3wstcIuM61Cj0IhXiNuAvOFwr5SgrxRiHeKMSbhnHfAVgU1i1gajhnBpwK6wnQtgxkDTlmSTq/L7rLYQ9byG+WpLvCOT8YQ6K5WgrxRiHeKMQbhXijEG8U4o1CvIkmxPrDquwMrI37KlFJSJake2BUxVlW0VytaEKsV6t5+8Ohak3rRmtIH9hav/QvRHO1FOKNQrwJheQfn+I9wflCIeNHLzuQc51PRP6rC1ZeIm1I8cC5AAAAAElFTkSuQmCC'
},
{
prizeId: 7,
prizeName: '谢谢参与',
prizeStock: 100,
prizeWeight: 10000,
prizeImage: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAABCElEQVRoge3YMa4BURSH8Y8o7UAp0WgkotBZwluAfhqlZSgUGr23ENUUCpppJnTswAIUSCaTiziZJ8d9/193zdzrfMltABF5plb+oLscDoAV0Pn8OC/lwDhL0k35QT3wstcIuM61Cj0IhXiNuAvOFwr5SgrxRiHeKMSbhnHfAVgU1i1gajhnBpwK6wnQtgxkDTlmSTq/L7rLYQ9byG+WpLvCOT8YQ6K5WgrxRiHeKMQbhXijEG8U4o1CvIkmxPrDquwMrI37KlFJSJake2BUxVlW0VytaEKsV6t5+8Ohak3rRmtIH9hav/QvRHO1FOKNQrwJheQfn+I9wflCIeNHLzuQc51PRP6rC1ZeIm1I8cC5AAAAAElFTkSuQmCC'
},
{
prizeId: 8,
prizeName: '100金币',
prizeStock: 100,
prizeWeight: 3000,
prizeImage: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAABCElEQVRoge3YMa4BURSH8Y8o7UAp0WgkotBZwluAfhqlZSgUGr23ENUUCpppJnTswAIUSCaTiziZJ8d9/193zdzrfMltABF5plb+oLscDoAV0Pn8OC/lwDhL0k35QT3wstcIuM61Cj0IhXiNuAvOFwr5SgrxRiHeKMSbhnHfAVgU1i1gajhnBpwK6wnQtgxkDTlmSTq/L7rLYQ9byG+WpLvCOT8YQ6K5WgrxRiHeKMQbhXijEG8U4o1CvIkmxPrDquwMrI37KlFJSJake2BUxVlW0VytaEKsV6t5+8Ohak3rRmtIH9hav/QvRHO1FOKNQrwJheQfn+I9wflCIeNHLzuQc51PRP6rC1ZeIm1I8cC5AAAAAElFTkSuQmCC'
}
]
// //
// //
@ -189,15 +243,15 @@
prizeWeightArrSort.sort((a, b) => b - a) prizeWeightArrSort.sort((a, b) => b - a)
this.prizeWeightMax = prizeWeightArrSort[0] this.prizeWeightMax = prizeWeightArrSort[0]
} }
} // }
} else { // } else {
uni.hideLoading() // uni.hideLoading()
uni.showToast({ // uni.showToast({
title: '获取奖品失败', // title: '',
mask: true, // mask: true,
icon: 'none' // icon: 'none'
}) // })
} // }
}, },
// //
// Promise // Promise
@ -276,113 +330,12 @@
// //
handleDrawStart() { handleDrawStart() {
console.log('触发抽奖按钮') console.log('触发抽奖按钮')
if (this.prizeing) return this.tryLotteryDraw()
this.prizeing = true
//
if (this.freeNum > 0 || this.goldCoin >= this.goldNum) {
//
if (this.freeNum > 0) {
this.freeNum--
} else if (this.goldCoin >= this.goldNum) {
this.goldCoin -= this.goldNum
}
this.tryLotteryDraw()
} else {
this.prizeing = false
uni.showModal({
title: '金币不足',
content: '是否前往赚取金币?',
success: (res) => {
//
console.log('金币不足', res)
}
})
}
}, },
// //
tryLotteryDraw() { tryLotteryDraw() {
console.log('旋转开始,获取中奖下标......') console.log('旋转开始,获取中奖下标......')
// this.remoteGetPrizeIndex()
if (this.onFrontend) {
this.localGetPrizeIndex()
} else {
this.remoteGetPrizeIndex()
}
},
//
localGetPrizeIndex() {
console.warn('###当前处于前端控制中奖概率,安全起见,强烈建议由后端控制###')
//
// prizeId
if (!this.prizeWeightMax) {
console.warn('###当前已开启前端控制中奖概率,但是奖品数据列表中的 prizeWeight 参数似乎配置不正确###')
return
}
console.log('当前权重最大值为 =>', this.prizeWeightMax)
// 使 Math.ceil 0
let randomWeight = Math.ceil(Math.random() * this.prizeWeightMax)
console.log('本次权重随机数 =>', randomWeight)
//
let tempMaxArrs = []
this.prizeList.forEach((item) => {
if (item.prizeWeight >= randomWeight) {
tempMaxArrs.push(item.prizeWeight)
}
})
console.log('tempMaxArrs', tempMaxArrs)
//
//
let tempMaxArrsLen = tempMaxArrs.length
if (tempMaxArrsLen) {
tempMaxArrs.sort((a, b) => a - b)
//
if (tempMaxArrsLen > 1) {
//
let sameCount = 0
for (let i = 0; i < tempMaxArrs.length; i++) {
if (tempMaxArrs[i] === tempMaxArrs[0]) {
sameCount++
}
}
// 1
if (sameCount === 1) {
this.prizeIndex = this.prizeWeightArr.indexOf(tempMaxArrs[0])
} else {
//
let sameWeight = tempMaxArrs[0]
let sameWeightArr = []
let sameWeightItem = {}
this.prizeWeightArr.forEach((item, index) => {
if (item === sameWeight) {
sameWeightArr.push({
prizeWeight: item,
index
})
}
})
console.log('sameWeightArr', sameWeightArr)
sameWeightItem = sameWeightArr[Math.floor(Math.random() * sameWeightArr.length)]
console.log('sameWeightItem', sameWeightItem)
this.prizeIndex = sameWeightItem.index
}
} else {
this.prizeIndex = this.prizeWeightArr.indexOf(tempMaxArrs[0])
}
}
console.log('本次抽中奖品 =>', this.prizeList[this.prizeIndex].prizeName)
//
if (this.onStock) {
console.log('本次奖品库存 =>', this.prizeList[this.prizeIndex].prizeStock)
}
}, },
// //
// //
@ -392,12 +345,9 @@
let stoTimer = setTimeout(() => { let stoTimer = setTimeout(() => {
clearTimeout(stoTimer) clearTimeout(stoTimer)
stoTimer = null stoTimer = null
let list = [...this.prizeList] let list = [...this.prizeList]
// prizeId prizeId // prizeId prizeId
let prizeId = Math.floor(Math.random() * list.length + 1) let prizeId = Math.floor(Math.random() * list.length + 1);
// prizeId // prizeId
for (let i = 0; i < list.length; i++) { for (let i = 0; i < list.length; i++) {
let item = list[i] let item = list[i]
@ -463,7 +413,6 @@
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
._notice { ._notice {
position: fixed; position: fixed;
left: 0; left: 0;
@ -486,6 +435,7 @@
._swiper { ._swiper {
line-height: 44upx; line-height: 44upx;
} }
.almost-lottery { .almost-lottery {
flex: 1; flex: 1;
background-color: #FF893F; background-color: #FF893F;

Loading…
Cancel
Save