feat: 头像显示
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { createRouter, createWebHistory } from 'vue-router'
|
import { createRouter, createWebHistory } from 'vue-router'
|
||||||
import { useUserInfoStore } from '@/stores/userInfo'
|
import { useUserInfoStore } from '@/stores/userInfo'
|
||||||
import { useGlobalStore } from '@/stores/global'
|
import { useGlobalStore } from '@/stores/global'
|
||||||
import { getUserLanguage } from '@/api/user'
|
import { getUserLanguage, fetchUserProfile } from '@/api/user'
|
||||||
import { fetchAllUnreadMessage } from '@/api/notification'
|
import { fetchAllUnreadMessage } from '@/api/notification'
|
||||||
import i18n from '@/lang/index'
|
import i18n from '@/lang/index'
|
||||||
import myEvent from '@/utils/myEvent'
|
import myEvent from '@/utils/myEvent'
|
||||||
@@ -113,6 +113,16 @@ router.afterEach(async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const avatarUrl = userInfoStore.state.userInfo.avatarUrl
|
||||||
|
if (!avatarUrl) {
|
||||||
|
fetchUserProfile().then((res) => {
|
||||||
|
const profile = res as any
|
||||||
|
if (profile.avatarUrl) {
|
||||||
|
userInfoStore.setAvatarUrl(profile.avatarUrl)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const globalStore = useGlobalStore()
|
const globalStore = useGlobalStore()
|
||||||
fetchAllUnreadMessage().then((res) => {
|
fetchAllUnreadMessage().then((res) => {
|
||||||
globalStore.setUnredCount(res.totalUnread)
|
globalStore.setUnredCount(res.totalUnread)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export const useUserInfoStore = defineStore('userInfo', () => {
|
|||||||
username: "",
|
username: "",
|
||||||
accessToken: "",
|
accessToken: "",
|
||||||
expiresIn: "",
|
expiresIn: "",
|
||||||
|
avatarUrl: "",
|
||||||
},
|
},
|
||||||
token: ''
|
token: ''
|
||||||
})
|
})
|
||||||
@@ -28,6 +29,10 @@ export const useUserInfoStore = defineStore('userInfo', () => {
|
|||||||
setLocal(data, 'token')
|
setLocal(data, 'token')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setAvatarUrl = (url: string) => {
|
||||||
|
state.value.userInfo.avatarUrl = url
|
||||||
|
}
|
||||||
|
|
||||||
const logout = async (reload: boolean = false) => {
|
const logout = async (reload: boolean = false) => {
|
||||||
// 处理退出登录的一些逻辑
|
// 处理退出登录的一些逻辑
|
||||||
const userId = state.value.userInfo.userId
|
const userId = state.value.userInfo.userId
|
||||||
@@ -38,6 +43,7 @@ export const useUserInfoStore = defineStore('userInfo', () => {
|
|||||||
username: "",
|
username: "",
|
||||||
accessToken: "",
|
accessToken: "",
|
||||||
expiresIn: "",
|
expiresIn: "",
|
||||||
|
avatarUrl: "",
|
||||||
}
|
}
|
||||||
state.value.token = ''
|
state.value.token = ''
|
||||||
removeLocal('token')
|
removeLocal('token')
|
||||||
@@ -49,6 +55,7 @@ export const useUserInfoStore = defineStore('userInfo', () => {
|
|||||||
state,
|
state,
|
||||||
setToken,
|
setToken,
|
||||||
setUserInfo,
|
setUserInfo,
|
||||||
|
setAvatarUrl,
|
||||||
logout
|
logout
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -51,7 +51,9 @@
|
|||||||
<div class="info">
|
<div class="info">
|
||||||
<img src="@/assets/images/profile-content-bg.jpg" alt="" />
|
<img src="@/assets/images/profile-content-bg.jpg" alt="" />
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="profile"></div>
|
<div class="profile">
|
||||||
|
<img class="profile-avatar" :src="userInfoStore.state.userInfo.avatarUrl" alt="" />
|
||||||
|
</div>
|
||||||
<div class="name">
|
<div class="name">
|
||||||
{{ $t('MainHeader.HiName', { name: userInfo.username }) }}
|
{{ $t('MainHeader.HiName', { name: userInfo.username }) }}
|
||||||
</div>
|
</div>
|
||||||
@@ -286,7 +288,12 @@
|
|||||||
width: 5rem;
|
width: 5rem;
|
||||||
height: 5rem;
|
height: 5rem;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background: #cfcfcf;
|
.profile-avatar{
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 50%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
> .name {
|
> .name {
|
||||||
font-size: 1.4rem;
|
font-size: 1.4rem;
|
||||||
|
|||||||
@@ -119,10 +119,6 @@
|
|||||||
loadUserProfile
|
loadUserProfile
|
||||||
} = useSettingsForm({ t, locale })
|
} = useSettingsForm({ t, locale })
|
||||||
|
|
||||||
// watch(locale, () => {
|
|
||||||
// loadUserProfile()
|
|
||||||
// })
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadUserProfile()
|
loadUserProfile()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user