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

147 lines
5.3 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/ReviewIntakeParsePanel.vue
用途:在接收解析阶段展示当前 Case 已授权的邮件正文、当前附件及安全预览。
依赖:vue、vue-i18n、ShippingOrderReviewIntakeParseContext。
逻辑:只消费父级按 Case 获取的受控上下文;仅 PDF 可请求/渲染 iframe;处置操作只 emit,
由父页沿用既有确认弹窗和 Case 命令。
-->
<script setup lang="ts">
import { watch } from 'vue';
import { useI18n } from 'vue-i18n';
import type { ShippingOrderReviewIntakeParseContext } from '@/features/chat/types/shipping.api.types';
const props = defineProps<{
context: ShippingOrderReviewIntakeParseContext | null;
loading: boolean;
loadFailed: boolean;
previewUrl: string | null;
previewLoading: boolean;
}>();
const emit = defineEmits<{
'retry-context': [];
'load-preview': [];
}>();
const { t } = useI18n();
/**
* 当前附件为 PDF 且尚无受控 Blob 时,通知父级使用当前 Case 加载预览。
* 仅 Case context 改变时触发,禁止对不受支持文件发起预览请求。
*/
watch(
() => props.context,
(context) => {
if (context?.attachment.preview_kind === 'pdf' && !props.previewUrl) {
emit('load-preview');
}
},
{ immediate: true },
);
</script>
<template>
<section
class="space-y-4"
data-testid="intake-parse-panel"
>
<div
v-if="loading"
class="rounded-xl border border-dashed border-default bg-surface-soft p-4 text-sm text-secondary dark:bg-slate-900/40"
data-testid="intake-parse-loading"
>
{{ t('chat.shippingOrderReview.lifecycle.intakeParse.loading') }}
</div>
<div
v-else-if="loadFailed"
class="rounded-xl border border-rose-200 bg-rose-50 p-4 text-sm text-rose-900 dark:border-rose-900 dark:bg-rose-950/40 dark:text-rose-100"
data-testid="intake-parse-load-failed"
>
<p>{{ t('chat.shippingOrderReview.lifecycle.intakeParse.loadFailed') }}</p>
<button
type="button"
class="mt-3 rounded border border-rose-300 px-2.5 py-1 text-xs hover:bg-rose-100 dark:border-rose-800 dark:hover:bg-rose-950"
data-testid="intake-parse-retry-context"
@click="emit('retry-context')"
>
{{ t('chat.shippingOrderReview.lifecycle.intakeParse.retry') }}
</button>
</div>
<template v-else-if="context">
<section class="rounded-xl border border-default bg-surface p-4 shadow-sm">
<h2 class="text-sm font-semibold">{{ t('chat.shippingOrderReview.lifecycle.intakeParse.email') }}</h2>
<template v-if="context.email">
<p class="mt-1 text-xs text-muted">{{ context.email.filename }}</p>
<iframe
v-if="context.email.render_kind === 'safe_html' && context.email.preview_url"
:src="context.email.preview_url"
sandbox=""
referrerpolicy="no-referrer"
:title="t('chat.shippingOrderReview.lifecycle.intakeParse.emailPreviewTitle')"
class="mt-3 h-72 w-full rounded border border-default bg-surface"
data-testid="intake-parse-email-html"
/>
<pre
v-else
class="mt-3 max-h-72 overflow-auto whitespace-pre-wrap break-words rounded bg-surface-soft p-3 text-xs text-secondary dark:bg-slate-950/50"
data-testid="intake-parse-email-body"
>{{ context.email.text }}</pre>
</template>
<p
v-else
class="mt-2 text-sm text-muted"
data-testid="intake-parse-no-email"
>
{{ t('chat.shippingOrderReview.lifecycle.intakeParse.noEmail') }}
</p>
</section>
<section class="rounded-xl border border-default bg-surface p-4 shadow-sm">
<h2 class="text-sm font-semibold" data-testid="intake-parse-attachment-heading">
{{ t('chat.shippingOrderReview.lifecycle.intakeParse.attachment') }} ·
<span class="font-normal text-muted">{{ context.attachment.filename }}</span>
</h2>
<div
v-if="context.attachment.preview_kind === 'pdf'"
class="mt-3"
data-testid="intake-parse-attachment-preview"
>
<p
v-if="previewLoading"
class="mt-2 text-sm text-muted"
data-testid="intake-parse-preview-loading"
>
{{ t('chat.shippingOrderReview.lifecycle.intakeParse.previewLoading') }}
</p>
<iframe
v-else-if="previewUrl"
:src="previewUrl"
:title="context.attachment.filename"
class="mt-2 h-[32rem] w-full rounded border border-default"
/>
<button
v-else
type="button"
class="mt-2 rounded border border-default px-2.5 py-1 text-xs hover-surface-soft"
data-testid="intake-parse-load-preview"
@click="emit('load-preview')"
>
{{ t('chat.shippingOrderReview.lifecycle.intakeParse.loadPreview') }}
</button>
</div>
<p
v-else
class="mt-4 rounded bg-surface-soft p-3 text-sm text-muted dark:bg-slate-950/50"
data-testid="intake-parse-preview-unsupported"
>
{{ t('chat.shippingOrderReview.lifecycle.intakeParse.previewUnsupported') }}
</p>
</section>
</template>
</section>
</template>