feat(shipping-notice): 落地字段资产治理与唯一 Schema,自动建单随版本冻结

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-07-29 16:23:15 +08:00
1 parent b7307fc573
commit 3a1dbf7ce5
144 files changed
+15167 -4480

No files matched your search

@@ -0,0 +1,484 @@
/**
* features/workspace/shipping-task-center/ShippingTaskCenterPage.vue
* 用途:发货「我的待办」壳——Pending|Processing|Done + 右侧任务工作台或复核深链。
* 依赖:shipping-tasks.api(my-todos)、shipping.api 详情、ShippingTaskWorkbench、useShippingTodoBadge。
* 逻辑:review_case 项用 review_run_no 打开人工复核;task 项打开任务处理工作台。
*/
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { ExternalLink, RefreshCw } from 'lucide-vue-next';
import {
getWorkspaceShippingTask,
listShippingChatAgents,
SHIPPING_NOTICE_AGENT_CODE,
type ShippingTaskDetail,
type ShippingTaskSummary,
} from '@/features/chat/api/shipping.api';
import {
countWorkspaceShippingMyTodos,
listWorkspaceShippingMyTodos,
type ShippingMyTodosCount,
} from '@/features/workspace/api/shipping-tasks.api';
import { useShippingTodoBadge } from '../composables/useShippingTodoBadge';
import ShippingTaskWorkbench from './ShippingTaskWorkbench.vue';
const route = useRoute();
const router = useRouter();
const { refreshShippingTodoBadge } = useShippingTodoBadge();
const bucket = ref<'pending' | 'processing' | 'done'>('pending');
const filterTodoCategory = ref<'all' | 'review' | 'exception' | 'manual_upload'>('all');
const filterCustomer = ref('');
const filterTaskNo = ref('');
const appliedFilters = ref({
todo_category: '',
customer: '',
task_no: '',
});
const loading = ref(false);
const detailLoading = ref(false);
const tasks = ref<ShippingTaskSummary[]>([]);
const selectedRef = ref<string | null>(null);
const detail = ref<ShippingTaskDetail | null>(null);
const currentPage = ref(1);
const pageSize = 20;
const totalTasks = ref(0);
const bucketCounts = ref<ShippingMyTodosCount>({
pending: 0,
processing: 0,
done: 0,
total_pending_badge: 0,
});
const chatAgentId = ref<number | null>(null);
const totalPages = computed(() => Math.max(1, Math.ceil(totalTasks.value / pageSize)));
const canHandle = computed(() => detail.value?.can_handle !== false);
const preferredTaskNo = computed(() =>
String(route.params.taskNo || route.query.task_no || '').trim().toUpperCase(),
);
const preferredReviewRun = computed(() => String(route.query.run_no || '').trim());
const selectedItem = computed(() =>
tasks.value.find((item) => todoItemKey(item) === selectedRef.value) || null,
);
const isReviewSelection = computed(() => selectedItem.value?.item_kind === 'review_case'
|| Boolean(selectedItem.value?.review_run_no && !selectedItem.value?.task_no));
/**
* 待办列表项稳定主键:复核用 case_no,任务用 task_no。
*/
function todoItemKey(item: ShippingTaskSummary): string {
if (item.item_kind === 'review_case' || item.review_case_no) {
return String(item.todo_ref || item.review_case_no || item.review_run_no || '');
}
return String(item.todo_ref || item.task_no || '');
}
/**
* 列表展示编号:复核显示 case_no,任务显示 SN。
*/
function todoDisplayNo(item: ShippingTaskSummary): string {
if (item.item_kind === 'review_case' || item.review_case_no) {
return String(item.review_case_no || item.review_run_no || item.todo_ref || '—');
}
return String(item.task_no || item.todo_ref || '—');
}
/**
* 解析货代 Chat Agent,供复核/会话深链。
*/
async function resolveChatAgent() {
try {
const agents = await listShippingChatAgents();
const found = agents.find((a) => String(a.agent_code || '').trim() === SHIPPING_NOTICE_AGENT_CODE);
if (found) chatAgentId.value = found.id;
} catch {
/* ignore */
}
}
/**
* 刷新各 bucket 计数与导航徽标。
*/
async function loadCounts() {
try {
bucketCounts.value = await countWorkspaceShippingMyTodos();
await refreshShippingTodoBadge(true);
} catch {
/* 计数失败不阻断列表 */
}
}
/**
* 将筛选表单同步为已应用条件并重置到第 1 页。
*/
function applyFilters() {
appliedFilters.value = {
todo_category: bucket.value === 'pending' && filterTodoCategory.value !== 'all'
? filterTodoCategory.value
: '',
customer: filterCustomer.value.trim(),
task_no: filterTaskNo.value.trim().toUpperCase(),
};
void loadTodos(true);
}
/**
* 清空筛选条件并重新拉取列表。
*/
function resetFilters() {
filterTodoCategory.value = 'all';
filterCustomer.value = '';
filterTaskNo.value = '';
appliedFilters.value = { todo_category: '', customer: '', task_no: '' };
void loadTodos(true);
}
/**
* 按当前 bucket 分页拉取「我的待办」;优先选中路由 task_no / run_no。
*/
async function loadTodos(resetPage = false) {
if (resetPage) currentPage.value = 1;
loading.value = true;
try {
const res = await listWorkspaceShippingMyTodos({
bucket: bucket.value,
page: currentPage.value,
page_size: pageSize,
...(appliedFilters.value.todo_category ? { todo_category: appliedFilters.value.todo_category } : {}),
...(appliedFilters.value.customer ? { customer: appliedFilters.value.customer } : {}),
...(appliedFilters.value.task_no ? { task_no: appliedFilters.value.task_no } : {}),
});
tasks.value = res.items || [];
totalTasks.value = Number(res.total || 0);
const byTask = preferredTaskNo.value
? tasks.value.find((item) => String(item.task_no || '').toUpperCase() === preferredTaskNo.value)
: null;
const byRun = preferredReviewRun.value
? tasks.value.find((item) => String(item.review_run_no || '') === preferredReviewRun.value)
: null;
const preferred = byTask || byRun;
if (preferred) {
selectedRef.value = todoItemKey(preferred);
} else if (selectedRef.value && !tasks.value.some((item) => todoItemKey(item) === selectedRef.value)) {
selectedRef.value = tasks.value[0] ? todoItemKey(tasks.value[0]) : null;
} else if (!selectedRef.value && tasks.value[0]) {
selectedRef.value = todoItemKey(tasks.value[0]);
}
} catch {
tasks.value = [];
totalTasks.value = 0;
} finally {
loading.value = false;
}
}
/**
* 拉取任务详情;复核项不拉 Task API。
*/
async function loadDetail(taskNo: string) {
detailLoading.value = true;
try {
detail.value = await getWorkspaceShippingTask(taskNo);
} catch {
detail.value = null;
} finally {
detailLoading.value = false;
}
}
/**
* 列表与详情联动刷新。
*/
async function refreshAll() {
await Promise.all([loadTodos(), loadCounts()]);
const item = selectedItem.value;
if (item?.task_no && item.item_kind !== 'review_case') {
await loadDetail(item.task_no);
}
}
/**
* 打开人工复核工作台(Chat 主区替换为 order-review 模式)。
*/
function openReview(item: ShippingTaskSummary) {
const runNo = String(item.review_run_no || '').trim();
if (!runNo) return;
const agentId = Number(item.owner_agent_id || chatAgentId.value || 0);
if (!agentId) return;
const query: Record<string, string> = {
mode: 'order-review',
run_no: runNo,
};
const cid = String(item.conversation_id || '').trim();
if (cid) query.conversation_id = cid;
const caseNo = String(item.review_case_no || '').trim();
if (caseNo) query.case_no = caseNo;
void router.push({ path: `/chat/${agentId}`, query });
}
/**
* 可选深链:打开 Chat 会话查看上下文(非履约写入口)。
*/
function openInChat() {
if (!chatAgentId.value || !detail.value) return;
const query: Record<string, string> = { task_id: detail.value.task_no };
const batchNo = String(detail.value.batch_no || '').trim();
if (batchNo) query.batch_no = batchNo;
const cid = String(detail.value.conversation_id || '').trim();
if (/^[0-9a-f]{32}$/i.test(cid)) query.conversation_id = cid;
void router.push({ path: `/chat/${chatAgentId.value}`, query });
}
/**
* 选中列表项:复核显示入口卡;任务加载工作台详情。
*/
async function selectTodo(item: ShippingTaskSummary) {
selectedRef.value = todoItemKey(item);
const nextQuery: Record<string, string> = { ...route.query as Record<string, string> };
if (item.item_kind === 'review_case' || item.review_run_no) {
delete nextQuery.task_no;
if (item.review_run_no) nextQuery.run_no = String(item.review_run_no);
detail.value = null;
} else if (item.task_no) {
delete nextQuery.run_no;
nextQuery.task_no = item.task_no;
await loadDetail(item.task_no);
}
void router.replace({
name: route.name || 'workspace-shipping-my-tasks',
params: route.params,
query: nextQuery,
});
}
watch(bucket, () => {
selectedRef.value = null;
detail.value = null;
filterTodoCategory.value = 'all';
appliedFilters.value = {
...appliedFilters.value,
todo_category: '',
};
void loadTodos(true);
});
watch(selectedItem, (item) => {
if (!item) {
detail.value = null;
return;
}
if (item.item_kind === 'review_case' || (item.review_run_no && !item.task_no)) {
detail.value = null;
return;
}
if (item.task_no && detail.value?.task_no !== item.task_no) {
void loadDetail(item.task_no);
}
});
onMounted(async () => {
await Promise.all([resolveChatAgent(), loadCounts(), loadTodos()]);
if (preferredTaskNo.value) {
const hit = tasks.value.find((item) => String(item.task_no || '').toUpperCase() === preferredTaskNo.value);
if (!hit) {
selectedRef.value = preferredTaskNo.value;
await loadDetail(preferredTaskNo.value);
}
}
});
</script>
<template>
<div class="space-y-5 animate-fade-in-up">
<div class="flex items-center justify-between gap-3">
<div>
<h2 class="text-2xl font-bold text-primary">{{ $t('workspace.shippingNotice.myTodos.title') }}</h2>
<p class="text-sm text-muted">{{ $t('workspace.shippingNotice.myTodos.subtitle') }}</p>
</div>
<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 hover:bg-surface-soft"
@click="refreshAll"
>
<RefreshCw class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.refresh') }}
</button>
</div>
<div class="flex flex-wrap gap-2">
<button
v-for="key in (['pending', 'processing', 'done'] as const)"
:key="key"
type="button"
class="rounded-xl px-3 py-1.5 text-sm font-medium"
:class="bucket === key ? 'bg-brand-600 text-white' : 'border border-default text-secondary hover:bg-surface-soft'"
@click="bucket = key"
>
{{ $t(`workspace.shippingNotice.myTodos.buckets.${key}`) }}
<span class="ml-1 opacity-80">({{ bucketCounts[key] }})</span>
</button>
</div>
<div class="flex flex-wrap items-end gap-3 rounded-2xl border border-default bg-surface px-4 py-3">
<label v-if="bucket === 'pending'" class="space-y-1">
<span class="text-xs font-medium text-muted">{{ $t('workspace.shippingNotice.myTodos.filters.todoCategory') }}</span>
<select v-model="filterTodoCategory" class="input-field text-sm min-w-[9rem]">
<option value="all">{{ $t('workspace.shippingNotice.myTodos.filters.all') }}</option>
<option value="review">{{ $t('workspace.shippingNotice.myTodos.filters.review') }}</option>
<option value="exception">{{ $t('workspace.shippingNotice.myTodos.filters.exception') }}</option>
<option value="manual_upload">{{ $t('workspace.shippingNotice.myTodos.filters.manualUpload') }}</option>
</select>
</label>
<label class="space-y-1 flex-1 min-w-[10rem]">
<span class="text-xs font-medium text-muted">{{ $t('workspace.shippingNotice.myTodos.filters.customer') }}</span>
<input
v-model="filterCustomer"
type="text"
class="input-field text-sm w-full"
:placeholder="$t('workspace.shippingNotice.myTodos.filters.customerPlaceholder')"
@keyup.enter="applyFilters"
/>
</label>
<label class="space-y-1 flex-1 min-w-[10rem]">
<span class="text-xs font-medium text-muted">{{ $t('workspace.shippingNotice.myTodos.filters.taskNo') }}</span>
<input
v-model="filterTaskNo"
type="text"
class="input-field text-sm w-full font-mono uppercase"
:placeholder="$t('workspace.shippingNotice.myTodos.filters.taskNoPlaceholder')"
@keyup.enter="applyFilters"
/>
</label>
<div class="flex gap-2">
<button
type="button"
class="rounded-xl bg-brand-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-brand-700 disabled:opacity-50"
:disabled="loading"
@click="applyFilters"
>
{{ $t('workspace.shippingNotice.myTodos.filters.apply') }}
</button>
<button
type="button"
class="rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary hover:bg-surface-soft disabled:opacity-50"
:disabled="loading"
@click="resetFilters"
>
{{ $t('workspace.shippingNotice.myTodos.filters.reset') }}
</button>
</div>
</div>
<div class="grid gap-5 lg:grid-cols-[minmax(18rem,0.85fr)_minmax(0,2.15fr)]">
<div class="space-y-2">
<div v-if="loading" class="rounded-2xl border border-dashed border-default py-10 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.loading') }}
</div>
<div v-else-if="!tasks.length" class="rounded-2xl border border-dashed border-default py-10 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.myTodos.empty') }}
</div>
<button
v-for="item in tasks"
:key="todoItemKey(item)"
type="button"
class="w-full rounded-2xl border px-4 py-3 text-left transition-colors"
:class="selectedRef === todoItemKey(item) ? 'border-brand-400 bg-brand-50/60' : 'border-default hover:bg-surface-soft/70'"
@click="selectTodo(item)"
>
<div class="flex items-center justify-between gap-2">
<span class="font-mono text-sm font-semibold text-primary">{{ todoDisplayNo(item) }}</span>
<span
v-if="item.todo_category === 'review' || item.item_kind === 'review_case'"
class="rounded-full bg-amber-50 px-2 py-0.5 text-[10px] text-amber-700"
>
{{ $t('workspace.shippingNotice.myTodos.openReview') }}
</span>
<span
v-else-if="item.can_handle === false"
class="rounded-full bg-slate-100 px-2 py-0.5 text-[10px] text-slate-600"
>
{{ $t('workspace.shippingNotice.todo.adminViewOnlyShort') }}
</span>
</div>
<div class="mt-1 truncate text-sm text-secondary">
{{ item.ui_state?.summary?.current_todo || item.ui_state?.summary?.title || item.process_status }}
</div>
<div class="mt-1 truncate text-xs text-muted">
{{ item.customer_name || item.source_file_name || item.review_run_no || '—' }}
</div>
</button>
<div v-if="totalPages > 1" class="flex items-center justify-between gap-2 pt-2 text-xs text-muted">
<button
type="button"
class="rounded-lg border border-default px-2 py-1 disabled:opacity-50"
:disabled="currentPage <= 1 || loading"
@click="currentPage -= 1; loadTodos()"
>
{{ $t('workspace.shippingNotice.pagination.previous') }}
</button>
<span>{{ currentPage }}/{{ totalPages }}</span>
<button
type="button"
class="rounded-lg border border-default px-2 py-1 disabled:opacity-50"
:disabled="currentPage >= totalPages || loading"
@click="currentPage += 1; loadTodos()"
>
{{ $t('workspace.shippingNotice.pagination.next') }}
</button>
</div>
</div>
<div>
<div
v-if="isReviewSelection && selectedItem"
class="space-y-4 rounded-2xl border border-default bg-surface p-6"
>
<div class="font-mono text-lg font-bold text-primary">{{ todoDisplayNo(selectedItem) }}</div>
<p class="text-sm text-secondary">
{{ selectedItem.ui_state?.summary?.message || selectedItem.ui_state?.summary?.current_todo }}
</p>
<p v-if="selectedItem.source_file_name" class="text-xs text-muted">
{{ selectedItem.source_file_name }}
<span v-if="selectedItem.review_run_no"> · {{ selectedItem.review_run_no }}</span>
</p>
<button
type="button"
class="inline-flex items-center gap-1.5 rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700 disabled:opacity-50"
:disabled="!selectedItem.review_run_no || !(selectedItem.owner_agent_id || chatAgentId)"
@click="openReview(selectedItem)"
>
<ExternalLink class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.myTodos.openReview') }}
</button>
</div>
<div v-else-if="detailLoading" class="rounded-2xl border border-dashed border-default py-16 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.loading') }}
</div>
<div v-else-if="!detail" class="rounded-2xl border border-dashed border-default py-16 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.selectCase') }}
</div>
<div v-else class="space-y-3">
<div class="flex flex-wrap items-center justify-between gap-2">
<div class="font-mono text-lg font-bold text-primary">{{ detail.task_no }}</div>
<button
v-if="chatAgentId"
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-default px-3 py-1.5 text-xs font-medium text-secondary hover:bg-surface-soft"
@click="openInChat"
>
<ExternalLink class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.openChat') }}
</button>
</div>
<ShippingTaskWorkbench
:detail="detail"
:can-handle="canHandle"
@refreshed="refreshAll"
/>
</div>
</div>
</div>
</div>
</template>