This commit is contained in:
zpc 2025-06-08 22:54:24 +08:00
parent e74403f72a
commit e55ce53e04
4 changed files with 212 additions and 458 deletions

View File

@ -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) => {

View File

@ -76,7 +76,7 @@ export default {
batchResults: [], //
batchCallback: null, //
batchIndices: [], //
chaoShenIndex: -1,
prizeIndices: [],
timers: {
skipButton: null, //
firstBatch: null, //
@ -333,10 +333,7 @@ export default {
},
//
endCallBack(prize) {
try {
console.log("[批次抽奖] endCallBack 被调用,批次模式:", this.isBatchMode, "当前模式:", this.internalMode, "批次计数:", this
.batchCount);
async endCallBack(prize) {
if (this.isSkip) {
return;
}
@ -348,151 +345,16 @@ export default {
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();
if (this.prizeIndices.length > 0) {
await sleep(800);
// this.$refs.myLucky.init();
this.startDrawWithResult(this.prizeIndices);
return;
}
this.timers.drawResult = setTimeout(() => {
await sleep(800);
//
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;
}
}
},
//
@ -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,95 +495,22 @@ 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(() => {
// DOMplay
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);
// DOMplay
this.$nextTick(() => {
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;
@ -737,53 +521,9 @@ export default {
//
this.stopDraw(resultIndices);
}, 2000);
} else {
console.error("抽奖特效组件未初始化");
//
if (this.drawResultCallback) {
this.drawResultCallback({
success: false,
error: "抽奖特效组件未初始化"
});
this.drawResultCallback = null;
}
}
});
} catch (error) {
sleep(500);
// DOMplay
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;
}
}
});
}
return this; // this
},

View File

@ -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);

View File

@ -10,10 +10,10 @@
</template>
<script>
import PageContainer from '@/components/page-container/page-container.vue'
import PageContainer from '@/components/page-container/page-container.vue'
export default {
export default {
components: {
PageContainer
},
@ -32,9 +32,17 @@
},
onLoad() {
this.load();
// const currentPage = getCurrentPages();
// console.log('currentPagecurrentPagecurrentPage', currentPage);
},
methods: {
toHome() {
// #ifdef H5 || MP
uni.switchTab({
url: '/pages/shouye/index'
});
// #endif
},
async load() {
var that = this;
uni.getNetworkType({
@ -45,7 +53,7 @@
//
console.log('无网络连接或权限被拒绝');
that.tips = "无网络连接或权限被拒绝";
uni.onNetworkStatusChange(function(res) {
uni.onNetworkStatusChange(function (res) {
console.log('网络状态变化:', res.isConnected, res.networkType);
if (res.isConnected) {
//
@ -68,6 +76,7 @@
} else {
//
console.log('网络权限已授予');
that.toHome();
}
},
fail() {
@ -79,17 +88,17 @@
},
}
}
}
</script>
<style lang="scss">
.index-page {
.index-page {
width: 100vw;
height: 100vh;
background-color: #f8f8f8;
}
}
.about-container {
.about-container {
display: flex;
flex-direction: column;
align-items: center;
@ -160,5 +169,5 @@
font-size: 14px;
}
}
}
}
</style>