2026-09-01 16:05:29 +03:30
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { computed } from 'vue';
|
|
|
|
|
import { toFaDigits } from '@/lib/jalali';
|
|
|
|
|
import type { HomeDashboardSourceDto } from '@mento/shared';
|
2026-09-10 01:22:24 +03:30
|
|
|
import UiChart, { type UiChartOption } from '@/components/ui/UiChart.vue';
|
2026-09-01 16:05:29 +03:30
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
sources: HomeDashboardSourceDto[];
|
|
|
|
|
}>();
|
|
|
|
|
|
2026-09-02 16:06:17 +03:30
|
|
|
const demoSources: HomeDashboardSourceDto[] = [
|
|
|
|
|
{ label: 'معرفی دوستان', count: 44, percent: 34 },
|
|
|
|
|
{ label: 'وبسایت', count: 33, percent: 26 },
|
|
|
|
|
{ label: 'شبکههای اجتماعی', count: 23, percent: 18 },
|
|
|
|
|
{ label: 'تبلیغات', count: 18, percent: 14 },
|
|
|
|
|
{ label: 'سایر', count: 10, percent: 8 },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const colors = ['#2563eb', '#14b8a6', '#22c55e', '#fb923c', '#94a3b8'];
|
|
|
|
|
|
|
|
|
|
const rows = computed(() => (props.sources.length ? props.sources : demoSources));
|
|
|
|
|
const total = computed(() => rows.value.reduce((a, s) => a + s.count, 0));
|
2026-09-10 01:22:24 +03:30
|
|
|
|
|
|
|
|
const option = computed<UiChartOption>(() => ({
|
|
|
|
|
animationDuration: 400,
|
|
|
|
|
color: colors,
|
|
|
|
|
tooltip: {
|
|
|
|
|
trigger: 'item',
|
|
|
|
|
textStyle: { fontFamily: 'IRANSans, Tahoma, sans-serif' },
|
|
|
|
|
formatter: (p) => {
|
|
|
|
|
const item = Array.isArray(p) ? p[0] : p;
|
|
|
|
|
return `${item.name}<br/>${toFaDigits(Number(item.value ?? 0))} — ${toFaDigits(item.percent ?? 0)}٪`;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
series: [
|
|
|
|
|
{
|
|
|
|
|
type: 'pie',
|
|
|
|
|
radius: ['58%', '82%'],
|
|
|
|
|
center: ['50%', '50%'],
|
|
|
|
|
avoidLabelOverlap: true,
|
|
|
|
|
label: { show: false },
|
|
|
|
|
labelLine: { show: false },
|
|
|
|
|
data: rows.value.map((s) => ({ name: s.label, value: s.count })),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}));
|
2026-09-01 16:05:29 +03:30
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<article class="panel">
|
|
|
|
|
<header class="panel-head">
|
|
|
|
|
<h2>منابع مشتریان</h2>
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
<div class="donut-wrap">
|
|
|
|
|
<div class="donut-chart-box">
|
2026-09-10 01:22:24 +03:30
|
|
|
<UiChart :option="option" height="132px" />
|
2026-09-01 16:05:29 +03:30
|
|
|
<div class="donut-center">
|
|
|
|
|
<strong>{{ toFaDigits(total) }}</strong>
|
|
|
|
|
<span>مشتری</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<ul class="donut-legend">
|
2026-09-10 01:22:24 +03:30
|
|
|
<li v-for="(row, i) in rows" :key="row.label">
|
|
|
|
|
<span class="dot" :style="{ background: colors[i % colors.length] }" />
|
|
|
|
|
<span class="lbl">{{ row.label }}</span>
|
|
|
|
|
<em>{{ toFaDigits(row.percent) }}٪</em>
|
2026-09-01 16:05:29 +03:30
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
</article>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.panel {
|
|
|
|
|
background: #fff;
|
2026-09-10 01:22:24 +03:30
|
|
|
border-radius: var(--radius);
|
|
|
|
|
padding: var(--pad-modal);
|
2026-09-01 16:05:29 +03:30
|
|
|
box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
|
2026-09-10 01:22:24 +03:30
|
|
|
border: 1px solid var(--line);
|
2026-09-01 16:05:29 +03:30
|
|
|
min-width: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.panel-head {
|
2026-09-02 16:06:17 +03:30
|
|
|
margin-bottom: 0.75rem;
|
2026-09-01 16:05:29 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
h2 {
|
|
|
|
|
margin: 0;
|
2026-09-02 16:06:17 +03:30
|
|
|
font-size: 0.95rem;
|
2026-09-01 16:05:29 +03:30
|
|
|
color: #0f172a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.donut-wrap {
|
|
|
|
|
display: grid;
|
2026-09-02 16:06:17 +03:30
|
|
|
grid-template-columns: 132px 1fr;
|
|
|
|
|
gap: 0.85rem;
|
2026-09-01 16:05:29 +03:30
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.donut-chart-box {
|
|
|
|
|
position: relative;
|
2026-09-02 16:06:17 +03:30
|
|
|
width: 132px;
|
|
|
|
|
height: 132px;
|
2026-09-01 16:05:29 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.donut-center {
|
|
|
|
|
position: absolute;
|
|
|
|
|
inset: 0;
|
|
|
|
|
display: grid;
|
|
|
|
|
place-content: center;
|
|
|
|
|
text-align: center;
|
|
|
|
|
gap: 0.05rem;
|
|
|
|
|
pointer-events: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.donut-center strong {
|
2026-09-02 16:06:17 +03:30
|
|
|
font-size: 1.15rem;
|
2026-09-01 16:05:29 +03:30
|
|
|
color: #0f172a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.donut-center span {
|
2026-09-02 16:06:17 +03:30
|
|
|
font-size: 0.7rem;
|
2026-09-01 16:05:29 +03:30
|
|
|
color: #94a3b8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.donut-legend {
|
|
|
|
|
list-style: none;
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
|
|
|
|
display: grid;
|
2026-09-02 16:06:17 +03:30
|
|
|
gap: 0.48rem;
|
|
|
|
|
font-size: 0.8rem;
|
2026-09-01 16:05:29 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.donut-legend li {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
2026-09-02 16:06:17 +03:30
|
|
|
gap: 0.4rem;
|
2026-09-01 16:05:29 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.lbl {
|
|
|
|
|
flex: 1;
|
|
|
|
|
color: #475569;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
em {
|
|
|
|
|
font-style: normal;
|
|
|
|
|
color: #94a3b8;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.dot {
|
2026-09-02 16:06:17 +03:30
|
|
|
width: 8px;
|
|
|
|
|
height: 8px;
|
2026-09-01 16:05:29 +03:30
|
|
|
border-radius: 999px;
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@media (max-width: 500px) {
|
|
|
|
|
.donut-wrap {
|
|
|
|
|
grid-template-columns: 1fr;
|
|
|
|
|
justify-items: center;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|