细节完善

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> <text class="player-name">{{ player.name }}</text>
</view> </view>
<image <image
v-if="winner === 0" v-if="winner === 2"
src="../static/winner-badge.png" src="../static/winner-badge.png"
mode="widthFix" mode="widthFix"
class="right-winner-badge" class="right-winner-badge"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -12,8 +12,7 @@ import TestDistance from "@/components/TestDistance.vue";
import TeamAvatars from "@/components/TeamAvatars.vue"; import TeamAvatars from "@/components/TeamAvatars.vue";
import ShootProgress2 from "@/components/ShootProgress2.vue"; import ShootProgress2 from "@/components/ShootProgress2.vue";
import { laserCloseAPI, getBattleAPI } from "@/apis"; import { laserCloseAPI, getBattleAPI } from "@/apis";
import { isGameEnded, formatTimestamp } from "@/util"; import { MESSAGETYPESV2 } from "@/constants";
import { MESSAGETYPES, MESSAGETYPESV2, roundsName } from "@/constants";
import audioManager from "@/audioManager"; import audioManager from "@/audioManager";
import useStore from "@/store"; import useStore from "@/store";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
@@ -128,9 +127,11 @@ async function onReceiveMessage(msg) {
}, 2000); }, 2000);
return; return;
} }
uni.redirectTo({ setTimeout(() => {
url: "/pages/battle-result?battleId=" + msg.matchId, 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) => { // export const isGameEnded = async (battleId) => {
const state = await getUserGameState(); // const state = await getUserGameState();
if (!state.gaming) { // if (!state.gaming) {
const result = await getGameAPI(battleId); // const result = await getGameAPI(battleId);
if (result.mode) { // if (result.mode) {
uni.redirectTo({ // uni.redirectTo({
url: `/pages/battle-result?battleId=${battleId}`, // url: `/pages/battle-result?battleId=${battleId}`,
}); // });
} else { // } else {
uni.showToast({ // uni.showToast({
title: "比赛已结束", // title: "比赛已结束",
icon: "none", // icon: "none",
}); // });
setTimeout(() => { // setTimeout(() => {
uni.navigateBack(); // uni.navigateBack();
}, 1000); // }, 1000);
} // }
} // }
return !state.gaming; // return !state.gaming;
}; // };
// 获取元素尺寸和位置信息 // 获取元素尺寸和位置信息
export const getElementRect = (classname) => { export const getElementRect = (classname) => {

View File

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