细节完善

This commit is contained in:
kron
2026-02-10 17:03:25 +08:00
parent 88f1ef5d95
commit 608de34dd3
10 changed files with 67 additions and 62 deletions

View File

@@ -73,7 +73,7 @@ defineProps({
<text class="player-name">{{ player.name }}</text>
</view>
<image
v-if="winner === 0"
v-if="winner === 2"
src="../static/winner-badge.png"
mode="widthFix"
class="right-winner-badge"

View File

@@ -1,7 +1,7 @@
<script setup>
import { ref, watch, onMounted, onBeforeUnmount } from "vue";
import audioManager from "@/audioManager";
import { MESSAGETYPES, MESSAGETYPESV2 } from "@/constants";
import { MESSAGETYPESV2 } from "@/constants";
import { getDirectionText } from "@/util";
import useStore from "@/store";
@@ -80,7 +80,7 @@ async function onReceiveMessage(message) {
title: "距离不足,无效",
icon: "none",
});
audioManager.pLay("射击无效");
audioManager.play("射击无效");
}
}

View File

@@ -143,12 +143,12 @@ async function onReceiveMessage(msg) {
} else if (msg.type === MESSAGETYPESV2.HalfRest) {
halfTime.value = true;
audioManager.play("中场休息");
} else if (type === MESSAGETYPESV2.InvalidShot) {
} else if (msg.type === MESSAGETYPESV2.InvalidShot) {
uni.showToast({
title: "距离不足,无效",
icon: "none",
});
audioManager.pLay("射击无效");
audioManager.play("射击无效");
}
}

View File

@@ -87,28 +87,34 @@ const handleLogin = async () => {
});
}
loading.value = true;
const wxResult = await wxLogin();
const fileManager = uni.getFileSystemManager();
const avatarBase64 = fileManager.readFileSync(avatarUrl.value, "base64");
const base64Url = `data:image/png;base64,${avatarBase64}`;
const result = await loginAPI(
phone.value,
nickName.value,
base64Url,
wxResult.code
);
const data = await getHomeData();
if (data.user) updateUser(data.user);
const devices = await getMyDevicesAPI();
if (devices.bindings && devices.bindings.length) {
updateDevice(devices.bindings[0].deviceId, devices.bindings[0].deviceName);
try {
try {
const wxResult = await wxLogin();
const fileManager = uni.getFileSystemManager();
const avatarBase64 = fileManager.readFileSync(avatarUrl.value, "base64");
const base64Url = `data:image/png;base64,${avatarBase64}`;
const result = await loginAPI(
phone.value,
nickName.value,
base64Url,
wxResult.code
);
const data = await getHomeData();
if (data.user) updateUser(data.user);
const devices = await getMyDevicesAPI();
if (devices.bindings && devices.bindings.length) {
updateDevice(
devices.bindings[0].deviceId,
devices.bindings[0].deviceName
);
const data = await getDeviceBatteryAPI();
updateOnline(data.online);
} catch (error) {}
}
props.onClose();
} catch (error) {
console.log("login error", error);
} finally {
loading.value = false;
}
loading.value = false;
props.onClose();
};
const openServiceLink = () => {

View File

@@ -16,7 +16,7 @@ const players = ref([]);
onLoad(async (options) => {
if (!options.battleId) return;
battleId.value = options.battleId || "60143330377469952";
battleId.value = options.battleId || "60510101693403136";
const result = await getBattleAPI(battleId.value);
data.value = result;
if (result.mode > 3) {
@@ -128,7 +128,7 @@ const checkBowData = (selected) => {
<text :style="{ color: team == 1 ? '#64BAFF' : '#FF6767' }">
{{ round.shoots[team].reduce((acc, cur) => acc + cur.ring, 0) }}
</text>
<text>得分 {{ round.scores[team].totalRing }}</text>
<text>得分 {{ round.scores[team].score }}</text>
</view>
</view>
</view>

View File

@@ -12,7 +12,6 @@ import ScreenHint from "@/components/ScreenHint.vue";
import TestDistance from "@/components/TestDistance.vue";
import audioManager from "@/audioManager";
import { getBattleAPI, laserCloseAPI } from "@/apis";
import { isGameEnded } from "@/util";
import { MESSAGETYPESV2 } from "@/constants";
import useStore from "@/store";
import { storeToRefs } from "pinia";
@@ -103,9 +102,11 @@ async function onReceiveMessage(msg) {
halfRest.value = true;
tips.value = "准备下半场";
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
uni.redirectTo({
url: "/pages/battle-result?battleId=" + msg.matchId,
});
setTimeout(() => {
uni.redirectTo({
url: "/pages/battle-result?battleId=" + msg.matchId,
});
}, 1000);
}
}
onMounted(async () => {

View File

@@ -21,7 +21,7 @@ import {
} from "@/apis";
import { sharePractiseData } from "@/canvas";
import { wxShare, debounce } from "@/util";
import { MESSAGETYPESV2, MESSAGETYPES, roundsName } from "@/constants";
import { MESSAGETYPESV2, roundsName } from "@/constants";
import useStore from "@/store";
import { storeToRefs } from "pinia";
@@ -31,7 +31,6 @@ const { user } = storeToRefs(store);
const start = ref(false);
const scores = ref([]);
const total = 12;
const currentRound = ref(0);
const practiseResult = ref({});
const practiseId = ref("");
const showGuide = ref(false);
@@ -39,7 +38,6 @@ const tips = ref("");
const onReady = async () => {
await startPractiseAPI();
currentRound.value = 0;
scores.value = [];
start.value = true;
audioManager.play("练习开始");
@@ -69,7 +67,6 @@ async function onComplete() {
practiseResult.value = {};
start.value = false;
scores.value = [];
currentRound.value = 0;
const result = await createPractiseAPI(total, 120);
if (result) practiseId.value = result.id;
}
@@ -132,7 +129,7 @@ onBeforeUnmount(() => {
</view>
<BowTarget
:totalRound="start ? total / 4 : 0"
:currentRound="currentRound"
:currentRound="scores.length % 3"
:scores="scores"
/>
<ScorePanel2 :arrows="scores" />

View File

@@ -12,8 +12,7 @@ import TestDistance from "@/components/TestDistance.vue";
import TeamAvatars from "@/components/TeamAvatars.vue";
import ShootProgress2 from "@/components/ShootProgress2.vue";
import { laserCloseAPI, getBattleAPI } from "@/apis";
import { isGameEnded, formatTimestamp } from "@/util";
import { MESSAGETYPES, MESSAGETYPESV2, roundsName } from "@/constants";
import { MESSAGETYPESV2 } from "@/constants";
import audioManager from "@/audioManager";
import useStore from "@/store";
import { storeToRefs } from "pinia";
@@ -128,9 +127,11 @@ async function onReceiveMessage(msg) {
}, 2000);
return;
}
uni.redirectTo({
url: "/pages/battle-result?battleId=" + msg.matchId,
});
setTimeout(() => {
uni.redirectTo({
url: "/pages/battle-result?battleId=" + msg.matchId,
});
}, 1000);
}
}

View File

@@ -89,26 +89,26 @@ export const wxShare = async (canvasId = "shareCanvas") => {
}
};
export const isGameEnded = async (battleId) => {
const state = await getUserGameState();
if (!state.gaming) {
const result = await getGameAPI(battleId);
if (result.mode) {
uni.redirectTo({
url: `/pages/battle-result?battleId=${battleId}`,
});
} else {
uni.showToast({
title: "比赛已结束",
icon: "none",
});
setTimeout(() => {
uni.navigateBack();
}, 1000);
}
}
return !state.gaming;
};
// export const isGameEnded = async (battleId) => {
// const state = await getUserGameState();
// if (!state.gaming) {
// const result = await getGameAPI(battleId);
// if (result.mode) {
// uni.redirectTo({
// url: `/pages/battle-result?battleId=${battleId}`,
// });
// } else {
// uni.showToast({
// title: "比赛已结束",
// icon: "none",
// });
// setTimeout(() => {
// uni.navigateBack();
// }, 1000);
// }
// }
// return !state.gaming;
// };
// 获取元素尺寸和位置信息
export const getElementRect = (classname) => {

View File

@@ -47,9 +47,9 @@ function createWebSocket(token, onMessage) {
uni.onSocketMessage((res) => {
const { data, event } = JSON.parse(res.data);
if (event === "pong") return;
if (data.type && data.data) {
if (data.type) {
console.log("收到消息:", getMessageTypeName(data.type), data.data);
if (onMessage) onMessage({ ...data.data, type: data.type });
if (onMessage) onMessage({ ...(data.data || {}), type: data.type });
return;
}
if (onMessage && data.updates) onMessage(data.updates);