更新记录
1.1.2(2025-08-13)
下载此版本
更新文档。
1.1.1(2025-08-13)
下载此版本
修改文档。
1.1.0(2025-08-13)
下载此版本
升级。
查看更多
平台兼容性
云端兼容性
uni-app(4.07)
Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
- |
√ |
√ |
- |
√ |
√ |
√ |
√ |
- |
微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
√ |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
uni-app x(4.07)
Chrome |
Safari |
Android |
iOS |
鸿蒙 |
微信小程序 |
- |
- |
- |
- |
- |
- |
其他
方便您的同时,请五星、收藏,让好的东西照亮更多深渊中负重前行的代码人。
创作不易,在您方便之际,赞赏作者,我们会更有动力继续下去。
简介
ljs-raffle-vue3,抽奖类随机控制器,超灵活,可配置。
可用场景:手机抽奖,大型抽奖页面等。
使用 uni_modules 安装(推荐)
使用 uni_modules 方式安装组件库,可以直接通过插件市场导入,通过右键菜单快速更新组件,不需要引用、注册,直接在页面中使用 ljs-raffle-vue3组件。
参数
参数 |
类型 |
必填项 |
默认值 |
说明 |
data |
Array<Object> |
√ |
|
奖品数据。 |
mode |
String |
× |
Random |
模式:Random - 随机;Line - 逐行;不匹配时按照Random执行。Line模式getRandomResult方法参数num只能为1。 |
wait |
Boolean |
× |
false |
等待,false无需等待。true所有闪动次数不执行,当为false时开始减少闪动次数。 |
interfere |
Boolean |
× |
|
干预开关。通常可用于等待接口返回数据后,搭配interfereResult和interfereResultWait动态干预结果。 |
interfereResult |
Number, Array |
× |
|
干预结果,传格子的索引。interfere为true时有效。getRandomResult方法参数num大于1时需为数组,且结果数组长度需与num一致。 |
interfereResultWait |
Boolean |
× |
false |
干预结果是否等待。interfere为true时有效。ture时等待中,false时结束等待。 |
options |
Object |
× |
参考options参数 |
配置。 |
options参数
参数 |
类型 |
必填项 |
默认值 |
说明 |
gridRows |
Number |
× |
3 |
格子:每行显示的数量。 |
gridGap |
Number |
× |
20 |
格子:间隙。单位rpx。 |
gridHeight |
String |
× |
null |
格子:高度。如:10%、200rpx等。不配置,则自动计算高度,效果为正方形。 |
panelPadding |
String |
× |
40rpx |
面板:padding。 |
panelBg |
String |
× |
#e47813 |
面板:背景。 |
configTime |
Number |
× |
300 |
配置:起始时间跨度。 |
configDecaySpan |
Number |
× |
0 |
配置:衰减值跨度。 |
configDecaySpanMin |
Number |
× |
10 |
配置:衰减值最小跨度。同时应用于最低时间下限判断,当configTime最小衰减至此数值。 |
configDecay |
Number |
× |
30 |
配置:实际衰减起始值。 |
configFrequency |
Number |
× |
150 |
配置:闪动次数。interfere为true时,interfereResultWait如果为true,则不停闪动,直至interfereResultWait为false时停止,并返回预设interfereResult。 |
暴露方法
方法名称 |
参数 |
说明 |
getRandomResult |
(num: Number = 1) |
获取随机结果。mode 为 Line时,num只能为1。 |
cleanResult |
无 |
清除最终的结果 |
插槽
插槽名 |
说明 |
default |
数据项回显插槽,显示样式由开发者自行定义。 |
operate |
操作栏,内容由开发者自行定义。可直接在组件外编写操作栏。如该插槽存在时,共用options.panelBg。 |
插槽default
参数 |
类型 |
说明 |
row |
Object |
所点击的对象。 |
index |
Number |
当前项的索引值。 |
activeIndex |
Number |
选中项的索引值。 |
height |
String |
格子的高度。小程序高度错误时,可以手动调控。 |
快速应用
常规示例
<ljs-raffle-vue3
ref="ljsRaffle"
:data="data"
@result="result">
<template #default="{row, activeIndex, index}">
<view class="content"
:class="{
active: activeIndex === index
}">
<image class="pic" :src="row.img"></image>
<view class="text">{{ row.label }}</view>
</view>
</template>
<template #operate>
<view class="butBox">
<view class="but" @click="getRandom">单抽</view>
<view class="but" @click="getRandom10">10连抽</view>
</view>
</template>
</ljs-raffle-vue3>
export default {
data() {
return {
data: [
{
label: '钻石',
img: 'https://wine-project.oss-cn-beijing.aliyuncs.com/weapp/mine/bayAVine_icon1.png',
},
{
label: '精美贴画',
img: 'https://wine-project.oss-cn-beijing.aliyuncs.com/weapp/mine/bayAVine_icon2.png',
},
{
label: 'Iphone 16',
img: 'https://wine-project.oss-cn-beijing.aliyuncs.com/weapp/mine/bayAVine_icon3.png',
},
{
label: '手机支架',
img: 'https://wine-project.oss-cn-beijing.aliyuncs.com/weapp/mine/bayAVine_icon4.png',
},
{
label: '唇膏',
img: 'https://wine-project.oss-cn-beijing.aliyuncs.com/weapp/mine/bayAVine_icon1.png',
},
{
label: '小夜灯',
img: 'https://wine-project.oss-cn-beijing.aliyuncs.com/weapp/mine/bayAVine_icon2.png',
},
{
label: '虎虎生威眼罩',
img: 'https://wine-project.oss-cn-beijing.aliyuncs.com/weapp/mine/bayAVine_icon3.png',
},
{
label: '降噪耳机',
img: 'https://wine-project.oss-cn-beijing.aliyuncs.com/weapp/mine/bayAVine_icon4.png',
},
{
label: '蓝牙耳机',
img: 'https://wine-project.oss-cn-beijing.aliyuncs.com/weapp/mine/bayAVine_icon1.png',
},
]
}
},
onLoad() {
},
methods: {
getRandom() {
this.$refs.ljsRaffle.getRandomResult(1);
},
getRandom10() {
this.$refs.ljsRaffle.getRandomResult(10);
},
result(val, index) {
console.log(val, index);
}
}
}
.content{
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-color: #999;
border-radius: 8rpx;
&.active{
background-color: rgba(245, 153, 66, .6);
}
.pic{
width: 60upx;
height: 60upx;
}
.pic{
width: 60upx;
height: 60upx;
}
.text{
font-size: 26upx;
color: #000;
margin-top: 20upx;
}
}
.butBox{
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
padding: 20upx 0;
.but{
width: 200upx;
height: 96upx;
line-height: 96upx;
text-align: center;
background-color: #f59942;
color: #FFF;
font-size: 32upx;
font-weight: 600;
margin-right: 40upx;
border-radius: 20upx;
&:last-child{
margin-right: 0;
}
}
}
干预示例
<ljs-raffle-vue3
ref="ljsRaffle"
:data="data"
:interfere="true"
:interfereResult="interfereResult"
:interfereResultWait="interfereResultWait"
@result="result">
<template #default="{row, activeIndex, index}">
<view class="content"
:class="{
active: activeIndex === index
}">
<image class="pic" :src="row.img"></image>
<view class="text">{{ row.label }}</view>
</view>
</template>
<template #operate>
<view class="butBox">
<view class="but" @click="getRandom">单抽</view>
<view class="but" @click="getRandom10">10连抽</view>
</view>
</template>
</ljs-raffle-vue3>
export default {
data() {
return {
interfereResult: null,
interfereResultWait: true, // 干预时
}
},
onLoad() {
setInterval(() => {
this.interfereResult = [1, 2, 1, 1, 1, 1, 1, 1, 1, 1]
this.interfereResultWait = false;
}, 5000)
},
methods: {
getRandom() {
this.$refs.ljsRaffle.getRandomResult(1);
},
getRandom10() {
this.$refs.ljsRaffle.getRandomResult(10);
},
result(val, index) {
console.log(val, index);
}
}
}
贡献代码
龙九山。有任何问题,请在平台留言,在手头宽裕得情况下,我会尽快修复问题。