From 5224d89450cf2421d9fdf31a2878615368b7a2b0 Mon Sep 17 00:00:00 2001 From: Burt <1020103647@qq.com> Date: Fri, 12 Jan 2024 16:15:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20totalRunAngle=20computed=E6=9C=89BUG?= =?UTF-8?q?=EF=BC=8C=E6=94=B9=E4=B8=BAref?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/lottery/big-wheel.vue | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/pages/lottery/big-wheel.vue b/src/pages/lottery/big-wheel.vue index 176ecf6..40d9d78 100644 --- a/src/pages/lottery/big-wheel.vue +++ b/src/pages/lottery/big-wheel.vue @@ -77,11 +77,8 @@ const rotateAngle = computed(() => { const _degree = 360 / prizeList.length return _degree }) - // 要执行总角度数 -const totalRunAngle = computed(() => { - return baseRunAngle + 360 - prizeId * rotateAngle.value - rotateAngle.value / 2 -}) +const totalRunAngle = ref(baseRunAngle - (prizeId + 0.5) * rotateAngle.value) // 计算绘制转盘背景 const bgColor = (() => { @@ -114,7 +111,13 @@ const getRandomNum = () => { const stopRun = () => { isRunning = false - styleObj.value = `${bgColor} transform: rotate(${totalRunAngle.value - baseRunAngle}deg);` + const prizeName = prizeList.find((e) => e.id === prizeId)!.name + uni.showModal({ + title: `恭喜你中奖 ${prizeName}`, + success() { + styleObj.value = `${bgColor} transform: rotate(0deg);` + }, + }) } const startRun = () => { @@ -128,12 +131,13 @@ const start = () => { isRunning = true console.log('开始抽奖,后台请求中奖奖品') - setTimeout(() => { - // 请求返回的奖品编号 这里使用随机数 - prizeId = getRandomNum() - console.log('中奖ID>>>', prizeId, prizeList[prizeId]) - }, 2000) - startRun() + // 请求返回的奖品编号 这里使用随机数 + prizeId = getRandomNum() + totalRunAngle.value = baseRunAngle - (prizeId + 0.5) * rotateAngle.value + console.log('中奖ID>>>', prizeId, prizeList[prizeId], totalRunAngle.value) + nextTick(() => { + startRun() + }) } }