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:
@@ -1,33 +1,44 @@
|
||||
import { computed, ref } from 'vue';
|
||||
import { computed } from 'vue';
|
||||
import { useQuery } from '@tanstack/vue-query';
|
||||
import type { ActivityPriority, ActivityPrioritySetting } from '@mento/shared';
|
||||
import {
|
||||
DEFAULT_ACTIVITY_PRIORITY_SETTINGS,
|
||||
parseActivityPrioritySettings,
|
||||
} from '@mento/shared';
|
||||
import { api } from '@/lib/api';
|
||||
import { activityPriorityKeys } from '@/queries/keys';
|
||||
import { queryClient } from '@/queries/queryClient';
|
||||
|
||||
const items = ref<ActivityPrioritySetting[]>([...DEFAULT_ACTIVITY_PRIORITY_SETTINGS]);
|
||||
const loaded = ref(false);
|
||||
let pending: Promise<void> | null = null;
|
||||
const REF_STALE_MS = 5 * 60_000;
|
||||
|
||||
/** تنظیمات اولویت فعالیت/روتین (کش مشترک) */
|
||||
async function fetchActivityPriorities(): Promise<ActivityPrioritySetting[]> {
|
||||
try {
|
||||
const { data } = await api.get<ActivityPrioritySetting[]>('/activities/priorities');
|
||||
return parseActivityPrioritySettings(data);
|
||||
} catch {
|
||||
return [...DEFAULT_ACTIVITY_PRIORITY_SETTINGS];
|
||||
}
|
||||
}
|
||||
|
||||
/** تنظیمات اولویت فعالیت/روتین (کش مشترک Vue Query) */
|
||||
export function useActivityPriorities() {
|
||||
const query = useQuery({
|
||||
queryKey: activityPriorityKeys.list(),
|
||||
queryFn: fetchActivityPriorities,
|
||||
staleTime: REF_STALE_MS,
|
||||
placeholderData: [...DEFAULT_ACTIVITY_PRIORITY_SETTINGS],
|
||||
});
|
||||
|
||||
const items = computed(
|
||||
() => query.data.value ?? [...DEFAULT_ACTIVITY_PRIORITY_SETTINGS],
|
||||
);
|
||||
const loaded = computed(() => query.isFetched.value);
|
||||
|
||||
async function load(force = false): Promise<void> {
|
||||
if (loaded.value && !force) return;
|
||||
if (pending && !force) return pending;
|
||||
pending = api
|
||||
.get<ActivityPrioritySetting[]>('/activities/priorities')
|
||||
.then(({ data }) => {
|
||||
items.value = parseActivityPrioritySettings(data);
|
||||
loaded.value = true;
|
||||
})
|
||||
.catch(() => {
|
||||
if (!loaded.value) items.value = [...DEFAULT_ACTIVITY_PRIORITY_SETTINGS];
|
||||
})
|
||||
.finally(() => {
|
||||
pending = null;
|
||||
});
|
||||
return pending;
|
||||
if (force) {
|
||||
await queryClient.invalidateQueries({ queryKey: activityPriorityKeys.all });
|
||||
}
|
||||
await query.refetch();
|
||||
}
|
||||
|
||||
const byKey = computed(() => {
|
||||
@@ -59,9 +70,11 @@ export function useActivityPriorities() {
|
||||
}
|
||||
|
||||
function setLocal(next: ActivityPrioritySetting[]) {
|
||||
items.value = parseActivityPrioritySettings(next);
|
||||
loaded.value = true;
|
||||
queryClient.setQueryData(
|
||||
activityPriorityKeys.list(),
|
||||
parseActivityPrioritySettings(next),
|
||||
);
|
||||
}
|
||||
|
||||
return { items, byKey, labels, colors, loaded, load, labelOf, colorOf, setLocal };
|
||||
return { items, byKey, labels, colors, loaded, load, labelOf, colorOf, setLocal, query };
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { computed, ref } from 'vue';
|
||||
import { computed } from 'vue';
|
||||
import { useQuery } from '@tanstack/vue-query';
|
||||
import type {
|
||||
ActivityDto,
|
||||
ActivityStageColor,
|
||||
@@ -9,6 +10,8 @@ import type {
|
||||
import { ACTIVITY_TYPE_LABELS } from '@mento/shared';
|
||||
import { api } from '@/lib/api';
|
||||
import { PIPELINE_ACCENT } from '@/lib/pipeline-board';
|
||||
import { activityTypeKeys } from '@/queries/keys';
|
||||
import { queryClient } from '@/queries/queryClient';
|
||||
|
||||
export const BASE_TYPE_ICON: Record<ActivityType, ActivityTypeIcon> = {
|
||||
call: 'phone',
|
||||
@@ -45,28 +48,29 @@ export const ACTIVITY_TYPE_ICON_LABELS: Record<ActivityTypeIcon, string> = {
|
||||
sparkle: 'درخشش',
|
||||
};
|
||||
|
||||
const types = ref<ActivityTypeDefDto[]>([]);
|
||||
const loaded = ref(false);
|
||||
let pending: Promise<void> | null = null;
|
||||
const REF_STALE_MS = 5 * 60_000;
|
||||
|
||||
/** انواع فعالیت سازمان (کش مشترک بین صفحات) */
|
||||
async function fetchActivityTypes(): Promise<ActivityTypeDefDto[]> {
|
||||
const { data } = await api.get<ActivityTypeDefDto[]>('/activities/types');
|
||||
return data;
|
||||
}
|
||||
|
||||
/** انواع فعالیت سازمان (کش مشترک Vue Query) */
|
||||
export function useActivityTypes() {
|
||||
const query = useQuery({
|
||||
queryKey: activityTypeKeys.list(),
|
||||
queryFn: fetchActivityTypes,
|
||||
staleTime: REF_STALE_MS,
|
||||
});
|
||||
|
||||
const types = computed(() => query.data.value ?? []);
|
||||
const loaded = computed(() => query.isFetched.value);
|
||||
|
||||
async function load(force = false): Promise<void> {
|
||||
if (loaded.value && !force) return;
|
||||
if (pending && !force) return pending;
|
||||
pending = api
|
||||
.get<ActivityTypeDefDto[]>('/activities/types')
|
||||
.then(({ data }) => {
|
||||
types.value = data;
|
||||
loaded.value = true;
|
||||
})
|
||||
.catch(() => {
|
||||
if (!loaded.value) types.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
pending = null;
|
||||
});
|
||||
return pending;
|
||||
if (force) {
|
||||
await queryClient.invalidateQueries({ queryKey: activityTypeKeys.all });
|
||||
}
|
||||
await query.refetch();
|
||||
}
|
||||
|
||||
const active = computed(() => types.value.filter((t) => t.isActive));
|
||||
@@ -84,7 +88,7 @@ export function useActivityTypes() {
|
||||
return systemOf.value[a.type] ?? null;
|
||||
}
|
||||
|
||||
return { types, active, byId, systemOf, loaded, load, defOf };
|
||||
return { types, active, byId, systemOf, loaded, load, defOf, query };
|
||||
}
|
||||
|
||||
export type TypeView = { name: string; icon: ActivityTypeIcon; color: ActivityStageColor };
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import axios from 'axios';
|
||||
|
||||
/** Extract a user-facing message from an API/axios error. */
|
||||
export function apiErrorMessage(e: unknown, fallback: string): string {
|
||||
if (axios.isAxiosError(e)) {
|
||||
const msg = (e.response?.data as { message?: string | string[] } | undefined)?.message;
|
||||
if (Array.isArray(msg)) return msg.join('، ');
|
||||
if (msg) return msg;
|
||||
if (!e.response) return 'اتصال به سرور برقرار نشد.';
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import { ref } from 'vue';
|
||||
import { computed } from 'vue';
|
||||
import { useQuery } from '@tanstack/vue-query';
|
||||
import type { CustomerGroupColor, CustomerGroupDto } from '@mento/shared';
|
||||
import { api } from '@/lib/api';
|
||||
import { customerGroupKeys } from '@/queries/keys';
|
||||
import { queryClient } from '@/queries/queryClient';
|
||||
|
||||
export const CUSTOMER_GROUP_COLOR_LABELS: Record<CustomerGroupColor, string> = {
|
||||
teal: 'سبزآبی',
|
||||
@@ -27,27 +30,31 @@ export function groupSwatch(color: string | null | undefined) {
|
||||
return CUSTOMER_GROUP_SWATCH[(color ?? 'teal') as CustomerGroupColor] ?? CUSTOMER_GROUP_SWATCH.teal;
|
||||
}
|
||||
|
||||
const groups = ref<CustomerGroupDto[]>([]);
|
||||
const loaded = ref(false);
|
||||
let pending: Promise<CustomerGroupDto[]> | null = null;
|
||||
const REF_STALE_MS = 5 * 60_000;
|
||||
|
||||
/** فهرست گروههای مشتری محیط (مشترک بین صفحهها) */
|
||||
async function fetchCustomerGroups(): Promise<CustomerGroupDto[]> {
|
||||
const { data } = await api.get<CustomerGroupDto[]>('/customer-groups');
|
||||
return data;
|
||||
}
|
||||
|
||||
/** فهرست گروههای مشتری محیط (کش مشترک Vue Query) */
|
||||
export function useCustomerGroups() {
|
||||
const query = useQuery({
|
||||
queryKey: customerGroupKeys.list(),
|
||||
queryFn: fetchCustomerGroups,
|
||||
staleTime: REF_STALE_MS,
|
||||
});
|
||||
|
||||
const groups = computed(() => query.data.value ?? []);
|
||||
const loaded = computed(() => query.isFetched.value);
|
||||
|
||||
async function load(force = false): Promise<CustomerGroupDto[]> {
|
||||
if (loaded.value && !force) return groups.value;
|
||||
if (pending && !force) return pending;
|
||||
pending = api
|
||||
.get<CustomerGroupDto[]>('/customer-groups')
|
||||
.then(({ data }) => {
|
||||
groups.value = data;
|
||||
loaded.value = true;
|
||||
return data;
|
||||
})
|
||||
.finally(() => {
|
||||
pending = null;
|
||||
});
|
||||
return pending;
|
||||
if (force) {
|
||||
await queryClient.invalidateQueries({ queryKey: customerGroupKeys.all });
|
||||
}
|
||||
const result = await query.refetch();
|
||||
return result.data ?? groups.value;
|
||||
}
|
||||
|
||||
return { groups, loaded, load };
|
||||
return { groups, loaded, load, query };
|
||||
}
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
import { ref } from 'vue';
|
||||
import type { RouteLocationNormalizedLoaded } from 'vue-router';
|
||||
|
||||
export type WorkspaceTab = {
|
||||
id: string;
|
||||
fullPath: string;
|
||||
path: string;
|
||||
title: string;
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'mento_workspace_tabs_v1';
|
||||
const MAX_TABS = 14;
|
||||
|
||||
const tabs = ref<WorkspaceTab[]>([]);
|
||||
const hydrated = ref(false);
|
||||
|
||||
const ROUTE_TITLES: Record<string, string> = {
|
||||
home: 'داشبورد',
|
||||
profile: 'حساب کاربری',
|
||||
reports: 'گزارشها',
|
||||
'tahesab-sales-report': 'گزارش فروش تهحساب',
|
||||
'disc-report': 'گزارش دیسک',
|
||||
'sales-forecast': 'هدف و پیشبینی',
|
||||
tickets: 'تیکتها',
|
||||
conversations: 'گفتگو',
|
||||
'ticket-new': 'تیکت جدید',
|
||||
'ticket-detail': 'جزئیات تیکت',
|
||||
activities: 'میز کار من',
|
||||
'activities-calendar': 'تقویم کارها',
|
||||
'activity-new': 'کار جدید',
|
||||
'activity-edit': 'ویرایش کار',
|
||||
'activity-detail': 'جزئیات کار',
|
||||
'routines-today': 'روتین امروز',
|
||||
'routines-overdue': 'روتین معوق',
|
||||
'routines-calendar': 'تقویم روتین',
|
||||
'routines-list': 'فهرست روتین',
|
||||
'routines-me': 'روتین من',
|
||||
'routines-team': 'روتین تیم',
|
||||
'routines-manage': 'مدیریت روتین',
|
||||
'routine-new': 'روتین جدید',
|
||||
'routine-edit': 'ویرایش روتین',
|
||||
'routines-settings': 'تنظیمات روتین',
|
||||
quotes: 'پیشفاکتورها',
|
||||
'quote-new': 'پیشفاکتور جدید',
|
||||
'quote-detail': 'جزئیات پیشفاکتور',
|
||||
invoices: 'فاکتورها',
|
||||
'invoice-new': 'فاکتور جدید',
|
||||
'invoice-detail': 'جزئیات فاکتور',
|
||||
inventory: 'انبار',
|
||||
cheques: 'چکها',
|
||||
finance: 'مدیریت مالی',
|
||||
'finance-accounts': 'حسابها',
|
||||
'finance-account': 'جزئیات حساب',
|
||||
'finance-incomes': 'دریافتها',
|
||||
'finance-expenses': 'پرداختها',
|
||||
'finance-receivables': 'مطالبات',
|
||||
'finance-payroll': 'حقوق',
|
||||
'finance-recurring': 'تراکنشهای تکراری',
|
||||
'finance-reports': 'گزارش مالی',
|
||||
'finance-audit': 'حسابرسی مالی',
|
||||
'finance-categories': 'دستهبندی مالی',
|
||||
reservations: 'رزرو و نوبتدهی',
|
||||
commissions: 'پورسانت',
|
||||
pipeline: 'مسیر فروش',
|
||||
leads: 'فهرست لیدها',
|
||||
'leads-board': 'مسیر لیدها',
|
||||
'lead-detail': 'جزئیات لید',
|
||||
projects: 'تابلوی پروژه',
|
||||
'project-card-new': 'کارت پروژه جدید',
|
||||
'project-card-detail': 'جزئیات کارت پروژه',
|
||||
loyalty: 'باشگاه مشتریان',
|
||||
gamification: 'باشگاه امتیازات',
|
||||
'gamification-admin': 'مدیریت باشگاه',
|
||||
'deal-new': 'معامله جدید',
|
||||
'deal-detail': 'جزئیات معامله',
|
||||
contacts: 'مشتریان',
|
||||
notes: 'یادداشتها',
|
||||
attachments: 'پیوستها',
|
||||
automations: 'اتوماسیون گردش کار',
|
||||
'message-automations': 'اتوماسیون پیامکها',
|
||||
'lead-stages': 'مراحل و وضعیتها',
|
||||
'pipeline-settings': 'تنظیمات مسیر فروش',
|
||||
'lead-forms': 'فرمساز سرنخ',
|
||||
'lead-form-builder': 'ویرایش فرم لید',
|
||||
'team-settings': 'تیم و نقشها',
|
||||
'audit-logs': 'لاگ فعالیت کاربران',
|
||||
'deletion-archives': 'تاریخچه کارها',
|
||||
'public-api': 'API و وبهوک',
|
||||
'sms-campaigns': 'پیامک گروهی',
|
||||
'sms-campaign-report': 'گزارش پیامک گروهی',
|
||||
'custom-fields': 'فیلدهای سفارشی',
|
||||
products: 'محصولات و خدمات',
|
||||
'product-new': 'محصول جدید',
|
||||
'product-edit': 'ویرایش محصول',
|
||||
currencies: 'ارزها',
|
||||
'tahesab-settings': 'تهحساب',
|
||||
'account-balance-settings': 'مانده حساب',
|
||||
'woocommerce-settings': 'ووکامرس',
|
||||
'montify-settings': 'فروشگاههای مونتیفای',
|
||||
'voip-settings': 'تلفن سازمانی',
|
||||
'faq-settings': 'FAQ',
|
||||
'person-new': 'شخص جدید',
|
||||
'person-edit': 'ویرایش شخص',
|
||||
'person-detail': 'پروفایل شخص',
|
||||
'company-new': 'شرکت جدید',
|
||||
'company-edit': 'ویرایش شرکت',
|
||||
'company-detail': 'پروفایل شرکت',
|
||||
settings: 'تنظیمات',
|
||||
};
|
||||
|
||||
function readStorage(): WorkspaceTab[] {
|
||||
try {
|
||||
const raw = sessionStorage.getItem(STORAGE_KEY);
|
||||
if (!raw) return [];
|
||||
const parsed = JSON.parse(raw) as WorkspaceTab[];
|
||||
if (!Array.isArray(parsed)) return [];
|
||||
return parsed.filter(
|
||||
(t) =>
|
||||
t &&
|
||||
typeof t.id === 'string' &&
|
||||
typeof t.fullPath === 'string' &&
|
||||
typeof t.title === 'string',
|
||||
);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function writeStorage(next: WorkspaceTab[]) {
|
||||
try {
|
||||
sessionStorage.setItem(STORAGE_KEY, JSON.stringify(next));
|
||||
} catch {
|
||||
/* ignore quota */
|
||||
}
|
||||
}
|
||||
|
||||
function ensureHydrated() {
|
||||
if (hydrated.value) return;
|
||||
tabs.value = readStorage();
|
||||
hydrated.value = true;
|
||||
}
|
||||
|
||||
export function titleForRoute(route: RouteLocationNormalizedLoaded): string {
|
||||
const metaTitle = route.meta?.title;
|
||||
if (typeof metaTitle === 'string' && metaTitle.trim()) return metaTitle.trim();
|
||||
|
||||
const name = typeof route.name === 'string' ? route.name : '';
|
||||
if (name && ROUTE_TITLES[name]) return ROUTE_TITLES[name];
|
||||
|
||||
for (let i = route.matched.length - 1; i >= 0; i -= 1) {
|
||||
const matchedName = route.matched[i]?.name;
|
||||
if (typeof matchedName === 'string' && ROUTE_TITLES[matchedName]) {
|
||||
return ROUTE_TITLES[matchedName];
|
||||
}
|
||||
}
|
||||
|
||||
const leaf = route.path.split('/').filter(Boolean).pop();
|
||||
if (!leaf) return 'صفحه';
|
||||
if (/^\d+$/.test(leaf) || leaf.length > 24) {
|
||||
const parent = route.path.split('/').filter(Boolean).slice(-2, -1)[0];
|
||||
if (parent && ROUTE_TITLES[parent]) return ROUTE_TITLES[parent];
|
||||
}
|
||||
return decodeURIComponent(leaf);
|
||||
}
|
||||
|
||||
export function useWorkspaceTabs() {
|
||||
ensureHydrated();
|
||||
|
||||
function syncFromRoute(route: RouteLocationNormalizedLoaded) {
|
||||
if (route.meta?.public) return;
|
||||
const fullPath = route.fullPath;
|
||||
const path = route.path;
|
||||
if (!path || path.startsWith('/login') || path.startsWith('/adm')) return;
|
||||
|
||||
const id = path;
|
||||
const title = titleForRoute(route);
|
||||
const existing = tabs.value.find((t) => t.id === id);
|
||||
if (existing) {
|
||||
let dirty = false;
|
||||
if (existing.fullPath !== fullPath) {
|
||||
existing.fullPath = fullPath;
|
||||
dirty = true;
|
||||
}
|
||||
if (existing.title !== title) {
|
||||
existing.title = title;
|
||||
dirty = true;
|
||||
}
|
||||
if (dirty) writeStorage(tabs.value);
|
||||
return;
|
||||
}
|
||||
|
||||
const next = [
|
||||
...tabs.value,
|
||||
{
|
||||
id,
|
||||
fullPath,
|
||||
path,
|
||||
title,
|
||||
},
|
||||
];
|
||||
while (next.length > MAX_TABS) next.shift();
|
||||
tabs.value = next;
|
||||
writeStorage(tabs.value);
|
||||
}
|
||||
|
||||
function activateTab(id: string, push: (to: string) => void) {
|
||||
const tab = tabs.value.find((t) => t.id === id);
|
||||
if (!tab) return;
|
||||
push(tab.fullPath);
|
||||
}
|
||||
|
||||
function closeTab(
|
||||
id: string,
|
||||
currentPath: string,
|
||||
push: (to: string) => void,
|
||||
) {
|
||||
const index = tabs.value.findIndex((t) => t.id === id);
|
||||
if (index < 0) return;
|
||||
const wasActive = currentPath === id;
|
||||
const next = tabs.value.filter((t) => t.id !== id);
|
||||
tabs.value = next;
|
||||
writeStorage(next);
|
||||
if (!wasActive) return;
|
||||
const fallback = next[index] ?? next[index - 1] ?? next[next.length - 1];
|
||||
push(fallback?.fullPath || '/');
|
||||
}
|
||||
|
||||
return {
|
||||
tabs,
|
||||
syncFromRoute,
|
||||
activateTab,
|
||||
closeTab,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user