添加抽奖

This commit is contained in:
zpc 2025-04-09 03:14:36 +08:00
parent 952f70d3e8
commit 154b8cfa19
2 changed files with 249 additions and 0 deletions

View File

@ -473,6 +473,13 @@
{
"navigationStyle": "custom"
}
},
{
"path" : "pages/other/prize_draw",
"style" :
{
"navigationStyle": "custom"
}
}
],
"subPackages": [{

242
pages/other/prize_draw.vue Normal file
View File

@ -0,0 +1,242 @@
<template>
<page-container title="每日免费送" :showBack="true">
<view class="prize-draw">
<view style="height: 512rpx;"></view>
<view class="choujiang">
<view style="height:52rpx;"></view>
<view class="neiquan">
<view class="grid-container">
<view class="jiangping" v-for="(item, index) in 9"
:class="{ 'xuanzhong': currentIndex === index && !isFinalWin, 'win-flash': currentIndex === index && isFinalWin }"
:key="index">
<!-- 奖品图片将在这里显示 -->
<image src="https://image.zfunbox.cn/huodong/kuang.png" style="width:95%;height:95%;margin-left: 1rpx;border-radius: 25rpx;">
</image>
</view>
</view>
</view>
<view class="draw-btn-container">
<view class="draw-btn" @click="startDraw"></view>
</view>
</view>
</view>
</page-container>
</template>
<script>
import PageContainer from '@/components/page-container/page-container.vue'
export default {
components: {
PageContainer
},
data() {
return {
isDrawing: false,
prizes: [
//
],
currentIndex: -1, //
timer: null, //
speed: 100, //
times: 0, //
targetIndex: 0, //
isFinalWin: false, //
};
},
methods: {
startDraw() {
if (this.isDrawing) return;
this.isDrawing = true;
this.isFinalWin = false; //
//
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
//
this.times = 0;
this.speed = 100;
// 0-8
this.targetIndex = Math.floor(Math.random() * 9);
//
this.runAnimation();
},
runAnimation() {
this.timer = setInterval(() => {
this.times++;
//
this.currentIndex = (this.currentIndex + 1) % 9;
//
if (this.times > 20) { // 20
if (this.times > 30) { // 30
this.speed += 10; //
}
//
if (this.speed > 300 && this.currentIndex === this.targetIndex) {
clearInterval(this.timer);
this.timer = null;
this.startWinAnimation();
return; //
}
//
clearInterval(this.timer);
this.timer = null;
this.runAnimation();
}
}, this.speed);
},
startWinAnimation() {
//
this.isFinalWin = true;
//
setTimeout(() => {
this.showResult();
}, 1500); // 1.5
},
showResult() {
//
setTimeout(() => {
this.isDrawing = false;
uni.showToast({
title: '恭喜获得奖品!',
icon: 'none',
duration: 2000
});
//
}, 500);
}
}
}
</script>
<style lang="scss">
.prize-draw {
background: url($baseurl+'huodong/bg.png') no-repeat center center;
background-size: 100% 100%;
height: 1495.14rpx;
width: 100vw;
.choujiang {
background: url($baseurl+'huodong/ke.png') no-repeat center center;
background-size: 100% 100%;
margin: 0px auto;
height: 829.86rpx;
width: 90%;
position: relative;
.neiquan {
width: 430rpx;
height: 465rpx;
margin: 0px auto;
padding: 15rpx;
box-sizing: border-box;
}
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 10rpx;
width: 100%;
height: 100%;
}
.jiangping {
// background: url($baseurl+'huodong/kuang.png') no-repeat center center;
// background-size: 100% 100%;
// border: 1px dashed #75C5FF;
border-radius: 12rpx;
display: flex;
align-items: center;
justify-content: center;
background-color: rgba(255, 255, 255, 0.7);
transition: all 0.05s; //
&:active {
transform: scale(0.95);
}
}
.draw-btn-container {
position: absolute;
bottom: 95rpx;
left: 50%;
transform: translateX(-50%);
width: 100%;
display: flex;
justify-content: center;
}
.draw-btn {
width: 298.61rpx;
height: 118.75rpx;
background: url($baseurl+'huodong/anniu.png') no-repeat;
background-size: 100% 100%;
font-size: 32rpx;
font-weight: bold;
//border-radius: 40rpx;
display: flex;
align-items: center;
justify-content: center;
//box-shadow: 0 4rpx 8rpx rgba(255, 87, 34, 0.3);
transition: all 0.3s;
&:active {
transform: scale(0.95);
//box-shadow: 0 2rpx 4rpx rgba(255, 87, 34, 0.3);
}
}
}
.xuanzhong {
background: url($baseurl+'huodong/xuanzhong.png') no-repeat !important;
background-size: 100% 100% !important;
width: 100% !important;
height: 100% !important;
}
.win-flash {
background: url($baseurl+'huodong/xuanzhong.png') no-repeat !important;
background-size: 100% 100% !important;
width: 100% !important;
height: 100% !important;
animation: win-blink 0.3s 5 alternate;
}
@keyframes win-blink {
0% {
opacity: 1;
transform: scale(1);
}
100% {
opacity: 0.5;
transform: scale(1.05);
}
}
@keyframes pulse {
from {
opacity: 1;
}
to {
opacity: 0.8;
}
}
}
</style>