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 +};