把socket放到最外面
This commit is contained in:
@@ -36,33 +36,34 @@ const createPractise = async (arrows) => {
|
||||
const result = await createPractiseAPI(arrows);
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
const token = uni.getStorageSync("token");
|
||||
websocket.createWebSocket(token, (content) => {
|
||||
const messages = JSON.parse(content).data.updates || [];
|
||||
messages.forEach((msg) => {
|
||||
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
||||
scores.value.push(msg.target);
|
||||
if (scores.value.length === total) {
|
||||
showScore.value = true;
|
||||
}
|
||||
// if (step.value === 2 && msg.target.dst / 100 > 5) {
|
||||
if (step.value === 2 && msg.target.dst > 5) {
|
||||
btnDisabled.value = false;
|
||||
}
|
||||
async function onReceiveMessage(content) {
|
||||
const messages = JSON.parse(content).data.updates || [];
|
||||
messages.forEach((msg) => {
|
||||
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
||||
scores.value.push(msg.target);
|
||||
if (scores.value.length === total) {
|
||||
showScore.value = true;
|
||||
}
|
||||
if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) {
|
||||
practiseResult.value = {
|
||||
...msg.practice,
|
||||
arrows: JSON.parse(msg.practice.arrows),
|
||||
};
|
||||
// if (step.value === 2 && msg.target.dst / 100 > 5) {
|
||||
if (step.value === 2 && msg.target.dst > 5) {
|
||||
btnDisabled.value = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) {
|
||||
practiseResult.value = {
|
||||
...msg.practice,
|
||||
arrows: JSON.parse(msg.practice.arrows),
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
uni.$on("socket-inbox", onReceiveMessage);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
websocket.closeWebSocket();
|
||||
uni.$off("socket-inbox", onReceiveMessage);
|
||||
});
|
||||
|
||||
const nextStep = async () => {
|
||||
|
||||
Reference in New Issue
Block a user