Files
syops/frontend/src/features/chat/components/shipping-review/ReviewProfileMatchPanel.vue
T

178 lines
8.6 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/chat/components/shipping-review/ReviewProfileMatchPanel.vue
用途:复核工作台文档模板匹配只读区(用户四态;管理员详细在技术诊断)。
依赖:vue-i18n、ShippingOrderReviewProfileMatch。
逻辑:普通用户只显示 matched/unmatched/ambiguous/unknown;
required_field_missing 不在此展示;分数/Profile ID 仅 admin visibility。
-->
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import type { ShippingOrderReviewProfileMatch } from '@/features/chat/types/shipping.api.types';
const props = defineProps<{
profileMatch: ShippingOrderReviewProfileMatch | null | undefined;
}>();
const { t, te } = useI18n();
const visible = computed(() => {
const match = props.profileMatch;
if (!match) return false;
if (match.visibility === 'admin_only' && match.available === false) return false;
return Boolean(match.available !== false);
});
const isAdminView = computed(() => String(props.profileMatch?.visibility || '') === 'admin');
const needsReview = computed(() => Boolean(props.profileMatch?.needs_review));
const candidateCount = computed(() => (props.profileMatch?.candidates || []).length);
// 候选模板始终按需披露,避免模板数量增长撑长工作台;人工关注状态仍通过徽标表达。
const defaultCandidatesExpanded = computed(() => false);
const candidatesOpenOverride = ref<boolean | null>(null);
const candidatesExpanded = computed(() => candidatesOpenOverride.value ?? defaultCandidatesExpanded.value);
const selectedCoordinateTransform = computed(() => {
if (!isAdminView.value) return null;
const selectedCode = String(props.profileMatch?.selected_profile?.profile_code || '');
const selectedVersion = props.profileMatch?.selected_profile?.version;
const candidate = (props.profileMatch?.candidates || []).find((item) => (
item.profile_code === selectedCode
&& (selectedVersion == null || item.version === selectedVersion)
));
return candidate?.coordinate_transform || null;
});
const coordinateTransformReasonCodes = computed(() => (
selectedCoordinateTransform.value?.reason_codes || []
));
/** 唯一命中仅证明版式身份;下游字段/明细恢复若受门禁阻断,必须在同卡明确说明。 */
const extractionBlockReasons = computed(() => (
(props.profileMatch?.fallback_reason_codes || []).filter((code) => String(code).trim())
));
watch(
() => `${props.profileMatch?.status || ''}:${props.profileMatch?.selected_profile?.profile_code || ''}:${candidateCount.value}`,
() => { candidatesOpenOverride.value = null; },
);
function toggleCandidates() {
candidatesOpenOverride.value = !candidatesExpanded.value;
}
/**
* 匹配状态本地化(用户四态)。
*/
const statusLabel = computed(() => {
const status = String(props.profileMatch?.status || '').trim();
const key = `chat.shippingOrderReview.profileMatch.status.${status}`;
return status && te(key) ? t(key) : (status || '—');
});
/**
* 选中模板展示名(用户仅 display_name)。
*/
const selectedLabel = computed(() => {
const selected = props.profileMatch?.selected_profile;
if (!selected) {
return t('chat.shippingOrderReview.profileMatch.noSelected');
}
const name = String(selected.display_name || '').trim();
if (!name) return t('chat.shippingOrderReview.profileMatch.noSelected');
if (!isAdminView.value) return name;
const version = selected.version != null ? ` v${selected.version}` : '';
return `${name}${version}`;
});
</script>
<template>
<section
v-if="visible"
class="rounded-xl border border-default bg-surface p-3 shadow-sm"
data-testid="review-profile-match-panel"
:data-status="String(profileMatch?.status || '')"
>
<header class="flex flex-wrap items-start justify-between gap-2">
<div>
<h2 class="text-sm font-semibold">{{ t('chat.shippingOrderReview.profileMatch.title') }}</h2>
<p class="mt-0.5 text-xs text-muted">{{ t('chat.shippingOrderReview.profileMatch.subtitle') }}</p>
</div>
<span
class="rounded-full px-2.5 py-1 text-xs font-medium"
:class="needsReview
? 'bg-amber-100 text-amber-900 dark:bg-amber-950 dark:text-amber-100'
: 'bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-100'"
data-testid="review-profile-match-badge"
>
{{ statusLabel }}
</span>
</header>
<dl class="mt-2 space-y-1 text-xs text-secondary">
<div class="flex flex-wrap gap-x-2">
<dt class="text-muted">{{ t('chat.shippingOrderReview.profileMatch.selected') }}</dt>
<dd class="font-medium text-primary" data-testid="review-profile-match-selected">{{ selectedLabel }}</dd>
</div>
</dl>
<div
v-if="extractionBlockReasons.length"
class="mt-3 rounded-lg border border-amber-200 bg-amber-50 px-2.5 py-2 text-xs text-amber-900 dark:border-amber-900 dark:bg-amber-950/30 dark:text-amber-100"
data-testid="review-profile-match-extraction-blocked"
>
<p class="font-medium">{{ t('chat.shippingOrderReview.profileMatch.extractionBlocked') }}</p>
<p class="mt-1 text-amber-800 dark:text-amber-200">
{{ t('chat.shippingOrderReview.profileMatch.extractionBlockedReason', { reasons: extractionBlockReasons.join(', ') }) }}
</p>
</div>
<template v-if="isAdminView && candidateCount">
<button
type="button"
class="mt-3 flex w-full items-center justify-between rounded-lg border border-default bg-surface-soft px-2.5 py-2 text-left text-xs font-medium text-secondary transition-colors hover-surface-soft"
data-testid="review-profile-match-candidates-toggle"
:aria-expanded="candidatesExpanded"
@click="toggleCandidates"
>
<span>{{ candidatesExpanded
? t('chat.shippingOrderReview.profileMatch.collapseCandidates')
: t('chat.shippingOrderReview.profileMatch.expandCandidates', { count: candidateCount }) }}</span>
<span aria-hidden="true" class="text-muted">{{ candidatesExpanded ? '−' : '+' }}</span>
</button>
<div v-if="candidatesExpanded" data-testid="review-profile-match-details">
<dl class="mt-2 space-y-1 text-xs text-secondary">
<div v-if="profileMatch?.route_type" class="flex flex-wrap gap-x-2">
<dt class="text-muted">{{ t('chat.shippingOrderReview.profileMatch.routeType') }}</dt>
<dd class="font-mono">{{ profileMatch.route_type }}</dd>
</div>
<div v-if="profileMatch?.execution_mode" class="flex flex-wrap gap-x-2">
<dt class="text-muted">{{ t('chat.shippingOrderReview.profileMatch.executionMode') }}</dt>
<dd class="font-mono">{{ profileMatch.execution_mode }}</dd>
</div>
<div v-if="selectedCoordinateTransform" data-testid="review-profile-match-coordinate-transform" class="mt-2 rounded-lg border border-sky-200 bg-sky-50 px-2.5 py-2 text-[11px] text-sky-950 dark:border-sky-900 dark:bg-sky-950/30 dark:text-sky-100">
<div class="font-medium">{{ t('chat.shippingOrderReview.profileMatch.coordinateModel.anchorFrame') }}</div>
<div class="mt-1 flex flex-wrap gap-x-3 gap-y-1">
<span>{{ t('chat.shippingOrderReview.profileMatch.coordinateModel.status') }}: {{ selectedCoordinateTransform.status }}</span>
<span v-if="selectedCoordinateTransform.translate_x != null">{{ t('chat.shippingOrderReview.profileMatch.coordinateModel.translateX') }}: {{ selectedCoordinateTransform.translate_x }}</span>
<span v-if="selectedCoordinateTransform.translate_y != null">{{ t('chat.shippingOrderReview.profileMatch.coordinateModel.translateY') }}: {{ selectedCoordinateTransform.translate_y }}</span>
</div>
<div v-if="coordinateTransformReasonCodes.length" class="mt-1">
{{ t('chat.shippingOrderReview.profileMatch.coordinateModel.reasonCodes') }}: {{ coordinateTransformReasonCodes.join(', ') }}
</div>
</div>
</dl>
<ul
class="mt-2 max-h-48 space-y-1.5 overflow-y-auto pr-1"
data-testid="review-profile-match-candidates"
>
<li
v-for="(item, idx) in profileMatch?.candidates || []"
:key="`${item.profile_code}-${item.version}-${idx}`"
class="rounded-lg border border-default bg-surface-soft px-2.5 py-1.5 text-[11px] text-secondary"
>
<span>{{ item.display_name || t('chat.shippingOrderReview.profileMatch.noSelected') }}</span>
<span v-if="item.score != null" class="ml-2 text-muted">{{ item.score }}</span>
</li>
</ul>
</div>
</template>
</section>
</template>