diff --git a/common/platform/MiniProgramPlatform.js b/common/platform/MiniProgramPlatform.js
index c3df34c..b1a884d 100644
--- a/common/platform/MiniProgramPlatform.js
+++ b/common/platform/MiniProgramPlatform.js
@@ -212,11 +212,16 @@ class MiniProgramPlatform extends BasePlatform {
updateManager.onUpdateFailed(function (res) {
// 新的版本下载失败
});
- if (options != null && options.path == "pages/index/index") {
- uni.switchTab({
- url: '/pages/shouye/index'
- });
- }
+ // setTimeout(() => {
+ // const currentPage = getCurrentPages().pop();
+ // console.log('currentPagecurrentPagecurrentPage', currentPage);
+ // }, 300);
+
+ // if (options != null && options.path == "pages/index/index") {
+ // uni.switchTab({
+ // url: '/pages/shouye/index'
+ // });
+ // }
}
async getOrderNo(event) {
return new Promise(async (resolve, reject) => {
diff --git a/components/detail-lucky/detail-lucky-canvas.vue b/components/detail-lucky/detail-lucky-canvas.vue
index 030758c..04ab6b9 100644
--- a/components/detail-lucky/detail-lucky-canvas.vue
+++ b/components/detail-lucky/detail-lucky-canvas.vue
@@ -76,7 +76,7 @@ export default {
batchResults: [], // 保存批次结果
batchCallback: null, // 批次模式回调
batchIndices: [], // 批次索引
- chaoShenIndex: -1,
+ prizeIndices: [],
timers: {
skipButton: null, // 控制跳过按钮渐显的定时器
firstBatch: null, // 第一批次抽奖的定时器,用于控制第一批次停止时间
@@ -333,166 +333,28 @@ export default {
},
// 抽奖结束回调
- endCallBack(prize) {
- try {
- console.log("[批次抽奖] endCallBack 被调用,批次模式:", this.isBatchMode, "当前模式:", this.internalMode, "批次计数:", this
- .batchCount);
- if (this.isSkip) {
- return;
- }
- // 准备中奖信息
- const prizeData =
- this.prizes[this.currentPrizeIndex]?.data || this.prizes[0]?.data;
-
- if (!prizeData) {
- console.error("无法获取奖品数据");
- return;
- }
-
- // 获取所有中奖奖品
- let allPrizes = [];
-
- // 检查prize是否是数组,如果是则使用map,否则只使用当前prize
- if (Array.isArray(prize)) {
- allPrizes = prize
- .map((item) => {
- const index = typeof item.index === "number" ? item.index : 0;
- return this.prizes[index]?.data || this.prizes[0]?.data;
- })
- .filter((item) => !!item);
- } else if (prize && typeof prize.index === "number") {
- // 如果prize是单个对象
- const index = prize.index;
- const itemData = this.prizes[index]?.data;
- if (itemData) {
- allPrizes.push(itemData);
- }
- } else {
- // 都不符合则使用当前索引的奖品
- allPrizes.push(prizeData);
- }
-
- // 准备返回结果
- const result = {
- prize: prize,
- prizeData: prizeData, // 主要奖品数据
- allPrizes: allPrizes, // 所有中奖奖品数据
- message: `恭喜您获得 ${prizeData.title}`,
- prizeInfo: {
- name: prizeData.title,
- image: prizeData.imgurl,
- 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("[批次抽奖] 第一批次完成,准备开始第二批次");
- this.timers.firstBatch = 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,
- },
- };
- this.$emit("luckyStop", "");
- if (this.chaoShenIndex != -1) {
- // 重置批次状态
- this.isBatchMode = false;
- this.batchCount = 0;
- this.batchResults = [];
- // this.$refs.detailGrandPrize.init();
- // this.$refs.detailGrandPrize.show();
- return;
- }
- this.timers.drawResult = setTimeout(() => {
-
- // 发送中奖信息到父组件
- this.$emit("end", false);
-
- // 调用保存的批次回调
- 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;
- }
- }
- this.$emit("luckyStop", "");
-
- if (this.chaoShenIndex != -1) {
- return;
- }
-
- this.timers.drawResult = setTimeout(() => {
-
- // 发送中奖信息到父组件
- this.$emit("end", false);
-
- // 调用startDrawWithResult方法中保存的回调函数
- if (this.drawResultCallback && typeof this.drawResultCallback === 'function') {
- this.drawResultCallback(result);
- // 清除回调,避免重复调用
- this.drawResultCallback = null;
- }
- }, 800);
-
- } catch (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;
- }
+ async endCallBack(prize) {
+ if (this.isSkip) {
+ return;
}
+ // 准备中奖信息
+ const prizeData =
+ this.prizes[this.currentPrizeIndex]?.data || this.prizes[0]?.data;
+
+ if (!prizeData) {
+ console.error("无法获取奖品数据");
+ return;
+ }
+ this.$emit("luckyStop", "");
+ if (this.prizeIndices.length > 0) {
+ await sleep(800);
+ // this.$refs.myLucky.init();
+ this.startDrawWithResult(this.prizeIndices);
+ return;
+ }
+ await sleep(800);
+ // 发送中奖信息到父组件
+ this.$emit("end", false);
},
// 强制结束抽奖
@@ -501,24 +363,9 @@ export default {
console.error("抽奖特效尚未初始化,请先调用init方法");
return this;
}
-
- this.$emit("luckyStop", "");
- console.log("[跳过动画] 批次模式:", this.isBatchMode, "当前模式:", this.internalMode, "批次计数:", this.batchCount);
-
this.hide();
- let stopIndex = 0;
- if (this.internalMode > 1) {
- stopIndex = [];
- let maxIndex = this.internalMode;
- if (maxIndex > 5) {
- maxIndex = 5;
- }
- for (let i = 0; i < maxIndex; i++) {
- stopIndex.push(0);
- }
- }
// 调用stop方法停止旋转
- this.$refs.myLucky.stop(stopIndex);
+ this.$refs.myLucky.init();
// 发送事件到父组件
this.$emit("end", true);
return this; // 返回this以支持链式调用
@@ -541,8 +388,7 @@ export default {
// 停止抽奖并指定中奖索引
- stopDraw(prizeIndices) {
- console.log("stopDraw", prizeIndices);
+ async stopDraw(prizeIndices) {
// 检查是否已初始化
if (!this.isInitialized) {
@@ -554,10 +400,13 @@ export default {
console.error("抽奖特效组件未初始化");
return this;
}
-
- // 如果是批次模式,添加日志
- if (this.isBatchMode && this.internalMode === 10) {
- console.log("[批次抽奖] 停止抽奖,批次:", this.batchCount + 1, "索引:", prizeIndices);
+ let prizeIndices_l = [];
+ if (prizeIndices.length > 0 && prizeIndices.length > 5) {
+ prizeIndices_l = prizeIndices.slice(5);
+ prizeIndices = prizeIndices.slice(0, 5);
+ this.prizeIndices = prizeIndices_l;
+ } else {
+ this.prizeIndices = [];
}
// 如果没有传入奖品索引数组或传入的不是数组
@@ -622,7 +471,15 @@ export default {
* @param {Function} callback 抽奖结束后的回调函数
* @return {Object} this 返回组件实例,支持链式调用
*/
- async startDrawWithResult(resultIndices, callback, chaoShenIndex = -1) {
+ async startDrawWithResult(resultIndices) {
+ this.prizeIndices = resultIndices;
+ if (this.internalMode == 0) {
+ if (resultIndices.length > 5) {
+ this.internalMode = 5;
+ } else {
+ this.internalMode = this.prizeIndices.length;
+ }
+ }
// 检查是否已初始化
if (!this.isInitialized) {
console.error("抽奖特效尚未初始化,请先调用init方法");
@@ -638,151 +495,34 @@ export default {
console.error("抽奖结果必须是数组");
return this;
}
- this.chaoShenIndex = chaoShenIndex;
- // 模式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(() => {
- // 确保DOM已渲染完成后再调用play方法
- this.$nextTick(() => {
- // 检查组件是否已初始化
- if (this.$refs.myLucky) {
- console.log("[批次抽奖] 开始第一批次抽奖");
- // 开始第一批次抽奖
- this.$refs.myLucky.play();
- this.$emit("luckyPlay", "")
- // 渐显跳过按钮
- this.timers.skipButton = setTimeout(() => {
- this.skipButtonOpacity = 1;
- }, 1000);
-
- // 2秒后停止第一批次抽奖
- this.timers.firstBatch = 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();
- try {
- await sleep(500);
- // 确保DOM已渲染完成后再调用play方法
- this.$nextTick(() => {
- // 检查组件是否已初始化
- if (this.$refs.myLucky) {
- // 开始旋转
- this.$refs.myLucky.play();
- this.$emit("luckyPlay", "")
+ await sleep(500);
- // 渐显跳过按钮
- this.timers.skipButton = setTimeout(() => {
- this.skipButtonOpacity = 1;
- }, 1000);
+ // 确保DOM已渲染完成后再调用play方法
+ this.$nextTick(async () => {
+ // 检查组件是否已初始化
+ if (this.$refs.myLucky) {
+ await sleep(200);
+ // 开始旋转
+ this.$refs.myLucky.play();
+ this.$emit("luckyPlay", "")
+ console.log('开始抽奖开始抽奖开始抽奖开始抽奖开始抽奖开始抽奖开始抽奖开始抽奖');
+ // 渐显跳过按钮
+ this.timers.skipButton = setTimeout(() => {
+ this.skipButtonOpacity = 1;
+ }, 1000);
- // 2秒后自动停止抽奖
- this.timers.drawResult = setTimeout(() => {
- // 停止抽奖并显示结果
- this.stopDraw(resultIndices);
- }, 2000);
- } else {
- console.error("抽奖特效组件未初始化");
- // 如果有回调,通知调用者初始化失败
- if (this.drawResultCallback) {
- this.drawResultCallback({
- success: false,
- error: "抽奖特效组件未初始化"
- });
- this.drawResultCallback = null;
- }
- }
- });
-
- } catch (error) {
- sleep(500);
- // 确保DOM已渲染完成后再调用play方法
- this.$nextTick(() => {
- // 检查组件是否已初始化
- if (this.$refs.myLucky) {
- // 开始旋转
- this.$refs.myLucky.play();
- this.$emit("luckyPlay", "")
-
- // 渐显跳过按钮
- this.timers.skipButton = setTimeout(() => {
- this.skipButtonOpacity = 1;
- }, 1000);
-
- // 2秒后自动停止抽奖
- this.timers.drawResult = setTimeout(() => {
- // 停止抽奖并显示结果
- this.stopDraw(resultIndices);
- }, 2000);
- } else {
- console.error("抽奖特效组件未初始化");
- // 如果有回调,通知调用者初始化失败
- if (this.drawResultCallback) {
- this.drawResultCallback({
- success: false,
- error: "抽奖特效组件未初始化"
- });
- this.drawResultCallback = null;
- }
- }
- });
- }
+ // 2秒后自动停止抽奖
+ this.timers.drawResult = setTimeout(() => {
+ // 停止抽奖并显示结果
+ this.stopDraw(resultIndices);
+ }, 2000);
+ }
+ });
return this; // 返回this以支持链式调用
},
diff --git a/components/detail-lucky/detail-lucky.vue b/components/detail-lucky/detail-lucky.vue
index bfca353..2cf7e89 100644
--- a/components/detail-lucky/detail-lucky.vue
+++ b/components/detail-lucky/detail-lucky.vue
@@ -97,7 +97,7 @@ export default {
this.chaoShenIndex = chaoShenIndex;
console.log('开始抽奖开始抽奖开始抽奖开始抽奖开始抽奖开始抽奖', this.prizeList, resultIndices,);
//#ifdef H5 || MP
- await this.$refs._detailLucky.startDrawWithResult(resultIndices, chaoShenIndex);
+ await this.$refs._detailLucky.startDrawWithResult(resultIndices);
//#endif
//#ifdef APP
this.$refs._detailLucky.init(this.prizeList, page, resultIndices);
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 3c51af4..9ee8dd9 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -10,155 +10,164 @@
\ No newline at end of file