LuckDraw 转盘抽奖请使用手机扫码体验

基本用法

  1. html
    <nut-luckdraw
  2. class="drawTable"
  3. ref="luckDrawPrize"
  4. :luck-width="luckWidth"
  5. :luck-height="luckheight"
  6. :prize-list="prizeList"
  7. :turns-number="turnsNumber"
  8. :turns-time="turnsTime"
  9. :prize-index="prizeIndex"
  10. :style-opt="styleOpt"
  11. @end-turns="endTurns"
  12. >
  13. <template slot="item" slot-scope="scope">
  14. <div class="drawTable-name">{{ scope.item.prizeName }}</div>
  15. <div class="drawTable-img">
  16. <img :src="scope.item.prizeImg">
  17. </div>
  18. </template>
  19. </nut-luckdraw>
  20. <div @click="startTurns" class="pointer" :style="pointerStyle"></div>
  1. javascript
    export default {
  2. data() {
  3. return {
  4. // 转盘大小
  5. luckWidth: '300px',
  6. luckheight: '300px',
  7. // 转盘指针图片样式
  8. pointerStyle: {
  9. width: '80px',
  10. height: '80px',
  11. backgroundImage: 'url("https://img11.360buyimg.com/imagetools/jfs/t1/89512/11/15244/137408/5e6f15edEf57fa3ff/cb57747119b3bf89.png")',
  12. backgroundSize: 'contain',
  13. backgroundRepeat: 'no-repeat',
  14. },
  15. // 奖品列表
  16. prizeList: [
  17. {
  18. id: 'xiaomi',
  19. prizeName: '小米手机',
  20. prizeImg: 'https://img14.360buyimg.com/imagetools/jfs/t1/104165/34/15186/96522/5e6f1435E46bc0cb0/d4e878a15bfd9362.png',
  21. },
  22. {
  23. id: 'blue',
  24. prizeName: '蓝牙耳机',
  25. prizeImg: 'https://img13.360buyimg.com/imagetools/jfs/t1/91864/11/15108/139003/5e6f146dE1c7b511d/1ddc5aa6e502060a.jpg',
  26. },
  27. {
  28. id: 'apple',
  29. prizeName: 'apple watch',
  30. prizeImg: 'https://img11.360buyimg.com/imagetools/jfs/t1/105385/19/15140/111093/5e6f1506E48bd0dfb/829a98a8cdb4c27f.png',
  31. },
  32. {
  33. id: 'fruit',
  34. prizeName: '迪士尼苹果',
  35. prizeImg: 'https://img11.360buyimg.com/imagetools/jfs/t1/108308/11/8890/237603/5e6f157eE489cccf1/26e0437cfd93b9c8.png',
  36. },
  37. {
  38. id: 'fish',
  39. prizeName: '海鲜套餐',
  40. prizeImg: 'https://img14.360buyimg.com/imagetools/jfs/t1/90507/38/15165/448364/5e6f15b4E5df0c718/4bd4c3d375eec312.png',
  41. },
  42. {
  43. id: 'thanks',
  44. prizeName: '谢谢参与',
  45. prizeImg: 'https://img11.360buyimg.com/imagetools/jfs/t1/96116/38/15085/5181/5e6f15d1E48e31d30/71353b61dff705d4.png',
  46. }
  47. ],
  48. turnsNumber: 5, // 转动圈数
  49. turnsTime: 5,// 转动时间:S
  50. styleOpt: {
  51. prizeBgColors: ['rgb(255, 231, 149)','rgb(255, 247, 223)','rgb(255, 231, 149)','rgb(255, 247, 223)','rgb(255, 231, 149)','rgb(255, 247, 223)'],
  52. borderColor: '#ff9800',
  53. },
  54. prizeIndex: -1, // 中奖奖品的index
  55. lock: false,// 防止多次连续点击抽奖
  56. num: 5,// 抽奖次数,根据需求定义
  57. }
  58. },
  59. methods: {
  60. startTurns() {
  61. if (!this.canBeRotated()) {
  62. return false;
  63. }
  64. this.lock = true;
  65. // 此为模拟随机数字,这里可以接受后台中奖信息
  66. const index = Math.floor(Math.random() * this.prizeList.length);
  67. // 成功后抽奖次数减1
  68. this.num--;
  69. // 中奖奖品的index
  70. this.prizeIndex = index;
  71. // 调用组件的方法,使转盘转动并停留在中奖奖品的那个扇形区域
  72. this.$refs.luckDrawPrize.rotate(index);
  73. },
  74. endTurns() {
  75. this.$dialog({
  76. content: `恭喜中奖!!!${this.prizeList[this.prizeIndex].prizeName}`,
  77. noCloseBtn: false,
  78. noOkBtn: true,
  79. cancelBtnTxt: "我知道了"
  80. });
  81. this.lock = false;
  82. },
  83. canBeRotated() {
  84. if (this.num <= 0) {
  85. this.$dialog({
  86. content: `已经没有次数了,继续加油赚积分吧!`,
  87. noCloseBtn: false,
  88. noOkBtn: true,
  89. cancelBtnTxt: "我知道了"
  90. });
  91. return false;
  92. }
  93. if (this.lock) {
  94. return false;
  95. }
  96. return true;
  97. },
  98. }
  99. }

Prop

字段说明类型默认值
ref当前转盘的类名,转动的时候根据类名执行回调函数StringluckDrawPrize
luck-width转盘的宽度String300px
luck-height转盘的高度String300px
prize-list奖品列表Array-
turns-number转动的圈数Number5
turns-time从开始转动到结束所用时间Number5(单位是秒)
style-opt转盘中的样式,包括每个扇区的背景颜色,扇区的边框颜色Object{prizeBgColors: [],borderColor: ‘’}
pointerStyle转盘中指针的样式,包括背景图片、大小等Object{width: ‘80px’,height: ‘80px’}

Event

字段说明回调参数
end-turns转盘中停止转动后的回调函数-

LuckDraw 转盘抽奖 - 图1