<template>
<div class="app">
<turntable :size="size" :columns="columns" @start="handleStart" @end="handleEnd"></turntable>
<h3>剩余抽奖次数:{{ count }}</h3>
</div>
</template>
<script setup>
import { ref } from "vue"
import turntable from "@/packages/turntable.vue"
const count = ref(2)
// 转盘尺寸
const size = 1
// 轮盘的数据
const columns = [
{
text: "20g水滴",
icon: water_drop,
id: "1",
},
{
text: "谢谢参与",
icon: love,
id: "5",
},
......
]
// 回调函数(开始)
const handleStart = (startRoate, stopRoate) => {
if (!count.value) {
// 次数为0取消抽奖
startRoate(false)
return
}
count.value --
// 开始抽奖
startRoate(true)
// 2s后抽到的id为6
setTimeout(() => {
stopRoate(6)
}, 2000)
}
// 回调函数(结束)
const handleEnd = () => {
alert('抽奖结束')
}
</script>