From 484a807dce524d07637dc1caed03c8f638ca4037 Mon Sep 17 00:00:00 2001 From: luo Date: Thu, 3 Sep 2026 16:40:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=89=AB=E7=A0=81?= =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E7=A0=81=E8=BF=9B=E5=85=A5=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/login/login.vue | 27 +++++++++++++++++++++------ store/user.js | 5 ++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/pages/login/login.vue b/pages/login/login.vue index f2d09f1..691db1b 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -86,7 +86,27 @@ }; onMounted(async () => { + const urlIdentifier = getPathDeviceId(); const token = uni.getStorageSync('token'); + const storedIdentifier = uni.getStorageSync('identifier') || ''; + + // 从外部链接进入时,链接中的资产标识优先于本地登录态。 + // 只有相同资产才能复用已登录的会话,避免将上一台设备的数据带到新链接中。 + if (urlIdentifier) { + identifier.value = urlIdentifier; + if (token && urlIdentifier === storedIdentifier) { + uni.reLaunch({ url: '/pages/index/index' }); + return; + } + + if (token || storedIdentifier) { + userStore.clearUser(); + } + + doLogin(); + return; + } + if (token) { uni.reLaunch({ url: '/pages/index/index' }); return; @@ -94,7 +114,6 @@ showPostBindReloginNotice(); handleWechatCallback(); - getPathDeviceId(); // 初始化微信 SDK (仅在微信浏览器内执行) // #ifdef H5 @@ -236,11 +255,7 @@ const getPathDeviceId = () => { const params = new URLSearchParams(window.location.search); - const idf = params.get('identifier'); - if (idf) { - identifier.value = idf; - handleLogin(); - } + return (params.get('identifier') || '').trim(); }; const doLogin = async () => { diff --git a/store/user.js b/store/user.js index 9ddd223..7a144c6 100644 --- a/store/user.js +++ b/store/user.js @@ -43,6 +43,9 @@ export const useUserStore = () => { const clearUser = () => { state.token = ''; state.assetToken = ''; + state.identifier = ''; + state.isDevice = false; + state.realNameStatus = 0; state.userInfo = { avatar: '', nickname: '' }; uni.removeStorageSync('token'); uni.removeStorageSync('identifier'); @@ -59,4 +62,4 @@ export const useUserStore = () => { setUserInfo, clearUser }; -}; \ No newline at end of file +};