461 lines
13 KiB
Vue
461 lines
13 KiB
Vue
<script setup lang="ts">
|
||||
|
|
import { computed, inject, reactive, ref, watch } from 'vue';
|
|||
|
|
import type {
|
|||
|
|
RoutineExecutionRowDto,
|
|||
|
|
RoutineStatsQuery,
|
|||
|
|
RoutineTaskSource,
|
|||
|
|
RoutineTaskStatus,
|
|||
|
|
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,
|
|||
|
|
formatPercent,
|
|||
|
|
percentTone,
|
|||
|
|
todayKey,
|
|||
|
|
} from '@/lib/routines';
|
|||
|
|
|
|||
|
|
const shell = inject(ROUTINES_CTX)!;
|
|||
|
|
|
|||
|
|
type Section = 'overview' | 'weekly' | 'monthly' | 'routines';
|
|||
|
|
const section = ref<Section>('overview');
|
|||
|
|
const sections = [
|
|||
|
|
{ value: 'overview' as const, label: 'نمای کلی تیم' },
|
|||
|
|
{ value: 'weekly' as const, label: 'گزارش هفتگی' },
|
|||
|
|
{ value: 'monthly' as const, label: 'گزارش ماهانه' },
|
|||
|
|
{ value: 'routines' as const, label: 'اجرای روتینها' },
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
const f = reactive({
|
|||
|
|
from: addDaysKey(todayKey(), -29),
|
|||
|
|
to: todayKey(),
|
|||
|
|
userId: '',
|
|||
|
|
teamId: '',
|
|||
|
|
categoryId: '',
|
|||
|
|
source: '' as RoutineTaskSource | '',
|
|||
|
|
status: '' as RoutineTaskStatus | '',
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
const users = computed(() => shell.context.value?.users ?? []);
|
|||
|
|
const teams = computed(() => shell.context.value?.teams ?? []);
|
|||
|
|
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 query = computed<RoutineStatsQuery>(() => {
|
|||
|
|
const q: RoutineStatsQuery = {};
|
|||
|
|
if (f.from) q.from = f.from;
|
|||
|
|
if (f.to) q.to = f.to;
|
|||
|
|
if (f.userId) q.userId = f.userId;
|
|||
|
|
if (f.teamId) q.teamId = f.teamId;
|
|||
|
|
if (f.categoryId) q.categoryId = f.categoryId;
|
|||
|
|
if (f.source) q.source = f.source;
|
|||
|
|
if (f.status) q.status = f.status;
|
|||
|
|
return q;
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
const hasFilters = computed(() => !!(f.userId || f.teamId || f.categoryId || f.source || f.status));
|
|||
|
|
|
|||
|
|
function resetFilters() {
|
|||
|
|
Object.assign(f, { userId: '', teamId: '', categoryId: '', source: '', status: '' });
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const data = ref<RoutineTeamPerformanceDto | null>(null);
|
|||
|
|
const exec = ref<RoutineExecutionRowDto[]>([]);
|
|||
|
|
const loading = ref(false);
|
|||
|
|
const error = ref('');
|
|||
|
|
|
|||
|
|
async function load() {
|
|||
|
|
if (section.value !== 'overview' && section.value !== 'routines') return;
|
|||
|
|
loading.value = true;
|
|||
|
|
error.value = '';
|
|||
|
|
try {
|
|||
|
|
if (section.value === 'overview') {
|
|||
|
|
const res = await api.get<RoutineTeamPerformanceDto>('/routines/stats/team', { params: query.value });
|
|||
|
|
data.value = res.data;
|
|||
|
|
} else {
|
|||
|
|
const res = await api.get<RoutineExecutionRowDto[]>('/routines/stats/routines', { params: query.value });
|
|||
|
|
exec.value = res.data;
|
|||
|
|
}
|
|||
|
|
} catch (e) {
|
|||
|
|
error.value = apiError(e, 'بارگذاری گزارش تیم ممکن نشد.');
|
|||
|
|
} finally {
|
|||
|
|
loading.value = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
watch([section, () => JSON.stringify(query.value), shell.refreshTick], load, { immediate: true });
|
|||
|
|
|
|||
|
|
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 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 execSort = ref<'percent' | 'occurrences'>('percent');
|
|||
|
|
const execRows = computed(() =>
|
|||
|
|
[...exec.value].sort((a, b) =>
|
|||
|
|
execSort.value === 'percent' ? (a.percent ?? -1) - (b.percent ?? -1) : b.occurrences - a.occurrences,
|
|||
|
|
),
|
|||
|
|
);
|
|||
|
|
</script>
|
|||
|
|
|
|||
|
|
<template>
|
|||
|
|
<div class="team">
|
|||
|
|
<UiSegmented v-model="section" :options="sections" class="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>
|
|||
|
|
|
|||
|
|
<p v-if="error" class="error">{{ error }}</p>
|
|||
|
|
|
|||
|
|
<!-- نمای کلی -->
|
|||
|
|
<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>
|
|||
|
|
|
|||
|
|
<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>
|
|||
|
|
|
|||
|
|
<section class="card">
|
|||
|
|
<h3>عملکرد اعضا</h3>
|
|||
|
|
<TeamPerformanceTable :members="d?.members ?? []" @select="(id) => (f.userId = id)" />
|
|||
|
|
</section>
|
|||
|
|
</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"
|
|||
|
|
/>
|
|||
|
|
|
|||
|
|
<!-- گزارش اجرای روتینها -->
|
|||
|
|
<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>
|
|||
|
|
|
|||
|
|
<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>
|