BigWheel 大转盘
大转盘组件
使用指南
安装 营销组件库
# taro3安装营销插件包npm install @lylb/tzo-ui-marketing# taro2安装tzo-ui包npm install @lylb/tzo-ui
在 Taro3项目 文件中引入组件
import { BigWheel } from '@lylb/tzo-ui-marketing'
在 Taro2项目 文件中引入组件
import { BigWheel } from '@lylb/tzo-ui'
一般用法
import Taro from '@tarojs/taro'import { BigWheel } from '@lylb/tzo-ui-marketing'export default class Index extends Taro.Component {constructor() {super(...arguments)this.state = {bigWheelConfig: {size: 523.5,prizeOffset: 30,turntableImage:'http://tzo-ui.wangchunhai.com/images/wheel-bg.png',offsetRotate: 30,prizeScale: 0.6,pointerImage:'https://qw-oss1.oss-cn-shenzhen.aliyuncs.com/ba_assistant/201a3a40-2f3e-49c6-a067-13a4afabaa94-signin_draw_pointer.png',prize: {textColor: '#222222'}},prizeGroup: [{id: 1,image: 'https://yanxuan.nosdn.127.net/static-union/1659516044c3a18c.png', // 奖品图片name: '199减5红包' // 奖品名称},{id: 2,image: 'https://yanxuan.nosdn.127.net/static-union/165951604487ef12.png',name: '99减5红包'},{id: 3,image: 'https://yanxuan.nosdn.127.net/static-union/165951604419ac9a.png',name: '5元直减红包'},{id: 4,image: 'https://yanxuan.nosdn.127.net/static-union/1659516044816161.png',name: '700加油红包'},{id: 5,image: 'https://yanxuan.nosdn.127.net/static-union/165951604419ac9a.png',name: '5元直减红包'},{id: 6,image: 'https://yanxuan.nosdn.127.net/static-union/1659516044816161.png',name: '700加油红包'}]}}handlePlay = (onFinish) => {onFinish(Math.ceil(Math.random() * 5) + 1).then((item) => {Taro.showToast({title: `恭喜中奖了!${item.name}`,icon: 'none'})},() => {console.log('未中奖')})}render() {const { bigWheelConfig, prizeGroup } = this.statereturn (<View><BigWheelconfig={bigWheelConfig}prizeGroup={prizeGroup}onPlay={this.handlePlay()}/></View>)}}
参数
config
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
size | 转盘大小 | number | 600 |
turntableImage | 转盘图片 | string | - |
pointerImage | 指针图片 | string | - |
offsetRotate | 奖品偏移角度,具体详见奖品偏移角度部分 | number | 0 |
prizeOffset | 奖品偏移量用于设置奖品距离转盘边缘的距离,具体详见奖品配置部分 | number | 0 |
prizeScale | 奖品缩放 | number, [0,1] | 0.7 |
prize | 奖品其他配置,具体详见奖品配置部分 | object | - |
奖品配置 prizeGroup
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
id | 奖品 id | number | - |
name | 奖品名称 | string | - |
image | 奖品图片 | string | - |
方法
函数名 | 说明 | 类型 |
---|---|---|
onPlay | 抽奖事件 | (finish: (prizeId) => Promise) => void |