|
|
@ -0,0 +1,52 @@ |
|
|
|
<script setup> |
|
|
|
|
|
|
|
import { ref, onBeforeMount } from 'vue' |
|
|
|
|
|
|
|
const myLucky = ref() |
|
|
|
const wheelConfig = ref({ |
|
|
|
}) |
|
|
|
const prizes = ref([ |
|
|
|
{ fonts: [{ text: '0', top: '10%' }], background: '#e9e8fe' }, |
|
|
|
{ fonts: [{ text: '1', top: '10%' }], background: '#b8c5f2' }, |
|
|
|
{ fonts: [{ text: '2', top: '10%' }], background: '#e9e8fe' }, |
|
|
|
{ fonts: [{ text: '3', top: '10%' }], background: '#b8c5f2' }, |
|
|
|
{ fonts: [{ text: '4', top: '10%' }], background: '#e9e8fe' }, |
|
|
|
{ fonts: [{ text: '5', top: '10%' }], background: '#b8c5f2' }, |
|
|
|
]) |
|
|
|
const blocks = ref([{ padding: '13px', background: '#617df2' }]) |
|
|
|
const buttons = ref([{ |
|
|
|
radius: '35%', |
|
|
|
background: '#8a9bf3', |
|
|
|
pointer: true, |
|
|
|
fonts: [{ text: '开始', top: '-10px' }] |
|
|
|
}]) |
|
|
|
|
|
|
|
function startCallback() { |
|
|
|
// 调用抽奖组件的play方法开始游戏 |
|
|
|
myLucky.value.play() |
|
|
|
// 模拟调用接口异步抽奖 |
|
|
|
setTimeout(() => { |
|
|
|
// 假设后端返回的中奖索引是0 |
|
|
|
const index = 0 |
|
|
|
// 调用stop停止旋转并传递中奖索引 |
|
|
|
myLucky.value.stop(index) |
|
|
|
}, 3000) |
|
|
|
} |
|
|
|
|
|
|
|
// 抽奖结束end回调 |
|
|
|
function endCallback(prize) { |
|
|
|
console.log(prize) |
|
|
|
} |
|
|
|
</script> |
|
|
|
|
|
|
|
<template> |
|
|
|
<h1> 大转盘 </h1> |
|
|
|
|
|
|
|
<div class="luckyWheel"> |
|
|
|
|
|
|
|
<LuckyWheel class="lucky" ref="myLucky" width="300px" height="300px" :default-config="wheelConfig" |
|
|
|
:prizes="prizes" :blocks="blocks" :buttons="buttons" @start="startCallback" @end="endCallback" /> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
|
|
|
|
<style scoped></style> |