🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 14:50
This commit is contained in:
@@ -80,6 +80,14 @@
|
||||
<!-- Toast & Modals -->
|
||||
<div id="toast-container" class="fixed top-8 left-1/2 -translate-x-1/2 z-[200] space-y-4"></div>
|
||||
<div id="modals" class="fixed inset-0 z-[150] hidden items-center justify-center p-6 bg-black/80 backdrop-blur-md"></div>
|
||||
|
||||
<!-- Global Loader -->
|
||||
<div id="global-loader" class="fixed inset-0 z-[250] hidden items-center justify-center bg-black/40 backdrop-blur-sm">
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<div class="w-16 h-16 border-4 border-primary border-t-transparent rounded-full animate-spin shadow-[0_0_30px_var(--primary-glow)]"></div>
|
||||
<p class="text-white font-bold animate-pulse">جاري المعالجة...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<script>
|
||||
@@ -87,13 +95,28 @@
|
||||
baseUrl: 'index.php?route=/api/v1',
|
||||
get token() { return localStorage.getItem('access_token'); },
|
||||
async req(method, path, body = null, files = false) {
|
||||
const headers = { 'Accept': 'application/json' };
|
||||
if (this.token) headers['Authorization'] = `Bearer ${this.token}`;
|
||||
if (!files && body) { headers['Content-Type'] = 'application/json'; body = JSON.stringify(body); }
|
||||
const res = await fetch(`${this.baseUrl}${path}`, { method, headers, body });
|
||||
const data = await res.json();
|
||||
if (!res.ok) { if (res.status === 401) logout(); throw data; }
|
||||
return data;
|
||||
const loader = document.getElementById('global-loader');
|
||||
if (loader) loader.classList.replace('hidden', 'flex');
|
||||
|
||||
try {
|
||||
const headers = { 'Accept': 'application/json' };
|
||||
if (this.token) headers['Authorization'] = `Bearer ${this.token}`;
|
||||
if (!files && body) { headers['Content-Type'] = 'application/json'; body = JSON.stringify(body); }
|
||||
|
||||
const res = await fetch(`${this.baseUrl}${path}`, { method, headers, body });
|
||||
const data = await res.json();
|
||||
|
||||
if (!res.ok) {
|
||||
if (res.status === 401) logout();
|
||||
throw data;
|
||||
}
|
||||
return data;
|
||||
} catch (err) {
|
||||
showToast(err.error?.message || 'حدث خطأ غير متوقع في النظام', 'error');
|
||||
throw err;
|
||||
} finally {
|
||||
if (loader) loader.classList.replace('flex', 'hidden');
|
||||
}
|
||||
},
|
||||
get(p) { return this.req('GET', p); },
|
||||
post(p, b) { return this.req('POST', p, b); },
|
||||
|
||||
Reference in New Issue
Block a user