Files
crmeb-mp/pages/goods/components/lottery/js/grids_lottery.js
karlcarlo a5c5d753b6 feat: 添加静态资源文件及基础组件
- 新增大量图片资源,包括图标、背景图、海报等,用于页面展示
- 添加字体文件及样式配置,支持自定义字体
- 引入 uni-ui 组件库,包括图标、弹窗、日期选择器等常用组件
- 添加网络状态监听、加密工具等基础工具函数
- 配置 Vuex 状态管理,包括购物车数量、热门搜索词等
- 增加页面组件,如用户协议、分销信息、提现状态等
- 配置项目构建和忽略文件,优化开发体验
2026-02-26 17:59:51 +08:00

47 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
function LotteryDraw(obj, callback) {
this.timer = null; //计时器
this.startIndex = obj.startIndex-1 || 0; //从第几个位置开始抽奖 [默认为零]
this.count = 0; //计数,跑的圈数
this.winingIndex = obj.winingIndex || 0;//获奖的位置
this.totalCount = obj.totalCount || 6;//抽奖跑的圈数
this.speed = obj.speed || 100;
this.domData=obj.domData;
this.rollFn();
this.callback = callback;
}
LotteryDraw.prototype = {
rollFn: function() {
var that = this;
// console.log(`获奖位置:${this.winingIndex}`)
// 活动index值增加,即移动到下一个格子
this.startIndex++;
//startIndex是最后一个时一圈走完,重新开始
if (this.startIndex >= this.domData.length - 1) {
this.startIndex = 0;
this.count++;
}
// 当跑的圈数等于设置的圈数,且活动的index值是奖品的位置时停止
if (this.count >= this.totalCount && this.startIndex === this.winingIndex) {
if (typeof this.callback === 'function') {
setTimeout(function() {
that.callback(that.startIndex,that.count); //执行回调函数,抽奖完成的相关操作
}, 400);
}
clearInterval(this.timer);
}else { //重新开始一圈
if (this.count >= this.totalCount - 1) {
this.speed += 30;
}
this.timer = setTimeout(function() {
that.callback(that.startIndex,that.count);
that.rollFn();
}, this.speed);
}
}
}
module.exports = LotteryDraw;