NineGrid 九宫格
九宫格组件
使用指南
安装 营销组件库
# taro3安装营销插件包npm install @lylb/tzo-ui-marketing# taro2安装tzo-ui包npm install @lylb/tzo-ui
在 Taro3项目 文件中引入组件
import { NineGrid } from '@lylb/tzo-ui-marketing'
在 Taro2项目 文件中引入组件
import { NineGrid } from '@lylb/tzo-ui'
一般用法
import Taro from '@tarojs/taro'import { NineGrid } from '@lylb/tzo-ui-marketing'export default class Index extends Taro.Component {constructor() {super(...arguments)this.state = {nineGridConfig: {size: 578,innerSize: 550,backgroundImage:'https://mystore-img.watsonsvip.com.cn/upload/6adf9ba5-0475-43d7-add2-7ad356b5bc0b.png',playImage:'https://mystore-img.watsonsvip.com.cn/upload/31e909fd-4645-4761-ba28-cb2840f28ce3.png',prizeStyle: {backgroundImage:'https://mystore-img.watsonsvip.com.cn/upload/b6189b66-5e91-4393-8951-096273f1cada.png'}},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加油红包'},{id: 7,image: 'https://yanxuan.nosdn.127.net/static-union/165951604419ac9a.png',name: '5元直减红包'},{id: 8,image: 'https://yanxuan.nosdn.127.net/static-union/1659516044816161.png',name: '700加油红包'}]}}handlePlay = (onFinish) => {onFinish(Math.ceil(Math.random() * 7) + 1).then((item) => {console.log('中奖啦 >>>>>>', item)Taro.showToast({title: `恭喜中奖了!${item.name}`,icon: 'none'})},() => {console.log('未中奖')})}render() {const { bigWheelConfig, prizeGroup } = this.statereturn (<View><NineGridconfig={nineGridConfig}prizeGroup={prizeGroup}onPlay={handlePlay}/></View>)}}
参数
config
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
size | 大小 | number | - |
innerSize | 内框大小 | number | - |
backgroundImage | 转盘图片 | string | - |
playImage | 指针图片 | string | - |
prizeStyle | 奖品配置,具体详见奖品配置部分 | object | - |
奖品配置 prizeGroup
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
id | 奖品 id | number | - |
name | 奖品名称 | string | - |
image | 奖品图片 | string | - |
方法
函数名 | 说明 | 类型 |
---|---|---|
onPlay | 抽奖事件 | (finish: (prizeId) => Promise) => void |