Grid.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <view class="prizeDrawBox">
  3. <LuckyGrid
  4. ref="myLucky"
  5. width="300px"
  6. height="300px"
  7. :prizes="prizes"
  8. :blocks="blocks"
  9. :buttons="buttons"
  10. :default-config="defaultConfig"
  11. :disabled="true"
  12. class="prizeDraw"
  13. @start="startCallback"
  14. @end="endCallback"
  15. />
  16. <view class="numberBox mt-5">您还剩余<span class="colorBase">{{ number }}</span>次抽奖机会</view>
  17. </view>
  18. </template>
  19. <script setup>
  20. import LuckyGrid from '@lucky-canvas/uni/lucky-grid'
  21. import { ref } from 'vue'
  22. import sheep from '@/sheep';
  23. const myLucky = ref()
  24. const blocks = [
  25. // { padding: '10px', background: '#fff', imgs:[] },
  26. { padding: '10px', background: '#00897B', borderRadius: 6 },
  27. ]
  28. const prizeImg = {
  29. src: 'https://img1.baidu.com/it/u=681765036,1809656907&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400',
  30. activeSrc: 'https://bpic.588ku.com/element_origin_min_pic/19/11/15/a6f8bd3b208aca40e3de49209ab309ca.jpg',
  31. width: '100%',
  32. top: '0%'
  33. }
  34. const prizes = [
  35. { x: 0, y: 0, imgs: [prizeImg] },
  36. { x: 1, y: 0, imgs: [prizeImg] },
  37. { x: 2, y: 0, imgs: [prizeImg] },
  38. { x: 2, y: 1, imgs: [prizeImg] },
  39. { x: 2, y: 2, imgs: [prizeImg] },
  40. { x: 1, y: 2, imgs: [prizeImg] },
  41. { x: 0, y: 2, imgs: [prizeImg] },
  42. { x: 0, y: 1, imgs: [prizeImg] }
  43. ]
  44. const buttons = [
  45. {
  46. x: 1, y: 1,
  47. background: '#fe920200',
  48. borderRadius: '10px',
  49. imgs: [{
  50. src: 'https://img1.baidu.com/it/u=3949019928,2138080900&fm=253&fmt=auto&app=138&f=PNG?w=300&h=300',
  51. width: '100%',
  52. height: '100%',
  53. }],
  54. }
  55. ]
  56. const defaultConfig = {
  57. gutter: 10, // 格子之间的间隙
  58. speed: 10 // 旋转速度的峰值
  59. }
  60. const startCallback = () => {
  61. // if (!number.value) return Snackbar.warning('抽奖次数已用完!')
  62. if (!number.value) {
  63. sheep.$helper.toast('抽奖次数已用完')
  64. return
  65. }
  66. // 调用抽奖组件的play方法开始游戏
  67. myLucky.value.play()
  68. // 模拟调用接口异步抽奖
  69. setTimeout(() => {
  70. // 假设后端返回的中奖索引是0
  71. const index = 3
  72. // 调用stop停止旋转并传递中奖索引
  73. myLucky.value.stop(index)
  74. }, 1500)
  75. }
  76. const endCallback = (prize) => {
  77. console.log(prize, 'end')
  78. getData()
  79. }
  80. // 获取抽奖次数
  81. const number = ref(3)
  82. const getData = async () => {
  83. number.value--
  84. // const data = await getProductDetail()
  85. // number.value = data || 0
  86. }
  87. getData()
  88. </script>
  89. <style scoped lang="scss">
  90. .prizeDrawBox {
  91. padding: 40px;
  92. background-color: var(--default-bgc);
  93. display: flex;
  94. flex-direction: column;
  95. // justify-content: center;
  96. align-items: center;
  97. }
  98. .prizeDraw {
  99. margin: 0 auto;
  100. cursor: pointer;
  101. }
  102. .numberBox {
  103. font-size: 20px;
  104. font-weight: bold;
  105. padding: 2px 38px;
  106. border-bottom: 3px solid #00897B;
  107. }
  108. .colorBase {
  109. color: var(--v-primary-base);
  110. margin: 0 6px;
  111. font-size: 22px;
  112. }
  113. </style>