支付寶小程序營銷組件 大轉(zhuǎn)盤·wheel-draw

2020-09-18 11:25 更新

通過點擊轉(zhuǎn)盤中心按鈕轉(zhuǎn)動轉(zhuǎn)盤,進(jìn)行抽獎,可以自定義轉(zhuǎn)盤轉(zhuǎn)動抽獎的次數(shù)。

更多詳細(xì)信息請參見 代碼市場。

掃碼體驗

示例代碼

安裝

npm i ant-mini-wheel-draw --save

注冊

//.json
{
  "usingComponents": {
    "wheel": "ant-mini-wheel-draw/es/wheel/index"
  }
}

調(diào)用

<!-- .axml -->
<view class="container">
  <wheel
    width="22em"
    prizeList="{{prizeList}}" // 獎項列表
    prizeName="{{prizeName}}" // 獲獎項目名稱
    rotTimes="{{totalTimes}}" // 轉(zhuǎn)盤機會次數(shù)
    onStart="onStart" // 轉(zhuǎn)盤開始旋轉(zhuǎn)回調(diào)
    onFinish="onFinish" // 轉(zhuǎn)盤結(jié)束旋轉(zhuǎn)回調(diào)
  />
  <view class="times">
    <text>你還有{{totalTimes - curTimes}}次抽獎機會</text>
  </view>
  <view class="result">
    <text>{{result}}</text>
  </view>
</view>undefined
// .js
Page({
  data: {
    prizeList: [
      {
        name: 'H&M100元優(yōu)惠券',
        img: 'https://gw.alipayobjects.com/zos/rmsportal/nIQUKeYBbJWliGJVhVmx.png'
      }, {
        name: '2元話費券',
        img: 'https://gw.alipayobjects.com/zos/rmsportal/HkrVjjjuxZPUMCUbPazb.png'
      }, {
        name: '45元飛豬出行券',
        img: 'https://gw.alipayobjects.com/zos/rmsportal/cDctUxwBLPCszQHRapYV.png'
      }, {
        name: 'H&M10元優(yōu)惠券',
        img: 'https://gw.alipayobjects.com/zos/rmsportal/FAmIWZAWpUwlRFKqQDLz.png'
      }, {
        name: '2元流量券',
        img: 'https://gw.alipayobjects.com/zos/rmsportal/cuGomeXzMyeeZMjvVjBj.png'
      }, {
        name: '未中獎',
        img: 'https://zos.alipayobjects.com/rmsportal/dwhgPyWAcXuvJAWlSSgU.png'
      }
    ],
    prizeName: '2元話費券',
    totalTimes: 2,
    curTimes: 0,
    result: '',
  },
  /*
    @param name 獲獎項名字
    @param times 當(dāng)前轉(zhuǎn)動次數(shù)
  */
  onStart (name, times) {
    // 轉(zhuǎn)盤開始轉(zhuǎn)動
    this.setData({
      result: `第${times}次抽獎中,請稍候...`,
      curTimes: times++
    })
  },
  /*
    @param name 獲獎項名字
    @param times 當(dāng)前轉(zhuǎn)動次數(shù)
  */
  onFinish (name, times) {
    // 轉(zhuǎn)盤結(jié)束轉(zhuǎn)動
     this.setData({
      result: name === '未中獎' ? '很遺憾,差點就中獎了' : `恭喜你,獲得${name}`,
      prizeName: this.data.prizeList[Math.floor(Math.random() * 6)].name,
    })
  }
});undefined

屬性

屬性 描述 類型 默認(rèn)值 必填
width 轉(zhuǎn)盤容器寬度,默認(rèn)單位 px。 Number 300
initDeg 轉(zhuǎn)盤初始化角度旋轉(zhuǎn)偏移,單位 reg。 Number 0
rotTimes 抽獎機會次數(shù),當(dāng)抽獎次數(shù)大于該值時不可再抽獎。 Number 1
prizeList 獎品列表,長度為6,每一項必須包含img(獎品圖片) 和 name(獎品名字)。 Array []
prizeName 中獎的獎品名字,值需要存在于 prizeList 的 name 字段中。 String ''
prizeWidth 獎品圖片寬度,默認(rèn)單位 px,插件會根據(jù) width 選項值自動計算,建議不填。 Number 80
prizePaddingTop 獎品圖片距圓弧的內(nèi)邊距,默認(rèn)單位 px,插件會根據(jù) width 選項值自動計算,建議不填。 Number 20
bgImg 轉(zhuǎn)盤扇面背景圖地址。 String -
btnImg 轉(zhuǎn)盤按鈕背景圖地址。 String -
onStart 旋轉(zhuǎn)開始回調(diào),name:中獎項name,times:當(dāng)前是第幾次旋轉(zhuǎn)。 Function (name, times) => {}
onFinish 旋轉(zhuǎn)結(jié)束回調(diào),name:中獎項name,times:當(dāng)前是第幾次旋轉(zhuǎn)。 Function (name, times) => {}
onTimesUp 抽獎次數(shù)用盡后,再次點擊抽獎按鈕會觸發(fā)該回調(diào)。 Function () => {}
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號