feat(web): add Ant workspace tabs and harden page chrome
Persist workspace tabs in the app shell with Ant Design styling aligned to the desktop top bar, and fix tab bar layout flicker on select. Add shared PageHeader components, query helpers, and missing header state across CRM views; improve mobile shell layout and Vite HMR stability on Windows. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+523
-218
@@ -1,50 +1,93 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { RouterLink, useRoute, useRouter } from 'vue-router';
|
||||
import { useQuery } from '@tanstack/vue-query';
|
||||
import axios from 'axios';
|
||||
import {
|
||||
Alert as AAlert,
|
||||
Button as AButton,
|
||||
Card as ACard,
|
||||
Checkbox as ACheckbox,
|
||||
Dropdown as ADropdown,
|
||||
Empty as AEmpty,
|
||||
Flex as AFlex,
|
||||
Grid,
|
||||
List as AList,
|
||||
ListItem as AListItem,
|
||||
Menu as AMenu,
|
||||
MenuItem as AMenuItem,
|
||||
Modal as AModal,
|
||||
Pagination as APagination,
|
||||
Select as ASelect,
|
||||
Space as ASpace,
|
||||
Spin as ASpin,
|
||||
Table as ATable,
|
||||
Tag as ATag,
|
||||
Typography,
|
||||
theme,
|
||||
} from 'ant-design-vue';
|
||||
import type { TableColumnsType } from 'ant-design-vue';
|
||||
import {
|
||||
BankOutlined,
|
||||
DeleteOutlined,
|
||||
EditOutlined,
|
||||
FileExcelOutlined,
|
||||
IdcardOutlined,
|
||||
MailOutlined,
|
||||
MoreOutlined,
|
||||
PhoneOutlined,
|
||||
TeamOutlined,
|
||||
} from '@/icons/ant-bridge';
|
||||
import { api } from '@/lib/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { formatJalaliNumeric, toFaDigits } from '@/lib/jalali';
|
||||
import CustomerMoodFace from '@/components/CustomerMoodFace.vue';
|
||||
import ExcelImportFlow from '@/components/ExcelImportFlow.vue';
|
||||
import PhoneContactsImport from '@/components/PhoneContactsImport.vue';
|
||||
import {
|
||||
UiBusyOverlay,
|
||||
UiButton,
|
||||
UiDropdownMenu,
|
||||
UiModal,
|
||||
UiPagination,
|
||||
UiEmptyState,
|
||||
} from '@/components/ui';
|
||||
import UiIcon from '@/components/UiIcon.vue';
|
||||
import { Drawer as ADrawer } from 'ant-design-vue';
|
||||
import { FilterChips, PageHeader } from '@/components/page';
|
||||
import type {
|
||||
PageHeaderActiveFilter,
|
||||
PageHeaderMenuItem,
|
||||
PageHeaderTab,
|
||||
} from '@/components/page';
|
||||
import { CrmSkeleton, CrmSkeletonTable } from '@/components/skeleton';
|
||||
import PersonFormView from '@/views/PersonFormView.vue';
|
||||
import CompanyFormView from '@/views/CompanyFormView.vue';
|
||||
import SavedFiltersBar from '@/components/SavedFiltersBar.vue';
|
||||
import TableColumnsMenu from '@/components/TableColumnsMenu.vue';
|
||||
import { registerTableColumns, useTableColumns } from '@/lib/tableColumns';
|
||||
import type {
|
||||
CompanyDto,
|
||||
CustomerGroupDto,
|
||||
ImportContactsResult,
|
||||
PaginatedResponse,
|
||||
PersonDto,
|
||||
PersonImportSource,
|
||||
PersonImportSourceStatDto,
|
||||
PersonMood,
|
||||
} from '@mento/shared';
|
||||
import {
|
||||
brand,
|
||||
PERSON_IMPORT_SOURCE_LABELS,
|
||||
PERSON_IMPORT_SOURCES,
|
||||
} from '@mento/shared';
|
||||
import { PERSON_MOOD_LABELS, PERSON_MOODS } from '@/lib/person-mood';
|
||||
import { canUseBehavior } from '@/lib/behavior-access';
|
||||
import DiscBadge from '@/components/behavior/DiscBadge.vue';
|
||||
import { PAGE_SIZE_OPTIONS, usePageSize } from '@/lib/pageSize';
|
||||
import CustomerGroupChips from '@/components/CustomerGroupChips.vue';
|
||||
import CustomerGroupsManager from '@/components/CustomerGroupsManager.vue';
|
||||
import { groupSwatch, useCustomerGroups } from '@/lib/customer-groups';
|
||||
import ContactsFilterPanel, { type ContactsFilterValue } from '@/components/ContactsFilterPanel.vue';
|
||||
import { useCustomerGroups } from '@/lib/customer-groups';
|
||||
import { type ContactsFilterValue } from '@/components/ContactsFilterPanel.vue';
|
||||
import { canManageSettings } from '@/lib/roles';
|
||||
import { contactKeys } from '@/queries/keys';
|
||||
import {
|
||||
fetchCompanies,
|
||||
fetchCompanyGroupStats,
|
||||
fetchPeople,
|
||||
fetchPeopleGroupStats,
|
||||
fetchPeopleSourceStats,
|
||||
invalidateContactQueries,
|
||||
} from '@/queries/contacts';
|
||||
|
||||
const { Link: ATypographyLink, Text: ATypographyText } = Typography;
|
||||
const { token } = theme.useToken();
|
||||
const screens = Grid.useBreakpoint();
|
||||
|
||||
type Tab = 'people' | 'companies';
|
||||
type SortKey = 'name' | 'newest';
|
||||
@@ -83,9 +126,7 @@ const discFilter = computed(() => {
|
||||
const sourceFilters = computed(() => queryList('source'));
|
||||
const activityExperienceFilters = computed(() => queryList('activityExperience'));
|
||||
const groupFilters = computed(() => queryList('group'));
|
||||
const { groups: customerGroups, load: loadCustomerGroups } = useCustomerGroups();
|
||||
/** گروههای فیلتر — با شمارش scoped بر اساس دسترسی کاربر */
|
||||
const filterGroups = ref<CustomerGroupDto[]>([]);
|
||||
const { groups: customerGroups } = useCustomerGroups();
|
||||
const canManageGroups = computed(() => canManageSettings(auth.user?.role));
|
||||
const groupsManagerOpen = ref(false);
|
||||
|
||||
@@ -124,15 +165,11 @@ const activeTags = computed<FilterTag[]>(() => {
|
||||
return tags;
|
||||
});
|
||||
const q = ref(typeof route.query.q === 'string' ? route.query.q : '');
|
||||
const loading = ref(false);
|
||||
const busy = ref(false);
|
||||
const pageBusy = ref(false);
|
||||
const busyMessage = ref('لطفاً صبر کنید…');
|
||||
const error = ref('');
|
||||
const importMsg = ref('');
|
||||
const people = ref<PaginatedResponse<PersonDto> | null>(null);
|
||||
const companies = ref<PaginatedResponse<CompanyDto> | null>(null);
|
||||
const sourceStats = ref<PersonImportSourceStatDto[]>([]);
|
||||
const menuId = ref<string | null>(null);
|
||||
const sortOpen = ref(false);
|
||||
const filterOpen = ref(false);
|
||||
@@ -158,6 +195,91 @@ const SORT_OPTIONS = [
|
||||
{ value: 'newest', label: 'جدیدترین' },
|
||||
];
|
||||
|
||||
const peopleParams = computed(() => ({
|
||||
q: q.value || undefined,
|
||||
page: page.value,
|
||||
limit: pageSize.value,
|
||||
sort: sort.value,
|
||||
mood: csv(moodFilters.value),
|
||||
importSource: csv(sourceFilters.value),
|
||||
activityExperience: csv(activityExperienceFilters.value),
|
||||
disc: discFilter.value || undefined,
|
||||
groupId: csv(groupFilters.value),
|
||||
}));
|
||||
|
||||
const companyParams = computed(() => ({
|
||||
q: q.value || undefined,
|
||||
page: page.value,
|
||||
limit: pageSize.value,
|
||||
groupId: csv(groupFilters.value),
|
||||
}));
|
||||
|
||||
const peopleQuery = useQuery({
|
||||
queryKey: computed(() => contactKeys.people({ ...peopleParams.value })),
|
||||
queryFn: () => fetchPeople({ ...peopleParams.value }),
|
||||
enabled: computed(() => tab.value === 'people'),
|
||||
placeholderData: (prev) => prev,
|
||||
});
|
||||
|
||||
const companiesQuery = useQuery({
|
||||
queryKey: computed(() => contactKeys.companies({ ...companyParams.value })),
|
||||
queryFn: () => fetchCompanies({ ...companyParams.value }),
|
||||
enabled: computed(() => tab.value === 'companies'),
|
||||
placeholderData: (prev) => prev,
|
||||
});
|
||||
|
||||
const peopleSourceStatsQuery = useQuery({
|
||||
queryKey: computed(() => contactKeys.peopleSourceStats({ ...peopleParams.value })),
|
||||
queryFn: () => fetchPeopleSourceStats({ ...peopleParams.value }),
|
||||
enabled: computed(() => tab.value === 'people'),
|
||||
staleTime: 60_000,
|
||||
placeholderData: (prev) => prev,
|
||||
});
|
||||
|
||||
const peopleGroupStatsQuery = useQuery({
|
||||
queryKey: computed(() => contactKeys.peopleGroupStats({ ...peopleParams.value })),
|
||||
queryFn: () => fetchPeopleGroupStats({ ...peopleParams.value }),
|
||||
enabled: computed(() => tab.value === 'people'),
|
||||
staleTime: 60_000,
|
||||
placeholderData: (prev) => prev,
|
||||
});
|
||||
|
||||
const companyGroupStatsQuery = useQuery({
|
||||
queryKey: computed(() => contactKeys.companyGroupStats({ ...companyParams.value })),
|
||||
queryFn: () => fetchCompanyGroupStats({ ...companyParams.value }),
|
||||
enabled: computed(() => tab.value === 'companies'),
|
||||
staleTime: 60_000,
|
||||
placeholderData: (prev) => prev,
|
||||
});
|
||||
|
||||
const people = computed(() => peopleQuery.data.value ?? null);
|
||||
const companies = computed(() => companiesQuery.data.value ?? null);
|
||||
const sourceStats = computed(() => peopleSourceStatsQuery.data.value ?? []);
|
||||
const filterGroups = computed(() =>
|
||||
tab.value === 'people'
|
||||
? (peopleGroupStatsQuery.data.value ?? [])
|
||||
: (companyGroupStatsQuery.data.value ?? []),
|
||||
);
|
||||
|
||||
const loading = computed(() => {
|
||||
if (tab.value === 'people') {
|
||||
return peopleQuery.isFetching.value && peopleQuery.data.value == null;
|
||||
}
|
||||
return companiesQuery.isFetching.value && companiesQuery.data.value == null;
|
||||
});
|
||||
|
||||
watch(
|
||||
() => (tab.value === 'people' ? peopleQuery.error.value : companiesQuery.error.value),
|
||||
(err) => {
|
||||
if (!err) return;
|
||||
if (axios.isAxiosError(err) && !err.response) {
|
||||
error.value = 'اتصال به API برقرار نشد.';
|
||||
} else {
|
||||
error.value = 'بارگذاری مخاطبین ناموفق بود.';
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const total = computed(() =>
|
||||
tab.value === 'people' ? people.value?.total ?? 0 : companies.value?.total ?? 0,
|
||||
);
|
||||
@@ -166,6 +288,14 @@ const rowOffset = computed(() => (page.value - 1) * pageSize.value);
|
||||
|
||||
const selectedIds = ref<string[]>([]);
|
||||
const pageIds = computed(() => people.value?.items.map((p) => p.id) ?? []);
|
||||
|
||||
watch(
|
||||
() => people.value?.items.map((p) => p.id) ?? [],
|
||||
(ids) => {
|
||||
const visible = new Set(ids);
|
||||
selectedIds.value = selectedIds.value.filter((id) => visible.has(id));
|
||||
},
|
||||
);
|
||||
const allSelected = computed(
|
||||
() => pageIds.value.length > 0 && pageIds.value.every((id) => selectedIds.value.includes(id)),
|
||||
);
|
||||
@@ -206,7 +336,7 @@ async function deleteSelected() {
|
||||
|
||||
function onPageSize(size: number) {
|
||||
pageSize.value = size;
|
||||
if (page.value === 1) void load();
|
||||
/* peopleParams/companyParams include limit → query key refetch */
|
||||
}
|
||||
|
||||
const peopleSavedFilters = computed(() => {
|
||||
@@ -316,63 +446,17 @@ function closePopups() {
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
closePopups();
|
||||
void loadCustomerGroups(true).catch(() => undefined);
|
||||
try {
|
||||
if (tab.value === 'people') {
|
||||
const [peopleRes, statsRes, groupStatsRes] = await Promise.all([
|
||||
api.get<PaginatedResponse<PersonDto>>('/people', {
|
||||
params: {
|
||||
q: q.value || undefined,
|
||||
page: page.value,
|
||||
limit: pageSize.value,
|
||||
sort: sort.value,
|
||||
mood: csv(moodFilters.value),
|
||||
importSource: csv(sourceFilters.value),
|
||||
activityExperience: csv(activityExperienceFilters.value),
|
||||
disc: discFilter.value || undefined,
|
||||
groupId: csv(groupFilters.value),
|
||||
},
|
||||
}),
|
||||
api.get<PersonImportSourceStatDto[]>('/people/source-stats').catch(() => ({
|
||||
data: [] as PersonImportSourceStatDto[],
|
||||
})),
|
||||
api.get<CustomerGroupDto[]>('/people/group-stats').catch(() => ({
|
||||
data: [] as CustomerGroupDto[],
|
||||
})),
|
||||
]);
|
||||
people.value = peopleRes.data;
|
||||
sourceStats.value = statsRes.data;
|
||||
filterGroups.value = groupStatsRes.data;
|
||||
const visible = new Set(peopleRes.data.items.map((p) => p.id));
|
||||
selectedIds.value = selectedIds.value.filter((id) => visible.has(id));
|
||||
} else {
|
||||
const [companiesRes, groupStatsRes] = await Promise.all([
|
||||
api.get<PaginatedResponse<CompanyDto>>('/companies', {
|
||||
params: {
|
||||
q: q.value || undefined,
|
||||
page: page.value,
|
||||
limit: pageSize.value,
|
||||
groupId: csv(groupFilters.value),
|
||||
},
|
||||
}),
|
||||
api.get<CustomerGroupDto[]>('/companies/group-stats').catch(() => ({
|
||||
data: [] as CustomerGroupDto[],
|
||||
})),
|
||||
]);
|
||||
companies.value = companiesRes.data;
|
||||
filterGroups.value = groupStatsRes.data;
|
||||
}
|
||||
} catch (e) {
|
||||
if (axios.isAxiosError(e) && !e.response) {
|
||||
error.value = 'اتصال به API برقرار نشد.';
|
||||
} else {
|
||||
error.value = 'بارگذاری مخاطبین ناموفق بود.';
|
||||
}
|
||||
} finally {
|
||||
loading.value = false;
|
||||
await invalidateContactQueries();
|
||||
if (tab.value === 'people') {
|
||||
await Promise.all([
|
||||
peopleQuery.refetch(),
|
||||
peopleSourceStatsQuery.refetch(),
|
||||
peopleGroupStatsQuery.refetch(),
|
||||
]);
|
||||
} else {
|
||||
await Promise.all([companiesQuery.refetch(), companyGroupStatsQuery.refetch()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -575,161 +659,381 @@ function onImportSettled() {
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [route.query.tab, route.query.q, route.query.page, route.query.sort, route.query.mood, route.query.disc, route.query.source, route.query.group],
|
||||
() => route.query.q,
|
||||
() => {
|
||||
q.value = typeof route.query.q === 'string' ? route.query.q : '';
|
||||
void load();
|
||||
},
|
||||
);
|
||||
|
||||
onMounted(load);
|
||||
const isCompact = computed(() => !screens.value.lg);
|
||||
const excelImportTrigger = ref<HTMLElement | null>(null);
|
||||
const phoneImportTrigger = ref<HTMLElement | null>(null);
|
||||
|
||||
const contactModalOpen = computed({
|
||||
get: () => contactModal.value !== null,
|
||||
set: (open: boolean) => {
|
||||
if (!open) contactModal.value = null;
|
||||
},
|
||||
});
|
||||
|
||||
/** سلکت سریع هدر — تکمقدار روی query چندمقداری */
|
||||
const moodFilter = computed<PersonMood | 'all'>(() => moodFilters.value[0] ?? 'all');
|
||||
const sourceFilter = computed<PersonImportSource | 'all'>(() => {
|
||||
const value = sourceFilters.value[0];
|
||||
return value && PERSON_IMPORT_SOURCES.includes(value as PersonImportSource)
|
||||
? (value as PersonImportSource)
|
||||
: 'all';
|
||||
});
|
||||
|
||||
const headerTabs: PageHeaderTab[] = [
|
||||
{ key: 'people', label: 'اشخاص' },
|
||||
{ key: 'companies', label: 'شرکتها' },
|
||||
];
|
||||
|
||||
const headerMenuItems = computed<PageHeaderMenuItem[]>(() => {
|
||||
const items: PageHeaderMenuItem[] = [
|
||||
{ key: 'export', label: 'خروجی اکسل', icon: FileExcelOutlined },
|
||||
{ key: 'import', label: 'ورود از اکسل', icon: FileExcelOutlined },
|
||||
];
|
||||
if (tab.value === 'people') {
|
||||
items.push({ key: 'phone', label: 'از مخاطبین گوشی', icon: PhoneOutlined });
|
||||
}
|
||||
if (canManageGroups.value) {
|
||||
items.push({
|
||||
key: 'groups',
|
||||
label: 'مدیریت گروهها',
|
||||
dividerBefore: true,
|
||||
});
|
||||
}
|
||||
return items;
|
||||
});
|
||||
|
||||
const KIND_LABEL: Record<FilterTag['kind'], string> = {
|
||||
group: 'گروه',
|
||||
source: 'منبع',
|
||||
mood: 'وضعیت',
|
||||
disc: 'DISC',
|
||||
activityExperience: 'سابقه',
|
||||
};
|
||||
|
||||
const activeFilterChips = computed<PageHeaderActiveFilter[]>(() =>
|
||||
activeTags.value.map((tag) => ({
|
||||
key: `${tag.kind}:${tag.value}`,
|
||||
label: KIND_LABEL[tag.kind],
|
||||
value: tag.label,
|
||||
})),
|
||||
);
|
||||
|
||||
function onHeaderMenu(key: string) {
|
||||
if (key === 'export') void exportExcel();
|
||||
else if (key === 'import') excelImportTrigger.value?.click();
|
||||
else if (key === 'phone') phoneImportTrigger.value?.click();
|
||||
else if (key === 'groups') groupsManagerOpen.value = true;
|
||||
}
|
||||
|
||||
function onHeaderTab(key: string | number) {
|
||||
setTab(String(key) === 'companies' ? 'companies' : 'people');
|
||||
}
|
||||
|
||||
function onSearchInput(value: string) {
|
||||
q.value = value;
|
||||
}
|
||||
|
||||
function onRemoveFilter(key: string) {
|
||||
const sep = key.indexOf(':');
|
||||
if (sep < 0) return;
|
||||
const kind = key.slice(0, sep) as FilterTag['kind'];
|
||||
const value = key.slice(sep + 1);
|
||||
const tag = activeTags.value.find((t) => t.kind === kind && t.value === value);
|
||||
if (tag) removeTag(tag);
|
||||
}
|
||||
|
||||
function clearPeopleFilters() {
|
||||
clearFilters();
|
||||
}
|
||||
|
||||
const PEOPLE_COL_LABELS = [
|
||||
'#',
|
||||
'وضعیت',
|
||||
'نام شخص',
|
||||
'منبع',
|
||||
'کد مبدأ',
|
||||
'سمت',
|
||||
'شرکت',
|
||||
'تلفن',
|
||||
'ایمیل',
|
||||
'تاریخ ثبت',
|
||||
];
|
||||
const COMPANY_COL_LABELS = [
|
||||
'#',
|
||||
'نام شرکت',
|
||||
'کد دیدار شرکت',
|
||||
'کد شرکت',
|
||||
'منبع',
|
||||
'گروه بندی',
|
||||
'استان',
|
||||
'شهرستان',
|
||||
'تلفن شرکت',
|
||||
'ایمیل شرکت',
|
||||
'شناسه ملی',
|
||||
'شماره اقتصادی',
|
||||
'مسئول شرکت',
|
||||
'تاریخ ثبت',
|
||||
'افراد',
|
||||
];
|
||||
registerTableColumns('contacts.people', PEOPLE_COL_LABELS);
|
||||
registerTableColumns('contacts.companies', COMPANY_COL_LABELS);
|
||||
const peopleCols = useTableColumns(() => 'contacts.people');
|
||||
const companyCols = useTableColumns(() => 'contacts.companies');
|
||||
|
||||
function shownColumns<T>(cols: TableColumnsType<T>, visible: (label: string) => boolean) {
|
||||
return cols.filter((col) => {
|
||||
const title = typeof col.title === 'string' ? col.title : '';
|
||||
if (!title || col.key === 'select' || col.key === 'actions') return true;
|
||||
return visible(title);
|
||||
});
|
||||
}
|
||||
|
||||
const peopleColumns = computed<TableColumnsType<PersonDto>>(() =>
|
||||
shownColumns(
|
||||
[
|
||||
{ title: '', key: 'select', width: 48 },
|
||||
{ title: '#', key: 'row', width: 72 },
|
||||
{ title: 'وضعیت', key: 'mood', width: 88 },
|
||||
{ title: 'نام شخص', key: 'name' },
|
||||
{ title: 'منبع', key: 'source' },
|
||||
{ title: 'کد مبدأ', key: 'code', width: 120 },
|
||||
{ title: 'سمت', key: 'position' },
|
||||
{ title: 'شرکت', key: 'company' },
|
||||
{ title: 'تلفن', key: 'phone' },
|
||||
{ title: 'ایمیل', key: 'email' },
|
||||
{ title: 'تاریخ ثبت', key: 'createdAt', width: 130 },
|
||||
{ title: '', key: 'actions', width: 56 },
|
||||
],
|
||||
(label) => peopleCols.isVisible(label),
|
||||
),
|
||||
);
|
||||
|
||||
const companyColumns = computed<TableColumnsType<CompanyDto>>(() =>
|
||||
shownColumns(
|
||||
[
|
||||
{ title: '#', key: 'row', width: 72 },
|
||||
{ title: 'نام شرکت', key: 'name' },
|
||||
{ title: 'کد دیدار شرکت', key: 'sourceRef' },
|
||||
{ title: 'کد شرکت', key: 'code' },
|
||||
{ title: 'منبع', key: 'source' },
|
||||
{ title: 'گروه بندی', key: 'group' },
|
||||
{ title: 'استان', key: 'province' },
|
||||
{ title: 'شهرستان', key: 'city' },
|
||||
{ title: 'تلفن شرکت', key: 'phone' },
|
||||
{ title: 'ایمیل شرکت', key: 'email' },
|
||||
{ title: 'شناسه ملی', key: 'nationalId' },
|
||||
{ title: 'شماره اقتصادی', key: 'economicCode' },
|
||||
{ title: 'مسئول شرکت', key: 'owner' },
|
||||
{ title: 'تاریخ ثبت', key: 'createdAt', width: 130 },
|
||||
{ title: 'افراد', key: 'peopleCount', width: 80 },
|
||||
],
|
||||
(label) => companyCols.isVisible(label),
|
||||
),
|
||||
);
|
||||
|
||||
const sortOptions: Array<{ value: SortKey; label: string }> = [
|
||||
{ value: 'name', label: 'نام' },
|
||||
{ value: 'newest', label: 'جدیدترین' },
|
||||
];
|
||||
|
||||
const moodOptions = computed(() => [
|
||||
{ value: 'all', label: 'همه' },
|
||||
...PERSON_MOODS.map((mood) => ({ value: mood, label: moodLabel(mood) })),
|
||||
]);
|
||||
|
||||
const sourceOptions = computed(() => [
|
||||
{ value: 'all', label: 'همه منابع' },
|
||||
...sourceStats.value.map((row) => ({
|
||||
value: row.source,
|
||||
label: `${row.label} (${toFaDigits(row.count)})`,
|
||||
})),
|
||||
]);
|
||||
|
||||
const discOptions = [
|
||||
{ value: 'D', label: 'D' },
|
||||
{ value: 'I', label: 'I' },
|
||||
{ value: 'S', label: 'S' },
|
||||
{ value: 'C', label: 'C' },
|
||||
];
|
||||
|
||||
const discSelected = computed(() =>
|
||||
discFilter.value ? discFilter.value.split('/').filter(Boolean) : [],
|
||||
);
|
||||
|
||||
function onDiscChange(next: string[]) {
|
||||
const cleaned = discOptions.map((o) => o.value).filter((v) => next.includes(v));
|
||||
patchQuery({ disc: cleaned.length ? cleaned.join('/') : undefined, page: undefined });
|
||||
}
|
||||
|
||||
function moodTagColor(mood: PersonMood) {
|
||||
if (mood === 'happy') return 'purple';
|
||||
if (mood === 'unhappy') return 'error';
|
||||
if (mood === 'special') return 'warning';
|
||||
return 'success';
|
||||
}
|
||||
|
||||
function onSortChange(value: unknown) {
|
||||
if (Array.isArray(value)) {
|
||||
setSort(value[0] === 'newest' ? 'newest' : 'name');
|
||||
return;
|
||||
}
|
||||
setSort(value === 'newest' ? 'newest' : 'name');
|
||||
}
|
||||
|
||||
function onMoodChange(value: unknown) {
|
||||
const next =
|
||||
typeof value === 'string' && PERSON_MOODS.includes(value as PersonMood)
|
||||
? (value as PersonMood)
|
||||
: undefined;
|
||||
patchQuery({ mood: next, page: undefined });
|
||||
}
|
||||
|
||||
function onSourceChange(value: unknown) {
|
||||
const next =
|
||||
typeof value === 'string' && PERSON_IMPORT_SOURCES.includes(value as PersonImportSource)
|
||||
? value
|
||||
: undefined;
|
||||
patchQuery({ source: next, page: undefined });
|
||||
}
|
||||
|
||||
function onPersonMenu(id: string, prefix: 't' | 'm', open: boolean) {
|
||||
menuId.value = open ? `${prefix}:${id}` : null;
|
||||
}
|
||||
|
||||
function onTablePage(nextPage: number, nextSize: number) {
|
||||
const size = Number(nextSize);
|
||||
if (size !== pageSize.value) onPageSize(size);
|
||||
if (nextPage !== page.value) setPage(nextPage);
|
||||
}
|
||||
|
||||
function pageTotalText(totalCount: number, range: [number, number]) {
|
||||
return `نمایش ${toFaDigits(range[0])} تا ${toFaDigits(range[1])} از ${toFaDigits(totalCount)}`;
|
||||
}
|
||||
|
||||
function peopleCustomRow(record: PersonDto) {
|
||||
return {
|
||||
style: selectedIds.value.includes(record.id)
|
||||
? { background: token.value.colorPrimaryBg }
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a-flex vertical :gap="16" @click="closePopups">
|
||||
<a-flex justify="space-between" align="center" wrap="wrap" :gap="12">
|
||||
<div>
|
||||
<a-typography-title :level="3" :style="{ margin: 0 }">مخاطبین</a-typography-title>
|
||||
</div>
|
||||
<a-space wrap>
|
||||
<RouterLink v-if="canBehavior" :to="{ name: 'disc-report' }">
|
||||
<a-button>گزارش DISC</a-button>
|
||||
</RouterLink>
|
||||
<a-button
|
||||
:disabled="busy"
|
||||
:loading="pageBusy && busyMessage.includes('خروجی')"
|
||||
@click.stop="exportExcel"
|
||||
>
|
||||
<template #icon><DownloadOutlined /></template>
|
||||
{{ isCompact ? 'خروجی' : 'خروجی اکسل' }}
|
||||
</a-button>
|
||||
<ExcelImportFlow
|
||||
:preview-path="importPreviewPath"
|
||||
:import-path="importPath"
|
||||
:disabled="busy"
|
||||
@start="onImportStart"
|
||||
@done="onImportDone"
|
||||
@fail="onImportFail"
|
||||
@settled="onImportSettled"
|
||||
>
|
||||
<template #default="{ loading: excelLoading }">
|
||||
<a-button :disabled="busy" :loading="excelLoading">
|
||||
<template #icon><FileExcelOutlined /></template>
|
||||
{{ isCompact ? 'ورود' : 'ورود از اکسل' }}
|
||||
</a-button>
|
||||
</template>
|
||||
</ExcelImportFlow>
|
||||
<PhoneContactsImport
|
||||
v-if="tab === 'people'"
|
||||
:disabled="busy"
|
||||
@start="onPhoneImportStart"
|
||||
@done="onPhoneImportDone"
|
||||
@fail="onPhoneImportFail"
|
||||
@settled="onPhoneImportSettled"
|
||||
>
|
||||
<a-button :disabled="busy">
|
||||
<template #icon><PhoneOutlined /></template>
|
||||
{{ isCompact ? 'گوشی' : 'از مخاطبین گوشی' }}
|
||||
</a-button>
|
||||
</PhoneContactsImport>
|
||||
<a-button type="primary" @click="contactModal = tab === 'companies' ? 'company' : 'person'">
|
||||
<template #icon><PlusOutlined /></template>
|
||||
{{ tab === 'companies' ? 'شرکت جدید' : 'شخص جدید' }}
|
||||
</a-button>
|
||||
</a-space>
|
||||
</a-flex>
|
||||
|
||||
<a-spin :spinning="pageBusy" :tip="busyMessage">
|
||||
<a-card :bordered="false">
|
||||
<a-flex justify="space-between" align="center" wrap="wrap" :gap="12">
|
||||
<a-radio-group :value="tab" button-style="solid" @change="onTabChange">
|
||||
<a-radio-button value="people">
|
||||
<UserOutlined />
|
||||
اشخاص
|
||||
<template v-if="people"> {{ toFaDigits(people.total) }}</template>
|
||||
</a-radio-button>
|
||||
<a-radio-button value="companies">
|
||||
<BankOutlined />
|
||||
شرکتها
|
||||
<template v-if="companies"> {{ toFaDigits(companies.total) }}</template>
|
||||
</a-radio-button>
|
||||
</a-radio-group>
|
||||
<TableColumnsMenu
|
||||
:table-key="tab === 'people' ? 'contacts.people' : 'contacts.companies'"
|
||||
<PageHeader
|
||||
title="مخاطبین"
|
||||
:icon="TeamOutlined"
|
||||
:primary-label="tab === 'companies' ? 'شرکت جدید' : 'شخص جدید'"
|
||||
:menu-items="headerMenuItems"
|
||||
:tabs="headerTabs"
|
||||
:active-tab="tab"
|
||||
searchable
|
||||
:search="q"
|
||||
:search-placeholder="tab === 'people' ? 'جستجو در اشخاص…' : 'جستجو در شرکتها…'"
|
||||
:active-filters="activeFilterChips"
|
||||
:result-count="activeFilterChips.length ? total : undefined"
|
||||
@primary="contactModal = tab === 'companies' ? 'company' : 'person'"
|
||||
@menu="onHeaderMenu"
|
||||
@update:active-tab="onHeaderTab"
|
||||
@update:search="onSearchInput"
|
||||
@search-submit="onSearch"
|
||||
@remove-filter="onRemoveFilter"
|
||||
@clear-filters="clearPeopleFilters"
|
||||
>
|
||||
<template #quick-filters>
|
||||
<template v-if="tab === 'people'">
|
||||
<a-select
|
||||
:value="moodFilter"
|
||||
:options="moodOptions"
|
||||
:style="{ width: '150px' }"
|
||||
@update:value="onMoodChange"
|
||||
/>
|
||||
</a-flex>
|
||||
|
||||
<a-divider orientation="left">جستجو و فیلتر</a-divider>
|
||||
|
||||
<a-form layout="vertical" @submit.prevent="onSearch">
|
||||
<a-row :gutter="[16, 16]">
|
||||
<a-col :xs="24" :md="tab === 'people' ? 8 : 12">
|
||||
<a-form-item label="جستجو">
|
||||
<a-input-search
|
||||
v-model:value="q"
|
||||
allow-clear
|
||||
:placeholder="tab === 'people' ? 'جستجو در اشخاص…' : 'جستجو در شرکتها…'"
|
||||
style="width: 100%"
|
||||
@search="onSearch"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="tab === 'people' ? 8 : 12">
|
||||
<a-form-item label="مرتبسازی">
|
||||
<a-select
|
||||
:value="sort"
|
||||
:options="sortOptions"
|
||||
style="width: 100%"
|
||||
@update:value="onSortChange"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col v-if="tab === 'people'" :xs="24" :md="8">
|
||||
<a-form-item label="وضعیت">
|
||||
<a-select
|
||||
:value="moodFilter"
|
||||
:options="moodOptions"
|
||||
style="width: 100%"
|
||||
@update:value="onMoodChange"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col v-if="tab === 'people' && sourceStats.length" :xs="24" :md="8">
|
||||
<a-form-item label="منبع">
|
||||
<a-select
|
||||
:value="sourceFilter"
|
||||
:options="sourceOptions"
|
||||
style="width: 100%"
|
||||
@update:value="onSourceChange"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col v-if="tab === 'people' && canBehavior" :xs="24" :md="sourceStats.length ? 16 : 24">
|
||||
<a-form-item label="تیپ DISC">
|
||||
<a-space wrap :size="8">
|
||||
<a-button
|
||||
v-for="chip in discChipItems"
|
||||
:key="chip.value || 'all'"
|
||||
:type="(chip.value ? discFilter === chip.value : !discFilter) ? 'primary' : 'default'"
|
||||
@click="setDisc(chip.value)"
|
||||
>
|
||||
{{ chip.label }}
|
||||
</a-button>
|
||||
</a-space>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-form>
|
||||
<a-select
|
||||
v-if="sourceStats.length"
|
||||
:value="sourceFilter"
|
||||
:options="sourceOptions"
|
||||
:style="{ width: '170px' }"
|
||||
@update:value="onSourceChange"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<template v-if="tab === 'people'" #saved-filters>
|
||||
<div :style="{ width: '280px', maxWidth: '100%' }">
|
||||
<SavedFiltersBar
|
||||
v-if="tab === 'people'"
|
||||
scope="people"
|
||||
compact
|
||||
:current-filters="peopleSavedFilters"
|
||||
@apply="applyPeopleSavedFilters"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<a-divider orientation="left">فهرست</a-divider>
|
||||
<template #toolbar-end>
|
||||
<TableColumnsMenu
|
||||
icon-only
|
||||
align="end"
|
||||
:table-key="tab === 'people' ? 'contacts.people' : 'contacts.companies'"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template v-if="tab === 'people' && canBehavior" #chips>
|
||||
<FilterChips
|
||||
label="DISC"
|
||||
:options="discOptions"
|
||||
:model-value="discSelected"
|
||||
@update:model-value="onDiscChange"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<!-- مرتبسازی فقط روی لیست اشخاص اثر دارد -->
|
||||
<template v-if="tab === 'people'" #chips-end>
|
||||
<FilterChips
|
||||
label="مرتبسازی"
|
||||
:options="sortOptions"
|
||||
:multiple="false"
|
||||
:show-all="false"
|
||||
:model-value="[sort]"
|
||||
@update:model-value="onSortChange"
|
||||
/>
|
||||
</template>
|
||||
</PageHeader>
|
||||
|
||||
<!-- تریگرهای ورود داده؛ از منوی «⋯» هدر کلیک میشوند (مودالهایشان به body تلپورت میشوند) -->
|
||||
<div hidden>
|
||||
<ExcelImportFlow
|
||||
:preview-path="importPreviewPath"
|
||||
:import-path="importPath"
|
||||
:disabled="busy"
|
||||
@start="onImportStart"
|
||||
@done="onImportDone"
|
||||
@fail="onImportFail"
|
||||
@settled="onImportSettled"
|
||||
>
|
||||
<span ref="excelImportTrigger"></span>
|
||||
</ExcelImportFlow>
|
||||
<PhoneContactsImport
|
||||
v-if="tab === 'people'"
|
||||
:disabled="busy"
|
||||
@start="onPhoneImportStart"
|
||||
@done="onPhoneImportDone"
|
||||
@fail="onPhoneImportFail"
|
||||
@settled="onPhoneImportSettled"
|
||||
>
|
||||
<span ref="phoneImportTrigger"></span>
|
||||
</PhoneContactsImport>
|
||||
</div>
|
||||
|
||||
<a-spin :spinning="pageBusy" :tip="busyMessage">
|
||||
<a-card :bordered="false">
|
||||
<a-flex vertical :gap="16">
|
||||
<a-alert v-if="importMsg" type="success" show-icon :message="importMsg" />
|
||||
<a-alert v-if="error" type="error" show-icon :message="error" />
|
||||
|
||||
@@ -1112,7 +1416,7 @@ onMounted(load);
|
||||
</CrmSkeletonTable>
|
||||
</CrmSkeleton>
|
||||
|
||||
<a-flex v-if="total" justify="flex-start" :style="{ marginTop: `${token.margin}px` }">
|
||||
<a-flex v-if="total" justify="flex-start">
|
||||
<a-pagination
|
||||
:current="page"
|
||||
:page-size="pageSize"
|
||||
@@ -1123,6 +1427,7 @@ onMounted(load);
|
||||
@change="onTablePage"
|
||||
/>
|
||||
</a-flex>
|
||||
</a-flex>
|
||||
</a-card>
|
||||
</a-spin>
|
||||
</a-flex>
|
||||
|
||||
Reference in New Issue
Block a user