fix: 模拟生成PDF

This commit is contained in:
sophie committed 2026-09-10 10:18:44 +08:00
1 parent c4a27324c8
commit 204e71b786
19 files changed
+2064 -110

No files matched your search

@@ -1,28 +1,36 @@
<script setup lang="ts">
/**
* features/workspace/views/AccountingVoucherCheckView.vue
* 用途:立账凭证检核任务列表——按资料所属期间查看批次统计。
* 依赖:voucherCheck.api、vue-i18n、useMessage、DeleteConfirmDialog、PaginationBar、formatLocalDateTime、voucherCheck.display。
* 逻辑:路由 /workspace/accounting-voucher-check;Tab 切换检核任务与企微发送记录;查看详情进入独立明细页;企微 ?run_id= 重定向到明细路由。
* 用途:立账凭证检核任务列表——按资料所属期间(年 + 月)查看批次统计,并展示最近一次检核进度。
* 依赖:voucherCheck.api、vue-i18n、useMessage、DeleteConfirmDialog、PaginationBar、formatLocalDateTime、voucherCheck.display、auth。
* 逻辑:路由 /workspace/accounting-voucher-check;进页默认上一个自然月;「最近一次检核」不跟筛选;强制重检仅 admin,进度在本卡轮询。
*/
import { computed, onMounted, onUnmounted, ref } from 'vue';
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { Download, Loader2, RefreshCw, RotateCcw, Search } from 'lucide-vue-next';
import { ChevronDown, Download, Loader2, RotateCcw, Search } from 'lucide-vue-next';
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
import PaginationBar from '@/shared/components/PaginationBar.vue';
import { useMessage } from '@/shared/composables/useMessage';
import { getStoredAuthUser } from '@/shared/utils/auth';
import { formatLocalDateTime } from '@/shared/utils/dateTime';
import { WORKSPACE_PATHS } from '../constants/routes';
import {
downloadVoucherCheckExcel,
getLatestVoucherCheckRun,
listVoucherCheckNotifications,
listVoucherCheckRuns,
triggerVoucherCheckForceAll,
type VoucherCheckLatestRun,
type VoucherCheckNotificationItem,
type VoucherCheckRunItem,
} from '../api/voucherCheck.api';
import { voucherCheckNotifyStatusLabel, voucherCheckStatusLabel } from '../utils/voucherCheck.display';
import {
voucherCheckModeLabel,
voucherCheckNotifyStatusLabel,
voucherCheckStatusLabel,
voucherCheckStepLabel,
} from '../utils/voucherCheck.display';
const { t } = useI18n();
const msg = useMessage();
@@ -36,7 +44,8 @@ const items = ref<VoucherCheckRunItem[]>([]);
const total = ref(0);
const page = ref(1);
const pageSize = ref(50);
const period = ref('');
const periodYear = ref('');
const periodMonth = ref('');
const status = ref('');
const listTab = ref<'tasks' | 'notifications'>('tasks');
const notifyLoading = ref(false);
@@ -45,19 +54,63 @@ const notifyTotal = ref(0);
const notifyPage = ref(1);
const notifyPageSize = ref(50);
const notifyStatus = ref('');
const latestRun = ref<VoucherCheckLatestRun | null>(null);
const latestLoading = ref(false);
let forcePollTimer: ReturnType<typeof setInterval> | null = null;
const isAdmin = computed(() => String(getStoredAuthUser()?.role || '').trim().toLowerCase() === 'admin');
const latestInProgress = computed(() => {
const cardStatus = latestRun.value?.status;
return cardStatus === 'queued' || cardStatus === 'running';
});
const latestHasMissing = computed(() => {
const row = latestRun.value;
if (!row) return false;
return (row.missing_file_count || 0) > 0 || (row.missing_invoice_count || 0) > 0;
});
const latestCanOpenDetail = computed(() => {
const row = latestRun.value;
if (!row?.schedule_run_id) return false;
return row.status === 'missing' || row.status === 'completed';
});
const MONTH_VALUES = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'] as const;
/**
* 默认资料所属期间为上一个自然月 YYYY-MM。
* 进页默认资料所属期间为上一个自然月。
*/
function previousPeriod(): string {
function previousYearMonth(): { year: string; month: 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}`;
return {
year: String(d.getFullYear()),
month: String(d.getMonth() + 1).padStart(2, '0'),
};
}
/**
* 组装列表查询 period:有月份则为 YYYY-MM,否则为 YYYY。
*/
const periodQuery = computed(() => {
if (!periodYear.value) return undefined;
if (periodMonth.value) return `${periodYear.value}-${periodMonth.value}`;
return periodYear.value;
});
const yearOptions = computed(() => {
const now = new Date().getFullYear();
const years: string[] = [];
for (let year = now - 5; year <= now; year += 1) {
years.push(String(year));
}
if (periodYear.value && !years.includes(periodYear.value)) {
years.unshift(periodYear.value);
years.sort();
}
return years;
});
const statusOptions = computed(() => [
{ value: '', label: t('workspace.voucherCheck.statusAll') },
{ value: 'missing', label: t('workspace.voucherCheck.statusMissing') },
@@ -89,7 +142,7 @@ async function loadNotifications() {
notifyLoading.value = true;
try {
const data = await listVoucherCheckNotifications({
period: period.value || undefined,
period: periodQuery.value,
send_status: notifyStatus.value || undefined,
page: notifyPage.value,
page_size: notifyPageSize.value,
@@ -117,6 +170,7 @@ function setListTab(tab: 'tasks' | 'notifications') {
}
page.value = 1;
void loadRuns();
void loadLatestRun();
}
/**
@@ -132,17 +186,6 @@ function searchCurrentTab() {
void loadNotifications();
}
/**
* 当前 Tab 刷新列表,不重置页码。
*/
function refreshCurrentTab() {
if (listTab.value === 'tasks') {
void loadRuns();
return;
}
void loadNotifications();
}
/**
* 下载该发送记录对应批次的 Excel。
* @param row - 企微发送记录
@@ -197,7 +240,7 @@ async function loadRuns() {
loading.value = true;
try {
const data = await listVoucherCheckRuns({
period: period.value || undefined,
period: periodQuery.value,
status: status.value || undefined,
page: page.value,
page_size: pageSize.value,
@@ -238,15 +281,96 @@ function openRunDetail(row: VoucherCheckRunItem) {
}
/**
* 停止强制重检后的列表轮询。
* 停止最近一次检核的进度轮询。
*/
function stopForcePoll() {
function stopLatestPoll() {
if (forcePollTimer) {
clearInterval(forcePollTimer);
forcePollTimer = null;
}
}
/**
* 拉取最近一次检核卡片;不跟下方列表的年/月/状态筛选。
* @param options.silent - 轮询时不切换卡片 loading,避免进度条闪烁
*/
async function loadLatestRun(options?: { silent?: boolean }) {
if (!options?.silent) latestLoading.value = true;
try {
latestRun.value = await getLatestVoucherCheckRun();
} catch (e: any) {
if (!options?.silent) {
msg.error(e?.message || t('workspace.voucherCheck.latestLoadFailed'));
}
} finally {
if (!options?.silent) latestLoading.value = false;
}
}
/**
* 排队或执行中时轮询卡片;进入终态后刷新下方列表。
*/
function syncLatestPoll() {
stopLatestPoll();
if (listTab.value !== 'tasks' || !latestInProgress.value) return;
forcePollTimer = setInterval(() => {
void (async () => {
const previous = latestRun.value?.status;
await loadLatestRun({ silent: true });
const next = latestRun.value?.status;
if ((previous === 'queued' || previous === 'running') && next !== 'queued' && next !== 'running') {
stopLatestPoll();
void loadRuns();
}
})();
}, 3000);
}
/**
* 最近一次检核状态徽章样式。
* @param value - 卡片状态
*/
function latestBadgeClass(value: string): string {
if (value === 'missing' || value === 'technical_failed') return 'bg-rose-50 text-rose-700';
if (value === 'completed') return 'bg-emerald-50 text-emerald-700';
if (value === 'queued' || value === 'running') return 'bg-blue-50 text-blue-700';
return 'bg-surface-soft text-secondary';
}
/**
* 卡片当前步骤主文案:终态用完成提示,其余按步骤码翻译。
* @param row - 最近一次检核
*/
function latestStepText(row: VoucherCheckLatestRun): string {
if (row.status === 'queued') return t('workspace.voucherCheck.stepQueued');
if (row.status === 'missing' && (row.current_step?.step === 'done' || !row.current_step)) {
return t('workspace.voucherCheck.latestDoneHint');
}
if (row.status === 'completed' && (row.current_step?.step === 'done' || !row.current_step)) {
return t('workspace.voucherCheck.latestCompleteHint');
}
if (row.status === 'technical_failed' && row.current_step?.step === 'fetch_erp') {
return t('workspace.voucherCheck.stepFetchErpIncomplete');
}
return voucherCheckStepLabel(t, row.current_step?.step);
}
/**
* 卡片步骤辅文案:失败原因、排队等待或扫描进度。
* @param row - 最近一次检核
*/
function latestHintText(row: VoucherCheckLatestRun): string {
if (row.error_message) return row.error_message;
if (row.status === 'queued') return t('workspace.voucherCheck.stepQueuedHint');
if (row.status === 'running' && row.current_step?.step === 'scan_dms' && row.subject_count > 0) {
return t('workspace.voucherCheck.processedHint', {
processed: row.processed_count,
total: row.subject_count,
});
}
return '';
}
/**
* 打开强制重检确认框;用公共 DeleteConfirmDialog 替代原生 window.confirm。
*/
@@ -264,13 +388,8 @@ async function forceRecheck() {
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);
await loadLatestRun({ silent: true });
syncLatestPoll();
} catch (e: any) {
msg.error(e?.message || t('workspace.voucherCheck.forceFailed'));
} finally {
@@ -278,16 +397,40 @@ async function forceRecheck() {
}
}
/**
* 从最近一次检核卡片打开本批明细。
*/
function openLatestDetail() {
const row = latestRun.value;
if (!row?.schedule_run_id) {
msg.error(t('workspace.voucherCheck.loadFailed'));
return;
}
void router.push({
path: WORKSPACE_PATHS.accountingVoucherCheckDetail(row.schedule_run_id),
query: row.run_no ? { runNo: row.run_no } : undefined,
});
}
/**
* 仅在检核任务 Tab 且最近一批仍在排队/执行时轮询卡片。
*/
watch([listTab, latestInProgress], () => {
syncLatestPoll();
});
onMounted(async () => {
if (redirectLegacyRunQuery()) return;
period.value = previousPeriod();
const previous = previousYearMonth();
periodYear.value = previous.year;
periodMonth.value = previous.month;
const qStatus = route.query.status;
if (typeof qStatus === 'string' && qStatus) status.value = qStatus;
await loadRuns();
await Promise.all([loadRuns(), loadLatestRun()]);
});
onUnmounted(() => {
stopForcePoll();
stopLatestPoll();
});
</script>
@@ -321,22 +464,143 @@ onUnmounted(() => {
</button>
</div>
<article
v-if="listTab === 'tasks'"
class="overflow-hidden rounded-2xl border border-default bg-surface"
aria-live="polite"
>
<div class="flex flex-wrap items-start justify-between gap-3 bg-blue-50 px-4 py-3.5">
<div>
<h2 class="text-[15px] font-semibold text-primary">{{ $t('workspace.voucherCheck.latestTitle') }}</h2>
<p v-if="latestRun" class="mt-1 text-xs text-muted">
<span class="mr-3">{{ $t('workspace.voucherCheck.latestBatch', { runNo: latestRun.run_no }) }}</span>
<span class="mr-3">{{ $t('workspace.voucherCheck.latestPeriod', { period: latestRun.period_month || '-' }) }}</span>
<span>{{ voucherCheckModeLabel(t, latestRun.mode) }}</span>
</p>
</div>
<div class="flex shrink-0 items-center gap-2">
<span
v-if="latestRun"
class="inline-flex rounded-full px-2.5 py-1 text-xs font-semibold"
:class="latestBadgeClass(latestRun.status)"
>
{{ voucherCheckStatusLabel(t, latestRun.status) }}
</span>
<button
v-if="isAdmin"
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-amber-300 bg-amber-50 px-3 py-1.5 text-sm font-medium text-amber-900 transition-colors hover:bg-amber-100 disabled:opacity-50"
:disabled="forcing || latestInProgress"
@click="openForceRecheck()"
>
<Loader2 v-if="forcing" class="h-3.5 w-3.5 animate-spin" />
<RotateCcw v-else class="h-3.5 w-3.5" />
{{ $t('workspace.voucherCheck.forceRecheck') }}
</button>
</div>
</div>
<div class="px-4 py-3.5">
<div v-if="latestLoading && !latestRun" class="flex items-center justify-center gap-2 py-8 text-sm text-muted">
<Loader2 class="h-4 w-4 animate-spin" />
{{ $t('workspace.voucherCheck.loading') }}
</div>
<p v-else-if="!latestRun" class="py-8 text-center text-sm text-muted">
{{ $t('workspace.voucherCheck.latestEmpty') }}
</p>
<template v-else>
<div class="h-2.5 overflow-hidden rounded-full bg-slate-200">
<div
class="h-full rounded-full transition-[width] duration-300"
:class="latestRun.status === 'technical_failed' ? 'bg-rose-600' : 'bg-teal-700'"
:style="{ width: `${latestRun.progress_percent || 0}%` }"
/>
</div>
<div class="mt-2 mb-3.5 flex flex-wrap justify-between gap-3 text-xs text-muted">
<span>{{ $t('workspace.voucherCheck.progress', { percent: latestRun.progress_percent || 0 }) }}</span>
<span>
{{ $t('workspace.voucherCheck.startedAt') }}:{{ formatLocalDateTime(latestRun.started_at) }}
 {{ $t('workspace.voucherCheck.finishedAt') }}:{{ latestInProgress ? $t('workspace.voucherCheck.inProgress') : formatLocalDateTime(latestRun.finished_at) }}
</span>
</div>
<div class="grid grid-cols-2 gap-2 md:grid-cols-4">
<div class="rounded-[10px] border border-default bg-slate-50 px-2.5 py-3">
<b class="block text-[22px] font-semibold leading-tight text-primary">{{ latestRun.subject_count }}</b>
<span class="text-xs text-muted">{{ $t('workspace.voucherCheck.subjectCount') }}</span>
</div>
<div class="rounded-[10px] border border-default bg-slate-50 px-2.5 py-3">
<b class="block text-[22px] font-semibold leading-tight text-primary">{{ latestRun.archived_file_count }}</b>
<span class="text-xs text-muted">{{ $t('workspace.voucherCheck.archivedFiles') }}</span>
</div>
<div class="rounded-[10px] border border-default bg-slate-50 px-2.5 py-3">
<b
class="block text-[22px] font-semibold leading-tight"
:class="latestHasMissing ? 'text-rose-700' : 'text-primary'"
>{{ latestRun.missing_file_count }}</b>
<span class="text-xs text-muted">{{ $t('workspace.voucherCheck.missingFiles') }}</span>
</div>
<div class="rounded-[10px] border border-default bg-slate-50 px-2.5 py-3">
<b
class="block text-[22px] font-semibold leading-tight"
:class="latestHasMissing ? 'text-rose-700' : 'text-primary'"
>{{ latestRun.missing_invoice_count }}</b>
<span class="text-xs text-muted">{{ $t('workspace.voucherCheck.missingInvoices') }}</span>
</div>
</div>
<p class="mt-3 text-[13px] text-slate-700">
{{ latestStepText(latestRun) }}
<small v-if="latestHintText(latestRun)" class="mt-0.5 block text-muted">{{ latestHintText(latestRun) }}</small>
</p>
<div v-if="latestCanOpenDetail" class="mt-3 flex justify-end">
<button
type="button"
class="text-sm font-semibold text-brand-700 hover:underline"
@click="openLatestDetail"
>
{{ $t('workspace.voucherCheck.viewLatestDetail') }}
</button>
</div>
</template>
</div>
</article>
<section class="flex flex-wrap items-end gap-3 rounded-2xl border border-default/80 bg-surface/70 px-4 py-3 shadow-sm">
<label class="flex flex-col gap-1 text-xs font-medium text-muted">
{{ $t('workspace.voucherCheck.period') }}
<input v-model="period" type="month" class="rounded-xl border border-default bg-surface px-3 py-1.5 text-sm text-primary" />
<span class="flex items-center gap-2">
<span class="period-select">
<select v-model="periodYear" class="period-select__control w-[4.75rem]">
<option v-for="year in yearOptions" :key="year" :value="year">{{ year }}</option>
</select>
<ChevronDown class="period-select__icon" aria-hidden="true" />
</span>
<span class="period-select">
<select v-model="periodMonth" class="period-select__control w-[4.75rem]">
<option value="">{{ $t('workspace.voucherCheck.periodMonthAll') }}</option>
<option v-for="month in MONTH_VALUES" :key="month" :value="month">
{{ $t('workspace.voucherCheck.periodMonthValue', { n: Number(month) }) }}
</option>
</select>
<ChevronDown class="period-select__icon" aria-hidden="true" />
</span>
</span>
</label>
<label v-if="listTab === 'tasks'" class="flex flex-col gap-1 text-xs font-medium text-muted">
{{ $t('workspace.voucherCheck.status') }}
<select v-model="status" class="rounded-xl border border-default bg-surface px-3 py-1.5 text-sm text-primary">
<option v-for="opt in statusOptions" :key="opt.value || 'all'" :value="opt.value">{{ opt.label }}</option>
</select>
<span class="period-select">
<select v-model="status" class="period-select__control w-[6rem]">
<option v-for="opt in statusOptions" :key="opt.value || 'all'" :value="opt.value">{{ opt.label }}</option>
</select>
<ChevronDown class="period-select__icon" aria-hidden="true" />
</span>
</label>
<label v-else class="flex flex-col gap-1 text-xs font-medium text-muted">
{{ $t('workspace.voucherCheck.notifyStatus') }}
<select v-model="notifyStatus" class="rounded-xl border border-default bg-surface px-3 py-1.5 text-sm text-primary">
<option v-for="opt in notifyStatusOptions" :key="opt.value || 'all'" :value="opt.value">{{ opt.label }}</option>
</select>
<span class="period-select">
<select v-model="notifyStatus" class="period-select__control w-[7.25rem]">
<option v-for="opt in notifyStatusOptions" :key="opt.value || 'all'" :value="opt.value">{{ opt.label }}</option>
</select>
<ChevronDown class="period-select__icon" aria-hidden="true" />
</span>
</label>
<button
type="button"
@@ -346,25 +610,6 @@ onUnmounted(() => {
<Search class="h-3.5 w-3.5" />
{{ $t('workspace.voucherCheck.search') }}
</button>
<button
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft"
@click="refreshCurrentTab"
>
<RefreshCw class="h-3.5 w-3.5" />
{{ $t('workspace.voucherCheck.refresh') }}
</button>
<button
v-if="listTab === 'tasks'"
type="button"
class="ml-auto inline-flex items-center gap-1 rounded-xl border border-amber-300 bg-amber-50 px-3 py-1.5 text-sm font-medium text-amber-900 transition-colors hover:bg-amber-100 disabled:opacity-50"
:disabled="forcing"
@click="openForceRecheck()"
>
<Loader2 v-if="forcing" class="h-3.5 w-3.5 animate-spin" />
<RotateCcw v-else class="h-3.5 w-3.5" />
{{ $t('workspace.voucherCheck.forceRecheck') }}
</button>
</section>
<section v-if="listTab === 'tasks'" class="overflow-hidden rounded-2xl border border-default bg-surface">
@@ -524,3 +769,51 @@ onUnmounted(() => {
/>
</div>
</template>
<style scoped>
/**
* 隐藏系统原生下拉箭头(含 Chromium ::picker-icon / Edge ::-ms-expand)。
* 只保留模板里的 ChevronDown,避免 Windows 下年份与月份箭头叠在一起。
*/
.period-select {
position: relative;
display: inline-flex;
align-items: center;
}
.period-select__control {
box-sizing: border-box;
border-radius: 0.75rem;
border: 1px solid var(--border-default);
background-color: var(--bg-surface);
background-image: none;
padding: 0.375rem 1.75rem 0.375rem 0.625rem;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--text-primary);
font-size: 0.875rem;
line-height: 1.25rem;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.period-select__control::-ms-expand {
display: none;
}
.period-select__control::picker-icon {
display: none;
content: none;
}
.period-select__icon {
pointer-events: none;
position: absolute;
right: 0.5rem;
height: 0.875rem;
width: 0.875rem;
color: var(--text-muted);
}
</style>