feat: 优化九宫格抽奖

This commit is contained in:
Burt 2024-01-10 17:18:55 +08:00
parent e63aa25902
commit 5787d29fbc

View File

@ -28,15 +28,17 @@
<script lang="ts" setup>
import { reactive, computed } from 'vue'
const giftLen = 8 // 8
const loop = 4 //
const totalStep = giftLen * loop // 32
const lastLoopStep = totalStep - giftLen // 24
const numList = [1, 2, 3, 8, -1, 4, 7, 6, 5]
const btnIndex = numList[4] //
// const activeIndex = ref(0)
const state = reactive({
lottery: 0, //
step: -1, //
stopStep: 32, // 32
stopStep: totalStep, //
speed: 2, //
timer: null, // ID
loading: false,
@ -46,7 +48,7 @@ const activeIndex = computed(() => {
return (state.step % 8) + 1
})
function runFn() {
function run() {
//
if (state.step >= state.stopStep) {
//
@ -55,17 +57,20 @@ function runFn() {
state.step = state.lottery
state.speed = 2
state.loading = false
console.log(`恭喜获得${state.lottery}号奖品`)
console.log(`恭喜获得${activeIndex.value}号奖品`)
uni.showModal({
title: `恭喜获得${activeIndex.value}号奖品`,
})
return
}
// speed
if (state.step > 24 + state.lottery) {
if (state.step > lastLoopStep + state.lottery) {
state.speed++
}
//
state.step++
//
state.timer = setTimeout(runFn, state.speed * 30)
state.timer = setTimeout(run, state.speed * 30)
}
//
function handleClick(n) {
@ -75,12 +80,12 @@ function handleClick(n) {
if (state.loading) return
state.loading = true
// 使
state.lottery = Math.floor(Math.random() * 9)
state.lottery = Math.ceil(Math.random() * giftLen)
console.log(state.lottery)
// 4
state.stopStep = state.lottery + 32
state.stopStep = state.lottery + totalStep
//
runFn()
run()
}
</script>