Files
CRM_Montzar/apps/web/src/components/ui/UiBusyOverlay.vue
T
2026-10-03 17:45:08 +03:30

140 lines
2.8 KiB
Vue

<script setup lang="ts">
import { computed } from 'vue';
import { toFaDigits } from '@/lib/jalali';
const props = withDefaults(
defineProps<{
open: boolean;
message?: string;
/** وقتی true باشد روی مودال هم دیده می‌شود */
nest?: boolean;
/** درصد پیشرفت ۰ تا ۱۰۰؛ اگر null باشد نوار نشان داده نمی‌شود */
progress?: number | null;
}>(),
{
message: 'لطفاً صبر کنید…',
nest: false,
progress: null,
},
);
const showBar = computed(
() => props.progress != null && Number.isFinite(props.progress),
);
const pct = computed(() => {
if (!showBar.value) return 0;
return Math.max(0, Math.min(100, Math.round(props.progress!)));
});
const pctLabel = computed(() => toFaDigits(String(pct.value)));
</script>
<template>
<Teleport to="body">
<div
v-if="open"
class="busy-overlay"
:class="{ nest }"
role="status"
aria-live="polite"
aria-busy="true"
:aria-valuenow="showBar ? pct : undefined"
aria-valuemin="0"
aria-valuemax="100"
>
<div class="card">
<span class="spinner" aria-hidden="true" />
<p>{{ message }}</p>
<div v-if="showBar" class="progress-wrap">
<div class="progress-track" aria-hidden="true">
<div class="progress-fill" :style="{ width: `${pct}%` }" />
</div>
<strong class="progress-pct">{{ pctLabel }}٪</strong>
</div>
</div>
</div>
</Teleport>
</template>
<style scoped>
.busy-overlay {
position: fixed;
inset: 0;
z-index: 90;
display: grid;
place-items: center;
padding: 16px;
background: rgba(15, 23, 42, 0.4);
backdrop-filter: blur(2px);
}
.busy-overlay.nest {
z-index: 110;
}
.card {
display: grid;
justify-items: center;
gap: 0.85rem;
min-width: min(20rem, 100%);
max-width: 22rem;
padding: 1.35rem 1.5rem;
border-radius: 16px;
background: #fff;
box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
color: #0f172a;
text-align: center;
}
.card p {
margin: 0;
font-size: 0.95rem;
font-weight: 600;
line-height: 1.6;
}
.progress-wrap {
display: grid;
gap: 0.45rem;
width: 100%;
justify-items: center;
}
.progress-track {
width: 100%;
height: 8px;
border-radius: 999px;
background: #e2e8f0;
overflow: hidden;
}
.progress-fill {
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #0d9488, #14b8a6);
transition: width 0.25s ease;
}
.progress-pct {
font-size: 1.15rem;
font-weight: 800;
font-variant-numeric: tabular-nums;
color: #0f766e;
letter-spacing: 0.02em;
}
.spinner {
width: 28px;
height: 28px;
border: 3px solid #ccfbf1;
border-top-color: #0d9488;
border-radius: 50%;
animation: busy-spin 0.7s linear infinite;
}
@keyframes busy-spin {
to {
transform: rotate(360deg);
}
}
</style>