添加开始游戏前,进行连接检测

This commit is contained in:
kron
2025-06-28 22:44:30 +08:00
parent 77691c411a
commit 21b3e38ff0
9 changed files with 41 additions and 21 deletions

View File

@@ -1,24 +1,23 @@
<script setup>
import { watch, onMounted, onUnmounted } from "vue";
import { watch } from "vue";
import { onShow } from "@dcloudio/uni-app";
import websocket from "@/websocket";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
const { updateConnect, updateUser } = store;
const { updateUser } = store;
watch(
() => user.value.id,
(newVal) => {
const token = uni.getStorageSync("token");
if (newVal && token) {
websocket.createWebSocket(token, updateConnect, (content) => {
websocket.createWebSocket(token, (content) => {
uni.$emit("socket-inbox", content);
});
}
if (!newVal) {
updateConnect(false);
websocket.closeWebSocket();
}
},