merge: bring latest origin/main into dev (design local, logic main)

Keep the local Ant screens and icon pack. Take treasury parties, routine self-service, Tahesab auto-sync, public lead registration, and contact merge from main.
This commit is contained in:
2026-11-05 15:10:48 +03:30
55 changed files with 2719 additions and 358 deletions
+135 -1
View File
@@ -10,7 +10,7 @@ import type {
UpdateTahesabConnectionRequest,
} from '@mento/shared';
import { brand } from '@mento/shared';
import { toFaDigits } from '@/lib/jalali';
import { formatJalaliDateTime, toFaDigits } from '@/lib/jalali';
import { registerTableColumns, useTableColumns } from '@/lib/tableColumns';
import {
Alert as AAlert,
@@ -103,6 +103,91 @@ const syncTablePageSize = ref(50);
const syncTablePage = ref(1);
const syncOnlyNew = ref(false);
const autoCount = ref('0');
const autoHours = ref<string[]>([]);
const autoSyncSaving = ref(false);
const AUTO_HOUR_PRESETS: Record<number, number[]> = {
1: [8],
2: [8, 14],
3: [8, 12, 16],
4: [8, 12, 16, 20],
5: [8, 11, 14, 17, 20],
6: [8, 10, 12, 14, 16, 20],
};
const selectedConnection = computed(() =>
items.value.find((row) => row.id === sync.connectionId),
);
function hourLabel(hour: number) {
return `${toFaDigits(String(hour).padStart(2, '0'))}:۰۰`;
}
const autoCountOptions = [
{ value: '0', label: 'خاموش' },
...Array.from({ length: 6 }, (_, index) => ({
value: String(index + 1),
label: `${toFaDigits(index + 1)} بار`,
})),
];
const hourOptions = Array.from({ length: 24 }, (_, hour) => ({
value: String(hour),
label: hourLabel(hour),
}));
function fillAutoSync() {
const hours = [...(selectedConnection.value?.customerSyncHours ?? [])]
.sort((a, b) => a - b)
.slice(0, 6);
autoCount.value = String(hours.length);
autoHours.value = hours.map(String);
}
function onAutoCount(value: string) {
const count = Math.min(6, Math.max(0, Number(value) || 0));
const preset = AUTO_HOUR_PRESETS[count] ?? [];
const next = autoHours.value.slice(0, count);
while (next.length < count) {
next.push(String(preset[next.length] ?? 8));
}
autoCount.value = String(count);
autoHours.value = next;
}
function setAutoHour(index: number, value: string) {
autoHours.value[index] = value;
}
async function saveAutoSync() {
if (!sync.connectionId) return;
const hours = autoHours.value.map((hour) => Number(hour));
if (hours.some((hour) => !Number.isInteger(hour) || hour < 0 || hour > 23)) {
error.value = 'ساعت باید بین ۰ و ۲۳ باشد.';
return;
}
if (new Set(hours).size !== hours.length) {
error.value = 'ساعت‌ها نباید تکراری باشند.';
return;
}
autoSyncSaving.value = true;
error.value = '';
ok.value = '';
try {
await api.patch(`/integrations/tahesab/connections/${sync.connectionId}`, {
customerSyncHours: hours,
});
ok.value = hours.length
? 'زمان‌بندی بروزرسانی ذخیره شد.'
: 'بروزرسانی خودکار خاموش شد.';
await load();
} catch (e) {
error.value = apiErr(e, 'ذخیره زمان‌بندی ناموفق بود');
} finally {
autoSyncSaving.value = false;
}
}
const syncVisibleResults = computed(() =>
syncOnlyNew.value
? syncResults.value.filter((r) => !r.alreadyLinked)
@@ -115,6 +200,7 @@ const syncPagedResults = computed(() => {
const start = (syncTablePage.value - 1) * syncTablePageSize.value;
return syncVisibleResults.value.slice(start, start + syncTablePageSize.value);
});
watch(() => sync.connectionId, () => fillAutoSync());
watch([syncOnlyNew, syncTablePageSize], () => {
syncTablePage.value = 1;
});
@@ -207,6 +293,7 @@ async function load() {
if (!editingId.value) form.isDefault = data.length === 0;
if (!sync.connectionId && data[0]) sync.connectionId = data[0].id;
if (!productSync.connectionId && data[0]) productSync.connectionId = data[0].id;
fillAutoSync();
} catch (e) {
error.value = axios.isAxiosError(e)
? String(
@@ -964,6 +1051,53 @@ onMounted(load);
</a-row>
</a-form>
<a-card type="inner" title="بروزرسانی خودکار">
<a-flex vertical :gap="12">
<a-typography-text type="secondary">
تعداد دفعات در روز و ساعت هر بار را برای همین اتصال مشخص کنید. سرور در آن ساعت‌ها، به وقت تهران،
مشتریان تازه را وارد می‌کند و نام مشتری‌های قبلی را هم با ته‌حساب تازه می‌کند. اگر شماره یکی باشد
همان مشتری می‌ماند، نام قبلی حفظ می‌شود و شماره به شکل ۰۹۱۲ ذخیره می‌شود. خاموش یعنی فقط ورود دستی.
</a-typography-text>
<a-form layout="vertical">
<a-row :gutter="[16, 0]">
<a-col :xs="24" :md="8">
<a-form-item label="تعداد در روز">
<a-select
:value="autoCount"
:options="autoCountOptions"
:disabled="!sync.connectionId || autoSyncSaving"
@update:value="(value) => onAutoCount(String(value ?? '0'))"
/>
</a-form-item>
</a-col>
<a-col v-for="(_, index) in autoHours" :key="index" :xs="24" :md="8">
<a-form-item :label="`ساعت ${toFaDigits(index + 1)}`">
<a-select
:value="autoHours[index]"
:options="hourOptions"
:disabled="autoSyncSaving"
@update:value="(value) => setAutoHour(index, String(value ?? '8'))"
/>
</a-form-item>
</a-col>
</a-row>
</a-form>
<a-button :loading="autoSyncSaving" :disabled="!sync.connectionId" @click="saveAutoSync">
ذخیره زمان‌بندی
</a-button>
<a-typography-text v-if="selectedConnection?.customerSyncLastRunAt" type="secondary">
آخرین اجرا:
{{ formatJalaliDateTime(new Date(selectedConnection.customerSyncLastRunAt)) }}
<template v-if="selectedConnection.customerSyncLastSummary">
— {{ toFaDigits(selectedConnection.customerSyncLastSummary) }}
</template>
</a-typography-text>
<a-typography-text v-if="selectedConnection?.customerSyncLastError" type="danger">
آخرین خطا: {{ selectedConnection.customerSyncLastError }}
</a-typography-text>
</a-flex>
</a-card>
<a-card type="inner" title="۱) وارد کردن دسته‌ای با بازه کد مشتری">
<a-flex vertical :gap="12">
<a-typography-text type="secondary">