Merge branch 'new-race-mode' into test
This commit is contained in:
@@ -4,7 +4,7 @@ import { onLoad } from "@dcloudio/uni-app";
|
|||||||
import Container from "@/components/Container.vue";
|
import Container from "@/components/Container.vue";
|
||||||
import Avatar from "@/components/Avatar.vue";
|
import Avatar from "@/components/Avatar.vue";
|
||||||
import UserUpgrade from "@/components/UserUpgrade.vue";
|
import UserUpgrade from "@/components/UserUpgrade.vue";
|
||||||
import { getBattleAPI } from "@/apis";
|
import { getBattleAPI, getRoomAPI } from "@/apis";
|
||||||
import { getBattleResultTips } from "@/constants";
|
import { getBattleResultTips } from "@/constants";
|
||||||
import audioManager from "@/audioManager";
|
import audioManager from "@/audioManager";
|
||||||
import useStore from "@/store";
|
import useStore from "@/store";
|
||||||
@@ -243,11 +243,36 @@ const exitBtnText = computed(() => data.value.way === 1 ? '返回房间' : '返
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 点击底部按钮跳转
|
* 点击底部按钮跳转
|
||||||
* - 好友约战(way=1):返回对战房间
|
* - 好友约战(way=1):先调接口确认用户仍在房间
|
||||||
|
* - 已被踢出或房间不存在 → toast 提示并 reLaunch 到首页
|
||||||
|
* - 仍在房间 → 跳回对战房间
|
||||||
* - 其他模式(排位赛等):跳转到排位赛首页
|
* - 其他模式(排位赛等):跳转到排位赛首页
|
||||||
*/
|
*/
|
||||||
function exit() {
|
async function exit() {
|
||||||
if (data.value.way === 1) {
|
if (data.value.way === 1) {
|
||||||
|
try {
|
||||||
|
const roomInfo = await getRoomAPI(data.value.roomId);
|
||||||
|
const members = roomInfo?.members || [];
|
||||||
|
const myIdStr = String(user.value.id);
|
||||||
|
// 判断当前用户是否仍在房间成员列表中
|
||||||
|
const stillInRoom = members.some(
|
||||||
|
(m) => String(m.userInfo?.id) === myIdStr
|
||||||
|
);
|
||||||
|
if (!stillInRoom) {
|
||||||
|
uni.showToast({ title: '您已经不在当前房间', icon: 'none' });
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.reLaunch({ url: '/pages/index' });
|
||||||
|
}, 1500);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// 接口异常(如房间已解散)同样视为已不在房间
|
||||||
|
uni.showToast({ title: '您已经不在当前房间', icon: 'none' });
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.reLaunch({ url: '/pages/index' });
|
||||||
|
}, 1500);
|
||||||
|
return;
|
||||||
|
}
|
||||||
uni.redirectTo({
|
uni.redirectTo({
|
||||||
url: `/pages/battle-room?roomNumber=${data.value.roomId}`,
|
url: `/pages/battle-room?roomNumber=${data.value.roomId}`,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user