fix: 修复扫码二维码进入同一个设备
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user