fix: 修复登录成功之后查询登录用户信息

This commit is contained in:
xieyonghong 2023-04-21 14:20:25 +08:00
parent 0bb5991231
commit 4b2b8c1728
1 changed files with 28 additions and 17 deletions

View File

@ -169,8 +169,8 @@ import {
getInitSet, getInitSet,
systemVersion, systemVersion,
bindInfo, bindInfo,
settingDetail, settingDetail, userDetail
} from '@/api/login'; } from '@/api/login'
import { useUserInfo } from '@/store/userInfo'; import { useUserInfo } from '@/store/userInfo';
import { LocalStore } from '@/utils/comm'; import { LocalStore } from '@/utils/comm';
import { BASE_API_PATH, TOKEN_KEY, Version_Code } from '@/utils/variable'; import { BASE_API_PATH, TOKEN_KEY, Version_Code } from '@/utils/variable';
@ -250,18 +250,29 @@ const onFinish = async () => {
const res: any = await authLogin(form); const res: any = await authLogin(form);
loading.value = false; loading.value = false;
if (res.success) { if (res.success) {
store.$patch({
...res.result,
username: form.username,
});
LocalStore.set(TOKEN_KEY, res?.result.token); LocalStore.set(TOKEN_KEY, res?.result.token);
if (res.result.user?.username === 'admin') { const userResp = await userDetail()
if (userResp.success) {
store.$patch({
userInfos: {
...userResp.result,
token: res?.result.token,
},
isAdmin: userResp.username === "admin",
});
if (userResp.result?.username === 'admin') {
const resp: any = await getInitSet(); const resp: any = await getInitSet();
if (resp.status === 200 && !resp.result.length) { if (resp.status === 200 && !resp.result.length) {
window.location.href = '/#/init-home'; window.location.href = '/#/init-home';
return; return;
} }
} }
} else {
store.$patch({
...res.result
});
}
window.location.href = '/'; window.location.href = '/';
} }
} catch (error) { } catch (error) {