Add Didar gap features: lost-reason reports, audit logs, tags, card assignees, and saved-views API.

Ignore Graphify local artifacts and expose new modules in superadmin.
This commit is contained in:
2026-09-26 14:59:48 +03:30
parent 35a618d0af
commit 6463275c3d
30 changed files with 1406 additions and 21 deletions
@@ -1,9 +1,11 @@
<script setup lang="ts">
import { ref, watch } from 'vue';
import { computed, ref, watch } from 'vue';
import { RouterLink } from 'vue-router';
import axios from 'axios';
import UiIcon from '@/components/UiIcon.vue';
import VoiceToTextButton from '@/components/VoiceToTextButton.vue';
import JalaliDateInput from '@/components/JalaliDateInput.vue';
import { formatLocalDateTimeInput } from '@/lib/jalali';
import { UiButton, UiModal } from '@/components/ui';
import { api } from '@/lib/api';
import { brand, type ActivityType, type AskMentoSourceDto, type PersonDto, type VoiceCommandDraft } from '@mento/shared';
@@ -93,15 +95,14 @@ function onActivityPersonEdit() {
if (draft.value?.activity) draft.value.activity.personId = null;
}
function toLocalInput(iso: string | null) {
const dueLocal = computed(() => {
const iso = draft.value?.activity?.dueAt;
if (!iso) return '';
const date = new Date(iso);
if (Number.isNaN(date.getTime())) return '';
const pad = (n: number) => String(n).padStart(2, '0');
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
}
return Number.isNaN(date.getTime()) ? '' : formatLocalDateTimeInput(date);
});
function onDueEdit(value: string) {
function onDueLocal(value: string) {
if (!draft.value?.activity) return;
if (!value) {
draft.value.activity.dueAt = null;
@@ -111,6 +112,25 @@ function onDueEdit(value: string) {
draft.value.activity.dueAt = Number.isNaN(date.getTime()) ? null : date.toISOString();
}
async function rematchActivityPerson() {
const activity = draft.value?.activity;
const name = activity?.personName.trim();
if (!activity || !name) {
if (activity) activity.personId = null;
return;
}
try {
const { data } = await api.get<{ items: Array<{ id: string; fullName: string }> }>('/people', {
params: { q: name, limit: 5 },
});
const exact = data.items.filter((row) => row.fullName.trim() === name);
const hit = exact.length === 1 ? exact[0] : data.items.length === 1 ? data.items[0] : null;
activity.personId = hit?.id ?? null;
} catch {
activity.personId = null;
}
}
async function parseCommand(text: string, fallbackToAsk: boolean) {
voiceBusy.value = true;
voiceError.value = '';
@@ -312,15 +332,14 @@ watch(
</label>
<label>
زمان
<input
type="datetime-local"
:value="toLocalInput(draft.activity.dueAt)"
@input="onDueEdit(($event.target as HTMLInputElement).value)"
/>
<JalaliDateInput :model-value="dueLocal" mode="datetime" @update:model-value="onDueLocal" />
</label>
<label>
مشتری
<input v-model="draft.activity.personName" @input="onActivityPersonEdit" @change="rematchActivityPerson" />
</label>
<label>مشتری <input v-model="draft.activity.personName" @input="onActivityPersonEdit" /></label>
<p v-if="draft.activity.personName && !draft.activity.personId" class="warn">
این نام به پرونده‌ای وصل نیست؛ فعالیت بدون لینک ثبت می‌شود.
در فهرست مشتریان پرونده‌ای با این نام پیدا نشد. فعالیت ذخیره می‌شود، ولی داخل پروندهٔ آن شخص دیده نمی‌شود.
</p>
<label>توضیح <textarea v-model="draft.activity.description" rows="2" /></label>
</div>
+9
View File
@@ -335,6 +335,15 @@ export const NAV_HUBS: NavHubDef[] = [
tint: 'violet',
module: 'team_settings',
},
{
to: '/settings/audit-logs',
title: 'لاگ فعالیت کاربران',
desc: 'تاریخچه ایجاد، ویرایش و حذف',
icon: 'layers',
tint: 'rose',
module: 'audit_logs',
admin: true,
},
{
to: '/settings/custom-fields',
title: 'فیلدهای سفارشی',
+6
View File
@@ -252,6 +252,12 @@ export const router = createRouter({
component: () => import('@/views/TeamSettingsView.vue'),
meta: { roles: ['owner', 'admin'] as UserRole[] },
},
{
path: 'settings/audit-logs',
name: 'audit-logs',
component: () => import('@/views/AuditLogsView.vue'),
meta: { roles: ['owner', 'admin'] as UserRole[] },
},
{
path: 'settings/custom-fields',
name: 'custom-fields',
+21
View File
@@ -71,6 +71,7 @@ const title = ref('');
const type = ref<ActivityType | ''>('');
const priority = ref<ActivityPriority>('medium');
const description = ref('');
const tagsRaw = ref('');
const dueDate = ref('');
const dueTime = ref('10:30');
const durationMinutes = ref(30);
@@ -155,6 +156,7 @@ function resetForm() {
type.value = '';
priority.value = 'medium';
description.value = '';
tagsRaw.value = '';
defaultDue();
durationMinutes.value = 30;
personId.value = '';
@@ -201,6 +203,7 @@ async function load() {
priority.value = data.priority ?? 'medium';
description.value = data.description ?? '';
needsNote.value = Boolean(data.description?.trim());
tagsRaw.value = (data.tags ?? []).join('، ');
splitDue(data.dueAt);
durationMinutes.value = data.durationMinutes ?? 30;
reminderAt.value = data.reminderAt
@@ -240,6 +243,17 @@ async function load() {
}
}
function parseTags(raw: string): string[] {
return [
...new Set(
raw
.split(/[,،#\n]/)
.map((t) => t.trim())
.filter(Boolean),
),
].slice(0, 40);
}
function payload(): CreateActivityRequest {
const due =
dueDate.value && dueTime.value ? new Date(`${dueDate.value}T${dueTime.value}:00`) : null;
@@ -249,6 +263,7 @@ function payload(): CreateActivityRequest {
type: type.value || 'task',
priority: priority.value,
description: description.value || undefined,
tags: parseTags(tagsRaw.value),
dueAt: due && !Number.isNaN(due.getTime()) ? due.toISOString() : null,
durationMinutes: durationMinutes.value || null,
reminderAt: reminder && !Number.isNaN(reminder.getTime()) ? reminder.toISOString() : null,
@@ -573,6 +588,12 @@ watch([id, isNew], () => void load(), { immediate: true });
:rows="8"
placeholder="جزئیات تماس، نتیجه جلسه یا یادداشت مرتبط را بنویسید…"
/>
<label for="activity-tags" class="tags-label">هشتگ / برچسب</label>
<UiInput
id="activity-tags"
v-model="tagsRaw"
placeholder="پیگیری، فوری (با کاما یا #)"
/>
</div>
<p v-if="error" class="error">{{ error }}</p>
+233
View File
@@ -0,0 +1,233 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import axios from 'axios';
import { api } from '@/lib/api';
import type { AuditLogListResponse } from '@mento/shared';
import {
UiButton,
UiCard,
UiEmptyState,
UiField,
UiInput,
UiPageHeader,
} from '@/components/ui';
import UiIcon from '@/components/UiIcon.vue';
import { formatJalaliNumeric, toFaDigits } from '@/lib/jalali';
const loading = ref(false);
const error = ref('');
const q = ref('');
const entityType = ref('');
const page = ref(1);
const data = ref<AuditLogListResponse | null>(null);
const totalPages = computed(() => {
if (!data.value) return 1;
return Math.max(1, Math.ceil(data.value.total / data.value.limit));
});
async function load(resetPage = false) {
if (resetPage) page.value = 1;
loading.value = true;
error.value = '';
try {
const { data: res } = await api.get<AuditLogListResponse>('/audit-logs', {
params: {
q: q.value.trim() || undefined,
entityType: entityType.value.trim() || undefined,
page: page.value,
limit: 30,
},
});
data.value = res;
} catch (e) {
if (axios.isAxiosError(e) && e.response?.status === 403) {
error.value = 'دسترسی به لاگ فعالیت برای این محیط فعال نیست.';
} else if (axios.isAxiosError(e) && !e.response) {
error.value = 'اتصال به API برقرار نشد.';
} else {
error.value = 'بارگذاری لاگ ناموفق بود.';
}
} finally {
loading.value = false;
}
}
function go(delta: number) {
page.value = Math.min(totalPages.value, Math.max(1, page.value + delta));
void load();
}
onMounted(() => {
void load();
});
</script>
<template>
<div class="audit-page">
<UiPageHeader
title="لاگ فعالیت کاربران"
description="ثبت تغییرات ایجاد، ویرایش و حذف در سامانه"
>
<template #actions>
<UiButton variant="secondary" :disabled="loading" @click="load()">
<UiIcon name="refresh" />
بروزرسانی
</UiButton>
</template>
</UiPageHeader>
<UiCard class="filters">
<div class="filters-grid">
<UiField label="جستجو">
<UiInput
v-model="q"
placeholder="خلاصه، مسیر یا نوع عملیات…"
@keydown.enter="load(true)"
/>
</UiField>
<UiField label="نوع منبع">
<UiInput
v-model="entityType"
placeholder="مثلاً deals یا people"
@keydown.enter="load(true)"
/>
</UiField>
<div class="filters-actions">
<UiButton :disabled="loading" @click="load(true)">اعمال فیلتر</UiButton>
</div>
</div>
</UiCard>
<p v-if="error" class="error">{{ error }}</p>
<UiCard v-if="loading && !data" title="در حال بارگذاری…">
<p class="muted">لطفاً صبر کنید.</p>
</UiCard>
<UiEmptyState
v-else-if="!loading && data && !data.items.length"
title="لاگی ثبت نشده"
description="پس از ایجاد یا ویرایش رکوردها، رویدادها اینجا دیده می‌شوند."
/>
<UiCard v-else-if="data?.items.length" title="رویدادها">
<div class="table-wrap">
<table>
<thead>
<tr>
<th>زمان</th>
<th>کاربر</th>
<th>عملیات</th>
<th>منبع</th>
<th>خلاصه</th>
</tr>
</thead>
<tbody>
<tr v-for="row in data.items" :key="row.id">
<td class="nowrap">{{ formatJalaliNumeric(row.createdAt) }}</td>
<td>{{ row.actor?.fullName ?? '—' }}</td>
<td>
<span class="pill">{{ row.action }}</span>
</td>
<td class="muted">{{ row.entityType ?? '—' }}</td>
<td>{{ row.summary }}</td>
</tr>
</tbody>
</table>
</div>
<div class="pager">
<UiButton
variant="secondary"
:disabled="loading || page <= 1"
@click="go(-1)"
>
قبلی
</UiButton>
<span class="muted">
صفحه {{ toFaDigits(page) }} از {{ toFaDigits(totalPages) }}
· {{ toFaDigits(data.total) }} مورد
</span>
<UiButton
variant="secondary"
:disabled="loading || page >= totalPages"
@click="go(1)"
>
بعدی
</UiButton>
</div>
</UiCard>
</div>
</template>
<style scoped>
.audit-page {
display: grid;
gap: 1rem;
}
.filters-grid {
display: grid;
grid-template-columns: 1.4fr 1fr auto;
gap: 0.75rem;
align-items: end;
}
.filters-actions {
display: flex;
align-items: end;
}
.error {
color: #b91c1c;
margin: 0;
font-weight: 600;
}
.muted {
color: #64748b;
margin: 0;
}
.table-wrap {
overflow: auto;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 0.9rem;
}
th,
td {
text-align: right;
padding: 0.65rem 0.55rem;
border-bottom: 1px solid #eef2f7;
vertical-align: top;
}
th {
color: #64748b;
font-weight: 700;
font-size: 0.8rem;
}
.nowrap {
white-space: nowrap;
}
.pill {
display: inline-flex;
padding: 0.15rem 0.55rem;
border-radius: var(--radius);
background: #f0fdfa;
color: #0f766e;
font-weight: 700;
font-size: 0.8rem;
}
.pager {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.75rem;
margin-top: 0.85rem;
flex-wrap: wrap;
}
@media (max-width: 860px) {
.filters-grid {
grid-template-columns: 1fr;
}
}
</style>
+22
View File
@@ -45,8 +45,20 @@ const email = ref('');
const website = ref('');
const address = ref('');
const notes = ref('');
const tagsRaw = ref('');
const customFields = ref<Record<string, unknown>>({});
function parseTags(raw: string): string[] {
return [
...new Set(
raw
.split(/[,،#\n]/)
.map((t) => t.trim())
.filter(Boolean),
),
].slice(0, 40);
}
function fill(c: CompanyDto) {
name.value = c.name;
nationalId.value = c.nationalId ?? '';
@@ -55,6 +67,7 @@ function fill(c: CompanyDto) {
website.value = c.website ?? '';
address.value = c.address ?? '';
notes.value = c.notes ?? '';
tagsRaw.value = (c.tags ?? []).join('، ');
customFields.value = { ...(c.customFields ?? {}) };
}
@@ -81,6 +94,7 @@ function payload(): CreateCompanyRequest {
website: website.value || undefined,
address: address.value || undefined,
notes: notes.value || undefined,
tags: parseTags(tagsRaw.value),
customFields: customFields.value,
};
}
@@ -236,6 +250,14 @@ onMounted(load);
/>
</UiField>
<UiField label="برچسب‌ها" class="col-span-2">
<UiInput
id="company-tags"
v-model="tagsRaw"
placeholder="شرکتی، VIP (با کاما جدا کنید)"
/>
</UiField>
<UiField label="یادداشت و توضیحات تکمیلی" class="col-span-2">
<UiTextarea
id="notes"
+24
View File
@@ -62,6 +62,7 @@ const position = ref('');
const website = ref('');
const referrer = ref('');
const notes = ref('');
const tagsRaw = ref('');
const companyId = ref('');
const mood = ref<PersonMood>('newcomer');
const customFields = ref<Record<string, unknown>>({});
@@ -205,6 +206,7 @@ function fill(p: PersonDto) {
website.value = p.website ?? '';
referrer.value = p.referrer ?? '';
notes.value = p.notes ?? '';
tagsRaw.value = (p.tags ?? []).join('، ');
companyId.value = p.company?.id ?? '';
mood.value = p.mood || 'newcomer';
customFields.value = { ...(p.customFields ?? {}) };
@@ -231,6 +233,17 @@ async function load() {
}
}
function parseTags(raw: string): string[] {
return [
...new Set(
raw
.split(/[,،#\n]/)
.map((t) => t.trim())
.filter(Boolean),
),
].slice(0, 40);
}
function payload(): CreatePersonRequest {
return {
firstName: firstName.value,
@@ -242,6 +255,7 @@ function payload(): CreatePersonRequest {
website: website.value || undefined,
referrer: referrer.value || undefined,
notes: notes.value || undefined,
tags: parseTags(tagsRaw.value),
companyId: companyId.value || null,
mood: mood.value,
customFields: customFields.value,
@@ -463,6 +477,16 @@ onMounted(load);
</UiField>
</div>
<div class="crm-col-span-full">
<UiField label="برچسب‌ها" for-id="tags">
<UiInput
id="tags"
v-model="tagsRaw"
placeholder="VIP، معرفی (با کاما جدا کنید)"
/>
</UiField>
</div>
<div class="crm-col-span-full">
<UiField label="یادداشت" for-id="notes">
<UiTextarea id="notes" v-model="notes" :rows="3" />
+66 -3
View File
@@ -3,7 +3,7 @@ import { computed, onMounted, ref } from 'vue';
import { RouterLink, useRoute, useRouter } from 'vue-router';
import axios from 'axios';
import { api } from '@/lib/api';
import type { ProjectCardDto } from '@mento/shared';
import type { OrgUserDto, ProjectCardDto } from '@mento/shared';
import UiIcon from '@/components/UiIcon.vue';
const props = withDefaults(
@@ -35,6 +35,29 @@ const saving = ref(false);
const error = ref('');
const title = ref('');
const notes = ref('');
const tagsRaw = ref('');
const selectedAssigneeIds = ref<string[]>([]);
const users = ref<OrgUserDto[]>([]);
function parseTags(raw: string): string[] {
return [
...new Set(
raw
.split(/[,،#\n]/)
.map((t) => t.trim())
.filter(Boolean),
),
].slice(0, 40);
}
async function loadUsers() {
try {
const { data } = await api.get<OrgUserDto[]>('/users');
users.value = data;
} catch {
users.value = [];
}
}
async function load() {
if (isNew.value) return;
@@ -46,6 +69,8 @@ async function load() {
const { data } = await api.get<ProjectCardDto>(`/project-cards/${cardId}`);
title.value = data.title;
notes.value = data.notes ?? '';
tagsRaw.value = (data.tags ?? []).join('، ');
selectedAssigneeIds.value = (data.assignees ?? []).map((a) => a.id);
} catch (e) {
if (axios.isAxiosError(e) && !e.response) {
error.value = 'اتصال به API برقرار نشد.';
@@ -71,6 +96,8 @@ async function save() {
const { data } = await api.post<ProjectCardDto>('/project-cards', {
title: title.value.trim(),
notes: notes.value.trim() || undefined,
tags: parseTags(tagsRaw.value),
assigneeIds: selectedAssigneeIds.value,
boardId,
stageId: props.embedded ? props.initialStageId : undefined,
personId:
@@ -85,6 +112,8 @@ async function save() {
await api.patch(`/project-cards/${id.value}`, {
title: title.value.trim(),
notes: notes.value.trim() || null,
tags: parseTags(tagsRaw.value),
assigneeIds: selectedAssigneeIds.value,
});
if (props.embedded) {
emit('saved');
@@ -121,7 +150,10 @@ function cancel() {
void router.push({ name: 'projects' });
}
onMounted(load);
onMounted(async () => {
await loadUsers();
await load();
});
</script>
<template>
@@ -188,6 +220,22 @@ onMounted(load);
<label for="card-title">عنوان</label>
<input id="card-title" v-model="title" type="text" required minlength="2" maxlength="200" />
</div>
<div class="field">
<label for="card-tags">برچسب‌ها</label>
<input
id="card-tags"
v-model="tagsRaw"
type="text"
placeholder="فوری، پشتیبانی (با کاما جدا کنید)"
/>
</div>
<div class="field">
<label for="card-assignees">مسئولان کارت</label>
<select id="card-assignees" v-model="selectedAssigneeIds" multiple class="multi">
<option v-for="u in users" :key="u.id" :value="u.id">{{ u.fullName }}</option>
</select>
<small class="hint">با نگه داشتن Ctrl می‌توانید چند نفر را انتخاب کنید.</small>
</div>
<div class="field">
<label for="card-notes">یادداشت</label>
<textarea id="card-notes" v-model="notes" rows="5" maxlength="4000" />
@@ -313,12 +361,27 @@ h1 {
}
input,
textarea {
textarea,
select {
width: 100%;
min-width: 0;
border: 1px solid #e2e8f0;
border-radius: var(--radius);
min-height: var(--control-h);
padding: 0 0.75rem;
font: inherit;
box-sizing: border-box;
}
select.multi {
min-height: 110px;
padding: 0.4rem;
}
.hint {
color: #64748b;
font-size: 0.8rem;
}
padding: 0 0.85rem;
font: inherit;
box-sizing: border-box;
+49
View File
@@ -160,6 +160,12 @@ function exportReport() {
'منبع,تعداد,درصد',
...d.sources.map((s) => `${s.label},${s.count},${s.percent}`),
'',
'دلایل شکست معاملات',
'دلیل,تعداد,درصد,مبلغ',
...(d.lostReasons ?? []).map(
(s) => `${s.label},${s.count},${s.percent},${s.amount ?? ''}`,
),
'',
'پرفروش‌ها',
'نام,تعداد,مبلغ',
...d.topProducts.map((p) => `${p.name},${p.quantity},${p.amount}`),
@@ -267,6 +273,39 @@ const sourcesOption = computed<UiChartOption>(() => {
};
});
const lostReasonsOption = computed<UiChartOption>(() => {
const rows = data.value?.lostReasons ?? [];
return {
tooltip: {
trigger: 'item',
formatter: (p: any) => {
const row = rows.find((r) => r.label === p.name);
const amountPart =
row?.amount != null ? `<br/>مبلغ: <strong>${money(row.amount)}</strong>` : '';
return `${p.name}: <strong>${num(p.value)}</strong> (${toFaDigits(p.percent)}٪)${amountPart}`;
},
},
legend: {
bottom: '0%',
left: 'center',
textStyle: { fontFamily: 'IRANSans', fontSize: 11, color: '#475569' },
},
color: CHART_PALETTE,
series: [
{
name: 'دلایل شکست',
type: 'pie',
radius: ['45%', '70%'],
center: ['50%', '42%'],
avoidLabelOverlap: true,
itemStyle: { borderRadius: 6, borderColor: '#fff', borderWidth: 2 },
label: { show: false },
data: rows.map((s) => ({ name: s.label, value: s.count })),
},
],
};
});
const monthlyOption = computed<UiChartOption>(() => {
const rows = data.value?.monthlyComparison ?? [];
return {
@@ -563,6 +602,16 @@ onMounted(() => {
<p v-else class="empty-msg">منبعی ثبت نشده است.</p>
</UiCard>
<!-- Lost reasons -->
<UiCard class="chart-card" title="دلایل عدم موفقیت فروش">
<UiChart
v-if="data.lostReasons?.length"
:option="lostReasonsOption"
height="260px"
/>
<p v-else class="empty-msg">معامله شکست‌خورده‌ای در این بازه نیست.</p>
</UiCard>
<!-- Monthly comparison -->
<UiCard class="chart-card" title="مقایسه فروش ماه‌های اخیر">
<UiChart