feat: migrate CRM screens to Ant Design Vue and expand home dashboard

Preserve the local Ant UI work across views/components and add the new home dashboard chart panels before merging latest main.
This commit is contained in:
2026-11-03 16:51:51 +03:30
parent 631a3267d1
commit 26792f9a37
80 changed files with 19982 additions and 24020 deletions
+320 -341
View File
@@ -8,24 +8,45 @@ import type {
RoutineTeamPerformanceDto,
} from '@mento/shared';
import { ROUTINE_TASK_SOURCE_LABELS, ROUTINE_TASK_STATUS_LABELS } from '@mento/shared';
import UiIcon from '@/components/UiIcon.vue';
import JalaliDateInput from '@/components/JalaliDateInput.vue';
import KpiCard from '@/components/routines/KpiCard.vue';
import TeamPerformanceTable from '@/components/routines/TeamPerformanceTable.vue';
import WeeklyReport from '@/components/routines/WeeklyReport.vue';
import MonthlyReport from '@/components/routines/MonthlyReport.vue';
import { UiButton, UiChart, UiSegmented, UiSelect } from '@/components/ui';
import { api } from '@/lib/api';
import { toFaDigits } from '@/lib/jalali';
import { categoryBar, membersBar, statusDonut, trendOption } from '@/lib/routineCharts';
import {
ROUTINES_CTX,
addDaysKey,
apiError,
formatDayNumeric,
formatPercent,
percentTone,
todayKey,
} from '@/lib/routines';
import type { TableColumnsType } from 'ant-design-vue';
import {
Alert as AAlert,
Button as AButton,
Card as ACard,
Col as ACol,
Divider as ADivider,
Empty as AEmpty,
Flex as AFlex,
Form as AForm,
FormItem as AFormItem,
Progress as AProgress,
Row as ARow,
Segmented as ASegmented,
Select as ASelect,
Spin as ASpin,
Table as ATable,
Tooltip as ATooltip,
Typography,
} from 'ant-design-vue';
import { CloseOutlined } from '@ant-design/icons-vue';
const { Title: ATypographyTitle, Text: ATypographyText } = Typography;
const shell = inject(ROUTINES_CTX)!;
@@ -54,6 +75,31 @@ const categories = computed(() => shell.context.value?.categories ?? []);
const sources = Object.entries(ROUTINE_TASK_SOURCE_LABELS) as Array<[RoutineTaskSource, string]>;
const statuses = Object.entries(ROUTINE_TASK_STATUS_LABELS) as Array<[RoutineTaskStatus, string]>;
const userOptions = computed(() => [
{ value: '', label: 'همه کاربران' },
...users.value.map((u) => ({ value: u.id, label: u.fullName })),
]);
const teamOptions = computed(() => [
{ value: '', label: 'همه تیم‌ها' },
...teams.value.map((t) => ({ value: t.id, label: t.name })),
]);
const categoryOptions = computed(() => [
{ value: '', label: 'همه دسته‌ها' },
...categories.value.map((c) => ({ value: c.id, label: c.name })),
]);
const sourceOptions = [
{ value: '', label: 'همه' },
...sources.map(([value, label]) => ({ value, label })),
];
const statusOptions = [
{ value: '', label: 'همه' },
...statuses.map(([value, label]) => ({ value, label })),
];
const execSortOptions = [
{ value: 'percent', label: 'مرتب‌سازی: کمترین اجرا' },
{ value: 'occurrences', label: 'مرتب‌سازی: بیشترین تکرار' },
];
const query = computed<RoutineStatsQuery>(() => {
const q: RoutineStatsQuery = {};
if (f.from) q.from = f.from;
@@ -100,13 +146,35 @@ watch([section, () => JSON.stringify(query.value), shell.refreshTick], load, { i
const d = computed(() => data.value);
const activeMembers = computed(() => (d.value?.members ?? []).filter((m) => m.total > 0).length);
const trendOpt = computed(() => trendOption(d.value?.trend ?? []));
const donutOpt = computed(() =>
statusDonut(d.value?.status ?? { completed: 0, notDone: 0, overdue: 0, skipped: 0, cancelled: 0 }),
const statusRows = computed(() => {
const s = d.value?.status ?? { completed: 0, notDone: 0, overdue: 0, skipped: 0, cancelled: 0 };
const totalAll = s.completed + s.notDone + s.overdue + s.skipped + s.cancelled;
const rows = [
{ key: 'completed', label: 'انجام‌شده', value: s.completed, color: 'var(--ant-color-success)' },
{ key: 'notDone', label: 'انجام‌نشده', value: s.notDone, color: 'var(--ant-color-text-quaternary)' },
{ key: 'overdue', label: 'عقب‌افتاده', value: s.overdue, color: 'var(--ant-color-error)' },
{ key: 'skipped', label: 'رد شده', value: s.skipped, color: 'var(--ant-color-warning)' },
{ key: 'cancelled', label: 'لغو شده', value: s.cancelled, color: 'var(--ant-color-warning)' },
];
return rows.map((r) => ({
...r,
percent: totalAll > 0 ? Math.round((r.value / totalAll) * 100) : 0,
}));
});
const memberRows = computed(() =>
[...(d.value?.members ?? [])]
.filter((m) => m.total > 0)
.sort((a, b) => (b.percent ?? -1) - (a.percent ?? -1)),
);
const membersOpt = computed(() => membersBar(d.value?.members ?? []));
const catOpt = computed(() => categoryBar(d.value?.byCategory ?? []));
const membersChartHeight = computed(() => `${Math.max(200, activeMembers.value * 34 + 40)}px`);
const TONE_COLORS: Record<string, string> = {
good: 'var(--ant-color-success)',
mid: 'var(--ant-color-warning)',
low: 'var(--ant-color-error)',
none: 'var(--ant-color-text-quaternary)',
};
const execSort = ref<'percent' | 'occurrences'>('percent');
const execRows = computed(() =>
@@ -114,347 +182,258 @@ const execRows = computed(() =>
execSort.value === 'percent' ? (a.percent ?? -1) - (b.percent ?? -1) : b.occurrences - a.occurrences,
),
);
const execColumns: TableColumnsType<RoutineExecutionRowDto> = [
{
title: 'روتین',
key: 'title',
customRender: ({ record }) => record.title,
},
{ title: 'مسئول', dataIndex: 'assigneeLabel', key: 'assigneeLabel' },
{ title: 'تکرار', dataIndex: 'recurrenceLabel', key: 'recurrenceLabel' },
{
title: 'دفعات',
key: 'occurrences',
customRender: ({ record }) => toFaDigits(record.occurrences),
},
{
title: 'انجام شده',
key: 'completed',
customRender: ({ record }) => toFaDigits(record.completed),
},
{
title: 'انجام نشده',
key: 'notDone',
customRender: ({ record }) => toFaDigits(record.notDone),
},
{
title: 'رد شده',
key: 'skipped',
customRender: ({ record }) => toFaDigits(record.skipped),
},
{ title: 'درصد اجرا', key: 'percent', width: 180 },
];
</script>
<template>
<div class="team">
<UiSegmented v-model="section" :options="sections" class="sections" />
<a-card :bordered="false">
<a-flex vertical :gap="16">
<a-segmented v-model:value="section" :options="sections" />
<!-- فیلترها -->
<section class="filters">
<div v-if="section === 'overview' || section === 'routines'" class="f-item date">
<label>از</label>
<JalaliDateInput v-model="f.from" mode="date" :clearable="false" />
</div>
<div v-if="section === 'overview' || section === 'routines'" class="f-item date">
<label>تا</label>
<JalaliDateInput v-model="f.to" mode="date" :clearable="false" />
</div>
<div class="f-item">
<label>کاربر</label>
<UiSelect v-model="f.userId" size="sm">
<option value="">همه کاربران</option>
<option v-for="u in users" :key="u.id" :value="u.id">{{ u.fullName }}</option>
</UiSelect>
</div>
<div v-if="teams.length" class="f-item">
<label>تیم</label>
<UiSelect v-model="f.teamId" size="sm">
<option value="">همه تیم‌ها</option>
<option v-for="t in teams" :key="t.id" :value="t.id">{{ t.name }}</option>
</UiSelect>
</div>
<div class="f-item">
<label>دسته‌بندی</label>
<UiSelect v-model="f.categoryId" size="sm">
<option value="">همه دسته‌ها</option>
<option v-for="c in categories" :key="c.id" :value="c.id">{{ c.name }}</option>
</UiSelect>
</div>
<div v-if="section !== 'routines'" class="f-item">
<label>نوع کار</label>
<UiSelect v-model="f.source" size="sm">
<option value="">همه</option>
<option v-for="[k, label] in sources" :key="k" :value="k">{{ label }}</option>
</UiSelect>
</div>
<div v-if="section === 'overview'" class="f-item">
<label>وضعیت</label>
<UiSelect v-model="f.status" size="sm">
<option value="">همه</option>
<option v-for="[k, label] in statuses" :key="k" :value="k">{{ label }}</option>
</UiSelect>
</div>
<UiButton v-if="hasFilters" variant="ghost" size="sm" class="reset" @click="resetFilters">
<template #icon><UiIcon name="x" :size="14" /></template>
حذف فیلترها
</UiButton>
</section>
<a-form layout="vertical">
<a-row :gutter="[16, 0]">
<a-col v-if="section === 'overview' || section === 'routines'" :xs="24" :sm="12" :md="8">
<a-form-item label="از">
<JalaliDateInput v-model="f.from" mode="date" :clearable="false" style="width: 100%" />
</a-form-item>
</a-col>
<a-col v-if="section === 'overview' || section === 'routines'" :xs="24" :sm="12" :md="8">
<a-form-item label="تا">
<JalaliDateInput v-model="f.to" mode="date" :clearable="false" style="width: 100%" />
</a-form-item>
</a-col>
<a-col :xs="24" :sm="12" :md="8">
<a-form-item label="کاربر">
<a-select v-model:value="f.userId" :options="userOptions" style="width: 100%" />
</a-form-item>
</a-col>
<a-col v-if="teams.length" :xs="24" :sm="12" :md="8">
<a-form-item label="تیم">
<a-select v-model:value="f.teamId" :options="teamOptions" style="width: 100%" />
</a-form-item>
</a-col>
<a-col :xs="24" :sm="12" :md="8">
<a-form-item label="دسته‌بندی">
<a-select v-model:value="f.categoryId" :options="categoryOptions" style="width: 100%" />
</a-form-item>
</a-col>
<a-col v-if="section !== 'routines'" :xs="24" :sm="12" :md="8">
<a-form-item label="نوع کار">
<a-select v-model:value="f.source" :options="sourceOptions" style="width: 100%" />
</a-form-item>
</a-col>
<a-col v-if="section === 'overview'" :xs="24" :sm="12" :md="8">
<a-form-item label="وضعیت">
<a-select v-model:value="f.status" :options="statusOptions" style="width: 100%" />
</a-form-item>
</a-col>
<a-col v-if="hasFilters" :xs="24" :sm="12" :md="8">
<a-form-item label=" ">
<a-button danger @click="resetFilters">
<template #icon><CloseOutlined /></template>
حذف فیلترها
</a-button>
</a-form-item>
</a-col>
</a-row>
</a-form>
<p v-if="error" class="error">{{ error }}</p>
<a-alert v-if="error" type="error" show-icon :message="error" />
<!-- نمای کلی -->
<template v-if="section === 'overview'">
<div class="kpis" :class="{ dim: loading }">
<KpiCard label="درصد انجام تیم" :value="formatPercent(d?.percent)" icon="target" tone="accent" />
<KpiCard
label="انجام‌شده"
:value="toFaDigits(d?.completed ?? 0)"
:hint="`از ${toFaDigits(d?.total ?? 0)} کار`"
icon="check"
tone="success"
/>
<KpiCard label="عقب‌افتاده" :value="toFaDigits(d?.overdue ?? 0)" icon="warning" tone="danger" />
<KpiCard
label="اعضای فعال"
:value="toFaDigits(activeMembers)"
:hint="`از ${toFaDigits(d?.members.length ?? 0)} نفر`"
icon="users"
tone="info"
/>
</div>
<template v-if="section === 'overview'">
<a-spin :spinning="loading">
<a-row :gutter="[16, 16]">
<a-col :xs="12" :lg="6">
<KpiCard label="درصد انجام تیم" :value="formatPercent(d?.percent)" icon="target" tone="accent" />
</a-col>
<a-col :xs="12" :lg="6">
<KpiCard
label="انجام‌شده"
:value="toFaDigits(d?.completed ?? 0)"
:hint="`از ${toFaDigits(d?.total ?? 0)} کار`"
icon="check"
tone="success"
/>
</a-col>
<a-col :xs="12" :lg="6">
<KpiCard label="عقب‌افتاده" :value="toFaDigits(d?.overdue ?? 0)" icon="warning" tone="danger" />
</a-col>
<a-col :xs="12" :lg="6">
<KpiCard
label="اعضای فعال"
:value="toFaDigits(activeMembers)"
:hint="`از ${toFaDigits(d?.members.length ?? 0)} نفر`"
icon="users"
tone="info"
/>
</a-col>
</a-row>
<div class="charts">
<section class="card wide">
<h3>روند درصد انجام تیم</h3>
<UiChart :option="trendOpt" height="260px" :loading="loading" />
</section>
<section class="card">
<h3>وضعیت کارها</h3>
<UiChart :option="donutOpt" height="260px" :loading="loading" />
</section>
<section class="card">
<h3>مقایسه اعضا</h3>
<UiChart v-if="activeMembers" :option="membersOpt" :height="membersChartHeight" :loading="loading" />
<p v-else class="muted">داده‌ای برای نمایش نیست.</p>
</section>
<section class="card wide">
<h3>انجام به تفکیک دسته‌بندی</h3>
<UiChart v-if="d?.byCategory.length" :option="catOpt" height="240px" :loading="loading" />
<p v-else class="muted">داده‌ای برای نمایش نیست.</p>
</section>
</div>
<a-row :gutter="[24, 24]" :style="{ marginTop: '24px' }">
<a-col :xs="24" :lg="14">
<a-typography-title :level="5" :style="{ margin: 0 }">روند درصد انجام تیم</a-typography-title>
<a-flex align="end" :gap="2" :style="{ height: '180px', marginTop: '16px' }">
<a-tooltip
v-for="p in d?.trend ?? []"
:key="p.date"
:title="`${formatDayNumeric(p.date)} — ${formatPercent(p.percent)} (${toFaDigits(p.completed)} از ${toFaDigits(p.total)})`"
>
<a-flex
:style="{
flex: 1,
minWidth: '3px',
height: `${Math.max(2, Math.round(p.percent ?? 0))}%`,
background: p.percent == null ? 'var(--ant-color-fill-secondary)' : 'var(--ant-color-primary)',
borderRadius: '2px 2px 0 0',
}"
/>
</a-tooltip>
<a-typography-text v-if="!d?.trend?.length" type="secondary">
داده‌ای برای نمایش نیست.
</a-typography-text>
</a-flex>
</a-col>
<a-col :xs="24" :lg="10">
<a-typography-title :level="5" :style="{ margin: 0 }">وضعیت کارها</a-typography-title>
<a-flex vertical :gap="12" :style="{ marginTop: '16px' }">
<div v-for="r in statusRows" :key="r.key">
<a-flex justify="space-between" align="center" :gap="8">
<a-typography-text>{{ r.label }}</a-typography-text>
<a-typography-text strong>
{{ toFaDigits(r.value) }} ({{ toFaDigits(r.percent) }}٪)
</a-typography-text>
</a-flex>
<a-progress :percent="r.percent" :show-info="false" :stroke-color="r.color" />
</div>
</a-flex>
</a-col>
<a-col :xs="24" :lg="14">
<a-typography-title :level="5" :style="{ margin: 0 }">مقایسه اعضا</a-typography-title>
<a-flex v-if="memberRows.length" vertical :gap="12" :style="{ marginTop: '16px' }">
<div v-for="m in memberRows" :key="m.user.id">
<a-flex justify="space-between" align="center" :gap="8">
<a-typography-text>{{ m.user.fullName }}</a-typography-text>
<a-typography-text strong>
{{ formatPercent(m.percent) }} · {{ toFaDigits(m.completed) }} از {{ toFaDigits(m.total) }}
</a-typography-text>
</a-flex>
<a-progress
:percent="Math.max(0, Math.min(100, Math.round(m.percent ?? 0)))"
:show-info="false"
:stroke-color="TONE_COLORS[percentTone(m.percent)]"
/>
</div>
</a-flex>
<a-empty v-else description="داده‌ای برای نمایش نیست." :style="{ marginTop: '16px' }" />
</a-col>
<a-col :xs="24" :lg="10">
<a-typography-title :level="5" :style="{ margin: 0 }">انجام به تفکیک دسته‌بندی</a-typography-title>
<a-flex v-if="d?.byCategory.length" vertical :gap="12" :style="{ marginTop: '16px' }">
<div v-for="c in d.byCategory" :key="c.categoryId ?? c.name">
<a-flex justify="space-between" align="center" :gap="8">
<a-typography-text>{{ c.name }}</a-typography-text>
<a-typography-text strong>
{{ formatPercent(c.percent) }} · {{ toFaDigits(c.completed) }} از {{ toFaDigits(c.total) }}
</a-typography-text>
</a-flex>
<a-progress
:percent="Math.max(0, Math.min(100, Math.round(c.percent ?? 0)))"
:show-info="false"
:stroke-color="c.color"
/>
</div>
</a-flex>
<a-empty v-else description="داده‌ای برای نمایش نیست." :style="{ marginTop: '16px' }" />
</a-col>
</a-row>
</a-spin>
<section class="card">
<h3>عملکرد اعضا</h3>
<a-divider orientation="right">عملکرد اعضا</a-divider>
<TeamPerformanceTable :members="d?.members ?? []" @select="(id) => (f.userId = id)" />
</section>
</template>
</template>
<WeeklyReport
v-else-if="section === 'weekly'"
view="team"
:filters="query"
:refresh-key="shell.refreshTick.value"
/>
<MonthlyReport
v-else-if="section === 'monthly'"
view="team"
:filters="query"
:refresh-key="shell.refreshTick.value"
/>
<WeeklyReport
v-else-if="section === 'weekly'"
view="team"
:filters="query"
:refresh-key="shell.refreshTick.value"
/>
<MonthlyReport
v-else-if="section === 'monthly'"
view="team"
:filters="query"
:refresh-key="shell.refreshTick.value"
/>
<!-- گزارش اجرای روتین‌ها -->
<section v-else class="card">
<div class="exec-head">
<h3>گزارش اجرای روتین‌ها</h3>
<UiSelect v-model="execSort" size="sm" class="exec-sort">
<option value="percent">مرتب‌سازی: کمترین اجرا</option>
<option value="occurrences">مرتب‌سازی: بیشترین تکرار</option>
</UiSelect>
</div>
<div class="crm-table-container" :class="{ dim: loading }">
<table class="crm-table">
<thead>
<tr>
<th>روتین</th>
<th>مسئول</th>
<th>تکرار</th>
<th>دفعات</th>
<th>انجام شده</th>
<th>انجام نشده</th>
<th>رد شده</th>
<th>درصد اجرا</th>
</tr>
</thead>
<tbody>
<tr v-for="r in execRows" :key="r.routineId">
<td><strong>{{ r.title }}</strong></td>
<td class="nowrap">{{ r.assigneeLabel }}</td>
<td class="nowrap">{{ r.recurrenceLabel }}</td>
<td>{{ toFaDigits(r.occurrences) }}</td>
<td class="ok">{{ toFaDigits(r.completed) }}</td>
<td :class="{ bad: r.notDone > 0 }">{{ toFaDigits(r.notDone) }}</td>
<td>{{ toFaDigits(r.skipped) }}</td>
<td>
<span class="pct" :class="`tone-${percentTone(r.percent)}`">
<strong>{{ formatPercent(r.percent) }}</strong>
<i><b :style="{ width: `${r.percent ?? 0}%` }" /></i>
</span>
</td>
</tr>
<tr v-if="!execRows.length && !loading">
<td colspan="8" class="empty">در این بازه روتینی اجرا نشده است.</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
<template v-else>
<a-flex justify="space-between" align="center" wrap="wrap" :gap="12">
<a-typography-title :level="5" :style="{ margin: 0 }">گزارش اجرای روتین‌ها</a-typography-title>
<a-select
v-model:value="execSort"
:options="execSortOptions"
:style="{ width: '240px' }"
/>
</a-flex>
<a-spin :spinning="loading">
<a-table
:columns="execColumns"
:data-source="execRows"
:pagination="false"
:row-key="(r: RoutineExecutionRowDto) => r.routineId"
:scroll="{ x: 'max-content' }"
>
<template #emptyText>
<a-empty description="در این بازه روتینی اجرا نشده است." />
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'title'">
<a-typography-text strong>{{ record.title }}</a-typography-text>
</template>
<template v-else-if="column.key === 'percent'">
<a-flex align="center" :gap="8" :style="{ minWidth: '8rem' }">
<a-typography-text strong>{{ formatPercent(record.percent) }}</a-typography-text>
<a-progress
:percent="Math.max(0, Math.min(100, Math.round(record.percent ?? 0)))"
:show-info="false"
:stroke-color="TONE_COLORS[percentTone(record.percent)]"
:style="{ flex: 1 }"
/>
</a-flex>
</template>
</template>
</a-table>
</a-spin>
</template>
</a-flex>
</a-card>
</template>
<style scoped>
.team {
display: grid;
gap: var(--sp-4);
}
.sections {
justify-self: start;
max-width: 100%;
overflow-x: auto;
}
.filters {
display: flex;
align-items: flex-end;
flex-wrap: wrap;
gap: var(--sp-3);
padding: var(--sp-3) var(--sp-4);
border: 1px solid var(--line);
border-radius: var(--radius);
background: var(--surface);
}
.f-item {
display: grid;
gap: 4px;
min-width: 150px;
}
.f-item.date {
min-width: 160px;
}
.f-item label {
font-size: var(--fs-xs);
color: var(--muted);
}
.reset {
margin-inline-start: auto;
}
.kpis {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: var(--sp-3);
transition: opacity var(--transition-fast);
}
.dim {
opacity: 0.55;
}
.charts {
display: grid;
grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
gap: var(--sp-4);
}
.card {
padding: var(--sp-4);
border: 1px solid var(--line);
border-radius: var(--radius);
background: var(--surface);
display: grid;
gap: var(--sp-3);
align-content: start;
min-width: 0;
}
.card h3 {
margin: 0;
font-size: var(--fs-sm);
font-weight: var(--fw-semibold);
color: var(--ink-secondary);
}
.muted {
margin: 0;
color: var(--muted);
font-size: var(--fs-sm);
text-align: center;
padding: var(--sp-6);
}
.exec-head {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: var(--sp-2);
}
.exec-sort {
width: 220px;
}
.nowrap {
white-space: nowrap;
}
.ok {
color: var(--success-deep);
}
.bad {
color: var(--danger);
font-weight: var(--fw-semibold);
}
.pct {
display: grid;
grid-template-columns: 44px 80px;
align-items: center;
gap: 8px;
}
.pct i {
height: 6px;
border-radius: 99px;
background: var(--surface-subtle);
overflow: hidden;
}
.pct b {
display: block;
height: 100%;
background: var(--line-strong);
}
.tone-good b {
background: var(--success);
}
.tone-mid b {
background: var(--warning);
}
.tone-low b {
background: var(--danger);
}
.empty {
text-align: center;
color: var(--muted);
padding: var(--sp-6);
}
.error {
margin: 0;
}
@media (max-width: 1000px) {
.charts {
grid-template-columns: 1fr;
}
.kpis {
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: var(--sp-2);
}
}
@media (max-width: 700px) {
.f-item,
.f-item.date {
min-width: calc(50% - var(--sp-3));
flex: 1 1 calc(50% - var(--sp-3));
}
.exec-sort {
width: 100%;
}
}
</style>