W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
通過點擊水果機(九宮格)中心按鈕來進行抽獎,可以自定義轉(zhuǎn)動抽獎的次數(shù)。
更多詳細信息請參見 代碼市場。
npm i ant-mini-fruit-slots --save
// .json
{
"usingComponents": {
"fruit-slots": "ant-mini-fruit-slots/es/fruit-slots/index"
}
}
<!-- .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
即可。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: