W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
通過點擊轉(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"
}
}
<!-- .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 | () => {} |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: