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,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(() => {
// 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(() => {
//
if (this.$refs.myLucky) {
//
this.$refs.myLucky.play();
this.$emit("luckyPlay", "")
await sleep(500);
//
this.timers.skipButton = setTimeout(() => {
this.skipButtonOpacity = 1;
}, 1000);
// DOMplay
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);
// 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;
}
}
});
}
// 2
this.timers.drawResult = setTimeout(() => {
//
this.stopDraw(resultIndices);
}, 2000);
}
});
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,155 +10,164 @@
</template>
<script>
import PageContainer from '@/components/page-container/page-container.vue'
import PageContainer from '@/components/page-container/page-container.vue'
export default {
components: {
PageContainer
},
data() {
let icon = "https://image.zfunbox.cn/icon_108.png";
let login_icon = "https://image.zfunbox.cn/app/index_login.gif";
// #ifdef APP
icon = "/static/app-plus/icon_108.png";
login_icon = "/static/app-plus/index_login.gif";
// #endif
return {
icon: icon,
login_icon: login_icon,
tips: "正在加载中。。。"
}
},
onLoad() {
this.load();
},
methods: {
async load() {
var that = this;
uni.getNetworkType({
success(res) {
if (res.networkType === 'none') {
// uni.hi
uni.hideToast();
//
console.log('无网络连接或权限被拒绝');
that.tips = "无网络连接或权限被拒绝";
uni.onNetworkStatusChange(function(res) {
console.log('网络状态变化:', res.isConnected, res.networkType);
if (res.isConnected) {
//
that.tips = "正在加载中。。。";
// #ifdef APP
if (plus.runtime.restart) {
plus.runtime.restart();
} else {
uni.showToast({
title: "重启失败",
icon: "none"
});
}
// #endif
} else {
//
that.tips = "网络断开";
}
});
} else {
//
console.log('网络权限已授予');
}
},
fail() {
//
console.log('获取网络状态失败,可能无权限');
}
});
},
export default {
components: {
PageContainer
},
data() {
let icon = "https://image.zfunbox.cn/icon_108.png";
let login_icon = "https://image.zfunbox.cn/app/index_login.gif";
// #ifdef APP
icon = "/static/app-plus/icon_108.png";
login_icon = "/static/app-plus/index_login.gif";
// #endif
return {
icon: icon,
login_icon: login_icon,
tips: "正在加载中。。。"
}
},
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({
success(res) {
if (res.networkType === 'none') {
// uni.hi
uni.hideToast();
//
console.log('无网络连接或权限被拒绝');
that.tips = "无网络连接或权限被拒绝";
uni.onNetworkStatusChange(function (res) {
console.log('网络状态变化:', res.isConnected, res.networkType);
if (res.isConnected) {
//
that.tips = "正在加载中。。。";
// #ifdef APP
if (plus.runtime.restart) {
plus.runtime.restart();
} else {
uni.showToast({
title: "重启失败",
icon: "none"
});
}
// #endif
} else {
//
that.tips = "网络断开";
}
});
} else {
//
console.log('网络权限已授予');
that.toHome();
}
},
fail() {
//
console.log('获取网络状态失败,可能无权限');
}
});
},
}
}
</script>
<style lang="scss">
.index-page {
width: 100vw;
height: 100vh;
background-color: #f8f8f8;
.index-page {
width: 100vw;
height: 100vh;
background-color: #f8f8f8;
}
.about-container {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
.app-icon {
width: 96px;
height: 96px;
margin-top: 20vh;
border-radius: 50%;
}
.about-container {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
.app-info {
margin-top: 20px;
text-align: center;
.app-icon {
width: 96px;
height: 96px;
margin-top: 20vh;
border-radius: 50%;
.app-name {
font-size: 18px;
font-weight: bold;
margin-bottom: 10px;
}
.app-info {
margin-top: 20px;
.app-version {
font-size: 14px;
color: #666;
margin-bottom: 5px;
}
}
.test-mode-container {
margin-top: 30px;
border: 1px dashed #ff6600;
border-radius: 8px;
padding: 15px;
width: 80%;
.test-mode-content {
width: 100%;
}
.test-mode-title {
text-align: center;
.app-name {
font-size: 18px;
font-weight: bold;
margin-bottom: 10px;
}
.app-version {
font-size: 14px;
color: #666;
margin-bottom: 5px;
}
font-weight: bold;
font-size: 16px;
color: #ff6600;
margin-bottom: 15px;
}
.test-mode-container {
margin-top: 30px;
border: 1px dashed #ff6600;
border-radius: 8px;
padding: 15px;
width: 80%;
.test-mode-item {
margin: 10px 0;
font-size: 14px;
}
.test-mode-content {
width: 100%;
}
.button-group {
display: flex;
justify-content: space-between;
}
.test-mode-title {
text-align: center;
font-weight: bold;
font-size: 16px;
color: #ff6600;
margin-bottom: 15px;
}
.log-button {
width: 48%;
margin: 0;
}
.test-mode-item {
margin: 10px 0;
font-size: 14px;
}
.button-group {
display: flex;
justify-content: space-between;
}
.log-button {
width: 48%;
margin: 0;
}
.test-button {
margin-top: 15px;
background-color: #ff6600;
color: white;
font-size: 14px;
}
.test-button {
margin-top: 15px;
background-color: #ff6600;
color: white;
font-size: 14px;
}
}
}
</style>