feat(shipping-notice): 添加识别定义和规则集管理功能,支持客户和站点的可配置识别规则

This commit is contained in:
hugo committed 2026-07-20 19:28:17 +08:00
1 parent 88408490d7
commit 34d489a2d1
167 files changed
+10365 -7978

No files matched your search

@@ -8,7 +8,8 @@
import { computed, onMounted, ref, watch } from 'vue';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { ArrowLeft, Download, ExternalLink, RefreshCw } from 'lucide-vue-next';
import { useAuthStore } from '@/features/auth';
import { Archive, ArrowLeft, Download, ExternalLink, RefreshCw, RotateCcw, Trash2 } from 'lucide-vue-next';
import ShippingWorkflowStepper from '@/features/chat/components/ShippingWorkflowStepper.vue';
import ShippingMatchResultCard from '@/features/chat/components/messages/ShippingMatchResultCard.vue';
import ShippingTaskParsedResultCard from '@/features/chat/components/ShippingTaskParsedResultCard.vue';
@@ -16,9 +17,13 @@ import { formatLocalDateTime } from '@/shared/utils/dateTime';
import { useMessage } from '@/shared/composables/useMessage';
import {
getWorkspaceShippingTask,
archiveWorkspaceShippingTasks,
deleteWorkspaceShippingTasks,
downloadWorkspaceShippingExportArchive,
listShippingChatAgents,
listWorkspaceShippingTasks,
purgeWorkspaceShippingTasks,
restoreWorkspaceShippingTasks,
SHIPPING_NOTICE_AGENT_CODE,
workspaceShippingExportUrl,
type ShippingCurrentStepProgress,
@@ -29,7 +34,6 @@ import { getAuthHeaders } from '@/shared/utils/auth';
import { resolveShippingWorkflowSteps } from '@/features/chat/shipping';
import { sanitizeShippingRuntimeStatusText } from '@/features/chat/shipping/shippingText';
import {
retainVisibleShippingExportSelection,
selectVisibleShippingExports,
updateShippingExportSelection,
} from '@/features/shipping-notice/utils/exportSelection';
@@ -42,16 +46,26 @@ const props = defineProps<{
const router = useRouter();
const { t, te } = useI18n();
const msg = useMessage();
const authStore = useAuthStore();
const isAdmin = computed(() => authStore.isAdmin);
const loading = ref(false);
const detailLoading = ref(false);
const tasks = ref<ShippingTaskSummary[]>([]);
const selectedTaskNo = ref<string | null>(null);
const selectedExportTaskNos = ref<string[]>([]);
const selectedTaskNos = ref<string[]>([]);
const archiveDownloading = ref(false);
const dispositionSubmitting = ref(false);
const detail = ref<ShippingTaskDetail | null>(null);
const statusFilter = ref('all');
const lifecycleFilter = ref('active');
const chatAgentId = ref<number | null>(null);
const currentPage = ref(1);
const pageSize = 10;
const totalTasks = ref(0);
const totalPages = computed(() => Math.max(1, Math.ceil(totalTasks.value / pageSize)));
const pageStart = computed(() => (totalTasks.value === 0 ? 0 : (currentPage.value - 1) * pageSize + 1));
const pageEnd = computed(() => Math.min(currentPage.value * pageSize, totalTasks.value));
const batchProgressLabel = computed(() => {
if (!detail.value?.batch_index || !detail.value?.batch_total) return '';
return t('chat.shippingNoticeUi.batchProgress', {
@@ -67,6 +81,12 @@ const statusOptions = computed(() => [
label: t(`workspace.shippingNotice.status.${labelKey}`),
})),
]);
const lifecycleOptions = computed(() => [
{ value: 'active', label: t('workspace.shippingNotice.lifecycle.active') },
{ value: 'deleted', label: t('workspace.shippingNotice.lifecycle.deleted') },
{ value: 'voided', label: t('workspace.shippingNotice.lifecycle.voided') },
{ value: 'archived', label: t('workspace.shippingNotice.lifecycle.archived') },
]);
type ShippingStatusSource = Pick<
ShippingTaskSummary,
@@ -179,24 +199,47 @@ const hasInventorySourceFields = computed(() => {
);
});
const loadCases = async () => {
/** 拉取当前筛选条件的一页任务;筛选/刷新时重置页码以避免落入空页。 */
const loadCases = async (resetPage = false) => {
if (resetPage) currentPage.value = 1;
loading.value = true;
try {
tasks.value = await listWorkspaceShippingTasks({
let result = await listWorkspaceShippingTasks({
process_status: statusFilter.value === 'all' ? undefined : statusFilter.value,
limit: 100,
lifecycle_status: lifecycleFilter.value,
page: currentPage.value,
page_size: pageSize,
});
selectedExportTaskNos.value = retainVisibleShippingExportSelection(
selectedExportTaskNos.value,
tasks.value.map((item) => item.task_no),
);
// 删除当前页最后一条后可能出现空页;回退一页重新查询,避免显示误导性的空结果。
if (result.items.length === 0 && result.total > 0 && currentPage.value > 1) {
currentPage.value = Math.ceil(result.total / pageSize);
result = await listWorkspaceShippingTasks({
process_status: statusFilter.value === 'all' ? undefined : statusFilter.value,
lifecycle_status: lifecycleFilter.value,
page: currentPage.value,
page_size: pageSize,
});
}
tasks.value = result.items;
totalTasks.value = result.total;
selectedTaskNos.value = [];
selectedTaskNo.value = null;
} catch {
tasks.value = [];
totalTasks.value = 0;
} finally {
loading.value = false;
}
};
/** 切换分页时清空仅当前页有效的下载选择,防止跨页误下载。 */
const changePage = async (page: number) => {
const normalized = Math.max(1, Math.min(page, totalPages.value));
if (normalized === currentPage.value || loading.value) return;
currentPage.value = normalized;
await loadCases();
};
const loadDetail = async (taskNo: string) => {
detailLoading.value = true;
try {
@@ -260,25 +303,59 @@ const downloadExportArchive = async (payload: { batch_no?: string; task_nos?: st
};
/** 更新单票勾选;数量门禁与后端 100 票限制一致。 */
const toggleExportTask = (taskNo: string, checked: boolean) => {
selectedExportTaskNos.value = updateShippingExportSelection(selectedExportTaskNos.value, taskNo, checked);
const toggleTask = (taskNo: string, checked: boolean) => {
selectedTaskNos.value = updateShippingExportSelection(selectedTaskNos.value, taskNo, checked);
};
/** 全选或清空当前查询结果,不跨筛选条件保留不可见任务。 */
const toggleAllVisibleExports = (checked: boolean) => {
selectedExportTaskNos.value = checked
/** 全选或清空当前页结果,切页后不保留选择。 */
const toggleAllVisibleTasks = (checked: boolean) => {
selectedTaskNos.value = checked
? selectVisibleShippingExports(tasks.value.map((item) => item.task_no))
: [];
};
const allVisibleExportsSelected = computed(() => (
tasks.value.length > 0 && tasks.value.every((item) => selectedExportTaskNos.value.includes(item.task_no))
const allVisibleTasksSelected = computed(() => (
tasks.value.length > 0 && tasks.value.every((item) => selectedTaskNos.value.includes(item.task_no))
));
/** 按用户显式选择下载,后端仍逐票执行权限与 Artifact 当前性校验。 */
const downloadSelectedExports = async () => {
if (!selectedExportTaskNos.value.length) return;
await downloadExportArchive({ task_nos: selectedExportTaskNos.value });
if (!selectedTaskNos.value.length) return;
await downloadExportArchive({ task_nos: selectedTaskNos.value });
};
/** 批量执行回收站、归档或恢复;删除必须显式录入原因,服务端仍逐票重算资格。 */
const applyTaskDisposition = async (action: 'delete' | 'archive' | 'restore' | 'purge') => {
if (!selectedTaskNos.value.length || dispositionSubmitting.value) return;
let reason = '';
if (action === 'delete' || action === 'purge') {
const promptKey = action === 'purge'
? 'workspace.shippingNotice.disposition.purgeReasonPrompt'
: 'workspace.shippingNotice.disposition.reasonPrompt';
reason = window.prompt(t(promptKey))?.trim() || '';
if (!reason) return;
}
if (!window.confirm(t('workspace.shippingNotice.disposition.confirm', {
action: t(`workspace.shippingNotice.disposition.actions.${action}`), count: selectedTaskNos.value.length,
}))) return;
dispositionSubmitting.value = true;
try {
const result = action === 'delete'
? await deleteWorkspaceShippingTasks(selectedTaskNos.value, reason)
: action === 'archive'
? await archiveWorkspaceShippingTasks(selectedTaskNos.value)
: action === 'restore'
? await restoreWorkspaceShippingTasks(selectedTaskNos.value)
: await purgeWorkspaceShippingTasks(selectedTaskNos.value, reason);
const blocked = result.results.filter((item) => item.status === 'blocked').length;
if (blocked) msg.error(t('workspace.shippingNotice.disposition.partial', { success: result.results.length - blocked, blocked }));
else msg.success(t('workspace.shippingNotice.disposition.success', { count: result.results.length }));
await loadCases();
} catch {
msg.error(t('workspace.shippingNotice.disposition.failed'));
} finally {
dispositionSubmitting.value = false;
}
};
const shortageLines = computed(() => detail.value?.shortage?.lines || []);
@@ -319,7 +396,7 @@ onMounted(async () => {
<button
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft"
@click="loadCases"
@click="loadCases(true)"
>
<RefreshCw class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.refresh') }}
@@ -333,34 +410,80 @@ onMounted(async () => {
<option v-for="opt in statusOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</option>
</select>
</div>
<div>
<label class="mb-1 block text-xs font-medium text-muted">{{ $t('workspace.shippingNotice.filters.lifecycle') }}</label>
<select v-model="lifecycleFilter" class="rounded-xl border border-default bg-surface px-3 py-2 text-sm">
<option v-for="opt in lifecycleOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</option>
</select>
</div>
<button
type="button"
class="rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700"
@click="loadCases"
@click="loadCases(true)"
>
{{ $t('workspace.shippingNotice.search') }}
</button>
<label class="ml-auto inline-flex items-center gap-2 text-sm text-secondary">
<input
type="checkbox"
:checked="allVisibleExportsSelected"
:checked="allVisibleTasksSelected"
:disabled="tasks.length === 0"
@change="toggleAllVisibleExports(($event.target as HTMLInputElement).checked)"
@change="toggleAllVisibleTasks(($event.target as HTMLInputElement).checked)"
>
{{ $t('workspace.shippingNotice.selectAllVisible') }}
</label>
<span class="text-sm text-muted">
{{ $t('workspace.shippingNotice.selectedCount', { count: selectedExportTaskNos.length }) }}
{{ $t('workspace.shippingNotice.selectedCount', { count: selectedTaskNos.length }) }}
</span>
<button
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-default px-3 py-2 text-sm font-medium text-secondary hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
:disabled="selectedExportTaskNos.length === 0 || archiveDownloading"
:disabled="selectedTaskNos.length === 0 || archiveDownloading"
@click="downloadSelectedExports"
>
<Download class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.downloadSelected') }}
</button>
<button
v-if="lifecycleFilter === 'active'"
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-default px-3 py-2 text-sm font-medium text-secondary hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
:disabled="selectedTaskNos.length === 0 || dispositionSubmitting"
@click="applyTaskDisposition('archive')"
>
<Archive class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.disposition.actions.archive') }}
</button>
<button
v-if="lifecycleFilter === 'active'"
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-rose-300 px-3 py-2 text-sm font-medium text-rose-700 hover:bg-rose-50 disabled:cursor-not-allowed disabled:opacity-50"
:disabled="selectedTaskNos.length === 0 || dispositionSubmitting"
@click="applyTaskDisposition('delete')"
>
<Trash2 class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.disposition.actions.delete') }}
</button>
<button
v-if="lifecycleFilter === 'deleted'"
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-default px-3 py-2 text-sm font-medium text-secondary hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
:disabled="selectedTaskNos.length === 0 || dispositionSubmitting"
@click="applyTaskDisposition('restore')"
>
<RotateCcw class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.disposition.actions.restore') }}
</button>
<button
v-if="lifecycleFilter === 'deleted' && isAdmin"
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-rose-300 px-3 py-2 text-sm font-medium text-rose-700 hover:bg-rose-50 disabled:cursor-not-allowed disabled:opacity-50"
:disabled="selectedTaskNos.length === 0 || dispositionSubmitting"
@click="applyTaskDisposition('purge')"
>
<Trash2 class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.disposition.actions.purge') }}
</button>
</div>
<div class="grid gap-5 lg:grid-cols-5">
@@ -381,8 +504,8 @@ onMounted(async () => {
type="checkbox"
class="mt-1"
:aria-label="$t('workspace.shippingNotice.selectForDownload', { taskNo: item.task_no })"
:checked="selectedExportTaskNos.includes(item.task_no)"
@change="toggleExportTask(item.task_no, ($event.target as HTMLInputElement).checked)"
:checked="selectedTaskNos.includes(item.task_no)"
@change="toggleTask(item.task_no, ($event.target as HTMLInputElement).checked)"
>
<button type="button" class="min-w-0 flex-1 text-left" @click="selectedTaskNo = item.task_no">
<div class="flex items-center justify-between gap-2">
@@ -404,6 +527,31 @@ onMounted(async () => {
</div>
</button>
</article>
<div
v-if="totalTasks > 0"
class="flex items-center justify-between gap-2 pt-2 text-sm text-muted"
>
<span>{{ $t('workspace.shippingNotice.pagination.summary', { start: pageStart, end: pageEnd, total: totalTasks }) }}</span>
<div class="flex items-center gap-2">
<button
type="button"
class="rounded-lg border border-default px-2.5 py-1.5 text-secondary hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
:disabled="currentPage <= 1 || loading"
@click="changePage(currentPage - 1)"
>
{{ $t('workspace.shippingNotice.pagination.previous') }}
</button>
<span class="whitespace-nowrap">{{ $t('workspace.shippingNotice.pagination.page', { page: currentPage, total: totalPages }) }}</span>
<button
type="button"
class="rounded-lg border border-default px-2.5 py-1.5 text-secondary hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
:disabled="currentPage >= totalPages || loading"
@click="changePage(currentPage + 1)"
>
{{ $t('workspace.shippingNotice.pagination.next') }}
</button>
</div>
</div>
</div>
<div class="lg:col-span-3 rounded-2xl border border-default bg-surface/50 p-5">