feat(agent): 立账凭证检核

(cherry picked from commit f9e2fb5efc1ec7bf4f6e52e08dd3591b4e77edd9)
This commit is contained in:
sophie committed 2026-08-06 10:05:46 +08:00
1 parent 9bcbf9d211
commit f615e56bb9
70 files changed
+4968 -108

No files matched your search

@@ -1,11 +1,11 @@
<script setup lang="ts">
/**
* features/chat/components/ToolRunProgressCard.vue
* 用途:展示文件检核等 Agent 异步 tool_run 的实时进度、知识库同步态与 Excel 下载。
* 用途:展示文件检核/立账凭证检核等 Agent 异步 tool_run 的实时进度、知识库同步态与 Excel 下载。
* 依赖:vue-i18n、lucide 图标、getAuthHeaders、toolRunProgress.api。
* 逻辑:由聊天消息列表在绑定 run_id 后挂载;轮询结果经 props.run 传入,本组件只负责展示与下载。
* 逻辑:由聊天消息列表在绑定 run_id 后挂载;有 progress_metrics 时按领域指标渲染,否则回退八格。
*/
import { ref } from 'vue';
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { AlertCircle, CheckCircle2, Clock3, Download, Loader2 } from 'lucide-vue-next';
import { getAuthHeaders } from '@/shared/utils/auth';
@@ -19,10 +19,26 @@ const props = defineProps<{
fallbackTitle?: string;
}>();
const { t } = useI18n();
const { t, te } = useI18n();
const downloadingExcel = ref(false);
const downloadError = ref('');
/**
* 领域自定义进度指标;有值时覆盖默认文件检核八格。
* 核心逻辑:读取 progress_metrics,按 label_key 做 i18n,缺省回退 label/key。
*/
const domainMetrics = computed(() => {
const metrics = props.run?.progress_metrics;
if (!Array.isArray(metrics) || !metrics.length) return null;
return metrics.map((item) => {
const labelKey = String(item.label_key || '').trim();
const label = labelKey && te(labelKey)
? t(labelKey)
: (item.label || item.key);
return { key: item.key, label, value: Number(item.value) || 0 };
});
});
/**
* 将后端 run.status 映射为本地化状态文案。
* 核心逻辑:命中已知状态码用 i18n;未知状态回退原始值,再回退“等待中”。
@@ -215,7 +231,20 @@ const downloadExcel = async () => {
<span>{{ $t('chat.toolRun.startedAt', { time: formatTime(run.started_at) }) }} · {{ $t('chat.toolRun.finishedAt', { time: formatTime(run.finished_at) }) }}</span>
</div>
<div class="grid grid-cols-2 gap-1.5 sm:grid-cols-4 lg:grid-cols-8">
<div
v-if="domainMetrics"
class="grid grid-cols-2 gap-1.5 sm:grid-cols-3 lg:grid-cols-5"
>
<div
v-for="metric in domainMetrics"
:key="metric.key"
class="rounded-lg bg-white/80 px-2 py-1.5"
>
<div class="whitespace-nowrap text-xs text-slate-500">{{ metric.label }}</div>
<div class="text-base font-bold text-slate-800">{{ metric.value }}</div>
</div>
</div>
<div v-else class="grid grid-cols-2 gap-1.5 sm:grid-cols-4 lg:grid-cols-8">
<div class="rounded-lg bg-white/80 px-2 py-1.5">
<div class="whitespace-nowrap text-xs text-slate-500">{{ $t('chat.toolRun.total') }}</div>
<div class="text-base font-bold text-slate-800">{{ run.total_count }}</div>
@@ -31,6 +31,13 @@ export interface ToolRunProgress {
dify_error_count?: number;
invalid_result_count?: number;
};
/** 领域自定义指标;有值时进度卡按此渲染,否则回退文件检核八格 */
progress_metrics?: Array<{
key: string;
label_key?: string;
label?: string;
value: number;
}> | null;
progress_percent: number;
started_at?: string | null;
finished_at?: string | null;
@@ -0,0 +1,91 @@
/**
* features/workspace/api/voucherCheck.api.ts
* 用途:工作台立账凭证检核记录查询 API 客户端。
* 依赖:@/shared/api/client、getAuthHeaders。
* 逻辑:AccountingVoucherCheckView 调用;对应 /api/workspace/accounting-voucher-check/*。
*/
import { requestJson } from '@/shared/api/client';
import { getAuthHeaders } from '@/shared/utils/auth';
export interface VoucherCheckStateItem {
id: number;
scope_code: string;
period_month: string | null;
invoice_no: string;
invoice_date?: string | null;
status: string;
folder_path?: string | null;
folder_exists?: boolean;
matched_files?: Record<string, string>;
missing_materials?: Array<{ code?: string; name?: string }>;
last_checked_at?: string | null;
last_missing_notified_on?: string | null;
}
export interface VoucherCheckStatesResponse {
scope_code: string;
period: string;
page: number;
page_size: number;
total: number;
items: VoucherCheckStateItem[];
}
export interface VoucherCheckRunItemsResponse {
run_id: number;
run_no: string;
page: number;
page_size: number;
total: number;
items: Array<{
id: number;
invoice_no: string;
invoice_date?: string | null;
result: string;
folder_path?: string | null;
folder_exists?: boolean;
matched_files?: Record<string, string>;
missing_materials?: Array<{ code?: string; name?: string }>;
error_code?: string | null;
error_message?: string | null;
checked_at?: string | null;
}>;
}
/**
* 按月份/状态/发票号筛选最新检核状态。
*/
export function listVoucherCheckStates(params: {
period?: string;
status?: string;
invoice_no?: string;
page?: number;
page_size?: number;
}) {
const q = new URLSearchParams();
if (params.period) q.set('period', params.period);
if (params.status) q.set('status', params.status);
if (params.invoice_no) q.set('invoice_no', params.invoice_no);
if (params.page) q.set('page', String(params.page));
if (params.page_size) q.set('page_size', String(params.page_size));
const qs = q.toString();
return requestJson<VoucherCheckStatesResponse>(
`/api/workspace/accounting-voucher-check/states${qs ? `?${qs}` : ''}`,
{ headers: getAuthHeaders() },
);
}
/**
* 分页查询指定批次明细。
*/
export function listVoucherCheckRunItems(runId: number, params?: { result?: string; page?: number; page_size?: number }) {
const q = new URLSearchParams();
if (params?.result) q.set('result', params.result);
if (params?.page) q.set('page', String(params.page));
if (params?.page_size) q.set('page_size', String(params.page_size));
const qs = q.toString();
return requestJson<VoucherCheckRunItemsResponse>(
`/api/workspace/accounting-voucher-check/runs/${runId}/items${qs ? `?${qs}` : ''}`,
{ headers: getAuthHeaders() },
);
}
@@ -8,7 +8,7 @@
import { inject } from 'vue';
import { useRoute } from 'vue-router';
import {
LayoutGrid, Bot, FileText, User, LogOut, Edit, Megaphone, Clock, Package, PanelLeftClose, PanelLeftOpen,
LayoutGrid, Bot, FileText, User, LogOut, Edit, Megaphone, Clock, Package, PanelLeftClose, PanelLeftOpen, ClipboardCheck,
} from 'lucide-vue-next';
import { WORKSPACE_PATHS } from '../constants/routes';
import { WORKSPACE_KEY } from '../composables/workspace.context';
@@ -26,6 +26,7 @@ const linkItems = [
{ path: WORKSPACE_PATHS.applications, labelKey: 'workspace.nav.applications', icon: LayoutGrid, match: ['workspace-applications'] },
{ path: WORKSPACE_PATHS.scheduleRuns, labelKey: 'workspace.nav.scheduleRuns', icon: Clock, match: ['workspace-schedule-runs'] },
{ path: WORKSPACE_PATHS.shippingNotice, labelKey: 'workspace.nav.shippingNotice', icon: Package, match: ['workspace-shipping-notice'] },
{ path: WORKSPACE_PATHS.accountingVoucherCheck, labelKey: 'workspace.nav.accountingVoucherCheck', icon: ClipboardCheck, match: ['workspace-accounting-voucher-check'] },
{ path: WORKSPACE_PATHS.feedback, labelKey: 'workspace.nav.feedback', icon: Edit, match: ['workspace-feedback'] },
{ path: WORKSPACE_PATHS.updates, labelKey: 'workspace.nav.updates', icon: Megaphone, match: ['workspace-updates'] },
] as const;
@@ -10,6 +10,7 @@ export const WORKSPACE_PATHS = {
knowledgeBase: '/workspace/knowledge-base',
scheduleRuns: '/workspace/schedule-runs',
shippingNotice: '/workspace/shipping-notice',
accountingVoucherCheck: '/workspace/accounting-voucher-check',
feedback: '/workspace/feedback',
history: '/workspace/history',
} as const;
@@ -23,6 +24,7 @@ export const LEGACY_VIEW_TO_PATH: Record<string, string> = {
knowledge_base: WORKSPACE_PATHS.knowledgeBase,
schedule_runs: WORKSPACE_PATHS.scheduleRuns,
shipping_notice: WORKSPACE_PATHS.shippingNotice,
accounting_voucher_check: WORKSPACE_PATHS.accountingVoucherCheck,
history: WORKSPACE_PATHS.history,
};
@@ -0,0 +1,13 @@
<script setup lang="ts">
/**
* features/workspace/pages/AccountingVoucherCheckPage.vue
* 用途:立账凭证检核工作台页面壳。
* 依赖:AccountingVoucherCheckView。
* 逻辑:路由懒加载入口。
*/
import AccountingVoucherCheckView from '../views/AccountingVoucherCheckView.vue';
</script>
<template>
<AccountingVoucherCheckView />
</template>
@@ -0,0 +1,255 @@
<script setup lang="ts">
/**
* features/workspace/views/AccountingVoucherCheckView.vue
* 用途:立账凭证检核记录页——按月筛选最新状态与缺资料票。
* 依赖:voucherCheck.api、vue-i18n、useMessage。
* 逻辑:路由 /workspace/accounting-voucher-check;企微 textcard 也可跳转至此。
*/
import { computed, onMounted, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { Loader2, RefreshCw, Search } from 'lucide-vue-next';
import { useMessage } from '@/shared/composables/useMessage';
import {
listVoucherCheckRunItems,
listVoucherCheckStates,
type VoucherCheckStateItem,
} from '../api/voucherCheck.api';
const { t } = useI18n();
const msg = useMessage();
const route = useRoute();
const loading = ref(false);
const items = ref<VoucherCheckStateItem[]>([]);
const total = ref(0);
const page = ref(1);
const pageSize = 50;
const period = ref('');
const status = ref('');
const invoiceNo = ref('');
const runIdFilter = ref<number | null>(null);
const runItems = ref<Awaited<ReturnType<typeof listVoucherCheckRunItems>>['items']>([]);
/**
* 默认检核月份(当前自然月 YYYY-MM)。
*/
function currentPeriod(): string {
const d = new Date();
const m = String(d.getMonth() + 1).padStart(2, '0');
return `${d.getFullYear()}-${m}`;
}
const statusOptions = computed(() => [
{ value: '', label: t('workspace.voucherCheck.statusAll') },
{ value: 'complete', label: t('workspace.voucherCheck.statusComplete') },
{ value: 'missing', label: t('workspace.voucherCheck.statusMissing') },
]);
/**
* 加载最新状态列表。
*/
async function loadStates() {
loading.value = true;
try {
const data = await listVoucherCheckStates({
period: period.value || undefined,
status: status.value || undefined,
invoice_no: invoiceNo.value || undefined,
page: page.value,
page_size: pageSize,
});
items.value = data.items || [];
total.value = data.total || 0;
if (data.period && !period.value) period.value = data.period;
} catch (e: any) {
msg.error(e?.message || t('workspace.voucherCheck.loadFailed'));
} finally {
loading.value = false;
}
}
/**
* 若 URL 带 run_id,额外加载该批次明细。
*/
async function loadRunItemsIfNeeded() {
const raw = route.query.run_id;
const id = Number(Array.isArray(raw) ? raw[0] : raw);
if (!Number.isFinite(id) || id <= 0) {
runIdFilter.value = null;
runItems.value = [];
return;
}
runIdFilter.value = id;
try {
const data = await listVoucherCheckRunItems(id, { page: 1, page_size: 100 });
runItems.value = data.items || [];
} catch (e: any) {
msg.error(e?.message || t('workspace.voucherCheck.loadFailed'));
}
}
function statusLabel(value: string) {
if (value === 'complete') return t('workspace.voucherCheck.statusComplete');
if (value === 'missing') return t('workspace.voucherCheck.statusMissing');
if (value === 'skipped') return t('workspace.voucherCheck.statusSkipped');
if (value === 'technical_error') return t('workspace.voucherCheck.statusTechError');
return value || '-';
}
function formatMissing(list?: Array<{ code?: string; name?: string }>) {
if (!list?.length) return '-';
return list.map((x) => x.name || x.code || '').filter(Boolean).join('、');
}
onMounted(async () => {
period.value = currentPeriod();
const qStatus = route.query.status;
if (typeof qStatus === 'string' && qStatus) status.value = qStatus;
await Promise.all([loadStates(), loadRunItemsIfNeeded()]);
});
watch(
() => route.query.run_id,
() => {
void loadRunItemsIfNeeded();
},
);
</script>
<template>
<div class="mx-auto flex h-full w-full max-w-6xl flex-col gap-4 p-4 md:p-6">
<header class="space-y-1">
<h1 class="text-xl font-semibold text-slate-800">{{ $t('workspace.voucherCheck.title') }}</h1>
<p class="text-sm text-slate-500">{{ $t('workspace.voucherCheck.subtitle') }}</p>
</header>
<section class="flex flex-wrap items-end gap-3 rounded-xl border border-slate-200 bg-white p-3">
<label class="flex flex-col gap-1 text-xs text-slate-500">
{{ $t('workspace.voucherCheck.period') }}
<input v-model="period" type="month" class="rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800" />
</label>
<label class="flex flex-col gap-1 text-xs text-slate-500">
{{ $t('workspace.voucherCheck.status') }}
<select v-model="status" class="rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800">
<option v-for="opt in statusOptions" :key="opt.value || 'all'" :value="opt.value">{{ opt.label }}</option>
</select>
</label>
<label class="flex min-w-[12rem] flex-1 flex-col gap-1 text-xs text-slate-500">
{{ $t('workspace.voucherCheck.invoiceNo') }}
<input
v-model="invoiceNo"
type="text"
class="rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800"
:placeholder="$t('workspace.voucherCheck.invoicePlaceholder')"
@keyup.enter="page = 1; loadStates()"
/>
</label>
<button
type="button"
class="inline-flex items-center gap-1 rounded-lg bg-sky-600 px-3 py-2 text-sm font-medium text-white hover:bg-sky-700"
@click="page = 1; loadStates()"
>
<Search class="h-4 w-4" />
{{ $t('workspace.voucherCheck.search') }}
</button>
<button
type="button"
class="inline-flex items-center gap-1 rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-700 hover:bg-slate-50"
@click="loadStates()"
>
<RefreshCw class="h-4 w-4" />
{{ $t('workspace.voucherCheck.refresh') }}
</button>
</section>
<section v-if="runIdFilter" class="rounded-xl border border-amber-200 bg-amber-50/60 p-3">
<h2 class="mb-2 text-sm font-semibold text-amber-900">
{{ $t('workspace.voucherCheck.runItemsTitle', { runId: runIdFilter }) }}
</h2>
<div class="overflow-x-auto">
<table class="min-w-full text-left text-sm">
<thead class="text-xs text-slate-500">
<tr>
<th class="px-2 py-1">{{ $t('workspace.voucherCheck.invoiceNo') }}</th>
<th class="px-2 py-1">{{ $t('workspace.voucherCheck.result') }}</th>
<th class="px-2 py-1">{{ $t('workspace.voucherCheck.missing') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="row in runItems" :key="row.id" class="border-t border-amber-100">
<td class="px-2 py-1.5 font-medium text-slate-800">{{ row.invoice_no }}</td>
<td class="px-2 py-1.5">{{ statusLabel(row.result) }}</td>
<td class="px-2 py-1.5 text-slate-600">{{ formatMissing(row.missing_materials) }}</td>
</tr>
</tbody>
</table>
</div>
</section>
<section class="min-h-0 flex-1 overflow-hidden rounded-xl border border-slate-200 bg-white">
<div v-if="loading" class="flex items-center justify-center gap-2 py-16 text-sm text-slate-500">
<Loader2 class="h-4 w-4 animate-spin" />
{{ $t('workspace.voucherCheck.loading') }}
</div>
<div v-else-if="!items.length" class="py-16 text-center text-sm text-slate-500">
{{ $t('workspace.voucherCheck.empty') }}
</div>
<div v-else class="max-h-full overflow-auto">
<table class="min-w-full text-left text-sm">
<thead class="sticky top-0 bg-slate-50 text-xs text-slate-500">
<tr>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.invoiceNo') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.invoiceDate') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.status') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.folder') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.missing') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.checkedAt') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="row in items" :key="row.id" class="border-t border-slate-100 hover:bg-slate-50/80">
<td class="px-3 py-2 font-medium text-slate-800">{{ row.invoice_no }}</td>
<td class="px-3 py-2 text-slate-600">{{ row.invoice_date || '-' }}</td>
<td class="px-3 py-2">
<span
class="inline-flex rounded-full px-2 py-0.5 text-xs font-medium"
:class="row.status === 'complete' ? 'bg-emerald-50 text-emerald-700' : 'bg-rose-50 text-rose-700'"
>
{{ statusLabel(row.status) }}
</span>
</td>
<td class="max-w-[16rem] truncate px-3 py-2 text-slate-600" :title="row.folder_path || ''">
{{ row.folder_path || '-' }}
</td>
<td class="px-3 py-2 text-slate-600">{{ formatMissing(row.missing_materials) }}</td>
<td class="px-3 py-2 text-slate-600">{{ row.last_checked_at || '-' }}</td>
</tr>
</tbody>
</table>
</div>
<div class="flex items-center justify-between border-t border-slate-100 px-3 py-2 text-xs text-slate-500">
<span>{{ $t('workspace.voucherCheck.totalCount', { total }) }}</span>
<div class="flex items-center gap-2">
<button
type="button"
class="rounded border border-slate-200 px-2 py-1 disabled:opacity-40"
:disabled="page <= 1 || loading"
@click="page -= 1; loadStates()"
>
{{ $t('workspace.voucherCheck.prevPage') }}
</button>
<span>{{ page }}</span>
<button
type="button"
class="rounded border border-slate-200 px-2 py-1 disabled:opacity-40"
:disabled="page * pageSize >= total || loading"
@click="page += 1; loadStates()"
>
{{ $t('workspace.voucherCheck.nextPage') }}
</button>
</div>
</div>
</section>
</div>
</template>