Commit 6e69738 1 parent 3c6d8a5 commit 6e69738 Copy full SHA for 6e69738
File tree 1 file changed +13
-1
lines changed
apps/client/components/Home
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 5
5
<div class =" mx-auto h-56 w-56 overflow-hidden" >
6
6
<img
7
7
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"
9
10
/>
10
11
</div >
11
12
<div class =" mt-4 truncate" >
@@ -56,6 +57,17 @@ const userStore = useUserStore();
56
57
const { learnRecord, setupLearnRecord, setQueryYear } = useLearnRecord ();
57
58
const { toggleYear } = useCalendarGraph ();
58
59
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
+
59
71
function useCalendarGraph() {
60
72
const data = ref <CalendarData []>([]);
61
73
const totalCount = ref <number >(0 );
You can’t perform that action at this time.
0 commit comments