uniapp 九宫格抽奖

抽奖

样式就自己写吧

实现思路:因为是九宫格,里面商品只会有九个,他们的index是固定的,然后根据后端返回的中奖商品id找出他的index,设置抽奖动画固定跑三遍然后加上你中奖id的index即可

代码:

// 点击后 true 获取奖品后 false 防止重复点击

rolling: false,

// 滚动选中的id

currentIdx: -1,

// 中奖id的key

prizeId: null

点击抽奖事件

复制代码
// 点击抽奖事件
			drawChange() {
				if (this.rolling) return
				this.currentIdx = -1
				this.rolling = true
				var id = 2
				// 根据key值所以加1
				this.prizeId = this.drawList.findIndex(item => item.id == id)
				if (this.prizeId < 0) {
					this.$Common.showToast('系统繁忙,请稍后重试')
				} else {
					this.prizeId += 1
					this.startAnimation()
				}
			},
			startAnimation() {
				let speed = 100; // 初始速度(ms)
				let step = 0;
				const totalSteps = 9 + this.prizeId; // 总滚动步数
				this.intervalId = setInterval(() => {
					if (step >= totalSteps) {
						clearInterval(this.intervalId);
						// 打开弹窗
						this.stopAtTarget();
					} else {
						this.currentIdx = (this.currentIdx + 1) % this.drawList.length;
						speed += 40; // 逐步增加间隔时间模拟减速
						step++;
					}
				}, speed);
			},
相关推荐
2501_9151063220 分钟前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_9151063230 分钟前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
宠友信息2 小时前
2025社交+IM及时通讯社区APP仿小红书小程序
java·spring boot·小程序·uni-app·web app
“负拾捌”2 小时前
python + uniapp 结合腾讯云实现实时语音识别功能(WebSocket)
python·websocket·微信小程序·uni-app·大模型·腾讯云·语音识别
局外人LZ1 天前
Uniapp脚手架项目搭建,uniapp+vue3+uView pro+vite+pinia+sass
前端·uni-app·sass
2501_915918411 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
前端呆头鹅1 天前
Websocket使用方案详解(uniapp版)
websocket·网络协议·uni-app
浮桥1 天前
uniapp+h5 公众号实现分享海报绘制
uni-app·notepad++
2501_916007471 天前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview
wangjun51591 天前
uniapp uni.downloadFile 偶发性下载文件失败 无响应
uni-app