提交代码

This commit is contained in:
zpc 2025-05-16 04:29:20 +08:00
parent 758198ec71
commit 9bddcd2b9c
7 changed files with 1122 additions and 396 deletions

13
App.vue
View File

@ -61,7 +61,18 @@ export default {
// Vue.prototype.bgmCtx = {};
Vue.prototype.bgmCtx.slotBgm = slotBgm;
slotBgm.src = src2;
//
let src3 = await that.$config.getAppSettingAsync("win_audio3");
if (src3 == null || src3 == "") {
src3 = that.$img("/static/mp3/chaoshen.mp3");
}
//
const csBgm = uni.createInnerAudioContext();
// Vue.prototype.bgmCtx = {};
Vue.prototype.bgmCtx.csBgm = csBgm;
csBgm.src = src3;

View File

@ -0,0 +1,113 @@
<template>
<view>
<!-- <img style="width: 0%; height: 0%;display: none;" :src="webpUrl"> -->
<view class="content-container" :class="{'fade-out': isFadingOut}" v-if="isVisible && isInitialized">
<img id="animatedWebp" style="width: 100%; height: 100%" :src="webpUrl" alt="超神特效" />
</view>
</view>
</template>
<script>
export default {
props: {
// prizeList props
},
data() {
return {
isVisible: false, // /
isInitialized: false, //
webpUrl: "https://image.zfunbox.cn/static/image/lucky/grand.webp",
isFadingOut: false, //
};
},
computed: {},
methods: {
//
init() {
this.isInitialized = true;
this.webpUrl = "";
},
playWebP() {
const webpImg = document.getElementById("animatedWebp");
//
webpImg.src = ""; //
webpImg.src = "https://image.zfunbox.cn/static/image/lucky/grand.webp"; // URL
webpImg.style.animationPlayState = "running";
if (this.bgmCtx && this.bgmCtx.csBgm) {
this.bgmCtx.csBgm.seek(0);
this.bgmCtx.csBgm.play();
}
},
pauseWebP() {
const webpImg = document.getElementById("animatedWebp");
webpImg.style.animationPlayState = "paused";
},
//
show() {
if (!this.isInitialized) {
console.error("尚未初始化请先调用init方法");
return this;
}
this.isVisible = true;
this.isFadingOut = false; //
this.webpUrl =
"https://image.zfunbox.cn/static/image/lucky/grand.webp?v=" +
new Date().getTime();
if (this.bgmCtx && this.bgmCtx.csBgm) {
this.bgmCtx.csBgm.seek(0);
this.bgmCtx.csBgm.play();
}
//
setTimeout(() => {
//
this.isFadingOut = true;
//
setTimeout(() => {
if (this.bgmCtx && this.bgmCtx.csBgm) {
this.bgmCtx.csBgm.pause();
}
this.isVisible = false;
this.$emit("end");
}, 400); // 800ms
}, 3800); // 44.2
return this;
},
},
mounted() {
//
},
};
</script>
<style lang="scss" scoped>
//
.content-container {
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
box-sizing: border-box;
//background-image: url('https://image.zfunbox.cn/static/image/lucky/grand.webp');
background-size: cover;
background-position: center;
position: fixed;
top: 0;
left: 0;
z-index: 999;
opacity: 1;
transition: opacity 0.8s ease;
}
//
.fade-out {
opacity: 0;
}
</style>

View File

@ -2,29 +2,18 @@
<view class="content-container" v-if="isVisible && isInitialized">
<view class="slot-container">
<view class="slot-icon">
<image
src="https://image.zfunbox.cn/static/image/lucky/icon.png"
mode="widthFix"
style="height: 90rpx; width: 249rpx"
></image>
<image src="https://image.zfunbox.cn/static/image/lucky/icon.png" mode="widthFix"
style="height: 90rpx; width: 249rpx"></image>
</view>
<view class="slot-view" :class="'slot-view-' + currentMode">
<!-- 老虎机组件 -->
<SlotMachine
ref="myLucky"
:width="windowWidth"
:height="slotHeight"
:blocks="blocks"
:slots="slots"
:prizes="prizes"
:defaultConfig="defaultConfig"
@start="startCallBack"
@end="endCallBack"
>
<SlotMachine ref="myLucky" :width="windowWidth" :height="slotHeight" :blocks="blocks" :slots="slots"
:prizes="prizes" :defaultConfig="defaultConfig" @start="startCallBack" @end="endCallBack">
</SlotMachine>
</view>
<view style="color: #484848;font-size: 19rpx;text-align: center;padding-top: 20rpx;">动画结果因设备差异可能会显示异常获得赏品以恭喜获得结果为准</view>
<view style="color: #249073;font-size: 21rpx;text-align: center;padding-top: 20rpx;">跳过动画</view>
<view style="color: #484848;font-size: 19rpx;text-align: center;padding-top: 20rpx;">
动画结果因设备差异可能会显示异常获得赏品以恭喜获得结果为准</view>
<view class="skip-animation" @click="skipAnimation" :style="skipButtonStyle">跳过动画</view>
</view>
</view>
</template>
@ -46,12 +35,12 @@ function shuffle(array) {
export default {
components: { SlotMachine },
props: {
// : 1, 3, 5 (135)
// : 1, 3, 5, 10 (13510)
mode: {
type: [Number, String],
default: 1,
validator: function(value) {
return [1, 3, 5, '1', '3', '5'].includes(value);
validator: function (value) {
return [1, 3, 5, 10, '1', '3', '5', '10'].includes(value);
}
}
},
@ -74,6 +63,12 @@ export default {
luckyPrize: null,
currentPrizeIndex: -1,
internalMode: 1, //
skipButtonOpacity: 0, //
isBatchMode: false, //
batchCount: 0, //
batchResults: [], //
batchCallback: null, //
batchIndices: [], //
};
},
computed: {
@ -85,15 +80,18 @@ export default {
},
//
currentMode() {
return parseInt(this.internalMode);
// internalMode105
return this.internalMode === 10 ? 5 : parseInt(this.internalMode);
},
//
slotHeight() {
const modeMap = {
1: "160rpx",
3: "480rpx",
5: "800rpx"
5: "800rpx",
10: "800rpx" // 10使5
};
// 使currentMode使internalMode
return modeMap[this.currentMode] || "480rpx";
},
//
@ -101,21 +99,31 @@ export default {
const modeMap = {
1: "di_5.png",
3: "di_3.png",
5: "di_5.png"
5: "di_5.png",
10: "di_5.png" // 10使5
};
// 使currentMode使internalMode
return modeMap[this.currentMode] || "di_3.png";
},
//
skipButtonStyle() {
return {
opacity: this.skipButtonOpacity,
transition: 'opacity 0.5s ease'
};
}
},
methods: {
//
init(prizeList, mode) {
//
if (mode !== undefined && [1, 3, 5].includes(parseInt(mode))) {
if (mode !== undefined && [1, 3, 5, 10].includes(parseInt(mode))) {
this.internalMode = parseInt(mode);
} else {
// 使propsmode
this.internalMode = parseInt(this.mode);
}
console.log("初始化模式:", this.internalMode, "显示模式:", this.currentMode);
//
if (prizeList && Array.isArray(prizeList) && prizeList.length > 0) {
@ -141,13 +149,15 @@ export default {
data: t[i], // prize便使
});
}
// slots
const arr = Array.from({ length: t.length }, (_, i) => i);
let slots = [];
//
for (let i = 0; i < this.currentMode; i++) {
// 1055
const slotColumns = this.currentMode;
for (let i = 0; i < slotColumns; i++) {
slots.push({ order: shuffle([...arr]), speed: 20 });
}
@ -301,10 +311,9 @@ export default {
//
endCallBack(prize) {
//
console.log("抽奖结束", prize);
try {
console.log("[批次抽奖] endCallBack 被调用,批次模式:", this.isBatchMode, "当前模式:", this.internalMode, "批次计数:", this.batchCount);
//
const prizeData =
this.prizes[this.currentPrizeIndex]?.data || this.prizes[0]?.data;
@ -337,8 +346,8 @@ export default {
allPrizes.push(prizeData);
}
//
this.$emit("end", {
//
const result = {
prize: prize,
prizeData: prizeData, //
allPrizes: allPrizes, //
@ -349,18 +358,213 @@ export default {
description: `价值:${prizeData.price}`,
data: prizeData,
},
});
};
//
if (this.isBatchMode && this.internalMode === 10) {
this.batchCount++;
//
this.batchResults.push(...allPrizes);
console.log("[批次抽奖] 批次抽奖完成", this.batchCount, "共", this.batchResults.length, "个奖品");
if (this.batchCount < 2) {
//
console.log("[批次抽奖] 第一批次完成,准备开始第二批次");
setTimeout(() => {
console.log("[批次抽奖] 即将调用startSecondBatch");
this.startSecondBatch();
}, 800);
return;
} else {
//
console.log("[批次抽奖] 两批次都完成,返回最终结果");
const batchResult = {
prize: prize,
prizeData: prizeData,
allPrizes: this.batchResults,
message: `恭喜您获得 ${this.batchResults.length} 件奖品`,
prizeInfo: {
name: "批次抽奖",
image: prizeData.imgurl,
description: `共获得 ${this.batchResults.length} 件奖品`,
data: this.batchResults,
},
};
setTimeout(() => {
//
this.$emit("end", batchResult);
//
if (this.batchCallback && typeof this.batchCallback === 'function') {
console.log("[批次抽奖] 调用批次回调函数");
this.batchCallback(batchResult);
this.batchCallback = null;
}
//
this.isBatchMode = false;
this.batchCount = 0;
this.batchResults = [];
}, 800);
return;
}
}
setTimeout(() => {
//
this.$emit("end", result);
// startDrawWithResult
if (this.drawResultCallback && typeof this.drawResultCallback === 'function') {
this.drawResultCallback(result);
//
this.drawResultCallback = null;
}
},800);
// //
// setTimeout(() => {
// this.hide();
// }, 2000);
} catch (error) {
console.error("处理抽奖结果时出错:", error);
console.error("[批次抽奖] 处理抽奖结果时出错:", error);
this.hide();
//
if (this.drawResultCallback && typeof this.drawResultCallback === 'function') {
this.drawResultCallback({ success: false, error: error.message || "处理抽奖结果时出错" });
this.drawResultCallback = null;
}
//
if (this.isBatchMode && this.batchCallback) {
this.batchCallback({ success: false, error: error.message || "批次抽奖出错" });
this.isBatchMode = false;
this.batchCount = 0;
this.batchResults = [];
this.batchCallback = null;
}
}
},
//
forceEndDraw() {
if (!this.isInitialized) {
console.error("老虎机尚未初始化请先调用init方法");
return this;
}
if (this.bgmCtx && this.bgmCtx.slotBgm) {
this.bgmCtx.slotBgm.stop();
}
console.log("[跳过动画] 批次模式:", this.isBatchMode, "当前模式:", this.internalMode, "批次计数:", this.batchCount);
this.hide();
//
if (this.isBatchMode && this.internalMode === 10) {
//
if (this.batchCallback && typeof this.batchCallback === 'function') {
console.log("[跳过动画] 批次模式下跳过动画,准备返回结果");
//
if (this.batchResults.length === 0) {
console.log("[跳过动画] 没有现有结果,创建随机结果");
// 使
let indices = [];
if (this.batchIndices && this.batchIndices.length > 0) {
indices = this.batchIndices;
} else {
// 10
for (let i = 0; i < 10; i++) {
indices.push(Math.floor(Math.random() * this.prizes.length));
}
}
//
for (let i = 0; i < indices.length; i++) {
const index = indices[i];
if (index >= 0 && index < this.prizes.length) {
const prizeData = this.prizes[index].data;
if (prizeData) {
this.batchResults.push(prizeData);
}
}
}
}
//
let firstPrize = this.batchResults[0] || null;
const result = {
allPrizes: this.batchResults,
message: `抽奖已跳过,共获得 ${this.batchResults.length} 件奖品`,
skipped: true,
prizeData: firstPrize,
prizeInfo: firstPrize ? {
name: firstPrize.title,
image: firstPrize.imgurl,
description: `价值:${firstPrize.price}`,
data: firstPrize,
} : null
};
//
this.$emit("end", result);
console.log("[跳过动画] 调用批次回调函数");
this.batchCallback(result);
this.batchCallback = null;
}
//
this.isBatchMode = false;
this.batchCount = 0;
this.batchResults = [];
return this;
}
//
if (this.currentPrizeIndex >= 0 && this.prizes.length > 0) {
const prizeData = this.prizes[this.currentPrizeIndex]?.data || this.prizes[0]?.data;
if (prizeData) {
const result = {
prize: { index: this.currentPrizeIndex },
prizeData: prizeData,
allPrizes: [prizeData],
message: `恭喜您获得 ${prizeData.title}`,
prizeInfo: {
name: prizeData.title,
image: prizeData.imgurl,
description: `价值:${prizeData.price}`,
data: prizeData,
},
skipped: true //
};
//
this.$emit("end", result);
// startDrawWithResult
if (this.drawResultCallback && typeof this.drawResultCallback === 'function') {
this.drawResultCallback(result);
//
this.drawResultCallback = null;
}
}
}
return this; // this
},
//
skipAnimation() {
//
this.forceEndDraw();
},
//
startDraw(callback) {
//
@ -369,7 +573,30 @@ export default {
return this;
}
// init
//
this.drawResultCallback = typeof callback === 'function' ? callback : null;
//
this.skipButtonOpacity = 0;
// 10
if (this.internalMode === 10) {
console.log("[批次抽奖] 检测到模式10启用批次模式");
this.isBatchMode = true;
this.batchCount = 0;
this.batchResults = [];
this.batchCallback = this.drawResultCallback; //
this.drawResultCallback = null; //
//
this.batchIndices = [];
for (let i = 0; i < 10; i++) {
this.batchIndices.push(Math.floor(Math.random() * this.prizes.length));
}
console.log("[批次抽奖] 生成随机索引:", this.batchIndices);
}
//
this.show();
setTimeout(() => {
@ -380,10 +607,27 @@ export default {
//
this.$refs.myLucky.play();
if (this.bgmCtx && this.bgmCtx.slotBgm) {
this.bgmCtx.slotBgm.seek(0);
this.bgmCtx.slotBgm.play();
}
if (typeof callback === "function") {
//
setTimeout(() => {
this.skipButtonOpacity = 1;
}, 1000);
//
if (this.isBatchMode && this.internalMode === 10) {
console.log("[批次抽奖] 设置2秒后自动停止第一批次");
setTimeout(() => {
// 使5
const firstBatchIndices = this.batchIndices.slice(0, 5);
console.log("[批次抽奖] 停止第一批次抽奖,使用索引:", firstBatchIndices);
this.stopDraw(firstBatchIndices);
}, 2000);
}
if (typeof callback === "function" && !this.isBatchMode) {
callback();
}
} else {
@ -397,6 +641,8 @@ export default {
//
stopDraw(prizeIndices) {
console.log("stopDraw",prizeIndices);
//
if (!this.isInitialized) {
console.error("老虎机尚未初始化请先调用init方法");
@ -408,6 +654,11 @@ export default {
return this;
}
//
if (this.isBatchMode && this.internalMode === 10) {
console.log("[批次抽奖] 停止抽奖,批次:", this.batchCount + 1, "索引:", prizeIndices);
}
//
if (
!prizeIndices ||
@ -442,13 +693,9 @@ export default {
this.currentPrizeIndex = indices[0];
// 使currentMode
if(indices.length > this.currentMode){
indices=indices.slice(0,this.currentMode)
if (indices.length > this.currentMode) {
indices = indices.slice(0, this.currentMode)
}
// // 33使3
// if (this.currentMode === 3 && indices.length > 3) {
// indices = indices.slice(0, 3);
// }
// stop
this.$refs.myLucky.stop(indices);
@ -456,17 +703,6 @@ export default {
return this;
},
//
forceEndDraw() {
if (!this.isInitialized) {
console.error("老虎机尚未初始化请先调用init方法");
return this;
}
this.hide();
return this; // this
},
//
reset() {
this.isInitialized = false;
@ -477,6 +713,247 @@ export default {
this.currentPrizeIndex = -1;
return this;
},
/**
* 开始抽奖并传入抽奖结果2秒后自动停止
* @param {Array} resultIndices 抽奖结果索引数组
* @param {Function} callback 抽奖结束后的回调函数
* @return {Object} this 返回组件实例支持链式调用
*/
startDrawWithResult(resultIndices, callback) {
//
if (!this.isInitialized) {
console.error("老虎机尚未初始化请先调用init方法");
return this;
}
//
if (!resultIndices || !Array.isArray(resultIndices)) {
console.error("抽奖结果必须是数组");
return this;
}
// 10
if (this.internalMode === 10) {
//
if (resultIndices.length < 10) {
console.error("模式10需要至少10个索引当前只有", resultIndices.length);
// 10
const originalLength = resultIndices.length;
for (let i = originalLength; i < 10; i++) {
resultIndices.push(Math.floor(Math.random() * this.prizes.length));
}
console.log("[批次抽奖] 自动补足索引到10个:", resultIndices);
}
console.log("[批次抽奖] 检测到模式10启用批次模式共", resultIndices.length, "个索引");
//
this.drawResultCallback = null;
this.batchCallback = typeof callback === 'function' ? callback : null;
//
this.isBatchMode = true;
this.batchCount = 0;
this.batchResults = [];
this.batchIndices = resultIndices;
//
this.skipButtonOpacity = 0;
//
this.show();
let that=this;
setTimeout(() => {
// DOMplay
this.$nextTick(() => {
//
if (this.$refs.myLucky) {
console.log("[批次抽奖] 开始第一批次抽奖");
//
this.$refs.myLucky.play();
//
if (that.bgmCtx && that.bgmCtx.slotBgm) {
console.log("[批次抽奖] 播放第一批次抽奖音乐");
that.bgmCtx.slotBgm.seek(0);
that.bgmCtx.slotBgm.play();
} else {
console.log("[批次抽奖] 未找到音乐上下文,无法播放音乐");
}
//
setTimeout(() => {
this.skipButtonOpacity = 1;
}, 1000);
// 2
setTimeout(() => {
// 使5
const firstBatchIndices = resultIndices.slice(0, 5);
console.log("[批次抽奖] 停止第一批次抽奖,使用索引:", firstBatchIndices);
this.stopDraw(firstBatchIndices);
}, 2000);
} else {
console.error("[批次抽奖] 老虎机组件未初始化");
if (this.batchCallback) {
this.batchCallback({ success: false, error: "老虎机组件未初始化" });
this.batchCallback = null;
}
this.isBatchMode = false;
}
});
}, 200);
return this; // this
}
//
//
this.drawResultCallback = typeof callback === 'function' ? callback : null;
//
this.skipButtonOpacity = 0;
//
this.show();
setTimeout(() => {
// DOMplay
this.$nextTick(() => {
//
if (this.$refs.myLucky) {
//
this.$refs.myLucky.play();
//
if (this.bgmCtx && this.bgmCtx.slotBgm) {
console.log("播放抽奖音乐");
this.bgmCtx.slotBgm.seek(0);
this.bgmCtx.slotBgm.play();
} else {
console.log("未找到音乐上下文,无法播放音乐");
}
//
setTimeout(() => {
this.skipButtonOpacity = 1;
}, 1000);
// 2
setTimeout(() => {
//
this.stopDraw(resultIndices);
}, 2000);
} else {
console.error("老虎机组件未初始化");
//
if (this.drawResultCallback) {
this.drawResultCallback({ success: false, error: "老虎机组件未初始化" });
this.drawResultCallback = null;
}
}
});
}, 200);
return this; // this
},
//
startSecondBatch() {
console.log("[批次抽奖] 尝试开始第二批次,批次模式:", this.isBatchMode, "当前模式:", this.internalMode);
if (!this.isBatchMode || this.internalMode !== 10) {
console.error("[批次抽奖] 不是批次模式或模式不是10无法开始第二批次");
return;
}
console.log("[批次抽奖] 开始第二批次抽奖");
//
this.skipButtonOpacity = 0;
//
try {
//
console.log("[批次抽奖] 重置老虎机状态,准备第二批次抽奖");
//
const arr = Array.from({ length: this.prizes.length }, (_, i) => i);
let slots = [];
//
const slotColumns = this.currentMode;
for (let i = 0; i < slotColumns; i++) {
slots.push({ order: shuffle([...arr]), speed: 20 });
}
// slots
this.slots = slots;
} catch (error) {
console.error("[批次抽奖] 重置老虎机状态失败:", error);
}
this.$nextTick(() => {
if (this.$refs.myLucky) {
//
console.log("[批次抽奖] 调用play方法开始第二批次");
this.$refs.myLucky.play();
//
if (this.bgmCtx && this.bgmCtx.slotBgm) {
console.log("[批次抽奖] 播放第二批次抽奖音乐");
this.bgmCtx.slotBgm.seek(0);
this.bgmCtx.slotBgm.play();
} else {
console.log("[批次抽奖] 未找到音乐上下文,无法播放音乐");
}
//
setTimeout(() => {
this.skipButtonOpacity = 1;
}, 1000);
// 2
setTimeout(() => {
// 使
let indices = [];
if (this.batchIndices && this.batchIndices.length > 5) {
// 使
indices = this.batchIndices.slice(5, 10);
console.log("[批次抽奖] 使用预设的第二批次索引", indices);
} else {
//
for (let i = 0; i < 5; i++) {
indices.push(Math.floor(Math.random() * this.prizes.length));
}
console.log("[批次抽奖] 生成随机第二批次索引", indices);
}
this.stopDraw(indices);
}, 2000);
} else {
console.error("[批次抽奖] 第二批次无法启动,老虎机组件未找到");
//
if (this.batchCallback && typeof this.batchCallback === 'function') {
const result = {
allPrizes: this.batchResults,
message: `第二批次抽奖失败,返回已有结果`,
error: "老虎机组件未找到",
success: false
};
this.batchCallback(result);
this.batchCallback = null;
//
this.isBatchMode = false;
this.batchCount = 0;
this.batchResults = [];
}
}
});
},
},
mounted() {
//
@ -486,7 +963,7 @@ export default {
mode: {
immediate: true,
handler(newVal) {
if ([1, 3, 5, '1', '3', '5'].includes(newVal)) {
if ([1, 3, 5, 10, '1', '3', '5', '10'].includes(newVal)) {
this.internalMode = parseInt(newVal);
}
}
@ -567,4 +1044,21 @@ export default {
box-sizing: border-box;
background-color: rgba(255, 255, 255, 1);
}
//
.skip-animation {
color: #249073;
font-size: 21rpx;
text-align: center;
padding-top: 20rpx;
padding-bottom: 10rpx;
display: inline-block;
opacity: 0;
transition: opacity 0.5s ease;
user-select: none;
}
.skip-animation:active {
opacity: 0.7;
}
</style>

View File

@ -38,8 +38,9 @@
</text>
</view>
<collect-btn v-if="pageData && pageData.goods" :goods-id="pageData.goods.id"
:goods-num="pageData.goods.num" :is-collected="pageData.goods.collection_is"
<collect-btn v-if="pageData && pageData.goods && pageData.goods.collection_is != null"
:goods-id="pageData.goods.id" :goods-num="pageData.goods.num"
:is-collected="pageData.goods.collection_is ? true : false"
@collection-changed="onCollectionChanged"></collect-btn>
<view
@ -163,6 +164,9 @@
<coupon-pop ref="couponPop"></coupon-pop>
<!-- 添加直接引用的预览组件 -->
<detail-preview-popup ref="localPreviewPopup"></detail-preview-popup>
<!-- 使用抽取的老虎机组件 -->
<DetailLucky ref="detailLucky" @end="onLuckyEnd" />
<DetailGrandPrize ref="detailGrandPrize" @end="onLuckyEnd" />
</view>
</page-container>
</template>
@ -175,14 +179,19 @@ import DetailButton from '@/components/detail-button/detail-button.vue'
//
import DetailPreviewPopup from '@/components/detail-preview-popup/detail-preview-popup.vue'
import preview from '@/components/detail-preview-popup/index.js'
//
import DetailLucky from "@/components/detail-lucky/detail-lucky.vue";
//
import DetailGrandPrize from "@/components/detail-lucky/detail-grand-prize.vue";
export default {
components: {
PageContainer,
OrderConfirmPopup,
DetailListItem,
DetailButton,
DetailPreviewPopup //
DetailPreviewPopup,
DetailLucky,
DetailGrandPrize
},
data() {
return {
@ -239,12 +248,21 @@ export default {
useMoney: true,
useIntegral: true,
useMoney2: true,
isPrizeLoading: false // loading
};
},
created() {
},
computed: {},
computed: {
getGoodList() {
if (this.pageData?.goodslist == null) {
return [];
}
return this.pageData.goodslist;
}
},
onShareAppMessage() {
if (this.$refs["couponPop"] != null) {
var co = this.$refs["couponPop"].getfengxiaodata();
@ -309,6 +327,17 @@ export default {
},
methods: {
//
onLuckyEnd(data) {
console.log("抽奖结束", data);
//
// console.log(":", data.allPrizes);
this.$refs.detailLucky.hide();
this.bgmCtx.openBgm.play()
this.open('resPop')
},
previewDetail(item) {
console.log(item);
// 使
@ -367,41 +396,68 @@ export default {
});
},
getPrize(order_num) {
async getPrize(order_num) {
if (!order_num) {
return;
}
let that = this;
setTimeout(() => {
this.req({
url: "prizeorderlog",
data: {
order_num,
},
success: (res) => {
if (res.status == 1) {
this.prizeData = res.data;
if (res.data.data.length <= 0) {
this.getPrize(order_num);
return;
}
if (that.buyNum == 0 || that.buyNum == null) {
if (res.data.prize_num != null) {
that.buyNum = res.data.prize_num;
}
}
// this.aniShow = true
// setTimeout(() => {
// this.aniShow = false
this.bgmCtx.openBgm.stop();
this.bgmCtx.openBgm.play();
this.open("resPop");
// }, 1300)
let that = this;
if (!this.isPrizeLoading) {
this.isPrizeLoading = true;
uni.showLoading({ title: '加载中...' });
}
setTimeout(async () => {
const res = await this.$request.post('prizeorderlog', { order_num }, false);
if (res.status == 1) {
res.data.data.map(item => {
item.isChoose = false
})
console.log(res.data);
this.prizeData = res.data
if (res.data.data.length <= 0) {
this.getPrize(order_num)
return
}
this.$refs.detailLucky.init(this.getGoodList, this.buyNum);
if (that.buyNum == 0 || that.buyNum == null) {
if (res.data.prize_num != null) {
that.buyNum = res.data.prize_num;
}
},
});
}, 500);
}
if (this.prizeData.data.length > 10) {
this.$refs.detailLucky.hide();
this.bgmCtx.openBgm.play()
this.open('resPop')
return;
}
let chaoshen = this.prizeData.data.findIndex(it => it.shang_id == 34);
if (chaoshen != -1) {
console.log('抽中超神');
uni.hideLoading();
this.$refs.detailGrandPrize.init();
this.$refs.detailGrandPrize.show();
return;
}
//
let resultIndices = this.prizeData.data.map(it => {
// console.log(it.id);
const index = this.getGoodList.findIndex(item => item.id == it.goodslist_id);
// console.log(index);
return index;
});
// console.log(resultIndices,this.getGoodList, this.prizeData.data, "resultIndices");
this.$refs.detailLucky.startDrawWithResult(resultIndices, () => {
console.log("抽奖结束");
});
this.isPrizeLoading = false;
uni.hideLoading();
}
}, 500)
},
changePay(e) {
@ -416,15 +472,69 @@ export default {
},
confirmSubmit([type, num, fromNotice = false]) {
let url = "ordermoney";
if (type === 0) {
//
this.calculateOrder(num);
} else if (type === 1) {
//
this.submitOrder(num, fromNotice);
}
},
if (type == 1) {
url = "orderbuy";
calculateOrder(num) {
this.buyNum = num;
let coupon_id = (this.couponData && this.couponData.id) || ''
if (coupon_id != '' && this.useIntegral) {
this.useIntegral = false;
} else if (this.useIntegral && coupon_id != '') {
this.couponData = null;
coupon_id = '';
}
let data = {
goods_id: this.pageData.goods.id,
prize_num: this.buyNum,
goods_num: this.pageData.goods.num,
use_money_is: this.useMoney ? 1 : 2,
use_integral_is: this.useIntegral ? 1 : 2,
coupon_id: coupon_id,
use_money2_is: this.useMoney2 ? 1 : 2
};
if (this.$refs.buyNotice.getIsShow() && !fromNotice) {
this.$refs.buyNotice.getRule(6);
return;
}
if (this.pageData.goods.type == 5) {
data.coupon_id = "";
}
this.req({
url: "ordermoney",
data,
success: (res) => {
if (res.status == 1) {
if (res.data.coupon_id) {
this.couponData = {
id: res.data.coupon_id,
price: res.data.coupon_price,
};
}
this.orderData = res.data;
// 使this.$nextTick
this.$nextTick(() => {
if (this.$refs.buyPop) {
this.$refs.buyPop.open();
} else {
console.error('buyPop组件引用不存在');
}
});
}
},
});
},
submitOrder(num, fromNotice = false) {
if (this.$refs.buyNotice.getIsShow() && !fromNotice) {
this.$refs.buyNotice.getRule(6);
return;
}
this.buyNum = num;
@ -449,60 +559,35 @@ export default {
data.coupon_id = "";
}
this.close("buyPop");
this.req({
url,
url: "orderbuy",
data,
success: async (res) => {
if (res.status == 1) {
if (type == 0) {
if (res.data.coupon_id) {
this.couponData = {
id: res.data.coupon_id,
price: res.data.coupon_price,
};
if (res.data.status == 1) {
const status = await this.$platform.pay({
data: res.data.res
})
if (status == "success") {
this.getPrize(res.data.order_num);
this.doRefresh();
}
this.orderData = res.data;
// 使this.$nextTick
this.$nextTick(() => {
if (this.$refs.buyPop) {
this.$refs.buyPop.open();
} else {
console.error('buyPop组件引用不存在');
}
});
}
if (type == 1) {
this.close("buyPop");
if (res.data.status == 1) {
const status = await this.$platform.pay({
data: res.data.res
})
if (status == "success") {
} else {
this.$c.toast({
title: res.msg,
duration: 500,
success: () => {
this.getPrize(res.data.order_num);
this.doRefresh();
}
} else {
this.$c.toast({
title: res.msg,
duration: 500,
success: () => {
this.getPrize(res.data.order_num);
this.doRefresh();
},
});
}
},
});
}
}
},
});
if (type == 1) {
this.close("buyPop");
}
},
onCollectionChanged() {

View File

@ -141,8 +141,8 @@
</template>
<!-- 选项按钮 冲一发-->
<detail-button v-if="pageData" :pageData="pageData" :isWuxian="true" @button-click="confirmSubmit"
@button-wx-click="wuxianchou"></detail-button>
<detail-button v-if="pageData" :pageData="pageData" :isWuxian="true"
@button-click="confirmSubmit"></detail-button>
<!-- 抽奖结果 -->
<uni-popup ref="resPop" type="center" mask-background-color="rgba(0,0,0,0.8)">
@ -241,31 +241,10 @@
<detail-preview-popup ref="localPreviewPopup"></detail-preview-popup>
</view>
<!-- 老虎机 -->
<uni-popup ref="slotPop" type="center">
<view class="slot-pop" style="">
<view class="slot-view">
<view class=""
style="width: 100%; height: 152.78rpx; background-color: aquamarine; margin-top: 195rpx;">
<tiner-swiper-loop ref="lottryRef" :items="productList" :aTime="5" :isLottry="true"
:excessCount="0" :disableTouch="true" style="height: 152.78rpx; width: 100%;">
<template v-slot="{ item, index }">
<view class="item-lottry">{{ item.title }}</view>
</template>
</tiner-swiper-loop>
</view>
</view>
<text style="color: #484848; font-size: 19rpx;">动画结果因设备差异可能会显示异常获得赏品以恭喜获得结果为准</text>
</view>
</uni-popup>
<!-- 使用抽取的老虎机组件 -->
<DetailLucky ref="detailLucky" @end="onLuckyEnd" />
<DetailGrandPrize ref="detailGrandPrize" @end="onLuckyEnd" />
</page-container>
</template>
@ -279,8 +258,10 @@ import DetailPreviewPopup from '@/components/detail-preview-popup/detail-preview
import preview from '@/components/detail-preview-popup/index.js'
import DetailWuxianLingzhu from '@/components/detail-wuxian-lingzhu/detail-wuxian-lingzhu.vue'
import DetailWuxianRage from '@/components/detail-wuxian-rage/detail-wuxian-rage.vue'
//
//
import DetailLucky from "@/components/detail-lucky/detail-lucky.vue";
//
import DetailGrandPrize from "@/components/detail-lucky/detail-grand-prize.vue";
export default {
components: {
PageContainer,
@ -290,7 +271,8 @@ export default {
DetailPreviewPopup,
DetailWuxianLingzhu,
DetailWuxianRage, //
DetailLucky
DetailLucky,
DetailGrandPrize
},
data() {
return {
@ -336,7 +318,8 @@ export default {
logList: [],
choujiangloading: false,
goods: null,
productList: []
productList: [],
isPrizeLoading: false // loading
}
},
@ -350,6 +333,12 @@ export default {
console.log(arr.length)
return arr.length
},
getGoodList() {
if (this.pageData?.goods_list?.data == null) {
return [];
}
return this.pageData.goods_list.data;
}
},
@ -423,8 +412,10 @@ export default {
console.log("抽奖结束", data);
//
console.log("所有中奖奖品:", data.allPrizes);
// console.log(":", data.allPrizes);
this.$refs.detailLucky.hide();
this.bgmCtx.openBgm.play()
this.open('resPop')
},
previewDetail(item, a) {
@ -532,43 +523,60 @@ export default {
})
},
getPrize(order_num) {
async getPrize(order_num) {
if (!order_num) {
return
}
if (!this.isPrizeLoading) {
this.isPrizeLoading = true;
uni.showLoading({ title: '加载中...' });
}
let that = this;
setTimeout(() => {
this.req({
url: 'infinite_prizeorderlog',
data: {
order_num
},
success: res => {
if (res.status == 1) {
res.data.data.map(item => {
item.isChoose = false
})
this.prizeData = res.data
setTimeout(async () => {
const res = await this.$request.post('infinite_prizeorderlog', { order_num }, false);
if (res.status == 1) {
res.data.data.map(item => {
item.isChoose = false
})
console.log(res.data);
if (res.data.data.length <= 0) {
this.getPrize(order_num)
return
}
// console.log(' res.data.prize_num', res.data.prize_num);
this.prizeData = res.data
if (that.buyNum == 0 || that.buyNum == null) {
if (res.data.prize_num != null) {
that.buyNum = res.data.prize_num;
}
}
// that.nu
this.bgmCtx.openBgm.play()
this.open('resPop')
// }, 1300)
if (res.data.data.length <= 0) {
this.getPrize(order_num)
return
}
this.$refs.detailLucky.init(this.getGoodList, this.buyNum);
if (that.buyNum == 0 || that.buyNum == null) {
if (res.data.prize_num != null) {
that.buyNum = res.data.prize_num;
}
}
})
let chaoshen = this.prizeData.data.findIndex(it => it.shang_id == 34);
if (chaoshen != -1) {
console.log('抽中超神');
uni.hideLoading();
this.$refs.detailGrandPrize.init();
this.$refs.detailGrandPrize.show();
return;
}
//
let resultIndices = this.prizeData.data.map(it => {
// console.log(it.id);
const index = this.getGoodList.findIndex(item => item.id == it.goodslist_id);
// console.log(index);
return index;
});
// console.log(resultIndices,this.getGoodList, this.prizeData.data, "resultIndices");
this.$refs.detailLucky.startDrawWithResult(resultIndices, () => {
console.log("抽奖结束");
});
this.isPrizeLoading = false;
uni.hideLoading();
}
}, 500)
},
@ -587,32 +595,24 @@ export default {
},
confirmSubmit([type, num, flag]) {
if (type === 0) {
//
this.calculateOrder(num);
} else if (type === 1) {
//
this.submitOrder(num, flag).then(res => {
console.log(res);
});
}
},
// this.$refs.slotPop.open();
// this.bgmCtx.slotBgm.play()
// this.$refs.lottryRef.startDraw();
// return;
this.choujiangloading = true;
uni.showLoading({
title: '加载中'
});
let data = {
goods_id: this.optData.goods_id,
goods_num: this.pageData.goods.num,
num: num,
use_money: this.useMoney ? 1 : 0,
use_integral: this.useIntegral ? 1 : 0,
use_money2: this.useMoney2 ? 1 : 0,
prize_id: this.optData.prize_id,
};
let url = 'infinite_ordermoney'
console.log(type);
//
calculateOrder(num) {
uni.showLoading({ title: '计算中...' });
this.buyNum = num;
//
let coupon_id = (this.couponData && this.couponData.id) || ''
if (coupon_id != '' && this.useIntegral) {
this.useIntegral = false;
@ -620,6 +620,8 @@ export default {
this.couponData = null;
coupon_id = '';
}
//
let postData = {
goods_id: this.pageData.goods.id,
prize_num: this.buyNum,
@ -628,67 +630,105 @@ export default {
use_money2_is: this.useMoney2 ? 1 : 2,
coupon_id: coupon_id,
};
if (type == 1) {
url = 'infinite_orderbuy'
if (this.$refs.buyNotice.getIsShow() && !flag) {
this.$refs.buyNotice.getRule(6)
return
}
postData = this.$platform.getPayData(url, postData);
}
//
this.req({
url,
url: 'infinite_ordermoney',
data: postData,
success: async res => {
success: res => {
if (res.status == 1) {
if (type == 0) {
if (res.data.coupon_id) {
this.couponData = {
id: res.data.coupon_id,
price: res.data.coupon_price
}
//
if (res.data.coupon_id) {
this.couponData = {
id: res.data.coupon_id,
price: res.data.coupon_price
}
this.orderData = res.data
this.$nextTick(() => {
if (this.$refs.buyPop) {
this.$refs.buyPop.open()
} else {
console.error('buyPop组件未找到')
}
})
}
if (type == 1) {
this.close('buyPop')
if (res.data.status == 1) {
const status = await this.$platform.pay({
data: res.data.res
})
if (status == 'success') {
this.getPrize(res.data.order_num);
this.doRefresh()
// this.$refs.detailLucky.init([], this.buyNum);
}
//
this.orderData = res.data
//
this.$nextTick(() => {
if (this.$refs.buyPop) {
this.$refs.buyPop.open()
} else {
this.$c.toast({
title: res.msg,
duration: 500,
success: () => {
this.getPrize(res.data.order_num)
this.doRefresh()
}
})
console.error('buyPop组件未找到')
}
}
})
}
uni.hideLoading();
}
})
if (type == 1) {
this.close('buyPop')
});
},
//
async submitOrder(num, flag) {
this.choujiangloading = true;
uni.showLoading({ title: '提交订单中' });
this.buyNum = num;
//
let coupon_id = (this.couponData && this.couponData.id) || ''
if (coupon_id != '' && this.useIntegral) {
this.useIntegral = false;
} else if (this.useIntegral && coupon_id != '') {
this.couponData = null;
coupon_id = '';
}
//
if (this.$refs.buyNotice.getIsShow() && !flag) {
this.$refs.buyNotice.getRule(6)
uni.hideLoading();
this.choujiangloading = false;
return
}
//
let baseData = {
goods_id: this.pageData.goods.id,
prize_num: this.buyNum,
use_money_is: this.useMoney ? 1 : 2,
use_integral_is: this.useIntegral ? 1 : 2,
use_money2_is: this.useMoney2 ? 1 : 2,
coupon_id: coupon_id,
};
//
let postData = this.$platform.getPayData('infinite_orderbuy', baseData);
//
this.close('buyPop');
const res = await this.$request.post('infinite_orderbuy', postData);
console.log(res);
uni.hideLoading();
if (res.status == 1) {
if (res.data.status == 1) {
//
const status = await this.$platform.pay({
data: res.data.res
})
if (status == 'success') {
//
this.getPrize(res.data.order_num);
this.getData(false)
// this.doRefresh();
}
} else {
// 使
this.$c.toast({
title: res.msg,
duration: 500,
success: () => {
this.getPrize(res.data.order_num);
this.getData(false)
}
})
}
}
this.choujiangloading = false;
},
doRefresh() {
@ -760,42 +800,25 @@ export default {
})
},
getData() {
this.req({
url: 'infinite_goodsdetail',
data: {
goods_id: this.optData.goods_id
},
success: res => {
if (res.status == 1) {
this.goods = res.data.goods;
res.data.goodslist.forEach(item => {
this.$set(item, 'open', false)
})
if (res.data.goods.type_text) {
this.title = res.data.goods.type_text
}
this.pageData = res.data
let goodType = this.$config.getGoodTypeFind(this.pageData.goods.type);
this.useMoney = goodType.pay_balance == 1 ? true : false;
this.useIntegral = goodType.pay_currency == 1 ? true : false;
this.useMoney2 = goodType.pay_currency2 == 1 ? true : false;
async getData(isLoading = true) {
console.log(this.pageData);
this.pageData.goodslist.forEach(item => {
item.goods_list.forEach(item => {
this.productList.push(item);
})
});
console.log("productList", this.productList);
}
const res = await this.$request.post("infinite_goodsdetail", { goods_id: this.optData.goods_id }, isLoading);
if (res.status == 1) {
this.goods = res.data.goods;
res.data.goodslist.forEach(item => {
this.$set(item, 'open', false)
})
if (res.data.goods.type_text) {
this.title = res.data.goods.type_text
}
})
this.pageData = res.data;
let goodType = this.$config.getGoodTypeFind(this.pageData.goods.type);
this.useMoney = goodType.pay_balance == 1 ? true : false;
this.useIntegral = goodType.pay_currency == 1 ? true : false;
this.useMoney2 = goodType.pay_currency2 == 1 ? true : false;
console.log(this.pageData);
}
},
close(e) {
@ -851,72 +874,6 @@ export default {
return "#FFEFB4";
break;
}
},
async wuxianchou() {
this.useMoney = true;
this.useIntegral = false;
this.useMoney2 = false;
if (this.choujiangloading) {
this.choujiangloading = false;
} else {
this.choujiangloading = true;
this.wuxianchou1();
}
},
async wuxianchou1() {
uni.showLoading({
title: '加载中'
});
let url = 'infinite_orderbuy'
this.buyNum = 10;
const {
status,
data,
msg
} = await this.req({
url,
data: {
goods_id: this.pageData.goods.id,
prize_num: this.buyNum,
use_money_is: this.useMoney ? 1 : 2,
use_integral_is: this.useIntegral ? 1 : 2,
use_money2_is: this.useMoney2 ? 1 : 2,
coupon_id: 0,
}
});
if (status == 0) {
this.$c.msg(msg);
return;
}
if (status == 1) {
if (data.status == 1) {
const status = await this.$c.wxMpPay({
data: data.res
})
if (status == 'success') {
this.getPrize(data.order_num)
}
} else {
this.$c.toast({
title: msg,
duration: 500,
success: () => {
this.getPrize(data.order_num)
setTimeout(() => {
if (this.choujiangloading) {
this.close('resPop');
this.wuxianchou1();
}
}, 2000)
}
})
}
}
}
}
}

View File

@ -43,18 +43,8 @@
<image class="" style="width: 200rpx; height: 200rpx; border-radius: 10rpx" :src="item.imgurl"
@click="$c.navTo(item, index)"></image>
</view>
<!-- <view class="" style="width: 181rpx; height: 181rpx; background-color: aquamarine;"></view>
<view class="" style="width: 181rpx; height: 181rpx; background-color: aquamarine;"></view> -->
</view>
</view>
<!-- <scroll-view scroll-x class="tab-list">
<view @click="getlist(i)"
:style="{background:tabCur == i? 'url('+ $img1('index/tabCheck.png')+') no-repeat 0 0 / 100% 100%':'none'}"
v-for="(v, i) in tabList" :key="i" class="tab-list-item center">
<text :class="{active: tabCur == i}">{{ v.title }}</text>
</view>
</scroll-view> -->
<scroll-view class="tab" scroll-x>
<view class="tab-item" v-for="(item, i) in tabList" :key="i" :class="{ act: tabCur == i }"
@click="getlist(i)">

View File

@ -5,15 +5,20 @@
<!-- 页面上的开始抽奖按钮 -->
<button class="start-draw-btn" @click="startDrawing">开始抽奖</button>
<!-- 新增的传入结果抽奖按钮 -->
<button class="start-draw-btn custom-draw-btn" @click="startCustomDraw">自定义结果抽奖</button>
<button class="start-draw-btn custom-draw-btn" @click="startGrandPrize" >超神特效</button>
<DetailGrandPrize ref="detailGrandPrize" @end="onLuckyEnd" />
</page-container>
</template>
<script>
//
import DetailLucky from "@/components/detail-lucky/detail-lucky.vue";
import DetailGrandPrize from "@/components/detail-lucky/detail-grand-prize.vue";
export default {
components: { DetailLucky },
components: { DetailLucky, DetailGrandPrize },
data() {
return {
//
@ -52,6 +57,10 @@ export default {
this.initLuckyMachine();
},
methods: {
startGrandPrize() {
this.$refs.detailGrandPrize.init();
this.$refs.detailGrandPrize.show();
},
//
initLuckyMachine() {
try {
@ -75,13 +84,6 @@ export default {
// 2
setTimeout(() => {
try {
// 5
// 1 -
// this.$refs.detailLucky.stopDraw();
// 2 -
// this.$refs.detailLucky.stopDraw([0, 0, 0, 0, 0]);
// 3 -
const prizeIndices = [0, 1, 0, 1, 0]; //
this.$refs.detailLucky.stopDraw(prizeIndices);
@ -102,6 +104,63 @@ export default {
});
}
},
//
startCustomDraw() {
//
const prizeIndices = [1, 1, 1]; //
this.startLuckyDraw(prizeIndices, () => {
console.log("自定义抽奖完成的回调执行了");
uni.showToast({
title: "自定义抽奖完成",
icon: "success",
});
});
},
/**
* 开始抽奖并传入抽奖结果
* @param {Array} resultIndices 抽奖结果索引数组
* @param {Function} callback 抽奖结束后的回调函数
*/
startLuckyDraw(resultIndices, callback) {
try {
if (!resultIndices || !Array.isArray(resultIndices)) {
console.error("抽奖结果必须是数组");
return;
}
//
this.$refs.detailLucky.startDraw(() => {
console.log("抽奖开始了将在2秒后展示指定结果");
// 2
setTimeout(() => {
try {
this.$refs.detailLucky.stopDraw(resultIndices);
// onLuckyEnd
if (typeof callback === 'function') {
//
this.luckyDrawCallback = callback;
}
} catch (error) {
console.error("停止抽奖时出错:", error);
uni.showToast({
title: "抽奖异常,请重试",
icon: "none",
});
}
}, 2000);
});
} catch (error) {
console.error("开始抽奖时出错:", error);
uni.showToast({
title: "抽奖异常,请重试",
icon: "none",
});
}
},
//
onLuckyStart() {
@ -113,14 +172,25 @@ export default {
console.log("抽奖结束", data);
//
console.log("所有中奖奖品:", data.allPrizes);
console.log("所有中奖奖品:", data?.allPrizes);
//
if (data.skipped) {
console.log("用户跳过了动画");
}
this.$refs.detailLucky.hide();
//
this.luckyMessage = data.message;
this.luckyPrize = data.prizeInfo;
//
this.$refs.luckyPopup && this.$refs.luckyPopup.open();
//
if (this.luckyDrawCallback && typeof this.luckyDrawCallback === 'function') {
this.luckyDrawCallback(data);
//
this.luckyDrawCallback = null;
}
},
//
@ -151,4 +221,10 @@ export default {
border-radius: 50rpx;
padding: 20rpx 40rpx;
}
//
.custom-draw-btn {
background-color: #4a9eff;
margin-top: 10rpx;
}
</style>