Files
syops/frontend/src/features/admin/modules/shipping-audit/ShippingAuditCenterPage.vue
T
hugo d0fe084999 feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验
- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全
- 引入审计事件的哈希链校验机制,支持数据完整性验证
- 增强订单抽取与审计功能,支持敏感快照的访问控制
- 更新相关模型与服务,确保新功能的完整性与可追溯性
- 完善文档与代码注释,反映新的业务逻辑与审计要求
2026-07-31 08:59:44 +08:00

351 lines
14 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!--
features/admin/modules/shipping-audit/ShippingAuditCenterPage.vue
用途:管理员货代统一审计中心——按 Workflow/Item/Run/PDF/Case/Task 筛选、详情 Diff、关联链、哈希校验、受控导出。
依赖:shipping-audit.api、ShippingAuditEventDetailDrawer、Vue I18n。
逻辑:列表不含快照全文;详情抽屉按权限脱敏;导出/校验写服务端访问审计。
-->
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import {
exportShippingAuditEvents,
getShippingAuditEvent,
listShippingAuditAssociationChain,
listShippingAuditEvents,
verifyShippingAuditHashChain,
type ShippingAuditEventDetail,
type ShippingAuditEventSummary,
type ShippingAuditFilters,
type ShippingAuditHashVerifyResult,
} from '@/features/admin/api/shipping-audit.api';
import ShippingAuditEventDetailDrawer from './ShippingAuditEventDetailDrawer.vue';
const { t } = useI18n();
const loading = ref(false);
const detailLoading = ref(false);
const exporting = ref(false);
const verifying = ref(false);
const error = ref('');
const page = ref(1);
const pageSize = 25;
const total = ref(0);
const rows = ref<ShippingAuditEventSummary[]>([]);
const detail = ref<ShippingAuditEventDetail | null>(null);
const chainHint = ref('');
const verifyResult = ref<ShippingAuditHashVerifyResult | null>(null);
const filters = ref<ShippingAuditFilters>({
event_type: '',
actor_type: '',
actor_id: '',
workflow_id: '',
workflow_item_id: '',
run_no: '',
document_id: '',
review_case_no: '',
task_no: '',
conversation_id: '',
owner_user_id: '',
operation_id: '',
request_id: '',
result: '',
created_from: '',
created_to: '',
q: '',
});
/**
* 将 datetime-local 值规范为 ISO 字符串供 API 查询。
*/
function normalizeDateTimeFilter(value?: string): string {
const raw = String(value || '').trim();
if (!raw) return '';
const date = new Date(raw);
if (Number.isNaN(date.getTime())) return raw;
return date.toISOString();
}
/**
* 组装当前筛选 payload。
*/
function buildFilterPayload(): ShippingAuditFilters {
return {
...filters.value,
created_from: normalizeDateTimeFilter(filters.value.created_from),
created_to: normalizeDateTimeFilter(filters.value.created_to),
};
}
const formatTime = (value?: string | null) => (value ? new Date(value).toLocaleString() : '—');
/**
* 加载审计列表;服务端已做管理员鉴权与访问留痕。
*/
async function load() {
loading.value = true;
error.value = '';
try {
const response = await listShippingAuditEvents(page.value, pageSize, buildFilterPayload());
rows.value = response.items;
total.value = response.total;
} catch {
error.value = t('admin.shippingAudit.loadFailed');
} finally {
loading.value = false;
}
}
/**
* 应用筛选并回到第一页。
*/
async function applyFilters() {
page.value = 1;
await load();
}
/**
* 打开详情抽屉并加载白名单 Diff。
*/
async function openDetail(eventId: number) {
detailLoading.value = true;
error.value = '';
try {
detail.value = await getShippingAuditEvent(eventId);
} catch {
error.value = t('admin.shippingAudit.detailFailed');
} finally {
detailLoading.value = false;
}
}
/**
* 按当前关联种子拉取全链摘要提示。
*/
async function loadAssociationChain() {
error.value = '';
chainHint.value = '';
try {
const payload = buildFilterPayload();
const hasSeed = Boolean(
payload.workflow_id || payload.workflow_item_id || payload.run_no
|| payload.document_id || payload.review_case_no || payload.task_no,
);
if (!hasSeed) {
error.value = t('admin.shippingAudit.chainSeedRequired');
return;
}
const chain = await listShippingAuditAssociationChain(payload, 500);
chainHint.value = t('admin.shippingAudit.chainSummary', {
total: chain.total,
truncated: chain.truncated ? t('admin.shippingAudit.chainTruncated') : '',
});
rows.value = chain.items.slice().reverse();
total.value = chain.total;
page.value = 1;
} catch {
error.value = t('admin.shippingAudit.chainFailed');
}
}
/**
* 触发哈希链校验。
*/
async function runHashVerify() {
verifying.value = true;
error.value = '';
verifyResult.value = null;
try {
const payload = buildFilterPayload();
verifyResult.value = await verifyShippingAuditHashChain({
workflow_id: payload.workflow_id || undefined,
workflow_item_id: payload.workflow_item_id || undefined,
sample_limit: 200,
});
} catch {
error.value = t('admin.shippingAudit.verifyFailed');
} finally {
verifying.value = false;
}
}
/**
* 导出当前筛选条件下的 CSV。
*/
async function exportCsv() {
exporting.value = true;
error.value = '';
try {
await exportShippingAuditEvents(buildFilterPayload(), 'csv');
} catch {
error.value = t('admin.shippingAudit.exportFailed');
} finally {
exporting.value = false;
}
}
onMounted(() => {
void load();
});
</script>
<template>
<section class="space-y-5 p-5 md:p-7" data-testid="shipping-audit-center">
<header class="flex flex-wrap items-start justify-between gap-4">
<div>
<h1 class="section-title">{{ t('admin.shippingAudit.title') }}</h1>
<p class="section-desc mt-1 max-w-3xl">{{ t('admin.shippingAudit.subtitle') }}</p>
</div>
<div class="flex flex-wrap gap-2">
<button type="button" class="btn-secondary btn-sm" :disabled="verifying" @click="runHashVerify">
{{ verifying ? t('admin.shippingAudit.verifying') : t('admin.shippingAudit.verifyChain') }}
</button>
<button type="button" class="btn-secondary btn-sm" @click="loadAssociationChain">
{{ t('admin.shippingAudit.loadChain') }}
</button>
<button type="button" class="btn-secondary btn-sm" :disabled="exporting" @click="exportCsv">
{{ exporting ? t('admin.shippingAudit.exporting') : t('admin.shippingAudit.export') }}
</button>
<button type="button" class="btn-secondary btn-sm" :disabled="loading" @click="load">
{{ t('admin.shippingAudit.refresh') }}
</button>
</div>
</header>
<div class="grid gap-3 rounded-xl border border-default bg-surface p-3 md:grid-cols-3 lg:grid-cols-4">
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.workflowId') }}</span>
<input v-model="filters.workflow_id" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.workflowItemId') }}</span>
<input v-model="filters.workflow_item_id" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.runNo') }}</span>
<input v-model="filters.run_no" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.documentId') }}</span>
<input v-model="filters.document_id" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.reviewCaseNo') }}</span>
<input v-model="filters.review_case_no" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.taskNo') }}</span>
<input v-model="filters.task_no" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.actorType') }}</span>
<select v-model="filters.actor_type" class="select-field text-sm" @change="applyFilters">
<option value="">{{ t('admin.shippingAudit.filters.all') }}</option>
<option value="user">user</option>
<option value="admin">admin</option>
<option value="system">system</option>
<option value="rpa">rpa</option>
</select>
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.actorId') }}</span>
<input v-model="filters.actor_id" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.eventType') }}</span>
<input v-model="filters.event_type" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.result') }}</span>
<input v-model="filters.result" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.createdFrom') }}</span>
<input v-model="filters.created_from" type="datetime-local" class="input-field text-sm" @change="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.createdTo') }}</span>
<input v-model="filters.created_to" type="datetime-local" class="input-field text-sm" @change="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary md:col-span-2 lg:col-span-1">
<span>{{ t('admin.shippingAudit.filters.q') }}</span>
<div class="flex gap-2">
<input v-model="filters.q" class="input-field text-sm flex-1" @keyup.enter="applyFilters">
<button type="button" class="btn-secondary btn-sm" @click="applyFilters">{{ t('admin.shippingAudit.apply') }}</button>
</div>
</label>
</div>
<p v-if="chainHint" class="rounded-lg border border-default bg-surface-soft px-3 py-2 text-xs text-secondary">{{ chainHint }}</p>
<p
v-if="verifyResult"
class="rounded-lg border border-default bg-surface-soft px-3 py-2 text-xs text-secondary"
data-testid="shipping-audit-verify-result"
>
{{ t('admin.shippingAudit.verifySummary', {
ok: verifyResult.ok ? t('admin.shippingAudit.verifyOk') : t('admin.shippingAudit.verifyFailedShort'),
checked: verifyResult.checked_chains,
failed: verifyResult.failed_chains,
}) }}
</p>
<p v-if="error" class="rounded-lg border border-rose-200 bg-rose-50 p-3 text-sm text-rose-700">{{ error }}</p>
<div class="overflow-x-auto rounded-xl border border-default bg-surface">
<table class="min-w-[1360px] w-full text-left text-sm">
<thead class="border-b border-default bg-surface-soft text-xs text-muted">
<tr>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.time') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.event') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.actor') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.workflow') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.workflowItem') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.reviewCase') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.run') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.task') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.result') }}</th>
<th class="px-3 py-2"></th>
</tr>
</thead>
<tbody>
<tr v-if="loading">
<td colspan="10" class="px-3 py-8 text-center text-muted">{{ t('admin.shippingAudit.loading') }}</td>
</tr>
<tr v-else-if="!rows.length">
<td colspan="10" class="px-3 py-8 text-center text-muted">{{ t('admin.shippingAudit.empty') }}</td>
</tr>
<tr v-for="row in rows" :key="row.id" class="border-b border-default last:border-0">
<td class="px-3 py-2 text-xs">{{ formatTime(row.created_at) }}</td>
<td class="px-3 py-2">
<div class="font-medium">{{ row.event_type }}</div>
<div class="text-[11px] text-muted">{{ row.action || '—' }}</div>
</td>
<td class="px-3 py-2 text-xs">{{ row.actor_type }}<span v-if="row.actor_id"> / {{ row.actor_id }}</span></td>
<td class="px-3 py-2 font-mono text-xs">{{ row.workflow_id || '—' }}</td>
<td class="px-3 py-2 font-mono text-xs">{{ row.workflow_item_id || '—' }}</td>
<td class="px-3 py-2 font-mono text-xs">{{ row.review_case_no || '—' }}</td>
<td class="px-3 py-2 font-mono text-xs">{{ row.run_no || '—' }}</td>
<td class="px-3 py-2 font-mono text-xs">{{ row.task_no || '—' }}</td>
<td class="px-3 py-2">{{ row.result || '—' }}</td>
<td class="px-3 py-2">
<button type="button" class="text-brand-600 hover:underline" @click="openDetail(row.id)">
{{ t('admin.shippingAudit.diff') }}
</button>
</td>
</tr>
</tbody>
</table>
</div>
<div class="flex items-center justify-end gap-3 text-sm">
<span class="text-xs text-muted">{{ t('admin.shippingAudit.total', { count: total }) }}</span>
<button type="button" class="rounded border border-default px-3 py-1.5 disabled:opacity-50" :disabled="page <= 1 || loading" @click="page -= 1; load()">{{ t('admin.shippingAudit.previous') }}</button>
<span>{{ page }}</span>
<button type="button" class="rounded border border-default px-3 py-1.5 disabled:opacity-50" :disabled="page * pageSize >= total || loading" @click="page += 1; load()">{{ t('admin.shippingAudit.next') }}</button>
</div>
<ShippingAuditEventDetailDrawer
:detail="detail"
:loading="detailLoading"
@close="detail = null"
/>
</section>
</template>