update:修复黑屏下挤号问题

This commit is contained in:
2026-05-20 18:29:57 +08:00
parent 52b26fdcfb
commit 8830650560
3 changed files with 38 additions and 17 deletions

View File

@@ -22,9 +22,7 @@
const {
updateUser,
updateOnline,
updateDevice,
updateGame,
updateRoomNumber
clearSessionState
} = store;
watch(
@@ -50,14 +48,9 @@
}
function onSessionKickedOut() {
uni.removeStorageSync(
`${uni.getAccountInfoSync().miniProgram.envVersion}_token`
);
updateUser();
updateDevice("", "");
updateOnline(false);
updateGame(false, "");
updateRoomNumber("");
const env = uni.getAccountInfoSync().miniProgram.envVersion;
uni.removeStorageSync(`${env}_token`);
clearSessionState();
uni.showModal({
title: "提示",
content: "账号已在其他设备登录",

View File

@@ -42,6 +42,7 @@ function request(method, url, data = {}) {
if (code === 0) resolve(data);
else if (message) {
if (message.indexOf("登录身份已失效") !== -1) {
console.log('1111111111111111111,token失效')
uni.removeStorageSync(
`${uni.getAccountInfoSync().miniProgram.envVersion}_token`
);

View File

@@ -1,5 +1,7 @@
import { defineStore } from "pinia";
const PERSISTED_STORE_KEY = "store";
const defaultUser = {
id: "",
nickName: "",
@@ -8,6 +10,22 @@ const defaultUser = {
lvlName: "",
};
const getDefaultUser = () => ({ ...defaultUser });
const getDefaultDevice = () => ({
deviceId: "",
deviceName: "",
});
const getDefaultGame = () => ({
roomID: "",
inBattle: false,
roomNumber: "",
currentShot: 0,
totalShot: 0,
tips: "",
});
const getLvlName = (rankLvl, rankList = []) => {
if (!rankList) return;
let lvlName = "";
@@ -65,11 +83,8 @@ const getLvlImageByScore = (score, rankList = []) => {
export default defineStore("store", {
// 状态
state: () => ({
user: defaultUser,
device: {
deviceId: "",
deviceName: "",
},
user: getDefaultUser(),
device: getDefaultDevice(),
config: {},
rankData: {
rank: [],
@@ -111,7 +126,7 @@ export default defineStore("store", {
this.online = online;
},
async updateUser(user = {}) {
this.user = { ...defaultUser, ...user };
this.user = { ...getDefaultUser(), ...user };
this.user.lvlName = getLvlNameByScore(this.user.scores, this.config.randInfos)
this.user.lvlImage = getLvlImageByScore(
this.user.scores,
@@ -152,6 +167,18 @@ export default defineStore("store", {
updateRoomNumber(number) {
this.game.roomNumber = number;
},
clearSessionState() {
this.$patch({
user: getDefaultUser(),
device: getDefaultDevice(),
online: false,
game: getDefaultGame(),
});
uni.removeStorageSync(PERSISTED_STORE_KEY);
setTimeout(() => {
uni.removeStorageSync(PERSISTED_STORE_KEY);
}, 0);
},
},
// 数据持久化via pinia-plugin-persistedstate