feat(抽奖活动页): 修复抽奖问题
This commit is contained in:
parent
caef58fa15
commit
44658c262b
@ -868,9 +868,6 @@ const barrageList = ref([
|
|||||||
// 活动详情
|
// 活动详情
|
||||||
const activity = ref({})
|
const activity = ref({})
|
||||||
|
|
||||||
// 奖品数据 (8个位置)
|
|
||||||
const prizes = ref([])
|
|
||||||
|
|
||||||
const userInfo = ref({}) //用户信息
|
const userInfo = ref({}) //用户信息
|
||||||
const userIdentity = ref({}) //用户身份
|
const userIdentity = ref({}) //用户身份
|
||||||
|
|
||||||
@ -1060,6 +1057,8 @@ const getGridPosition = (index) => {
|
|||||||
|
|
||||||
// 抽奖动画
|
// 抽奖动画
|
||||||
const startLottery = (resultIndex) => {
|
const startLottery = (resultIndex) => {
|
||||||
|
console.log('开始抽奖动画')
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
activeIndex.value = -1
|
activeIndex.value = -1
|
||||||
|
|
||||||
@ -1069,14 +1068,15 @@ const startLottery = (resultIndex) => {
|
|||||||
let totalCycles = 1 // 至少旋转2圈数
|
let totalCycles = 1 // 至少旋转2圈数
|
||||||
|
|
||||||
const roll = () => {
|
const roll = () => {
|
||||||
activeIndex.value = (activeIndex.value + 1) % prizes.value.length
|
activeIndex.value = (activeIndex.value + 1) % activity.value.prizeList.length
|
||||||
|
console.log('当前索引:', activeIndex.value)
|
||||||
|
|
||||||
if (activeIndex.value === resultIndex && speed > 200) {
|
if (activeIndex.value === resultIndex && speed > 200) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
resolve() // 抽奖结束
|
resolve() // 抽奖结束
|
||||||
}, 500)
|
}, 500)
|
||||||
} else {
|
} else {
|
||||||
if (activeIndex.value === prizes.value.length - 1) {
|
if (activeIndex.value === activity.value.prizeList.length - 1) {
|
||||||
currentCycle++
|
currentCycle++
|
||||||
}
|
}
|
||||||
// 加速旋转
|
// 加速旋转
|
||||||
@ -1084,7 +1084,7 @@ const startLottery = (resultIndex) => {
|
|||||||
speed -= 20
|
speed -= 20
|
||||||
} else {
|
} else {
|
||||||
// 匀速旋转
|
// 匀速旋转
|
||||||
if (activeIndex.value === prizes.value.length - 1) {
|
if (activeIndex.value === activity.value.prizeList.length - 1) {
|
||||||
constantSpeedCycle++
|
constantSpeedCycle++
|
||||||
}
|
}
|
||||||
if (constantSpeedCycle > 2) {
|
if (constantSpeedCycle > 2) {
|
||||||
@ -1110,26 +1110,12 @@ const sweepstakes = async (consecutive) => {
|
|||||||
activityId: activity.value.activity.id,
|
activityId: activity.value.activity.id,
|
||||||
drawCount: consecutive,
|
drawCount: consecutive,
|
||||||
}
|
}
|
||||||
// 单抽
|
try {
|
||||||
if (consecutive == 1) {
|
// 单抽
|
||||||
const resOnceDraw = await onceDraw(data)
|
if (consecutive == 1) {
|
||||||
if (resOnceDraw.status && resOnceDraw.body) {
|
const resOnceDraw = await onceDraw(data)
|
||||||
const resItem = resOnceDraw.body //接口获取的抽奖结果
|
if (resOnceDraw.status && resOnceDraw.body) {
|
||||||
const index = activity.value.prizeList.findIndex(
|
const resItem = resOnceDraw.body //接口获取的抽奖结果
|
||||||
(prize) => prize.prizeName == resItem?.prize.prizeName
|
|
||||||
) //转盘第几位停下
|
|
||||||
console.log('index:', index)
|
|
||||||
await startLottery(index)
|
|
||||||
result.value.push(resItem)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//连抽
|
|
||||||
else {
|
|
||||||
const resMultiDraw = await multiDraw(data)
|
|
||||||
if (resMultiDraw.status && resMultiDraw.body) {
|
|
||||||
const resDrawList = resMultiDraw.body //连抽获取的抽奖列表结果
|
|
||||||
for (let i = 0; i < resDrawList.results.length; i++) {
|
|
||||||
const resItem = resDrawList.results[i]
|
|
||||||
const index = activity.value.prizeList.findIndex(
|
const index = activity.value.prizeList.findIndex(
|
||||||
(prize) => prize.prizeName == resItem?.prize.prizeName
|
(prize) => prize.prizeName == resItem?.prize.prizeName
|
||||||
) //转盘第几位停下
|
) //转盘第几位停下
|
||||||
@ -1138,10 +1124,28 @@ const sweepstakes = async (consecutive) => {
|
|||||||
result.value.push(resItem)
|
result.value.push(resItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//连抽
|
||||||
|
else {
|
||||||
|
const resMultiDraw = await multiDraw(data)
|
||||||
|
if (resMultiDraw.status && resMultiDraw.body) {
|
||||||
|
const resDrawList = resMultiDraw.body //连抽获取的抽奖列表结果
|
||||||
|
for (let i = 0; i < resDrawList.results.length; i++) {
|
||||||
|
const resItem = resDrawList.results[i]
|
||||||
|
const index = activity.value.prizeList.findIndex(
|
||||||
|
(prize) => prize.prizeName == resItem?.prize.prizeName
|
||||||
|
) //转盘第几位停下
|
||||||
|
console.log('index:', index)
|
||||||
|
await startLottery(index)
|
||||||
|
result.value.push(resItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getTickets() //重新获取拥有的抽奖券
|
||||||
|
resultShow.value = true
|
||||||
|
isRolling.value = false
|
||||||
|
} catch (error) {
|
||||||
|
isRolling.value = false
|
||||||
}
|
}
|
||||||
getTickets() //重新获取拥有的抽奖券
|
|
||||||
resultShow.value = true
|
|
||||||
isRolling.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user