feat: add client-side onerror fallback to default avatar

This commit is contained in:
antv
2026-07-09 09:10:15 +07:00
parent 48bdf21de2
commit badc453389
3 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -31,7 +31,7 @@
$deptName = $deptVal ?? 'Team'; $deptName = $deptVal ?? 'Team';
} }
@endphp @endphp
<img src="{{ $avatarUrl }}" alt="Avatar" class="w-full h-full object-cover"> <img src="{{ $avatarUrl }}" alt="Avatar" class="w-full h-full object-cover" onerror="this.onerror=null; this.src='{{ asset('images/avatar.png') }}';">
</div> </div>
<div class="hidden sm:flex flex-col leading-tight pr-1"> <div class="hidden sm:flex flex-col leading-tight pr-1">
<span class="text-[13px] font-bold text-[#1a2b49] block truncate max-w-[100px]" title="{{ Auth::user()->name }}">{{ Auth::user()->name }}</span> <span class="text-[13px] font-bold text-[#1a2b49] block truncate max-w-[100px]" title="{{ Auth::user()->name }}">{{ Auth::user()->name }}</span>
@@ -18,7 +18,7 @@
<!-- Avatar & Info --> <!-- Avatar & Info -->
<div class="flex items-center gap-3 ml-1 min-w-0 flex-1"> <div class="flex items-center gap-3 ml-1 min-w-0 flex-1">
<img src="{{ $avatar }}" alt="{{ $name }}" class="w-10 h-10 rounded-full object-cover shadow-sm border border-gray-100 flex-shrink-0"> <img src="{{ $avatar }}" alt="{{ $name }}" class="w-10 h-10 rounded-full object-cover shadow-sm border border-gray-100 flex-shrink-0" onerror="this.onerror=null; this.src='{{ asset('images/avatar.png') }}';">
<div class="flex flex-col min-w-0 flex-1"> <div class="flex flex-col min-w-0 flex-1">
<span class="text-[14px] font-bold {{ $isCurrent ? 'text-[#1a2b49]' : 'text-gray-800' }} leading-tight mb-0.5 truncate">{{ $name }}</span> <span class="text-[14px] font-bold {{ $isCurrent ? 'text-[#1a2b49]' : 'text-gray-800' }} leading-tight mb-0.5 truncate">{{ $name }}</span>
<span class="text-[12px] text-gray-500 font-medium truncate" title="{{ $team }}">{{ $team }}</span> <span class="text-[12px] text-gray-500 font-medium truncate" title="{{ $team }}">{{ $team }}</span>
+1 -1
View File
@@ -15,7 +15,7 @@
<!-- Avatar preview and upload --> <!-- Avatar preview and upload -->
<div class="flex items-center gap-4 mb-6"> <div class="flex items-center gap-4 mb-6">
<div class="w-16 h-16 rounded-full overflow-hidden border border-gray-200"> <div class="w-16 h-16 rounded-full overflow-hidden border border-gray-200">
<img src="{{ Auth::user()->avatar ?? asset('images/avatar.png') }}" alt="Avatar" class="w-full h-full object-cover" id="avatar-preview"> <img src="{{ Auth::user()->avatar ?? asset('images/avatar.png') }}" alt="Avatar" class="w-full h-full object-cover" id="avatar-preview" onerror="this.onerror=null; this.src='{{ asset('images/avatar.png') }}';">
</div> </div>
<div class="flex-1"> <div class="flex-1">
<label class="block text-[13px] font-bold text-gray-700 mb-1" for="avatar">Thay đổi ảnh đại diện</label> <label class="block text-[13px] font-bold text-gray-700 mb-1" for="avatar">Thay đổi ảnh đại diện</label>