Wheel.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <view>
  3. <LuckyWheel
  4. ref="myLucky"
  5. width="600rpx"
  6. height="600rpx"
  7. :blocks="blocks"
  8. :prizes="prizes"
  9. :buttons="buttons"
  10. :defaultStyle="defaultStyle"
  11. @start="startCallBack"
  12. @end="endCallBack"
  13. />
  14. </view>
  15. </template>
  16. <script>
  17. import LuckyWheel from '@lucky-canvas/uni/lucky-wheel'
  18. export default {
  19. components: { LuckyWheel },
  20. data () {
  21. return {
  22. blocks: [{ padding: '13px', background: '#617df2' }],
  23. prizes: [
  24. { fonts: [{ text: '0', top: '10%' }], background: '#e9e8fe' },
  25. { fonts: [{ text: '1', top: '10%' }], background: '#b8c5f2' },
  26. { fonts: [{ text: '2', top: '10%' }], background: '#e9e8fe' },
  27. { fonts: [{ text: '3', top: '10%' }], background: '#b8c5f2' },
  28. { fonts: [{ text: '4', top: '10%' }], background: '#e9e8fe' },
  29. { fonts: [{ text: '5', top: '10%' }], background: '#b8c5f2' },
  30. ],
  31. buttons: [
  32. { radius: '50px', background: '#617df2' },
  33. { radius: '45px', background: '#afc8ff' },
  34. {
  35. radius: '40px', background: '#869cfa',
  36. pointer: true,
  37. fonts: [{ text: '开始\n抽奖', top: '-20px' }]
  38. },
  39. ],
  40. }
  41. },
  42. methods: {
  43. // 点击抽奖按钮触发回调
  44. startCallBack () {
  45. // 先开始旋转
  46. this.$refs.myLucky.play()
  47. // 使用定时器来模拟请求接口
  48. setTimeout(() => {
  49. // 假设后端返回的中奖索引是0
  50. const index = 0
  51. // 调用stop停止旋转并传递中奖索引
  52. this.$refs.myLucky.stop(index)
  53. }, 3000)
  54. },
  55. // 抽奖结束触发回调
  56. endCallBack (prize) {
  57. // 奖品详情
  58. console.log(prize)
  59. }
  60. }
  61. }
  62. </script>