Skip to content

Commit 6e69738

Browse files
committed
fix: user avatar placeholder using transparent GIF (#698)
1 parent 3c6d8a5 commit 6e69738

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

apps/client/components/Home/index.vue

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<div class="mx-auto h-56 w-56 overflow-hidden">
66
<img
77
class="h-full w-full rounded-full border-2 border-gray-300 bg-gray-300 object-cover dark:border-gray-700 dark:bg-gray-700"
8-
:src="userStore.userInfo?.picture!"
8+
:src="userStore.userInfo?.picture || DEFAULT_AVATAR"
9+
@error="onImageError"
910
/>
1011
</div>
1112
<div class="mt-4 truncate">
@@ -56,6 +57,17 @@ const userStore = useUserStore();
5657
const { learnRecord, setupLearnRecord, setQueryYear } = useLearnRecord();
5758
const { toggleYear } = useCalendarGraph();
5859
60+
// 默认 1x1 像素的透明 GIF 图片,用于消除头像图片加载失败时的白色边框
61+
const DEFAULT_AVATAR =
62+
"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
63+
64+
function onImageError(e: Event) {
65+
const target = e.target as HTMLImageElement;
66+
if (target) {
67+
target.src = DEFAULT_AVATAR;
68+
}
69+
}
70+
5971
function useCalendarGraph() {
6072
const data = ref<CalendarData[]>([]);
6173
const totalCount = ref<number>(0);

0 commit comments

Comments
 (0)