feat(shipping-process-gates): 落地全门禁中断恢复并消除双真相

纳入 Execution/Gate/Attempt 模型与迁移、Worker/API/前端恢复卡片与 Admin 诊断,
Gate 阻断时清零旧 action_buttons,异常摘要统一脱敏,并为运维筛选与 Attempt Diff 补齐入口。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-08-01 13:08:32 +08:00
1 parent b352c281d5
commit 323928626b
92 files changed
+11930 -458

No files matched your search

@@ -0,0 +1,794 @@
<!--
features/admin/modules/shipping-process-gates/ShippingProcessGateDiagnosticsPage.vue
用途:管理员 Process Gate Execution 诊断——列表、Gate 轨道与 Attempt 明细。
依赖:process-gates.api、Vue Router、Vue I18n(admin + workspace.processGate 动作文案)。
逻辑:只读诊断;多维度筛选(status/gate/reason/party/q/时间);小屏卡片化列表,lg+ 横向表格(nowrap + 滚动提示);
状态/动作展示业务标签并附技术码;Gate 诊断结构化卡片(findings/blocking/effective_result);
Attempt 展示 snapshot_diff 摘要并可跳转 AdminShippingAudit。
-->
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import {
getAdminProcessExecution,
listAdminProcessExecutions,
listAdminProcessGateAttempts,
type AdminProcessExecutionDetail,
type AdminProcessExecutionListFilters,
type AdminProcessExecutionSummary,
type AdminProcessGateAttemptsPayload,
} from '@/features/shipping-process-gates/api/process-gates.api';
const { t, te } = useI18n();
const router = useRouter();
const loading = ref(false);
const detailLoading = ref(false);
const attemptsLoading = ref(false);
const error = ref('');
const page = ref(1);
const pageSize = 25;
const total = ref(0);
const filters = ref<AdminProcessExecutionListFilters>({
status: '',
gate_code: '',
blocking_reason_code: '',
responsible_party: '',
q: '',
updated_from: '',
updated_to: '',
});
const rows = ref<AdminProcessExecutionSummary[]>([]);
const detail = ref<AdminProcessExecutionDetail | null>(null);
const selectedGateCode = ref('');
const attemptsPayload = ref<AdminProcessGateAttemptsPayload | null>(null);
const EXECUTION_STATUS_OPTIONS = [
'active',
'blocked',
'waiting_external',
'completed',
'failed',
'cancelled',
] as const;
type GateFinding = {
severity?: string;
field_code?: string;
field?: string;
responsible_party?: string;
party?: string;
reason_code?: string;
reason?: string;
code?: string;
finding_code?: string;
message?: string;
details?: Record<string, unknown>;
};
type SnapshotKeyDiff = {
added?: string[];
removed?: string[];
changed?: string[];
};
type SnapshotDiffPayload = {
previous_attempt_no?: number;
input?: SnapshotKeyDiff;
output?: SnapshotKeyDiff;
input_hash_changed?: boolean;
output_hash_changed?: boolean;
};
const EMPTY_FILTERS: AdminProcessExecutionListFilters = {
status: '',
gate_code: '',
blocking_reason_code: '',
responsible_party: '',
q: '',
updated_from: '',
updated_to: '',
};
const formatTime = (value?: string | null) => (value ? new Date(value).toLocaleString() : '—');
/**
* 将 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();
}
/**
* Execution / Gate 状态业务标签;无翻译时回落原始码。
*/
function statusLabel(code?: string | null): string {
const key = String(code || '').trim();
if (!key) return '—';
const i18nKey = `admin.shippingProcessGates.statusLabels.${key}`;
return te(i18nKey) ? t(i18nKey) : key;
}
/**
* 主动作业务标签(复用 workspace 动作文案)+ 技术码,便于运维对照。
*/
function actionLabel(code?: string | null): string {
const key = String(code || '').trim();
if (!key) return '—';
const i18nKey = `workspace.shippingNotice.processGate.actionCodes.${key}`;
const label = te(i18nKey) ? t(i18nKey) : key;
return label === key ? key : `${label} (${key})`;
}
/**
* 组装当前列表筛选 payload,剔除空值并规范化时间。
*/
function buildListFilters(): AdminProcessExecutionListFilters {
const payload: AdminProcessExecutionListFilters = {};
(Object.entries(filters.value) as Array<[keyof AdminProcessExecutionListFilters, string | undefined]>).forEach(
([key, value]) => {
const text = String(value || '').trim();
if (!text) return;
if (key === 'updated_from' || key === 'updated_to') {
payload[key] = normalizeDateTimeFilter(text);
return;
}
payload[key] = text;
},
);
return payload;
}
/** 兼容后端 items / attempts 双字段。 */
const attemptRows = computed(() => {
const payload = attemptsPayload.value;
if (!payload) return [];
const list = payload.items || payload.attempts || [];
return Array.isArray(list) ? list : [];
});
/** 详情中的完整 Gate 列表(含 findings)。 */
const diagnosticGates = computed(() => {
const gates = detail.value?.gates;
return Array.isArray(gates) ? gates : [];
});
const selectedGateDetail = computed(() => {
if (!selectedGateCode.value) return null;
return diagnosticGates.value.find((gate) => String(gate.gate_code) === selectedGateCode.value) || null;
});
const selectedGateFindings = computed(() => normalizeFindings(selectedGateDetail.value?.findings));
const selectedBlockingReasonRows = computed(() => blockingReasonRows(selectedGateDetail.value?.blocking_reason));
const selectedEffectiveResultSummary = computed(() => effectiveResultSummary(selectedGateDetail.value?.effective_result));
const selectedEffectiveResultRemainder = computed(() => (
effectiveResultRemainder(selectedGateDetail.value?.effective_result, selectedEffectiveResultSummary.value)
));
/**
* 将任意 JSON 安全格式化为可展示文本。
*/
function formatJson(value: unknown): string {
if (value == null) return '—';
try {
return JSON.stringify(value, null, 2);
} catch {
return String(value);
}
}
/**
* 将单元格值转为短文本。
*/
function formatCellValue(value: unknown): string {
if (value == null) return '—';
if (typeof value === 'string') return value;
if (typeof value === 'number' || typeof value === 'boolean') return String(value);
try {
return JSON.stringify(value);
} catch {
return String(value);
}
}
/**
* 规范化 Gate findings 数组。
*/
function normalizeFindings(raw: unknown): GateFinding[] {
if (!Array.isArray(raw)) return [];
return raw.filter((item): item is GateFinding => Boolean(item) && typeof item === 'object');
}
/**
* 提取 Finding 展示字段。
*/
function findingField(finding: GateFinding): string {
return String(finding.field_code || finding.field || '').trim() || '—';
}
function findingParty(finding: GateFinding): string {
return String(finding.responsible_party || finding.party || '').trim() || '—';
}
function findingReason(finding: GateFinding): string {
return String(finding.reason_code || finding.reason || finding.code || finding.finding_code || '').trim() || '—';
}
function findingMessage(finding: GateFinding): string {
if (finding.message) return String(finding.message);
const details = finding.details;
if (details && typeof details === 'object' && details.message != null) {
return String(details.message);
}
return '—';
}
/**
* 将 blocking_reason 对象转为 key-value 行。
*/
function blockingReasonRows(raw: unknown): Array<{ key: string; value: string }> {
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return [];
return Object.entries(raw as Record<string, unknown>).map(([key, value]) => ({
key,
value: formatCellValue(value),
}));
}
/**
* 从 effective_result 提取摘要 chips(优先常见键 + findings 计数)。
*/
function effectiveResultSummary(raw: unknown): Array<{ key: string; value: string }> {
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return [];
const obj = raw as Record<string, unknown>;
const chips: Array<{ key: string; value: string }> = [];
const priorityKeys = ['passed', 'status', 'case', 'outcome', 'summary'];
for (const key of priorityKeys) {
if (Object.prototype.hasOwnProperty.call(obj, key) && obj[key] != null) {
chips.push({ key, value: formatCellValue(obj[key]) });
}
}
if (Array.isArray(obj.findings)) {
chips.push({ key: 'findings', value: String(obj.findings.length) });
}
return chips;
}
/**
* 返回 effective_result 中未出现在摘要 chips 内的剩余 JSON。
*/
function effectiveResultRemainder(
raw: unknown,
summary: Array<{ key: string; value: string }>,
): Record<string, unknown> | null {
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
const obj = { ...(raw as Record<string, unknown>) };
const consumed = new Set(summary.map((item) => item.key));
for (const key of consumed) {
delete obj[key];
}
return Object.keys(obj).length ? obj : null;
}
/**
* 格式化 Attempt snapshot_diff 单段(input/output)摘要。
*/
function formatSnapshotDiffSection(scope: 'input' | 'output', diff: SnapshotDiffPayload | null | undefined): string | null {
const section = diff?.[scope];
if (!section) return null;
const added = section.added?.length ?? 0;
const removed = section.removed?.length ?? 0;
const changed = section.changed?.length ?? 0;
if (!added && !removed && !changed) return null;
const scopeLabel = scope === 'input' ? 'input' : 'output';
return t('admin.shippingProcessGates.attemptDiff', {
scope: scopeLabel,
added,
removed,
changed,
});
}
/**
* 合并 Attempt snapshot_diff 的 input/output 摘要行。
*/
function formatAttemptDiffSummary(raw: unknown): string[] {
if (!raw || typeof raw !== 'object') return [];
const diff = raw as SnapshotDiffPayload;
const lines: string[] = [];
const inputLine = formatSnapshotDiffSection('input', diff);
const outputLine = formatSnapshotDiffSection('output', diff);
if (inputLine) lines.push(inputLine);
if (outputLine) lines.push(outputLine);
return lines;
}
/**
* 跳转 Admin 审计中心,预填 Execution 与 process_gate_ 事件前缀。
*/
function openAuditForExecution(executionNo: string) {
void router.push({
name: 'AdminShippingAudit',
query: {
q: executionNo,
event_type: 'process_gate_',
},
});
}
/**
* 加载 Execution 列表。
*/
async function load() {
loading.value = true;
error.value = '';
try {
const response = await listAdminProcessExecutions(page.value, pageSize, buildListFilters());
rows.value = response.items;
total.value = response.total;
} catch {
error.value = t('admin.shippingProcessGates.loadFailed');
} finally {
loading.value = false;
}
}
/**
* 应用筛选并重置到第一页。
*/
function applyFilters() {
page.value = 1;
void load();
}
/**
* 清空筛选并刷新列表。
*/
function resetFilters() {
filters.value = { ...EMPTY_FILTERS };
page.value = 1;
void load();
}
/**
* 打开 Execution 诊断详情。
*/
async function openDetail(executionNo: string) {
detailLoading.value = true;
selectedGateCode.value = '';
attemptsPayload.value = null;
try {
detail.value = await getAdminProcessExecution(executionNo);
const current = detail.value.current_gate?.gate_code
|| detail.value.current_blocking_gate?.gate_code;
if (current) await loadAttempts(String(current));
} catch {
error.value = t('admin.shippingProcessGates.detailFailed');
detail.value = null;
} finally {
detailLoading.value = false;
}
}
/**
* 加载指定 Gate 的 Attempt 列表。
*/
async function loadAttempts(gateCode: string) {
if (!detail.value?.execution_no) return;
selectedGateCode.value = gateCode;
attemptsLoading.value = true;
try {
attemptsPayload.value = await listAdminProcessGateAttempts(detail.value.execution_no, gateCode);
} catch {
attemptsPayload.value = null;
error.value = t('admin.shippingProcessGates.attemptsFailed');
} finally {
attemptsLoading.value = false;
}
}
/**
* 关闭详情面板。
*/
function closeDetail() {
detail.value = null;
selectedGateCode.value = '';
attemptsPayload.value = null;
}
onMounted(() => {
void load();
});
</script>
<template>
<div class="space-y-6 p-4 sm:p-6">
<header>
<h1 class="text-xl font-bold">{{ t('admin.shippingProcessGates.title') }}</h1>
<p class="mt-1 max-w-3xl text-sm text-muted">{{ t('admin.shippingProcessGates.subtitle') }}</p>
</header>
<section class="rounded-xl border border-default bg-surface p-4">
<div class="grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
<label class="text-sm">
<span class="mb-1 block text-xs text-muted">{{ t('admin.shippingProcessGates.status') }}</span>
<select v-model="filters.status" class="w-full rounded border border-default px-2 py-1.5 text-sm">
<option value="">{{ t('admin.shippingProcessGates.allStatuses') }}</option>
<option v-for="code in EXECUTION_STATUS_OPTIONS" :key="code" :value="code">
{{ statusLabel(code) }}
</option>
</select>
</label>
<label class="text-sm">
<span class="mb-1 block text-xs text-muted">{{ t('admin.shippingProcessGates.filterGate') }}</span>
<input
v-model="filters.gate_code"
type="text"
class="w-full rounded border border-default px-2 py-1.5 text-sm font-mono"
:placeholder="t('admin.shippingProcessGates.gateCode')"
/>
</label>
<label class="text-sm">
<span class="mb-1 block text-xs text-muted">{{ t('admin.shippingProcessGates.filterReason') }}</span>
<input
v-model="filters.blocking_reason_code"
type="text"
class="w-full rounded border border-default px-2 py-1.5 text-sm font-mono"
:placeholder="t('admin.shippingProcessGates.blockingReasonCode')"
/>
</label>
<label class="text-sm">
<span class="mb-1 block text-xs text-muted">{{ t('admin.shippingProcessGates.filterParty') }}</span>
<input
v-model="filters.responsible_party"
type="text"
class="w-full rounded border border-default px-2 py-1.5 text-sm"
:placeholder="t('admin.shippingProcessGates.responsibleParty')"
/>
</label>
<label class="text-sm sm:col-span-2 lg:col-span-1">
<span class="mb-1 block text-xs text-muted">{{ t('admin.shippingProcessGates.filterSearch') }}</span>
<input
v-model="filters.q"
type="search"
class="w-full rounded border border-default px-2 py-1.5 text-sm"
:placeholder="t('admin.shippingProcessGates.executionNo')"
/>
</label>
<label class="text-sm">
<span class="mb-1 block text-xs text-muted">{{ t('admin.shippingProcessGates.filterFrom') }}</span>
<input v-model="filters.updated_from" type="datetime-local" class="w-full rounded border border-default px-2 py-1.5 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-xs text-muted">{{ t('admin.shippingProcessGates.filterTo') }}</span>
<input v-model="filters.updated_to" type="datetime-local" class="w-full rounded border border-default px-2 py-1.5 text-sm" />
</label>
</div>
<div class="mt-3 flex flex-wrap items-center gap-2">
<button type="button" class="rounded border border-default px-3 py-1.5 text-sm" @click="applyFilters">
{{ t('admin.shippingProcessGates.applyFilters') }}
</button>
<button type="button" class="rounded border border-default px-3 py-1.5 text-sm" @click="resetFilters">
{{ t('admin.shippingProcessGates.resetFilters') }}
</button>
<button type="button" class="rounded border border-default px-3 py-1.5 text-sm" @click="load">
{{ t('admin.shippingProcessGates.refresh') }}
</button>
<span class="text-xs text-muted">{{ t('admin.shippingProcessGates.total', { count: total }) }}</span>
</div>
</section>
<p v-if="error" class="text-sm text-rose-600">{{ error }}</p>
<!-- 小屏:卡片列表,避免列标题逐字换行 -->
<div class="space-y-3 lg:hidden" data-testid="shipping-process-gate-cards">
<p v-if="loading" class="rounded-xl border border-default px-4 py-8 text-center text-sm text-muted">
{{ t('admin.shippingProcessGates.loading') }}
</p>
<p v-else-if="!rows.length" class="rounded-xl border border-default px-4 py-8 text-center text-sm text-muted">
{{ t('admin.shippingProcessGates.empty') }}
</p>
<article
v-for="row in rows"
:key="row.execution_no"
class="rounded-xl border border-default bg-surface px-4 py-3 text-sm"
>
<div class="font-mono text-xs break-all">{{ row.execution_no }}</div>
<dl class="mt-2 grid grid-cols-1 gap-1.5 sm:grid-cols-2">
<div>
<dt class="text-xs text-muted">{{ t('admin.shippingProcessGates.status') }}</dt>
<dd>
<span>{{ statusLabel(row.status) }}</span>
<span class="ml-1 font-mono text-[11px] text-muted">{{ row.status }}</span>
</dd>
</div>
<div>
<dt class="text-xs text-muted">{{ t('admin.shippingProcessGates.currentGate') }}</dt>
<dd class="font-mono text-xs break-all">{{ row.current_gate_code || '—' }}</dd>
</div>
<div class="sm:col-span-2">
<dt class="text-xs text-muted">{{ t('admin.shippingProcessGates.nextAction') }}</dt>
<dd class="text-xs">{{ actionLabel(row.primary_next_action_code) }}</dd>
</div>
<div>
<dt class="text-xs text-muted">{{ t('admin.shippingProcessGates.updatedAt') }}</dt>
<dd class="text-xs">{{ formatTime(row.updated_at) }}</dd>
</div>
</dl>
<button
type="button"
class="mt-3 text-sm text-brand-600 hover:underline"
@click="openDetail(row.execution_no)"
>
{{ t('admin.shippingProcessGates.viewDetail') }}
</button>
</article>
</div>
<!-- lg+:横向表格;表头 nowrap + 外层滚动 -->
<div class="hidden lg:block">
<p class="mb-2 text-xs text-muted">{{ t('admin.shippingProcessGates.scrollHint') }}</p>
<div class="overflow-x-auto rounded-xl border border-default">
<table class="min-w-[720px] w-full text-sm">
<thead class="bg-surface-soft text-left text-xs uppercase text-muted">
<tr>
<th class="whitespace-nowrap px-4 py-3">{{ t('admin.shippingProcessGates.executionNo') }}</th>
<th class="whitespace-nowrap px-4 py-3">{{ t('admin.shippingProcessGates.status') }}</th>
<th class="whitespace-nowrap px-4 py-3">{{ t('admin.shippingProcessGates.currentGate') }}</th>
<th class="whitespace-nowrap px-4 py-3">{{ t('admin.shippingProcessGates.nextAction') }}</th>
<th class="whitespace-nowrap px-4 py-3">{{ t('admin.shippingProcessGates.updatedAt') }}</th>
<th class="whitespace-nowrap px-4 py-3">{{ t('admin.shippingProcessGates.actions') }}</th>
</tr>
</thead>
<tbody>
<tr v-if="loading">
<td colspan="6" class="px-4 py-8 text-center text-muted">{{ t('admin.shippingProcessGates.loading') }}</td>
</tr>
<tr v-else-if="!rows.length">
<td colspan="6" class="px-4 py-8 text-center text-muted">{{ t('admin.shippingProcessGates.empty') }}</td>
</tr>
<tr v-for="row in rows" :key="row.execution_no" class="border-t border-default">
<td class="whitespace-nowrap px-4 py-3 font-mono text-xs">{{ row.execution_no }}</td>
<td class="px-4 py-3">
<div>{{ statusLabel(row.status) }}</div>
<div class="font-mono text-[11px] text-muted">{{ row.status }}</div>
</td>
<td class="whitespace-nowrap px-4 py-3 font-mono text-xs">{{ row.current_gate_code || '—' }}</td>
<td class="px-4 py-3 text-xs">{{ actionLabel(row.primary_next_action_code) }}</td>
<td class="whitespace-nowrap px-4 py-3">{{ formatTime(row.updated_at) }}</td>
<td class="whitespace-nowrap px-4 py-3">
<button type="button" class="text-brand-600 hover:underline" @click="openDetail(row.execution_no)">
{{ t('admin.shippingProcessGates.viewDetail') }}
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="flex items-center gap-2 text-sm">
<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.shippingProcessGates.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.shippingProcessGates.next') }}
</button>
</div>
<aside
v-if="detail"
class="rounded-xl border border-default bg-surface p-4"
data-testid="shipping-process-gate-detail"
>
<div class="mb-4 flex items-center justify-between gap-2">
<h2 class="text-lg font-semibold">{{ t('admin.shippingProcessGates.detailTitle') }}</h2>
<button type="button" class="text-sm text-muted hover:text-primary" @click="closeDetail">{{ t('admin.close') }}</button>
</div>
<p v-if="detailLoading" class="text-sm text-muted">{{ t('admin.shippingProcessGates.loading') }}</p>
<template v-else>
<dl class="grid gap-2 text-sm sm:grid-cols-2">
<div><dt class="text-muted">{{ t('admin.shippingProcessGates.executionNo') }}</dt><dd class="font-mono text-xs break-all">{{ detail.execution_no }}</dd></div>
<div>
<dt class="text-muted">{{ t('admin.shippingProcessGates.status') }}</dt>
<dd>
{{ statusLabel(detail.status) }}
<span class="ml-1 font-mono text-[11px] text-muted">{{ detail.status }}</span>
</dd>
</div>
<div><dt class="text-muted">{{ t('admin.shippingProcessGates.taskNo') }}</dt><dd class="font-mono text-xs">{{ detail.task_no || '—' }}</dd></div>
<div><dt class="text-muted">{{ t('admin.shippingProcessGates.caseNo') }}</dt><dd class="font-mono text-xs">{{ detail.review_case_no || detail.case_no || '—' }}</dd></div>
</dl>
<h3 class="mt-6 text-sm font-semibold">{{ t('admin.shippingProcessGates.gates') }}</h3>
<div class="mt-2 space-y-2 lg:hidden">
<article
v-for="gate in diagnosticGates"
:key="String(gate.gate_code)"
class="rounded-lg border border-default px-3 py-2 text-xs"
:class="{ 'bg-amber-50/60 dark:bg-amber-950/20': selectedGateCode === gate.gate_code }"
>
<div class="font-semibold">#{{ gate.sequence_no }} · {{ gate.gate_code }}</div>
<div class="mt-1">{{ statusLabel(String(gate.status)) }} <span class="font-mono text-muted">{{ gate.status }}</span></div>
<div class="mt-1 font-mono text-muted">{{ gate.blocking_reason_code || '—' }}</div>
<button type="button" class="mt-2 text-brand-600 hover:underline" @click="loadAttempts(String(gate.gate_code))">
{{ t('admin.shippingProcessGates.viewAttempts') }}
</button>
</article>
</div>
<div class="mt-2 hidden overflow-x-auto rounded-lg border border-default lg:block">
<table class="min-w-[640px] w-full text-xs">
<thead class="bg-surface-soft text-left text-muted">
<tr>
<th class="whitespace-nowrap px-3 py-2">#</th>
<th class="whitespace-nowrap px-3 py-2">{{ t('admin.shippingProcessGates.gateCode') }}</th>
<th class="whitespace-nowrap px-3 py-2">{{ t('admin.shippingProcessGates.gateStatus') }}</th>
<th class="whitespace-nowrap px-3 py-2">{{ t('admin.shippingProcessGates.blockingReason') }}</th>
<th class="whitespace-nowrap px-3 py-2">{{ t('admin.shippingProcessGates.actions') }}</th>
</tr>
</thead>
<tbody>
<tr
v-for="gate in diagnosticGates"
:key="String(gate.gate_code)"
class="border-t border-default"
:class="{ 'bg-amber-50/60 dark:bg-amber-950/20': selectedGateCode === gate.gate_code }"
>
<td class="whitespace-nowrap px-3 py-2">{{ gate.sequence_no }}</td>
<td class="whitespace-nowrap px-3 py-2 font-mono">{{ gate.gate_code }}</td>
<td class="px-3 py-2">
<div>{{ statusLabel(String(gate.status)) }}</div>
<div class="font-mono text-[11px] text-muted">{{ gate.status }}</div>
</td>
<td class="whitespace-nowrap px-3 py-2 font-mono">{{ gate.blocking_reason_code || '—' }}</td>
<td class="whitespace-nowrap px-3 py-2">
<button type="button" class="text-brand-600 hover:underline" @click="loadAttempts(String(gate.gate_code))">
{{ t('admin.shippingProcessGates.viewAttempts') }}
</button>
</td>
</tr>
</tbody>
</table>
</div>
<section v-if="selectedGateDetail" class="mt-4 rounded-lg border border-default px-3 py-3 text-xs">
<h4 class="font-semibold">{{ t('admin.shippingProcessGates.gateDiagnostics') }}</h4>
<p class="mt-1 text-muted">
{{ t('admin.shippingProcessGates.nextAction') }}:
<span>{{ actionLabel(String(selectedGateDetail.next_action_code || '')) }}</span>
</p>
<div class="mt-3">
<div class="font-medium text-muted">{{ t('admin.shippingProcessGates.findingsStructured') }}</div>
<p v-if="!selectedGateFindings.length" class="mt-1 text-muted">{{ t('admin.shippingProcessGates.noFindings') }}</p>
<div v-else class="mt-2 space-y-2">
<article
v-for="(finding, index) in selectedGateFindings"
:key="`${finding.finding_code || finding.reason_code || index}`"
class="rounded border border-default bg-surface-soft px-3 py-2"
>
<div class="flex flex-wrap items-center gap-2">
<span
class="rounded px-1.5 py-0.5 font-mono text-[11px]"
:class="finding.severity === 'blocking'
? 'bg-rose-100 text-rose-800 dark:bg-rose-950 dark:text-rose-200'
: 'bg-slate-100 text-slate-700 dark:bg-slate-900 dark:text-slate-200'"
>
{{ t('admin.shippingProcessGates.severity') }}: {{ finding.severity || '—' }}
</span>
</div>
<dl class="mt-2 grid gap-1 sm:grid-cols-2">
<div>
<dt class="text-muted">{{ t('admin.shippingProcessGates.field') }}</dt>
<dd class="font-mono">{{ findingField(finding) }}</dd>
</div>
<div>
<dt class="text-muted">{{ t('admin.shippingProcessGates.party') }}</dt>
<dd>{{ findingParty(finding) }}</dd>
</div>
<div>
<dt class="text-muted">{{ t('admin.shippingProcessGates.reason') }}</dt>
<dd class="font-mono">{{ findingReason(finding) }}</dd>
</div>
<div class="sm:col-span-2">
<dt class="text-muted">{{ t('admin.shippingProcessGates.message') }}</dt>
<dd class="break-words">{{ findingMessage(finding) }}</dd>
</div>
</dl>
</article>
</div>
</div>
<div class="mt-3">
<div class="font-medium text-muted">{{ t('admin.shippingProcessGates.blockingReasonDetail') }}</div>
<p v-if="!selectedBlockingReasonRows.length" class="mt-1 text-muted">—</p>
<dl v-else class="mt-2 divide-y divide-default rounded border border-default">
<div
v-for="row in selectedBlockingReasonRows"
:key="row.key"
class="grid gap-1 px-3 py-2 sm:grid-cols-[minmax(8rem,30%)_1fr]"
>
<dt class="font-mono text-muted">{{ row.key }}</dt>
<dd class="break-words">{{ row.value }}</dd>
</div>
</dl>
</div>
<div class="mt-3">
<div class="font-medium text-muted">{{ t('admin.shippingProcessGates.effectiveResult') }}</div>
<p v-if="!selectedEffectiveResultSummary.length && !selectedEffectiveResultRemainder" class="mt-1 text-muted">—</p>
<div v-else class="mt-2 space-y-2">
<div v-if="selectedEffectiveResultSummary.length" class="flex flex-wrap gap-2">
<span
v-for="chip in selectedEffectiveResultSummary"
:key="chip.key"
class="rounded-full border border-default bg-surface-soft px-2 py-0.5 font-mono text-[11px]"
>
{{ chip.key }}: {{ chip.value }}
</span>
</div>
<details v-if="selectedEffectiveResultRemainder">
<summary class="cursor-pointer text-brand-600">
{{ Object.keys(selectedEffectiveResultRemainder).join(', ') }}
</summary>
<pre class="mt-2 max-h-48 overflow-auto rounded bg-surface-soft p-2">{{ formatJson(selectedEffectiveResultRemainder) }}</pre>
</details>
</div>
</div>
</section>
<div class="mt-6 flex flex-wrap items-center justify-between gap-2">
<h3 class="text-sm font-semibold">
{{ t('admin.shippingProcessGates.attempts') }}
<span v-if="selectedGateCode" class="font-mono text-xs text-muted">({{ selectedGateCode }})</span>
</h3>
<button
type="button"
class="text-xs text-brand-600 hover:underline"
@click="openAuditForExecution(detail.execution_no)"
>
{{ t('admin.shippingProcessGates.openAudit') }}
</button>
</div>
<p class="text-xs text-muted">{{ t('admin.shippingProcessGates.auditLink') }}</p>
<p v-if="attemptsLoading" class="mt-2 text-sm text-muted">{{ t('admin.shippingProcessGates.loading') }}</p>
<div v-else-if="attemptRows.length" class="mt-2 space-y-2">
<article
v-for="attempt in attemptRows"
:key="String(attempt.id || attempt.attempt_no)"
class="rounded-lg border border-default px-3 py-2 text-xs"
>
<div class="font-mono">#{{ attempt.attempt_no }} · {{ statusLabel(String(attempt.status)) }} <span class="text-muted">({{ attempt.status }})</span></div>
<div v-if="attempt.error_code" class="mt-1 text-rose-700">{{ attempt.error_code }}: {{ attempt.error_summary }}</div>
<div class="mt-1 text-muted">{{ formatTime(attempt.started_at as string) }} → {{ formatTime(attempt.finished_at as string) }}</div>
<div class="mt-1 text-muted">
hash:
in={{ attempt.input_snapshot_hash || '—' }}
/ out={{ attempt.output_snapshot_hash || '—' }}
</div>
<ul v-if="formatAttemptDiffSummary(attempt.snapshot_diff).length" class="mt-2 space-y-0.5 text-muted">
<li v-for="(line, lineIndex) in formatAttemptDiffSummary(attempt.snapshot_diff)" :key="lineIndex">
{{ line }}
</li>
</ul>
<details v-if="attempt.input_snapshot || attempt.output_snapshot" class="mt-2">
<summary class="cursor-pointer text-brand-600">{{ t('admin.shippingProcessGates.viewSnapshots') }}</summary>
<div class="mt-2 grid gap-2 md:grid-cols-2">
<pre class="max-h-48 overflow-auto rounded bg-surface-soft p-2">{{ formatJson(attempt.input_snapshot) }}</pre>
<pre class="max-h-48 overflow-auto rounded bg-surface-soft p-2">{{ formatJson(attempt.output_snapshot) }}</pre>
</div>
</details>
</article>
</div>
<p v-else class="mt-2 text-sm text-muted">{{ t('admin.shippingProcessGates.noAttempts') }}</p>
</template>
</aside>
</div>
</template>