This commit is contained in:
sophie committed 2026-09-07 11:13:33 +08:00
1 parent 78576f5745
commit 63b997a7e4
68 files changed
+3680 -1413

No files matched your search

@@ -3,6 +3,7 @@
* 常用问题 / FAQ 缓存创建与编辑居中弹窗。
* 依赖:QuestionFormState、admin 通用 modal 样式。
* 逻辑:QuestionsPage 打开本组件;提交时 emit save,由 composable 调 API。
* is_enabled 仅控制工作台首页入口;cache_enabled 单独控制聊天是否跳过 Dify。
*/
<script setup lang="ts">
import { computed } from 'vue';
@@ -86,13 +87,16 @@ const isStale = computed(() => Boolean(props.form.stale_at));
<label class="label-field">{{ t('admin.question.fields.sortOrder') }}</label>
<input v-model.number="form.sort_order" type="number" class="input-field text-sm" />
</div>
<div class="md:col-span-2 flex flex-wrap gap-6">
<label class="inline-flex items-center gap-2 text-sm text-secondary cursor-pointer">
<input v-model="form.is_enabled" type="checkbox" class="accent-brand-600" />
<span>{{ t('admin.question.fields.isEnabled') }}</span>
<div class="md:col-span-2 space-y-3">
<label class="flex items-start gap-2 text-sm text-secondary cursor-pointer">
<input v-model="form.is_enabled" type="checkbox" class="mt-0.5 accent-brand-600" />
<span>
<span class="block">{{ t('admin.question.fields.isEnabled') }}</span>
<span class="block text-xs text-muted mt-0.5">{{ t('admin.question.fields.isEnabledHelp') }}</span>
</span>
</label>
<label class="inline-flex items-center gap-2 text-sm text-secondary cursor-pointer">
<input v-model="form.cache_enabled" type="checkbox" class="accent-brand-600" />
<label class="flex items-start gap-2 text-sm text-secondary cursor-pointer">
<input v-model="form.cache_enabled" type="checkbox" class="mt-0.5 accent-brand-600" />
<span>{{ t('admin.question.fields.cacheEnabled') }}</span>
</label>
</div>
@@ -1,82 +1,89 @@
/**
* features/workspace/api/voucherCheck.api.ts
* 用途:工作台立账凭证检核记录查询 API 客户端。
* 用途:工作台立账凭证检核任务列表、批次明细与强制重检 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 {
export interface VoucherCheckRunItem {
id: number;
scope_code: string;
schedule_run_id?: number | null;
run_no: string;
profile_code: string;
period_month: string | null;
invoice_no: string;
invoice_date?: string | null;
mode: string;
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;
subject_count: number;
missing_file_count: number;
missing_invoice_count: number;
technical_error_count: number;
staged_file_count: number;
finished_at?: string | null;
}
export interface VoucherCheckStatesResponse {
scope_code: string;
period: string;
export interface VoucherCheckRunsResponse {
page: number;
page_size: number;
total: number;
items: VoucherCheckStateItem[];
items: VoucherCheckRunItem[];
}
export interface VoucherCheckRunInvoiceItem {
id: number;
invoice_no: string;
result: string;
status_label?: string | null;
missing_materials?: Array<{ code?: string; name?: string }>;
cells?: Record<string, string>;
checked_at?: string | null;
}
export interface VoucherCheckRunItemsResponse {
run_id: number;
engine_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;
}>;
items: VoucherCheckRunInvoiceItem[];
}
export interface VoucherCheckForceRunResponse {
schedule_task_id: number;
schedule_run_id: number;
run_no: string;
job_id: number;
mode: string;
status: string;
}
/**
* 按月份/状态/发票号筛选最新检核状态。
* 分页查询检核任务列表。
*/
export function listVoucherCheckStates(params: {
export function listVoucherCheckRuns(params: {
period?: string;
profile_code?: 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.profile_code) q.set('profile_code', params.profile_code);
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}` : ''}`,
return requestJson<VoucherCheckRunsResponse>(
`/api/workspace/accounting-voucher-check/runs${qs ? `?${qs}` : ''}`,
{ headers: getAuthHeaders() },
);
}
/**
* 分页查询指定批次明细。
* 分页查询指定排程批次的 invoice 明细。
*/
export function listVoucherCheckRunItems(runId: number, params?: { result?: string; page?: number; page_size?: number }) {
const q = new URLSearchParams();
@@ -89,3 +96,17 @@ export function listVoucherCheckRunItems(runId: number, params?: { result?: stri
{ headers: getAuthHeaders() },
);
}
/**
* 强制重检上一个自然月(不走增量跳过)。
*/
export function triggerVoucherCheckForceAll() {
return requestJson<VoucherCheckForceRunResponse>(
'/api/workspace/accounting-voucher-check/runs',
{
method: 'POST',
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
body: JSON.stringify({ mode: 'force_all' }),
},
);
}
@@ -1,19 +1,21 @@
<script setup lang="ts">
/**
* features/workspace/views/AccountingVoucherCheckView.vue
* 用途:立账凭证检核记录页——按月筛选最新状态与缺资料票。
* 用途:立账凭证检核任务列表——按资料所属期间查看批次统计,并可展开 invoice 明细。
* 依赖:voucherCheck.api、vue-i18n、useMessage。
* 逻辑:路由 /workspace/accounting-voucher-check;企微 textcard 也可跳转至此。
* 逻辑:路由 /workspace/accounting-voucher-check;企微汇总卡片可带 run_id 跳转批次明细;强制重检入队周批 force_all。
*/
import { computed, onMounted, ref, watch } from 'vue';
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { Loader2, RefreshCw, Search } from 'lucide-vue-next';
import { Loader2, RefreshCw, RotateCcw, Search } from 'lucide-vue-next';
import { useMessage } from '@/shared/composables/useMessage';
import {
listVoucherCheckRunItems,
listVoucherCheckStates,
type VoucherCheckStateItem,
listVoucherCheckRuns,
triggerVoucherCheckForceAll,
type VoucherCheckRunInvoiceItem,
type VoucherCheckRunItem,
} from '../api/voucherCheck.api';
const { t } = useI18n();
@@ -21,47 +23,49 @@ const msg = useMessage();
const route = useRoute();
const loading = ref(false);
const items = ref<VoucherCheckStateItem[]>([]);
const forcing = ref(false);
const items = ref<VoucherCheckRunItem[]>([]);
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']>([]);
const runItems = ref<VoucherCheckRunInvoiceItem[]>([]);
let forcePollTimer: ReturnType<typeof setInterval> | null = null;
/**
* 默认检核月份(当前自然月 YYYY-MM)。
* 默认资料所属期间为上一个自然月 YYYY-MM。
*/
function currentPeriod(): string {
function previousPeriod(): string {
const d = new Date();
d.setDate(1);
d.setMonth(d.getMonth() - 1);
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') },
{ value: 'completed', label: t('workspace.voucherCheck.statusComplete') },
{ value: 'technical_failed', label: t('workspace.voucherCheck.statusTechError') },
]);
/**
* 加载最新状态列表。
* 加载检核任务列表。
*/
async function loadStates() {
async function loadRuns() {
loading.value = true;
try {
const data = await listVoucherCheckStates({
const data = await listVoucherCheckRuns({
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 {
@@ -70,7 +74,7 @@ async function loadStates() {
}
/**
* 若 URL 带 run_id,额外加载该批次明细。
* 若 URL 带 run_id(排程批次),加载该批 invoice 明细。
*/
async function loadRunItemsIfNeeded() {
const raw = route.query.run_id;
@@ -90,10 +94,11 @@ async function loadRunItemsIfNeeded() {
}
function statusLabel(value: string) {
if (value === 'complete') return t('workspace.voucherCheck.statusComplete');
if (value === 'complete' || value === 'completed') 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');
if (value === 'technical_error' || value === 'technical_failed') return t('workspace.voucherCheck.statusTechError');
if (value === 'pending') return t('workspace.voucherCheck.statusPending');
return value || '-';
}
@@ -102,11 +107,60 @@ function formatMissing(list?: Array<{ code?: string; name?: string }>) {
return list.map((x) => x.name || x.code || '').filter(Boolean).join('、');
}
async function openRunDetail(row: VoucherCheckRunItem) {
if (!row.schedule_run_id) {
msg.error(t('workspace.voucherCheck.loadFailed'));
return;
}
const scheduleRunId = row.schedule_run_id;
runIdFilter.value = scheduleRunId;
try {
const data = await listVoucherCheckRunItems(scheduleRunId, { page: 1, page_size: 100 });
runItems.value = data.items || [];
} catch (e: any) {
msg.error(e?.message || t('workspace.voucherCheck.loadFailed'));
}
}
/**
* 停止强制重检后的列表轮询。
*/
function stopForcePoll() {
if (forcePollTimer) {
clearInterval(forcePollTimer);
forcePollTimer = null;
}
}
/**
* 入队强制重检上一个月:不跳过已归档记录,期间取执行日的上一个自然月。
*/
async function forceRecheck() {
if (forcing.value) return;
if (!window.confirm(t('workspace.voucherCheck.forceConfirm'))) return;
forcing.value = true;
try {
const data = await triggerVoucherCheckForceAll();
msg.success(t('workspace.voucherCheck.forceQueued', { runNo: data.run_no }));
await loadRuns();
stopForcePoll();
const started = Date.now();
forcePollTimer = setInterval(() => {
void loadRuns();
if (Date.now() - started > 120_000) stopForcePoll();
}, 5000);
} catch (e: any) {
msg.error(e?.message || t('workspace.voucherCheck.forceFailed'));
} finally {
forcing.value = false;
}
}
onMounted(async () => {
period.value = currentPeriod();
period.value = previousPeriod();
const qStatus = route.query.status;
if (typeof qStatus === 'string' && qStatus) status.value = qStatus;
await Promise.all([loadStates(), loadRunItemsIfNeeded()]);
await Promise.all([loadRuns(), loadRunItemsIfNeeded()]);
});
watch(
@@ -115,6 +169,10 @@ watch(
void loadRunItemsIfNeeded();
},
);
onUnmounted(() => {
stopForcePoll();
});
</script>
<template>
@@ -135,20 +193,10 @@ watch(
<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()"
@click="page = 1; loadRuns()"
>
<Search class="h-4 w-4" />
{{ $t('workspace.voucherCheck.search') }}
@@ -156,11 +204,21 @@ watch(
<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()"
@click="loadRuns()"
>
<RefreshCw class="h-4 w-4" />
{{ $t('workspace.voucherCheck.refresh') }}
</button>
<button
type="button"
class="ml-auto inline-flex items-center gap-1 rounded-lg border border-amber-300 bg-amber-50 px-3 py-2 text-sm font-medium text-amber-900 hover:bg-amber-100 disabled:opacity-50"
:disabled="forcing"
@click="forceRecheck()"
>
<Loader2 v-if="forcing" class="h-4 w-4 animate-spin" />
<RotateCcw v-else class="h-4 w-4" />
{{ $t('workspace.voucherCheck.forceRecheck') }}
</button>
</section>
<section v-if="runIdFilter" class="rounded-xl border border-amber-200 bg-amber-50/60 p-3">
@@ -177,7 +235,7 @@ watch(
</tr>
</thead>
<tbody>
<tr v-for="row in runItems" :key="row.id" class="border-t border-amber-100">
<tr v-for="(row, idx) in runItems" :key="`${row.invoice_no}-${idx}`" 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>
@@ -199,31 +257,43 @@ watch(
<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.runNo') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.profile') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.period') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.subjectCount') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.missingFiles') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.missingInvoices') }}</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>
<th class="px-3 py-2"></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 font-medium text-slate-800">{{ row.run_no }}</td>
<td class="px-3 py-2 text-slate-600">{{ row.profile_code }}</td>
<td class="px-3 py-2 text-slate-600">{{ row.period_month || '-' }}</td>
<td class="px-3 py-2 text-slate-600">{{ row.subject_count }}</td>
<td class="px-3 py-2 text-slate-600">{{ row.missing_file_count }}</td>
<td class="px-3 py-2 text-slate-600">{{ row.missing_invoice_count }}</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'"
:class="row.status === 'missing' ? 'bg-rose-50 text-rose-700' : row.status === 'completed' ? 'bg-emerald-50 text-emerald-700' : 'bg-slate-100 text-slate-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 class="px-3 py-2 text-slate-600">{{ row.finished_at || '-' }}</td>
<td class="px-3 py-2">
<button
type="button"
class="text-sky-700 hover:underline"
@click="openRunDetail(row)"
>
{{ $t('workspace.voucherCheck.viewDetail') }}
</button>
</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>
@@ -235,7 +305,7 @@ watch(
type="button"
class="rounded border border-slate-200 px-2 py-1 disabled:opacity-40"
:disabled="page <= 1 || loading"
@click="page -= 1; loadStates()"
@click="page -= 1; loadRuns()"
>
{{ $t('workspace.voucherCheck.prevPage') }}
</button>
@@ -244,7 +314,7 @@ watch(
type="button"
class="rounded border border-slate-200 px-2 py-1 disabled:opacity-40"
:disabled="page * pageSize >= total || loading"
@click="page += 1; loadStates()"
@click="page += 1; loadRuns()"
>
{{ $t('workspace.voucherCheck.nextPage') }}
</button>