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:
@@ -11,6 +11,20 @@ import {
|
||||
weekdayIndex,
|
||||
} from '@/lib/routines';
|
||||
import { ROUTINE_WEEKDAY_LABELS } from '@mento/shared';
|
||||
import {
|
||||
Card as ACard,
|
||||
Col as ACol,
|
||||
Flex as AFlex,
|
||||
Progress as AProgress,
|
||||
Row as ARow,
|
||||
Tag as ATag,
|
||||
Tooltip as ATooltip,
|
||||
Typography,
|
||||
theme,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
const { Title: ATypographyTitle, Text: ATypographyText } = Typography;
|
||||
const { token } = theme.useToken();
|
||||
|
||||
const props = defineProps<{
|
||||
score: RoutineScoreDto | null;
|
||||
@@ -29,216 +43,98 @@ const rows = computed(() => {
|
||||
});
|
||||
|
||||
const strip = computed(() => props.days ?? []);
|
||||
|
||||
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 STATE_STYLES: Record<string, { bg: string; fg: string }> = {
|
||||
complete: { bg: 'var(--ant-color-success-bg)', fg: 'var(--ant-color-success)' },
|
||||
partial: { bg: 'var(--ant-color-warning-bg)', fg: 'var(--ant-color-warning)' },
|
||||
missed: { bg: 'var(--ant-color-error-bg)', fg: 'var(--ant-color-error)' },
|
||||
empty: { bg: 'var(--ant-color-fill-secondary)', fg: 'var(--ant-color-text-quaternary)' },
|
||||
};
|
||||
|
||||
function stateStyle(state: string) {
|
||||
return STATE_STYLES[state] ?? STATE_STYLES.empty;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="score-card">
|
||||
<header>
|
||||
<h3>امتیاز روزانه</h3>
|
||||
<span class="streak" :title="'روزهای متوالی با انجام همه کارهای اجباری'">
|
||||
<strong>{{ toFaDigits(score?.streak ?? 0) }}</strong>
|
||||
روز پیاپی کامل
|
||||
</span>
|
||||
</header>
|
||||
<a-card :bordered="false">
|
||||
<a-flex vertical :gap="16">
|
||||
<a-flex justify="space-between" align="center" :gap="8">
|
||||
<a-typography-title :level="5" :style="{ margin: 0 }">امتیاز روزانه</a-typography-title>
|
||||
<a-typography-text type="secondary" title="روزهای متوالی با انجام همه کارهای اجباری">
|
||||
<a-typography-text strong :style="{ color: 'var(--ant-color-primary)' }">
|
||||
{{ toFaDigits(score?.streak ?? 0) }}
|
||||
</a-typography-text>
|
||||
روز پیاپی کامل
|
||||
</a-typography-text>
|
||||
</a-flex>
|
||||
|
||||
<div class="scores">
|
||||
<div v-for="r in rows" :key="r.label" class="score" :class="`tone-${percentTone(r.value)}`">
|
||||
<span>{{ r.label }}</span>
|
||||
<strong>{{ formatPercent(r.value) }}</strong>
|
||||
<i class="bar"><b :style="{ width: `${r.value ?? 0}%` }" /></i>
|
||||
</div>
|
||||
</div>
|
||||
<a-row :gutter="[16, 16]">
|
||||
<a-col v-for="r in rows" :key="r.label" :span="12">
|
||||
<a-flex justify="space-between" align="baseline" :gap="8">
|
||||
<a-typography-text type="secondary">{{ r.label }}</a-typography-text>
|
||||
<a-typography-text strong>{{ formatPercent(r.value) }}</a-typography-text>
|
||||
</a-flex>
|
||||
<a-progress
|
||||
:percent="r.value ?? 0"
|
||||
:show-info="false"
|
||||
:stroke-color="TONE_COLORS[percentTone(r.value)]"
|
||||
/>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<div v-if="strip.length" class="strip-wrap">
|
||||
<div class="strip" role="list" aria-label="وضعیت روزهای اخیر">
|
||||
<span
|
||||
v-for="d in strip"
|
||||
:key="d.date"
|
||||
role="listitem"
|
||||
class="cell"
|
||||
:class="`s-${d.state}`"
|
||||
:title="`${formatDayNumeric(d.date)} — ${DAY_STATE_LABELS[d.state]}${d.total ? ` (${toFaDigits(d.completed)} از ${toFaDigits(d.total)})` : ''}`"
|
||||
>
|
||||
<em>{{ DAY_STATE_SYMBOLS[d.state] }}</em>
|
||||
<small>{{ ROUTINE_WEEKDAY_LABELS[weekdayIndex(d.date)]?.charAt(0) }}</small>
|
||||
</span>
|
||||
</div>
|
||||
<div class="legend">
|
||||
<span><i class="s-complete">✓</i> کامل</span>
|
||||
<span><i class="s-partial">△</i> ناقص</span>
|
||||
<span><i class="s-missed">×</i> از دست رفته</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<template v-if="strip.length">
|
||||
<a-flex :gap="4" role="list" aria-label="وضعیت روزهای اخیر">
|
||||
<a-flex
|
||||
v-for="d in strip"
|
||||
:key="d.date"
|
||||
vertical
|
||||
align="center"
|
||||
:gap="2"
|
||||
role="listitem"
|
||||
:style="{ flex: 1, minWidth: 0 }"
|
||||
>
|
||||
<a-tooltip
|
||||
:title="`${formatDayNumeric(d.date)} — ${DAY_STATE_LABELS[d.state]}${d.total ? ` (${toFaDigits(d.completed)} از ${toFaDigits(d.total)})` : ''}`"
|
||||
>
|
||||
<a-flex
|
||||
justify="center"
|
||||
align="center"
|
||||
:style="{
|
||||
width: '26px',
|
||||
height: '26px',
|
||||
flexShrink: 0,
|
||||
borderRadius: token.borderRadiusSM,
|
||||
background: stateStyle(d.state).bg,
|
||||
color: stateStyle(d.state).fg,
|
||||
}"
|
||||
>
|
||||
<a-typography-text
|
||||
strong
|
||||
:style="{ color: stateStyle(d.state).fg, lineHeight: 1 }"
|
||||
>
|
||||
{{ DAY_STATE_SYMBOLS[d.state] }}
|
||||
</a-typography-text>
|
||||
</a-flex>
|
||||
</a-tooltip>
|
||||
<a-typography-text type="secondary">
|
||||
{{ ROUTINE_WEEKDAY_LABELS[weekdayIndex(d.date)]?.charAt(0) }}
|
||||
</a-typography-text>
|
||||
</a-flex>
|
||||
</a-flex>
|
||||
<a-flex wrap="wrap" :gap="8">
|
||||
<a-tag color="success" :bordered="false">✓ کامل</a-tag>
|
||||
<a-tag color="warning" :bordered="false">△ ناقص</a-tag>
|
||||
<a-tag color="error" :bordered="false">× از دست رفته</a-tag>
|
||||
</a-flex>
|
||||
</template>
|
||||
</a-flex>
|
||||
</a-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.score-card {
|
||||
display: grid;
|
||||
gap: var(--sp-4);
|
||||
padding: var(--sp-4);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow-xs);
|
||||
}
|
||||
|
||||
header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: var(--sp-2);
|
||||
}
|
||||
|
||||
h3 {
|
||||
margin: 0;
|
||||
font-size: var(--fs-md);
|
||||
font-weight: var(--fw-semibold);
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.streak {
|
||||
display: inline-flex;
|
||||
align-items: baseline;
|
||||
gap: 5px;
|
||||
font-size: var(--fs-xs);
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.streak strong {
|
||||
font-size: var(--fs-lg);
|
||||
color: var(--accent-deep);
|
||||
}
|
||||
|
||||
.scores {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: var(--sp-3);
|
||||
}
|
||||
|
||||
.score {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto;
|
||||
align-items: baseline;
|
||||
gap: 4px 8px;
|
||||
}
|
||||
|
||||
.score span {
|
||||
font-size: var(--fs-xs);
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.score strong {
|
||||
font-size: var(--fs-md);
|
||||
color: var(--ink);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.bar {
|
||||
grid-column: 1 / -1;
|
||||
height: 5px;
|
||||
border-radius: 99px;
|
||||
background: var(--surface-subtle);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.bar b {
|
||||
display: block;
|
||||
height: 100%;
|
||||
border-radius: inherit;
|
||||
background: var(--line-strong);
|
||||
transition: width 0.4s ease;
|
||||
}
|
||||
|
||||
.tone-good .bar b {
|
||||
background: var(--success);
|
||||
}
|
||||
|
||||
.tone-mid .bar b {
|
||||
background: var(--warning);
|
||||
}
|
||||
|
||||
.tone-low .bar b {
|
||||
background: var(--danger);
|
||||
}
|
||||
|
||||
.strip-wrap {
|
||||
display: grid;
|
||||
gap: var(--sp-2);
|
||||
}
|
||||
|
||||
.strip {
|
||||
display: grid;
|
||||
grid-auto-flow: column;
|
||||
grid-auto-columns: minmax(0, 1fr);
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.cell {
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.cell em {
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
max-width: 26px;
|
||||
border-radius: 6px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
font-style: normal;
|
||||
font-size: 0.75rem;
|
||||
font-weight: var(--fw-bold);
|
||||
background: var(--surface-subtle);
|
||||
color: var(--muted-light);
|
||||
}
|
||||
|
||||
.cell small {
|
||||
font-size: 0.62rem;
|
||||
color: var(--muted-light);
|
||||
}
|
||||
|
||||
.s-complete,
|
||||
.cell.s-complete em {
|
||||
background: var(--success-soft);
|
||||
color: var(--success-deep);
|
||||
}
|
||||
|
||||
.s-partial,
|
||||
.cell.s-partial em {
|
||||
background: var(--warning-soft);
|
||||
color: var(--warning-deep);
|
||||
}
|
||||
|
||||
.s-missed,
|
||||
.cell.s-missed em {
|
||||
background: var(--danger-soft);
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.legend {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--sp-3);
|
||||
font-size: var(--fs-xs);
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.legend span {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.legend i {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 4px;
|
||||
display: inline-grid;
|
||||
place-items: center;
|
||||
font-style: normal;
|
||||
font-size: 0.65rem;
|
||||
font-weight: var(--fw-bold);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,14 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
import UiIcon from '@/components/UiIcon.vue';
|
||||
import { computed, type Component } from 'vue';
|
||||
import {
|
||||
Avatar as AAvatar,
|
||||
Card as ACard,
|
||||
Flex as AFlex,
|
||||
Statistic as AStatistic,
|
||||
Typography,
|
||||
} from 'ant-design-vue';
|
||||
import {
|
||||
AimOutlined,
|
||||
CalendarOutlined,
|
||||
CheckOutlined,
|
||||
ClockCircleOutlined,
|
||||
CloseCircleOutlined,
|
||||
FlagOutlined,
|
||||
SyncOutlined,
|
||||
TeamOutlined,
|
||||
WarningOutlined,
|
||||
} from '@ant-design/icons-vue';
|
||||
|
||||
type IconName = InstanceType<typeof UiIcon>['$props']['name'];
|
||||
const { Text: ATypographyText } = Typography;
|
||||
|
||||
withDefaults(
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
label: string;
|
||||
value: string;
|
||||
hint?: string;
|
||||
icon?: IconName;
|
||||
icon?: string;
|
||||
tone?: 'accent' | 'success' | 'warning' | 'danger' | 'info' | 'neutral';
|
||||
/** تغییر نسبت به دوره قبل (درصد یا عدد)؛ مثبت = بهتر */
|
||||
delta?: number | null;
|
||||
@@ -17,135 +35,68 @@ withDefaults(
|
||||
{ hint: '', icon: undefined, tone: 'neutral', delta: null, deltaSuffix: '' },
|
||||
);
|
||||
|
||||
const ICONS: Record<string, Component> = {
|
||||
check: CheckOutlined,
|
||||
clock: ClockCircleOutlined,
|
||||
warning: WarningOutlined,
|
||||
target: AimOutlined,
|
||||
'x-circle': CloseCircleOutlined,
|
||||
calendar: CalendarOutlined,
|
||||
flag: FlagOutlined,
|
||||
users: TeamOutlined,
|
||||
refresh: SyncOutlined,
|
||||
};
|
||||
|
||||
const TONES: Record<string, { bg: string; fg: string }> = {
|
||||
accent: { bg: 'var(--ant-color-primary-bg)', fg: 'var(--ant-color-primary)' },
|
||||
success: { bg: 'var(--ant-color-success-bg)', fg: 'var(--ant-color-success)' },
|
||||
warning: { bg: 'var(--ant-color-warning-bg)', fg: 'var(--ant-color-warning)' },
|
||||
danger: { bg: 'var(--ant-color-error-bg)', fg: 'var(--ant-color-error)' },
|
||||
info: { bg: 'var(--ant-color-info-bg)', fg: 'var(--ant-color-info)' },
|
||||
neutral: { bg: 'var(--ant-color-fill-secondary)', fg: 'var(--ant-color-text-secondary)' },
|
||||
};
|
||||
|
||||
const iconComp = computed(() => (props.icon ? (ICONS[props.icon] ?? AimOutlined) : null));
|
||||
const toneStyle = computed(() => TONES[props.tone] ?? TONES.neutral);
|
||||
|
||||
function fa(n: number) {
|
||||
return Math.abs(n).toLocaleString('fa-IR');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="kpi" :class="`tone-${tone}`">
|
||||
<div class="kpi-top">
|
||||
<span class="kpi-label">{{ label }}</span>
|
||||
<span v-if="icon" class="kpi-ico"><UiIcon :name="icon" :size="16" /></span>
|
||||
</div>
|
||||
<strong class="kpi-value">{{ value }}</strong>
|
||||
<div v-if="hint || delta != null" class="kpi-foot">
|
||||
<span v-if="delta != null && delta !== 0" class="delta" :class="delta > 0 ? 'up' : 'down'">
|
||||
{{ delta > 0 ? '▲' : '▼' }} {{ fa(delta) }}{{ deltaSuffix }}
|
||||
</span>
|
||||
<span v-else-if="delta === 0" class="delta flat">بدون تغییر</span>
|
||||
<span v-if="hint" class="kpi-hint">{{ hint }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<a-card :bordered="false" :style="{ height: '100%' }">
|
||||
<a-flex vertical :gap="6">
|
||||
<a-flex justify="space-between" align="center" :gap="8">
|
||||
<a-typography-text type="secondary">{{ label }}</a-typography-text>
|
||||
<a-avatar
|
||||
v-if="iconComp"
|
||||
:style="{ background: toneStyle.bg, color: toneStyle.fg, flexShrink: 0 }"
|
||||
>
|
||||
<template #icon><component :is="iconComp" /></template>
|
||||
</a-avatar>
|
||||
</a-flex>
|
||||
<a-statistic
|
||||
:value="value"
|
||||
:value-style="
|
||||
tone === 'danger'
|
||||
? { color: 'var(--ant-color-error)', fontWeight: 700 }
|
||||
: { fontWeight: 700 }
|
||||
"
|
||||
/>
|
||||
<a-flex v-if="hint || delta != null" align="center" wrap="wrap" :gap="6">
|
||||
<a-typography-text
|
||||
v-if="delta != null && delta !== 0"
|
||||
:type="delta > 0 ? 'success' : 'danger'"
|
||||
strong
|
||||
>
|
||||
{{ delta > 0 ? '▲' : '▼' }} {{ fa(delta) }}{{ deltaSuffix }}
|
||||
</a-typography-text>
|
||||
<a-typography-text v-else-if="delta === 0" type="secondary">
|
||||
بدون تغییر
|
||||
</a-typography-text>
|
||||
<a-typography-text v-if="hint" type="secondary">{{ hint }}</a-typography-text>
|
||||
</a-flex>
|
||||
</a-flex>
|
||||
</a-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.kpi {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
padding: var(--sp-4);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow-xs);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.kpi-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: var(--sp-2);
|
||||
}
|
||||
|
||||
.kpi-label {
|
||||
font-size: var(--fs-sm);
|
||||
color: var(--muted);
|
||||
font-weight: var(--fw-medium);
|
||||
}
|
||||
|
||||
.kpi-ico {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 8px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: var(--surface-subtle);
|
||||
color: var(--ink-secondary);
|
||||
}
|
||||
|
||||
.tone-accent .kpi-ico {
|
||||
background: var(--accent-subtle);
|
||||
color: var(--accent-deep);
|
||||
}
|
||||
|
||||
.tone-success .kpi-ico {
|
||||
background: var(--success-soft);
|
||||
color: var(--success-deep);
|
||||
}
|
||||
|
||||
.tone-warning .kpi-ico {
|
||||
background: var(--warning-soft);
|
||||
color: var(--warning-deep);
|
||||
}
|
||||
|
||||
.tone-danger .kpi-ico {
|
||||
background: var(--danger-soft);
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.tone-info .kpi-ico {
|
||||
background: var(--info-soft);
|
||||
color: var(--info-deep);
|
||||
}
|
||||
|
||||
.kpi-value {
|
||||
font-size: var(--fs-2xl);
|
||||
font-weight: var(--fw-bold);
|
||||
color: var(--ink);
|
||||
line-height: 1.2;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.tone-danger .kpi-value {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.kpi-foot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
font-size: var(--fs-xs);
|
||||
}
|
||||
|
||||
.kpi-hint {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.delta {
|
||||
font-weight: var(--fw-semibold);
|
||||
}
|
||||
|
||||
.delta.up {
|
||||
color: var(--success-deep);
|
||||
}
|
||||
|
||||
.delta.down {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.delta.flat {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.kpi {
|
||||
padding: var(--sp-3);
|
||||
}
|
||||
|
||||
.kpi-value {
|
||||
font-size: var(--fs-xl);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -4,6 +4,15 @@ import type { RoutineCalendarDayDto } from '@mento/shared';
|
||||
import { ROUTINE_WEEKDAY_LABELS } from '@mento/shared';
|
||||
import { dateToJalali, toFaDigits } from '@/lib/jalali';
|
||||
import { DAY_STATE_LABELS, addDaysKey, keyToDate, todayKey, weekdayIndex } from '@/lib/routines';
|
||||
import {
|
||||
Button as AButton,
|
||||
Flex as AFlex,
|
||||
Typography,
|
||||
theme,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
const { Text: ATypographyText } = Typography;
|
||||
const { token } = theme.useToken();
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
@@ -47,6 +56,39 @@ function heatLevel(d?: RoutineCalendarDayDto): number {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const STATE_BG: Record<string, string> = {
|
||||
complete: 'var(--ant-color-success-bg)',
|
||||
partial: 'var(--ant-color-warning-bg)',
|
||||
missed: 'var(--ant-color-error-bg)',
|
||||
empty: 'var(--ant-color-bg-container)',
|
||||
future: 'var(--ant-color-fill-quaternary)',
|
||||
};
|
||||
|
||||
const STATE_DOT: Record<string, string> = {
|
||||
complete: 'var(--ant-color-success)',
|
||||
partial: 'var(--ant-color-warning)',
|
||||
missed: 'var(--ant-color-error)',
|
||||
empty: 'var(--ant-color-text-quaternary)',
|
||||
future: 'var(--ant-color-text-quaternary)',
|
||||
};
|
||||
|
||||
const HEAT_BG: Record<number, string> = {
|
||||
0: 'var(--ant-color-fill-quaternary)',
|
||||
1: 'var(--ant-color-info-bg)',
|
||||
2: 'var(--ant-color-primary-bg)',
|
||||
3: 'var(--ant-color-success-bg)',
|
||||
4: 'var(--ant-color-success)',
|
||||
};
|
||||
|
||||
function cellKey(c: (typeof cells.value)[number]) {
|
||||
return c.future && !c.day?.total ? 'future' : (c.day?.state ?? 'empty');
|
||||
}
|
||||
|
||||
function cellBackground(c: (typeof cells.value)[number]) {
|
||||
if (props.mode === 'heat') return HEAT_BG[heatLevel(c.day)];
|
||||
return STATE_BG[cellKey(c)] ?? STATE_BG.empty;
|
||||
}
|
||||
|
||||
function title(c: (typeof cells.value)[number]) {
|
||||
const d = c.day;
|
||||
if (!d || !d.total) return 'بدون کار';
|
||||
@@ -55,211 +97,78 @@ function title(c: (typeof cells.value)[number]) {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mgrid" :class="[mode, { compact }]">
|
||||
<div v-for="w in ROUTINE_WEEKDAY_LABELS" :key="w" class="wd">{{ compact ? w.charAt(0) : w }}</div>
|
||||
<template v-for="c in cells" :key="c.key">
|
||||
<span v-if="c.blank" class="cell blank" />
|
||||
<button
|
||||
v-else
|
||||
type="button"
|
||||
class="cell"
|
||||
:class="[
|
||||
mode === 'state' ? `s-${c.future && !c.day?.total ? 'future' : (c.day?.state ?? 'empty')}` : `h-${heatLevel(c.day)}`,
|
||||
{ sel: selected === c.key, today: c.key === today },
|
||||
]"
|
||||
:title="title(c)"
|
||||
@click="emit('select', c.key)"
|
||||
<a-flex vertical :gap="6">
|
||||
<a-flex :gap="6">
|
||||
<a-typography-text
|
||||
v-for="w in ROUTINE_WEEKDAY_LABELS"
|
||||
:key="w"
|
||||
type="secondary"
|
||||
strong
|
||||
:style="{ flex: '1 1 0', minWidth: 0, textAlign: 'center' }"
|
||||
>
|
||||
<span class="num">{{ toFaDigits(c.jd) }}</span>
|
||||
<template v-if="!compact && c.day?.total">
|
||||
<span class="frac">{{ toFaDigits(c.day.completed) }}/{{ toFaDigits(c.day.total) }}</span>
|
||||
<i v-if="mode === 'state'" class="dot" />
|
||||
</template>
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
{{ compact ? w.charAt(0) : w }}
|
||||
</a-typography-text>
|
||||
</a-flex>
|
||||
<a-flex wrap="wrap" :gap="6">
|
||||
<template v-for="c in cells" :key="c.key">
|
||||
<a-flex
|
||||
v-if="c.blank"
|
||||
:style="{ flex: '0 0 calc((100% - 36px) / 7)', minWidth: 0 }"
|
||||
/>
|
||||
<a-button
|
||||
v-else
|
||||
:title="title(c)"
|
||||
:style="{
|
||||
flex: '0 0 calc((100% - 36px) / 7)',
|
||||
minWidth: 0,
|
||||
height: compact ? '44px' : '74px',
|
||||
padding: '8px',
|
||||
background: cellBackground(c),
|
||||
borderColor:
|
||||
selected === c.key
|
||||
? token.colorPrimary
|
||||
: c.key === today
|
||||
? token.colorPrimaryBorder
|
||||
: undefined,
|
||||
boxShadow: selected === c.key ? `0 0 0 1px ${token.colorPrimary}` : undefined,
|
||||
}"
|
||||
@click="emit('select', c.key)"
|
||||
>
|
||||
<a-flex
|
||||
vertical
|
||||
align="start"
|
||||
justify="space-between"
|
||||
:style="{ width: '100%', height: '100%' }"
|
||||
>
|
||||
<a-typography-text
|
||||
strong
|
||||
:style="c.key === today ? { color: 'var(--ant-color-primary)' } : undefined"
|
||||
>
|
||||
{{ toFaDigits(c.jd) }}
|
||||
</a-typography-text>
|
||||
<a-flex
|
||||
v-if="!compact && c.day?.total"
|
||||
justify="space-between"
|
||||
align="center"
|
||||
:style="{ width: '100%' }"
|
||||
>
|
||||
<a-typography-text type="secondary">
|
||||
{{ toFaDigits(c.day.completed) }}/{{ toFaDigits(c.day.total) }}
|
||||
</a-typography-text>
|
||||
<a-flex
|
||||
v-if="mode === 'state'"
|
||||
:style="{
|
||||
width: '8px',
|
||||
height: '8px',
|
||||
borderRadius: token.borderRadiusLG,
|
||||
background: STATE_DOT[cellKey(c)],
|
||||
flexShrink: 0,
|
||||
}"
|
||||
/>
|
||||
</a-flex>
|
||||
</a-flex>
|
||||
</a-button>
|
||||
</template>
|
||||
</a-flex>
|
||||
</a-flex>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.mgrid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, minmax(0, 1fr));
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.wd {
|
||||
text-align: center;
|
||||
font-size: var(--fs-xs);
|
||||
color: var(--muted);
|
||||
font-weight: var(--fw-semibold);
|
||||
padding-bottom: 2px;
|
||||
}
|
||||
|
||||
.cell {
|
||||
position: relative;
|
||||
min-height: 74px;
|
||||
padding: 8px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
background: var(--surface);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 4px;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
text-align: right;
|
||||
transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
|
||||
}
|
||||
|
||||
.cell.blank {
|
||||
border: 0;
|
||||
background: transparent;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.cell:not(.blank):hover {
|
||||
border-color: var(--line-strong);
|
||||
}
|
||||
|
||||
.cell.sel {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 2px var(--accent-soft);
|
||||
}
|
||||
|
||||
.cell.today .num {
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.num {
|
||||
min-width: 24px;
|
||||
height: 24px;
|
||||
padding: 0 4px;
|
||||
border-radius: 99px;
|
||||
display: inline-grid;
|
||||
place-items: center;
|
||||
font-size: var(--fs-sm);
|
||||
font-weight: var(--fw-semibold);
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.frac {
|
||||
font-size: var(--fs-xs);
|
||||
color: var(--muted);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.dot {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
inset-inline-end: 10px;
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
border-radius: 50%;
|
||||
background: var(--line-strong);
|
||||
}
|
||||
|
||||
/* وضعیت روز */
|
||||
.s-complete {
|
||||
background: color-mix(in srgb, var(--success-soft) 45%, var(--surface));
|
||||
}
|
||||
|
||||
.s-complete .dot {
|
||||
background: var(--success);
|
||||
}
|
||||
|
||||
.s-partial {
|
||||
background: color-mix(in srgb, var(--warning-soft) 45%, var(--surface));
|
||||
}
|
||||
|
||||
.s-partial .dot {
|
||||
background: var(--warning);
|
||||
}
|
||||
|
||||
.s-missed {
|
||||
background: color-mix(in srgb, var(--danger-soft) 45%, var(--surface));
|
||||
}
|
||||
|
||||
.s-missed .dot {
|
||||
background: var(--danger);
|
||||
}
|
||||
|
||||
.s-future {
|
||||
background: var(--surface);
|
||||
}
|
||||
|
||||
.s-empty {
|
||||
background: var(--surface);
|
||||
}
|
||||
|
||||
/* Heatmap */
|
||||
.h-0 {
|
||||
background: var(--surface-subtle);
|
||||
}
|
||||
|
||||
.h-1 {
|
||||
background: color-mix(in srgb, var(--accent) 14%, white);
|
||||
}
|
||||
|
||||
.h-2 {
|
||||
background: color-mix(in srgb, var(--accent) 32%, white);
|
||||
}
|
||||
|
||||
.h-3 {
|
||||
background: color-mix(in srgb, var(--accent) 55%, white);
|
||||
}
|
||||
|
||||
.h-4 {
|
||||
background: color-mix(in srgb, var(--accent) 80%, white);
|
||||
}
|
||||
|
||||
.h-3 .num,
|
||||
.h-4 .num,
|
||||
.h-3 .frac,
|
||||
.h-4 .frac {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.compact {
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.compact .cell {
|
||||
min-height: 0;
|
||||
aspect-ratio: 1;
|
||||
padding: 2px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
.compact .num {
|
||||
font-size: 0.7rem;
|
||||
min-width: 0;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
@media (max-width: 700px) {
|
||||
.mgrid {
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.cell {
|
||||
min-height: 54px;
|
||||
padding: 4px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.frac {
|
||||
font-size: 0.62rem;
|
||||
}
|
||||
|
||||
.dot {
|
||||
position: static;
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,29 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { computed } from 'vue';
|
||||
import type { RoutineMemberStatDto } from '@mento/shared';
|
||||
import UserAvatar from '@/components/UserAvatar.vue';
|
||||
import { toFaDigits } from '@/lib/jalali';
|
||||
import { formatMinutes, formatPercent, percentTone } from '@/lib/routines';
|
||||
import {
|
||||
Empty as AEmpty,
|
||||
Flex as AFlex,
|
||||
Progress as AProgress,
|
||||
Space as ASpace,
|
||||
Table as ATable,
|
||||
Typography,
|
||||
} from 'ant-design-vue';
|
||||
import type { TableColumnsType } from 'ant-design-vue';
|
||||
|
||||
const { Text: ATypographyText } = Typography;
|
||||
|
||||
const props = defineProps<{ members: RoutineMemberStatDto[] }>();
|
||||
const emit = defineEmits<{ select: [userId: string] }>();
|
||||
|
||||
type SortKey = 'name' | 'total' | 'completed' | 'overdue' | 'skipped' | 'percent' | 'streak' | 'avg';
|
||||
|
||||
const sortKey = ref<SortKey>('percent');
|
||||
const sortDir = ref<'asc' | 'desc'>('desc');
|
||||
|
||||
const columns: Array<{ key: SortKey; label: string }> = [
|
||||
{ key: 'name', label: 'کاربر' },
|
||||
{ key: 'total', label: 'کل کارها' },
|
||||
{ key: 'completed', label: 'انجام شده' },
|
||||
{ key: 'overdue', label: 'عقبافتاده' },
|
||||
{ key: 'skipped', label: 'رد شده' },
|
||||
{ key: 'percent', label: 'درصد انجام' },
|
||||
{ key: 'streak', label: 'روز پیاپی کامل' },
|
||||
{ key: 'avg', label: 'میانگین زمان انجام' },
|
||||
];
|
||||
|
||||
function value(m: RoutineMemberStatDto, key: SortKey): number | string {
|
||||
switch (key) {
|
||||
case 'name':
|
||||
@@ -37,155 +34,101 @@ function value(m: RoutineMemberStatDto, key: SortKey): number | string {
|
||||
}
|
||||
}
|
||||
|
||||
const rows = computed(() => {
|
||||
const dir = sortDir.value === 'asc' ? 1 : -1;
|
||||
return [...props.members].sort((a, b) => {
|
||||
const va = value(a, sortKey.value);
|
||||
const vb = value(b, sortKey.value);
|
||||
if (typeof va === 'string' && typeof vb === 'string') return va.localeCompare(vb, 'fa') * dir;
|
||||
return ((va as number) - (vb as number)) * dir;
|
||||
});
|
||||
});
|
||||
function sorterFor(key: SortKey) {
|
||||
return (a: RoutineMemberStatDto, b: RoutineMemberStatDto) => {
|
||||
const va = value(a, key);
|
||||
const vb = value(b, key);
|
||||
if (typeof va === 'string' && typeof vb === 'string') return va.localeCompare(vb, 'fa');
|
||||
return (va as number) - (vb as number);
|
||||
};
|
||||
}
|
||||
|
||||
function sortBy(key: SortKey) {
|
||||
if (sortKey.value === key) sortDir.value = sortDir.value === 'asc' ? 'desc' : 'asc';
|
||||
else {
|
||||
sortKey.value = key;
|
||||
sortDir.value = key === 'name' || key === 'avg' ? 'asc' : 'desc';
|
||||
}
|
||||
const columns = computed<TableColumnsType<RoutineMemberStatDto>>(() => [
|
||||
{ title: 'کاربر', key: 'name', sorter: sorterFor('name'), defaultSortOrder: undefined },
|
||||
{
|
||||
title: 'کل کارها',
|
||||
key: 'total',
|
||||
sorter: sorterFor('total'),
|
||||
customRender: ({ record }) => toFaDigits(record.total),
|
||||
},
|
||||
{
|
||||
title: 'انجام شده',
|
||||
key: 'completed',
|
||||
sorter: sorterFor('completed'),
|
||||
customRender: ({ record }) => toFaDigits(record.completed),
|
||||
},
|
||||
{
|
||||
title: 'عقبافتاده',
|
||||
key: 'overdue',
|
||||
sorter: sorterFor('overdue'),
|
||||
customRender: ({ record }) => toFaDigits(record.overdue),
|
||||
},
|
||||
{
|
||||
title: 'رد شده',
|
||||
key: 'skipped',
|
||||
sorter: sorterFor('skipped'),
|
||||
customRender: ({ record }) => toFaDigits(record.skipped),
|
||||
},
|
||||
{ title: 'درصد انجام', key: 'percent', sorter: sorterFor('percent'), defaultSortOrder: 'descend' },
|
||||
{
|
||||
title: 'روز پیاپی کامل',
|
||||
key: 'streak',
|
||||
sorter: sorterFor('streak'),
|
||||
customRender: ({ record }) => toFaDigits(record.streak),
|
||||
},
|
||||
{
|
||||
title: 'میانگین زمان انجام',
|
||||
key: 'avg',
|
||||
sorter: sorterFor('avg'),
|
||||
customRender: ({ record }) => formatMinutes(record.avgCompletionMinutes),
|
||||
},
|
||||
]);
|
||||
|
||||
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)',
|
||||
};
|
||||
|
||||
function rowProps(record: RoutineMemberStatDto) {
|
||||
return {
|
||||
onClick: () => emit('select', record.user.id),
|
||||
style: { cursor: 'pointer' },
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="crm-table-container">
|
||||
<table class="crm-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th
|
||||
v-for="c in columns"
|
||||
:key="c.key"
|
||||
:aria-sort="sortKey === c.key ? (sortDir === 'asc' ? 'ascending' : 'descending') : 'none'"
|
||||
>
|
||||
<button type="button" class="sort" :class="{ on: sortKey === c.key }" @click="sortBy(c.key)">
|
||||
{{ c.label }}
|
||||
<span class="arrow">{{ sortKey === c.key ? (sortDir === 'asc' ? '▲' : '▼') : '↕' }}</span>
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="m in rows" :key="m.user.id" class="clickable" @click="emit('select', m.user.id)">
|
||||
<td>
|
||||
<span class="who">
|
||||
<UserAvatar :name="m.user.fullName" :user-id="m.user.id" :size="28" />
|
||||
{{ m.user.fullName }}
|
||||
</span>
|
||||
</td>
|
||||
<td>{{ toFaDigits(m.total) }}</td>
|
||||
<td class="ok">{{ toFaDigits(m.completed) }}</td>
|
||||
<td :class="{ bad: m.overdue > 0 }">{{ toFaDigits(m.overdue) }}</td>
|
||||
<td>{{ toFaDigits(m.skipped) }}</td>
|
||||
<td>
|
||||
<span class="pct" :class="`tone-${percentTone(m.percent)}`">
|
||||
<strong>{{ formatPercent(m.percent) }}</strong>
|
||||
<i><b :style="{ width: `${m.percent ?? 0}%` }" /></i>
|
||||
</span>
|
||||
</td>
|
||||
<td>{{ toFaDigits(m.streak) }}</td>
|
||||
<td class="nowrap">{{ formatMinutes(m.avgCompletionMinutes) }}</td>
|
||||
</tr>
|
||||
<tr v-if="!rows.length">
|
||||
<td colspan="8" class="empty">دادهای برای این بازه نیست.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<a-table
|
||||
:columns="columns"
|
||||
:data-source="props.members"
|
||||
:pagination="false"
|
||||
:row-key="(r: RoutineMemberStatDto) => r.user.id"
|
||||
:custom-row="rowProps"
|
||||
:scroll="{ x: 'max-content' }"
|
||||
>
|
||||
<template #emptyText>
|
||||
<a-empty description="دادهای برای این بازه نیست." />
|
||||
</template>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'name'">
|
||||
<a-space :size="8">
|
||||
<UserAvatar :name="record.user.fullName" :user-id="record.user.id" :size="28" />
|
||||
<a-typography-text strong>{{ record.user.fullName }}</a-typography-text>
|
||||
</a-space>
|
||||
</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>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.sort {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
font-weight: inherit;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.sort.on {
|
||||
color: var(--accent-deep);
|
||||
}
|
||||
|
||||
.arrow {
|
||||
font-size: 0.6rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.clickable {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.who {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
white-space: nowrap;
|
||||
font-weight: var(--fw-medium);
|
||||
}
|
||||
|
||||
.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);
|
||||
}
|
||||
|
||||
.nowrap {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.empty {
|
||||
text-align: center;
|
||||
color: var(--muted);
|
||||
padding: var(--sp-6);
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user