Skip to content

Commit ae252b5

Browse files
committed
fix the user icon in the upper right corner flickered when switching between pages on desktop version
1 parent 73e5d68 commit ae252b5

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

src/components/desktop/MainPageLayout.vue

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,8 @@
109109
</v-btn>
110110
<v-avatar class="cursor-pointer ms-3" variant="tonal"
111111
:color="currentUserAvatar ? 'rgba(0,0,0,0)' : 'primary'">
112-
<v-img :src="currentUserAvatar" v-if="currentUserAvatar">
113-
<template #placeholder>
114-
<div class="d-flex align-center justify-center bg-light-primary">
115-
<v-icon color="primary" :icon="mdiAccount"/>
116-
</div>
117-
</template>
118-
</v-img>
119-
<v-icon :icon="mdiAccount" v-else-if="!currentUserAvatar"/>
112+
<v-icon :color="currentUserAvatar ? 'primary' : undefined" :icon="mdiAccount"/>
113+
<span class="user-avatar-image" :style="currentUserAvatarStyle" v-if="currentUserAvatar"></span>
120114
<v-menu activator="parent" width="230" location="bottom end" offset="14px">
121115
<v-list>
122116
<v-list-item>
@@ -259,7 +253,10 @@ const showMobileQrCode = ref<boolean>(false);
259253
const showAboutDialog = ref<boolean>(false);
260254
261255
const currentNickName = computed<string>(() => userStore.currentUserNickname || tt('User'));
262-
const currentUserAvatar = computed<string | null>(() => userStore.getUserAvatarUrl(userStore.currentUserBasicInfo, true));
256+
const currentUserAvatar = computed<string | null>(() => userStore.currentUserAvatar);
257+
const currentUserAvatarStyle = computed<Record<string, string> | undefined>(() => currentUserAvatar.value ? {
258+
backgroundImage: `url("${currentUserAvatar.value}")`
259+
} : undefined);
263260
264261
const currentTheme = computed<string>({
265262
get: () => {
@@ -338,4 +335,14 @@ function showAddDialogInTransactionListPage(): void {
338335
min-width: 38px;
339336
border-radius: 10px;
340337
}
338+
339+
.user-avatar-image {
340+
position: absolute;
341+
z-index: 1;
342+
background-position: center;
343+
background-repeat: no-repeat;
344+
background-size: cover;
345+
inset: 0;
346+
pointer-events: none;
347+
}
341348
</style>

src/stores/user.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import {
2828
isNumber
2929
} from '@/lib/common.ts';
3030

31+
import {
32+
generateRandomUUID
33+
} from '@/lib/misc.ts';
34+
3135
import {
3236
getCurrentUserInfo,
3337
updateCurrentUserInfo,
@@ -40,6 +44,7 @@ import services from '@/lib/services.ts';
4044
export const useUserStore = defineStore('user', () => {
4145
const settingsStore = useSettingsStore();
4246
const currentUserBasicInfo = ref<UserBasicInfo | null>(getCurrentUserInfo());
47+
const currentUserAvatarNoCacheId = ref<string>(generateRandomUUID());
4348

4449
const currentUserNickname = computed<string | null>(() => {
4550
const userInfo = currentUserBasicInfo.value || EMPTY_USER_BASIC_INFO;
@@ -48,7 +53,7 @@ export const useUserStore = defineStore('user', () => {
4853

4954
const currentUserAvatar = computed<string | null>(() => {
5055
const userInfo = currentUserBasicInfo.value || EMPTY_USER_BASIC_INFO;
51-
return getUserAvatarUrl(userInfo, false);
56+
return getUserAvatarUrl(userInfo, currentUserAvatarNoCacheId.value);
5257
});
5358

5459
const currentUserDefaultAccountId = computed<string>(() => {
@@ -167,6 +172,7 @@ export const useUserStore = defineStore('user', () => {
167172

168173
function resetUserBasicInfo(): void {
169174
currentUserBasicInfo.value = null;
175+
currentUserAvatarNoCacheId.value = generateRandomUUID();
170176
clearCurrentUserInfo();
171177
}
172178

@@ -233,6 +239,7 @@ export const useUserStore = defineStore('user', () => {
233239
}
234240

235241
storeUserBasicInfo(data.result);
242+
currentUserAvatarNoCacheId.value = generateRandomUUID();
236243

237244
resolve(data.result);
238245
}).catch(error => {

0 commit comments

Comments
 (0)