update:优化多端登录
This commit is contained in:
25
src/App.vue
25
src/App.vue
@@ -21,7 +21,10 @@
|
||||
} = storeToRefs(store);
|
||||
const {
|
||||
updateUser,
|
||||
updateOnline
|
||||
updateOnline,
|
||||
updateDevice,
|
||||
updateGame,
|
||||
updateRoomNumber
|
||||
} = store;
|
||||
|
||||
watch(
|
||||
@@ -46,6 +49,22 @@
|
||||
updateUser(value);
|
||||
}
|
||||
|
||||
function onSessionKickedOut() {
|
||||
uni.removeStorageSync(
|
||||
`${uni.getAccountInfoSync().miniProgram.envVersion}_token`
|
||||
);
|
||||
updateUser();
|
||||
updateDevice("", "");
|
||||
updateOnline(false);
|
||||
updateGame(false, "");
|
||||
updateRoomNumber("");
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "账号已在其他设备登录",
|
||||
showCancel: false,
|
||||
});
|
||||
}
|
||||
|
||||
async function emitUpdateOnline() {
|
||||
const data = await getDeviceBatteryAPI();
|
||||
updateOnline(data.online);
|
||||
@@ -65,6 +84,7 @@
|
||||
onShow(() => {
|
||||
uni.$on("update-user", emitUpdateUser);
|
||||
uni.$on("update-online", emitUpdateOnline);
|
||||
uni.$on("session-kicked-out", onSessionKickedOut);
|
||||
const token = uni.getStorageSync(
|
||||
`${uni.getAccountInfoSync().miniProgram.envVersion}_token`
|
||||
);
|
||||
@@ -77,6 +97,7 @@
|
||||
onHide(() => {
|
||||
uni.$off("update-user", emitUpdateUser);
|
||||
uni.$off("update-online", emitUpdateOnline);
|
||||
uni.$off("session-kicked-out", onSessionKickedOut);
|
||||
websocket.closeWebSocket();
|
||||
});
|
||||
</script>
|
||||
@@ -289,4 +310,4 @@
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user