fix: 修复扫码二维码进入同一个设备

This commit is contained in:
luo
2026-09-03 16:40:11 +08:00
parent 6845e97b14
commit 484a807dce
2 changed files with 25 additions and 7 deletions

View File

@@ -86,7 +86,27 @@
}; };
onMounted(async () => { onMounted(async () => {
const urlIdentifier = getPathDeviceId();
const token = uni.getStorageSync('token'); 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) { if (token) {
uni.reLaunch({ url: '/pages/index/index' }); uni.reLaunch({ url: '/pages/index/index' });
return; return;
@@ -94,7 +114,6 @@
showPostBindReloginNotice(); showPostBindReloginNotice();
handleWechatCallback(); handleWechatCallback();
getPathDeviceId();
// 初始化微信 SDK (仅在微信浏览器内执行) // 初始化微信 SDK (仅在微信浏览器内执行)
// #ifdef H5 // #ifdef H5
@@ -236,11 +255,7 @@
const getPathDeviceId = () => { const getPathDeviceId = () => {
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
const idf = params.get('identifier'); return (params.get('identifier') || '').trim();
if (idf) {
identifier.value = idf;
handleLogin();
}
}; };
const doLogin = async () => { const doLogin = async () => {

View File

@@ -43,6 +43,9 @@ export const useUserStore = () => {
const clearUser = () => { const clearUser = () => {
state.token = ''; state.token = '';
state.assetToken = ''; state.assetToken = '';
state.identifier = '';
state.isDevice = false;
state.realNameStatus = 0;
state.userInfo = { avatar: '', nickname: '' }; state.userInfo = { avatar: '', nickname: '' };
uni.removeStorageSync('token'); uni.removeStorageSync('token');
uni.removeStorageSync('identifier'); uni.removeStorageSync('identifier');
@@ -59,4 +62,4 @@ export const useUserStore = () => {
setUserInfo, setUserInfo,
clearUser clearUser
}; };
}; };