fix: totalRunAngle computed有BUG,改为ref

This commit is contained in:
Burt 2024-01-12 16:15:36 +08:00
parent c71d3b3053
commit 5224d89450

View File

@ -77,11 +77,8 @@ const rotateAngle = computed(() => {
const _degree = 360 / prizeList.length const _degree = 360 / prizeList.length
return _degree return _degree
}) })
// //
const totalRunAngle = computed(() => { const totalRunAngle = ref(baseRunAngle - (prizeId + 0.5) * rotateAngle.value)
return baseRunAngle + 360 - prizeId * rotateAngle.value - rotateAngle.value / 2
})
// //
const bgColor = (() => { const bgColor = (() => {
@ -114,7 +111,13 @@ const getRandomNum = () => {
const stopRun = () => { const stopRun = () => {
isRunning = false 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 = () => { const startRun = () => {
@ -128,12 +131,13 @@ const start = () => {
isRunning = true isRunning = true
console.log('开始抽奖,后台请求中奖奖品') console.log('开始抽奖,后台请求中奖奖品')
setTimeout(() => { // 使
// 使 prizeId = getRandomNum()
prizeId = getRandomNum() totalRunAngle.value = baseRunAngle - (prizeId + 0.5) * rotateAngle.value
console.log('中奖ID>>>', prizeId, prizeList[prizeId]) console.log('中奖ID>>>', prizeId, prizeList[prizeId], totalRunAngle.value)
}, 2000) nextTick(() => {
startRun() startRun()
})
} }
} }
</script> </script>