支付寶小程序營銷組件 水果機·wheel-draw

2020-09-18 11:25 更新

通過點擊水果機(九宮格)中心按鈕來進行抽獎,可以自定義轉(zhuǎn)動抽獎的次數(shù)。

更多詳細信息請參見 代碼市場。

掃碼體驗

示例代碼

安裝

npm i ant-mini-fruit-slots --save

注冊

// .json
{
  "usingComponents": {
    "fruit-slots": "ant-mini-fruit-slots/es/fruit-slots/index"
  }
}

調(diào)用

<!-- .axml -->
<view class="container">
  <fruit-slots
    prizeList="{{prizeList}}"
    prizeName="{{prizeName}}"
    disabled="{{disabled}}"
    currentIndex="{{currentIndex}}"
    onStart="onStart"
    onFinish="onFinish"
  />
  <view class='tip-text'>{{tipText}}</view>
</view>undefined
// .js
Page({
  data: {
    prizeList: [ // prizeList 長度必須為8,其中須包含獎項名字 name 和圖標地址 icon
      {
        'name': '謝謝參與',
        'icon': 'https://zos.alipayobjects.com/rmsportal/dexmbhnbsLRGIZGBqTcA.png'
      },
      {
        'name': '666元紅包',
        'icon': 'https://zos.alipayobjects.com/rmsportal/nxpXbcNBOmbeIOVCUsuS.png'
      },
      {
      'name': '1元紅包',
      'icon': 'https://zos.alipayobjects.com/rmsportal/RxQruKQwiQCeYXhvwCfP.png'
      },
      {
        'name': '3元紅包',
        'icon': 'https://zos.alipayobjects.com/rmsportal/tyMAYvTdjRFOVxqWVhsj.png'
      },
      {
        'name': '謝謝參與',
        'icon': 'https://zos.alipayobjects.com/rmsportal/dexmbhnbsLRGIZGBqTcA.png'
      },
      {
        'name': '1元紅包',
        'icon': 'https://zos.alipayobjects.com/rmsportal/RxQruKQwiQCeYXhvwCfP.png'
      },
      {
        'name': '謝謝參與',
        'icon': 'https://zos.alipayobjects.com/rmsportal/dexmbhnbsLRGIZGBqTcA.png'
      },
      {
        'name': '5元紅包',
        'icon': 'https://zos.alipayobjects.com/rmsportal/qanDEFeGBoiPflYxkhJY.png'
      }
    ],
    prizeName: '5元紅包',
    disabled: false,
    currentIndex: 4,
    tipText: '',
  },
  onStart() {
    this.setData({
      tipText: '正在抽獎...'
    });
  },
  onFinish(index, name) {
    this.setData({
      currentIndex: Math.floor(Math.random() * 8),
      tipText: `抽獎結(jié)果:${name}`
    });
  }
});undefined

屬性

屬性 描述 類型 默認值 必填
width 組件寬度,單位 rpx。 Number 700
margin 格子間的邊距,單位 rpx。 Number 20
prizeList 獎項列表,長度必須為8,須包含 name 和 icon字段。 Array []
prizeName 抽獎結(jié)果的獎品 name,其值必須位于 prizeList 中。 String ''
rollTimes 轉(zhuǎn)動圈數(shù)。 Number 3
currentIndex 轉(zhuǎn)動開始的格子下標。 Number 0
speed 轉(zhuǎn)動速度,單位 ms。 Number 100
class 自定義類名。 String ''
disabled 抽獎按鈕是否可點擊。 Boolean false
onStart 轉(zhuǎn)動開始的回調(diào)。 Function () => {}
onFinish 轉(zhuǎn)動結(jié)束的回調(diào), @params(index: 獎品所在格子下標,name: 獎品名稱)。 Function (index, name) => {}

說明:組件中格子自左上角順時針開始標號,圍繞中間按鈕,下標從 0 開始遞增到 7。當需要組件從左下角的格子為初始位置開始轉(zhuǎn)動,只需要設(shè)置 currentIndex = 6 即可。

水果機序號demo.png

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號