390 lines
12 KiB
JavaScript
390 lines
12 KiB
JavaScript
getDetial() {
|
|
getFightData(this.id).then(res => { ///////////获取对战数据
|
|
this.detialList = res.data.data;///////初始化数据
|
|
this.roomstatus = res.data.data.status;/////房间的状态0为等待
|
|
this.detialList.boxData = JSON.parse(res.data.data.boxData);////所有宝箱
|
|
this.detialList.userData = JSON.parse(res.data.data.userData);///所有用户
|
|
this.detialList.currentPeople = res.data.data.userData.length;///人数
|
|
this.detialList.boxData = res.data.data.boxData.flatMap(item =>
|
|
Array.from({ length: item.boxNum }, () => item)
|
|
);//////////////////处理宝箱数据
|
|
this.totalround = this.detialList.boxData.length; /////几个宝箱就是几个回合
|
|
|
|
this.waitpeople = { people: [] };/////等待的人
|
|
|
|
for (let index = 0; index < this.detialList.playerNum; index++) {
|
|
const obj = (this.joinSeatNumV2.people[index] = { realget: [] });
|
|
obj.joinSeatNum = index + 1;
|
|
if (this.detialList.userData[index]) {
|
|
this.waitpeople.people.push(this.detialList.userData[index]);
|
|
this.waitpeople.people[index].status = "1";
|
|
this.waitpeople.people[index].joinSeatNum = index + 1;
|
|
} else {
|
|
this.waitpeople.people.push({
|
|
status: "0",
|
|
joinSeatNum: index + 1
|
|
});
|
|
}
|
|
}///人数判断有几个人
|
|
// v2 将用户分配到指定座位
|
|
// 遍历arr1中的每一项
|
|
this.joinSeatNumV2.status = res.data.data.status;
|
|
this.joinSeatNumV2.people.forEach(item1 => {
|
|
// 遍历arr2中的每一项,寻找joinSeatNum相等的项
|
|
res.data.data.userData.forEach(item2 => {
|
|
if (item1.joinSeatNum === item2.joinSeatNum) {
|
|
// 如果找到相等的项,在arr1的当前项中添加realuser属性,并设置其值为arr2的当前项
|
|
item1.realuser = item2;
|
|
}
|
|
});
|
|
});
|
|
//每个人
|
|
this.joinSeatNumV2.people = this.joinSeatNumV2.people.map(item => ({
|
|
...item,
|
|
realdrop: []
|
|
}));
|
|
if (this.roomstatus == "0") { /////////如果他的状态时0的话就是等待中
|
|
///this.get(this.totalround);//总回合数
|
|
this.deng = setTimeout(() => {
|
|
this.getDetial()
|
|
}, 1000);
|
|
} else if (this.roomstatus == "1") {
|
|
getpkrealdetial({
|
|
fightId: this.$route.query.id,
|
|
rounds: this.totalround
|
|
}).then(res => {
|
|
const roundresult = res.data.data.playerGainsOrnamentsData;
|
|
if (res.data.code === 500) {
|
|
console.log("结束")
|
|
} else {
|
|
this.realround = res.data.data.round;///第几回合
|
|
if (res.data.data.playerGainsOrnamentsData == null) {
|
|
this.getpkResult()
|
|
} else {
|
|
getBoxdetial({//根据宝箱的id获取宝箱的数据
|
|
id: this.detialList.boxData[Number(res.data.data.round - 1)].boxId
|
|
}).then(res => {
|
|
// const money=
|
|
this.joinSeatNumV2.people.forEach(item1 => {
|
|
roundresult.forEach(item2 => {
|
|
if (item1.joinSeatNum === item2.joinSeatNum) {
|
|
let drawList = this.generateRandomDrawList(
|
|
res.data.data.boxOrnamentsList,
|
|
20
|
|
);
|
|
item1.roundresult = drawList;
|
|
item1.roundresult.push(item2.ornamentsData);
|
|
item1.realmoney = 0;
|
|
this.$forceUpdate();
|
|
setTimeout(() => {
|
|
item1.realmoney += Number(
|
|
item2.ornamentsData.ornamentsPrice
|
|
);
|
|
item1.realget.unshift(item2.ornamentsData);
|
|
}, 6200);
|
|
|
|
}
|
|
});
|
|
});
|
|
this.begin = false;
|
|
setTimeout(() => {
|
|
this.begin = true;
|
|
}, 10);
|
|
});
|
|
}
|
|
}
|
|
});
|
|
this.aaaaa = setTimeout(() => {
|
|
this.get(this.totalround);//传总回合数
|
|
|
|
}, 6000);
|
|
} else if (this.roomstatus == "2") {
|
|
/* this.refresh() */
|
|
clearTimeout(this.deng);
|
|
this.getpkResult();
|
|
clearTimeout(this.aaaaa)
|
|
clearTimeout(this.aaa)
|
|
this.aaa = null
|
|
|
|
clearTimeout(this.timerv2)
|
|
clearTimeout(this.ding)
|
|
this.timerv2 = null
|
|
}
|
|
});
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
cleantimer(){
|
|
clearTimeout(this.timerv2);
|
|
this.timerv2 = null;
|
|
},
|
|
refresh() {
|
|
location.reload();
|
|
},
|
|
|
|
get(round) {
|
|
this.timerv2 = setInterval(() => {
|
|
if (this.realround == null) {
|
|
|
|
this.cleantimer();
|
|
this.getpkResult();
|
|
|
|
|
|
this.refresh()
|
|
|
|
} else {
|
|
|
|
|
|
|
|
getpkrealdetial({
|
|
fightId: this.$route.query.id,
|
|
rounds: round
|
|
}).then(res => {
|
|
if (res.data.code == 500) {
|
|
this.cleantimer();
|
|
|
|
/* this.aaaa=setTimeout(() => { */
|
|
this.getpkResult();
|
|
/* this.getDetial(); */
|
|
/* this.clearTimeout(this.aaaa)
|
|
}, 6500); */
|
|
//
|
|
} else {
|
|
const roundresult = res.data.data.playerGainsOrnamentsData;
|
|
|
|
this.realround = res.data.data.round;
|
|
if (res.data.data.playerGainsOrnamentsData == null) {
|
|
clearTimeout(this.timerv2);
|
|
this.timerv2 = null;
|
|
this.getDetial();
|
|
} else {
|
|
getBoxdetial({
|
|
id: this.detialList.boxData[Number(res.data.data.round - 1)]
|
|
.boxId
|
|
}).then(res => {
|
|
// const money=
|
|
|
|
this.joinSeatNumV2.people.forEach(item1 => {
|
|
roundresult.forEach(item2 => {
|
|
if (item1.joinSeatNum === item2.joinSeatNum) {
|
|
let drawList = this.generateRandomDrawList(
|
|
res.data.data.boxOrnamentsList,
|
|
20
|
|
);
|
|
item1.roundresult = drawList;
|
|
item1.roundresult.push(item2.ornamentsData);
|
|
this.$forceUpdate();
|
|
setTimeout(() => {
|
|
item1.realmoney += Number(
|
|
item2.ornamentsData.ornamentsPrice
|
|
);
|
|
item1.realget.unshift(item2.ornamentsData);
|
|
}, 6200);
|
|
|
|
}
|
|
});
|
|
});
|
|
this.begin = false;
|
|
setTimeout(() => {
|
|
this.begin = true;
|
|
}, 100);
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}, 5000);
|
|
},
|
|
|
|
generateRandomDrawList(ornamentsArray, drawListLength) {
|
|
const drawList = [];
|
|
|
|
for (let i = 0; i < drawListLength; i++) {
|
|
const randomIndex = Math.floor(Math.random() * ornamentsArray.length);
|
|
drawList.push(ornamentsArray[randomIndex]);
|
|
}
|
|
|
|
return drawList;
|
|
},
|
|
formatter(value) {
|
|
// 格式化函数,可以根据需要自定义
|
|
return value.toFixed(2); // 格式化为本地数字字符串
|
|
},
|
|
|
|
|
|
handlejointrue() {
|
|
let obj = {
|
|
fightId: this.$route.query.id,
|
|
joinSeatNum: this.peopleselect,
|
|
rounds: this.totalround
|
|
};
|
|
joinFight(obj).then(() => {
|
|
this.isjoin = false;
|
|
this.dings = setTimeout(() => {
|
|
this.getDetial();
|
|
clearTimeout(this.dings)
|
|
}, 500);
|
|
});
|
|
},
|
|
handleJoin(res) {
|
|
this.peopleselect = res;
|
|
this.title = "加入房间";
|
|
this.isjoin = true;
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
///复制分享链接
|
|
async handlecopy() {
|
|
const url = window.location.href; // 获取当前地址栏的URL
|
|
const textarea = document.createElement("textarea");
|
|
textarea.value = url;
|
|
document.body.appendChild(textarea);
|
|
textarea.focus();
|
|
textarea.select();
|
|
// 执行复制操作
|
|
try {
|
|
const successful = document.execCommand("copy");
|
|
if (successful) {
|
|
// 复制成功,使用 Element UI 的 $message 显示通知
|
|
this.$message({
|
|
message: "复制成功",
|
|
type: "success",
|
|
customClass: "log_success"
|
|
});
|
|
} else {
|
|
// 复制失败,显示错误信息
|
|
this.$message({
|
|
message: "浏览器版本过低,请升级浏览器",
|
|
type: "warning",
|
|
customClass: "log_warning"
|
|
});
|
|
}
|
|
} catch (err) {
|
|
this.$message({
|
|
message: "浏览器版本过低,请升级浏览器",
|
|
type: "warning",
|
|
customClass: "log_warning"
|
|
});
|
|
}
|
|
|
|
// 移除textarea元素
|
|
document.body.removeChild(textarea);
|
|
},
|
|
getrealPeople() { },
|
|
getpkResult() {
|
|
clearTimeout(this.aaa)
|
|
clearTimeout(this.deng);
|
|
this.aaa = null
|
|
getFightResult(this.id).then(res => {
|
|
this.jieshuList = res.data.data;
|
|
this.jieshuList.winnerGainsOrnamentsData.forEach(item => {
|
|
let totalPrice = 0;
|
|
if (item.ornamentsDataList) {
|
|
item.ornamentsDataList.forEach(ornament => {
|
|
totalPrice += ornament.ornamentsPrice;
|
|
});
|
|
item.totalprize = totalPrice;
|
|
}
|
|
});
|
|
this.ding = setTimeout(() => {
|
|
if (this.detialList.status == "2") {
|
|
for (let i = 0; i < this.waitpeople.people.length; i++) {
|
|
// 遍历 arr2
|
|
for (
|
|
let j = 0;
|
|
j < this.jieshuList.winnerGainsOrnamentsData.length;
|
|
j++
|
|
) {
|
|
// 如果 joinSeatNum 相等
|
|
if (
|
|
this.waitpeople.people[i].joinSeatNum ===
|
|
this.jieshuList.winnerGainsOrnamentsData[j].joinSeatNum
|
|
) {
|
|
// 如果 arr1 的当前项没有 result 属性,则添加该属性
|
|
|
|
// 将 arr2 的当前项添加到 arr1 的 result 属性中
|
|
this.waitpeople.people[
|
|
i
|
|
].result = this.jieshuList.winnerGainsOrnamentsData[j];
|
|
this.waitpeople.people[i].winner = true;
|
|
} else {
|
|
this.waitpeople.people[i].winner = false;
|
|
this.waitpeople.people[i].resultcoin = "0.00";
|
|
}
|
|
}
|
|
}
|
|
this.waitpeople.people.forEach(item => {
|
|
let resultcoin = 0;
|
|
if (item.result) {
|
|
item.result.ornamentsDataList.forEach(ornament => {
|
|
resultcoin += ornament.ornamentsPrice;
|
|
});
|
|
item.resultcoin = resultcoin;
|
|
}
|
|
});
|
|
this.loading = false;
|
|
this.$forceUpdate();
|
|
}
|
|
if (this.joinSeatNumV2.status == "2") {
|
|
for (let i = 0; i < this.joinSeatNumV2.people.length; i++) {
|
|
// 遍历 arr2
|
|
for (
|
|
let j = 0;
|
|
j < this.jieshuList.winnerGainsOrnamentsData.length;
|
|
j++
|
|
) {
|
|
// 如果 joinSeatNum 相等
|
|
if (
|
|
this.joinSeatNumV2.people[i].joinSeatNum ===
|
|
this.jieshuList.winnerGainsOrnamentsData[j].joinSeatNum
|
|
) {
|
|
// 如果 arr1 的当前项没有 result 属性,则添加该属性
|
|
|
|
// 将 arr2 的当前项添加到 arr1 的 result 属性中
|
|
this.joinSeatNumV2.people[
|
|
i
|
|
].result = this.jieshuList.winnerGainsOrnamentsData[j];
|
|
this.joinSeatNumV2.people[i].winner = true;
|
|
} else {
|
|
this.joinSeatNumV2.people[i].winner = false;
|
|
this.joinSeatNumV2.people[i].resultcoin = "0.00";
|
|
}
|
|
}
|
|
}
|
|
this.joinSeatNumV2.people.forEach(item => {
|
|
let resultcoin = 0;
|
|
if (item.result) {
|
|
item.result.ornamentsDataList.forEach(ornament => {
|
|
resultcoin += ornament.ornamentsPrice;
|
|
});
|
|
item.resultcoin = resultcoin;
|
|
}
|
|
});
|
|
}
|
|
}, 450);
|
|
|
|
/* clearTimeout(this.ding) */
|
|
|
|
});
|
|
// 对战结果
|
|
setInterval(() => {
|
|
// 遍历arr2,找到arr1中对应的项,并将ornamentsDataList添加到realdrop属性中
|
|
this.jieshuList.playerGainsOrnamentsData.forEach(item2 => {
|
|
const foundIndex = this.joinSeatNumV2.people.findIndex(
|
|
item1 => item1.joinSeatNum === item2.joinSeatNum
|
|
);
|
|
if (foundIndex !== -1) {
|
|
// 如果找到了对应的项,则添加ornamentsDataList到realdrop中
|
|
this.joinSeatNumV2.people[foundIndex].realdrop.push(
|
|
...item2.ornamentsDataList
|
|
);
|
|
}
|
|
});
|
|
}, 700);
|
|
} |