Grid.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. const myLucky = ref()
  23. const blocks = [
  24. // { padding: '10px', background: '#fff', imgs:[] },
  25. { padding: '10px', background: '#00897B', borderRadius: 6 },
  26. ]
  27. const prizeImg = {
  28. src: 'https://img1.baidu.com/it/u=681765036,1809656907&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400',
  29. activeSrc: 'https://bpic.588ku.com/element_origin_min_pic/19/11/15/a6f8bd3b208aca40e3de49209ab309ca.jpg',
  30. width: '100%',
  31. top: '0%'
  32. }
  33. const prizes = [
  34. { x: 0, y: 0, imgs: [prizeImg] },
  35. { x: 1, y: 0, imgs: [prizeImg] },
  36. { x: 2, y: 0, imgs: [prizeImg] },
  37. { x: 2, y: 1, imgs: [prizeImg] },
  38. { x: 2, y: 2, imgs: [prizeImg] },
  39. { x: 1, y: 2, imgs: [prizeImg] },
  40. { x: 0, y: 2, imgs: [prizeImg] },
  41. { x: 0, y: 1, imgs: [prizeImg] }
  42. ]
  43. const buttons = [
  44. {
  45. x: 1, y: 1,
  46. background: '#fe920200',
  47. borderRadius: '10px',
  48. imgs: [{
  49. src: 'https://img1.baidu.com/it/u=3949019928,2138080900&fm=253&fmt=auto&app=138&f=PNG?w=300&h=300',
  50. width: '100%',
  51. height: '100%',
  52. }],
  53. }
  54. ]
  55. const defaultConfig = {
  56. gutter: 10, // 格子之间的间隙
  57. speed: 10 // 旋转速度的峰值
  58. }
  59. const startCallback = () => {
  60. // 调用抽奖组件的play方法开始游戏
  61. myLucky.value.play()
  62. // 模拟调用接口异步抽奖
  63. setTimeout(() => {
  64. // 假设后端返回的中奖索引是0
  65. const index = 3
  66. // 调用stop停止旋转并传递中奖索引
  67. myLucky.value.stop(index)
  68. }, 1500)
  69. }
  70. const endCallback = (prize) => {
  71. // getData()
  72. }
  73. </script>
  74. <style scoped lang="scss">
  75. .prizeDrawBox {
  76. padding: 40px;
  77. background-color: var(--default-bgc);
  78. display: flex;
  79. flex-direction: column;
  80. // justify-content: center;
  81. align-items: center;
  82. }
  83. .prizeDraw {
  84. margin: 0 auto;
  85. cursor: pointer;
  86. }
  87. .numberBox {
  88. font-size: 20px;
  89. font-weight: bold;
  90. padding: 2px 38px;
  91. border-bottom: 3px solid #00897B;
  92. }
  93. .colorBase {
  94. color: var(--v-primary-base);
  95. margin: 0 6px;
  96. font-size: 22px;
  97. }
  98. </style>