Files
syops/frontend/src/features/chat/components/shipping-review/ReviewCurrentProcessingCard.vue
T
hugo 1e5aedb9ed feat(shipping-notice): 实现滚动履约功能,优化发货通知流程与代码清理
清理废弃的ShippingCase相关代码与依赖,统一使用ShippingNotice直接关联客户数据。调整库存网关依赖规则,支持仅对库存满足或已人工放行的订单行生成发货Excel,实现滚动履约逻辑。
2026-08-26 02:47:07 +08:00

470 lines
18 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/ReviewCurrentProcessingCard.vue
用途:发货通知工作台右侧唯一的「当前任务」主卡(阶段 + 用户状态 + 阻断 + 动作)。
依赖:vue-i18n、ShippingProcessingBlockingReason/PrimaryAction 类型、resolveShippingProcessingStageLabel。
逻辑:主卡内部 section = 「当前阶段/状态/正式OT → 下一步 → 动作区」;
状态文案严格绑定 user_status;blocking_reason 只作下一步问题说明;按钮显隐由后端 retryable + primary_action.parameters 决定;
由 ShippingOrderReviewView 在 mountCurrentProcessingCard 时挂载。
-->
<script setup lang="ts">
import { computed } from 'vue';
import { Bot, RefreshCw, Crosshair } from 'lucide-vue-next';
import { useI18n } from 'vue-i18n';
import type {
ShippingProcessingBlockingReason,
ShippingProcessingPrimaryAction,
} from '@/features/chat/types/shipping.api.types';
import { resolveShippingProcessingStageLabel } from '@/features/chat/shipping/shippingProcessingLabels';
import { resolveGateReasonLabel } from '@/features/shipping-progress/gateReasonLabel';
import { lookupWorkbenchAction, shouldRenderWorkbenchAction } from '@/features/shipping-progress/workbenchActionRegistry';
import { inventoryActionLabelKey, isInternalInventoryAction } from '@/features/shipping-progress/actionPresentation';
const props = defineProps<{
stageCode?: string | null;
stageLabelKey?: string | null;
stageInconsistent?: boolean;
hasFormalOt?: boolean;
shippingNoticeNo?: string | null;
userStatus?:
| 'running'
| 'waiting_human'
| 'retryable'
| 'failed'
| 'completed'
| 'cancelled'
| null;
retryable?: boolean;
blockingReason?: ShippingProcessingBlockingReason | null;
primaryAction?: ShippingProcessingPrimaryAction | null;
recoveryActions?: Array<{
code: string;
i18nKey?: string | null;
label_key?: string | null;
parameters?: Record<string, unknown>;
}>;
/** 正式 Gate 原始状态仅用于区分未入队、运行中与外部回执等待;不参与按钮裁决。 */
gateStatus?: string | null;
taskMissing?: boolean;
confirmedTaskId?: number | null;
showAdminDiagnosis?: boolean;
retrying?: boolean;
locating?: boolean;
/** 仅 UI 展示的 running 文案(如 inventory_preparation 正在跑时主卡按钮 loading 附加信息)。 */
automation?: {
status?: string | null;
message?: string | null;
} | null;
showRetry?: boolean;
loading?: boolean;
}>();
const emit = defineEmits<{
locate: [lineKey?: string | null, fieldId?: string | null];
action: [code: string, parameters?: Record<string, unknown>];
}>();
const { t, te } = useI18n();
/**
* 当前阶段展示文案:优先消费 stage_label_key,禁止直接展示 stage 码。
*/
const stageLabel = computed(() => {
if (props.loading) {
return t('chat.shippingOrderReview.caseSwitchLoading');
}
if (props.stageInconsistent) {
return t('chat.shippingOrderReview.currentProcessing.stateInconsistent');
}
return resolveShippingProcessingStageLabel(
String(props.stageCode || ''),
te,
t,
props.stageLabelKey,
);
});
/**
* 「状态」行用户态文案:严格绑定 user_status,不再由前端推断。
*/
const statusLabel = computed(() => {
if (props.loading) {
return t('chat.shippingOrderReview.currentTask.statusRunning');
}
const s = String(props.userStatus || '').trim() as ReviewCurrentUserStatus | '';
const map: Record<ReviewCurrentUserStatus, string> = {
running: t('chat.shippingOrderReview.currentTask.statusRunning'),
waiting_human: t('chat.shippingOrderReview.currentTask.statusWaitingHuman'),
retryable: t('chat.shippingOrderReview.currentTask.statusRetryable'),
failed: t('chat.shippingOrderReview.currentTask.statusFailed'),
completed: t('chat.shippingOrderReview.currentTask.statusCompleted'),
cancelled: t('chat.shippingOrderReview.currentTask.statusCancelled'),
};
if (props.taskMissing) {
return t('chat.shippingOrderReview.currentProcessing.taskMissing');
}
if (s === 'running' && String(props.gateStatus || '').trim().toLowerCase() === 'pending') {
return t('chat.shippingOrderReview.currentProcessing.waitingStart');
}
if (!s) return t('chat.shippingOrderReview.currentProcessing.statusIdle');
return map[s] ?? t('chat.shippingOrderReview.currentProcessing.statusIdle');
});
/**
* 下一步(「下一步」section 的问题/说明文案):优先展示 blocking_reason 的统一 i18n 映射,
* 否则按 user_status 给系统态文案;禁止将后端内部原因码直接展示给用户。
*/
const nextStepText = computed(() => {
const safeMessage = (value: unknown): string => {
const raw = String(value || '').trim();
const lowered = raw.toLowerCase();
if (!raw) return '';
if (
lowered.includes('cannot import name')
|| lowered.includes('traceback')
|| lowered.includes('site-packages')
|| lowered.includes('\\app\\')
|| lowered.includes('/app/')
) {
return t('chat.shippingOrderReview.currentTask.nextStepFailedNoRetry');
}
return raw;
};
if (props.loading) {
return safeMessage(props.automation?.message) || t('chat.shippingOrderReview.currentTask.nextStepRunning');
}
// 1) blocking_reason → 用后端给的 i18n_key 渲染具体阻断
const br = props.blockingReason;
if (br) {
const i18nKey = String(br.i18nKey || '').trim();
if (i18nKey && te(i18nKey)) {
return t(i18nKey);
}
return resolveGateReasonLabel(br.code, { t, te })
|| t('chat.shippingOrderReview.currentTask.nextStepUnknown');
}
// 建单前订单冻结校验尚未提交时,明确告诉用户下一步是保存并校验。
// 保存是底栏唯一的表单提交入口,不升级为右栏 CTA;该分支也兼容历史响应
// 仍携带 validate 的情形,避免「待人工」与「无需操作」产生语义矛盾。
if (
String(props.stageCode || '').trim() === 'order_review'
&& !props.blockingReason
&& (
String(props.primaryAction?.code || '').trim() === 'validate'
|| String(props.userStatus || '').trim() === 'waiting_human'
)
) {
return t('chat.shippingOrderReview.saveOrderAndValidate');
}
if (
String(props.userStatus || '').trim() === 'running'
&& String(props.gateStatus || '').trim().toLowerCase() === 'waiting_external'
) {
return t('chat.shippingOrderReview.currentTask.nextStepWaitingExternal');
}
// 2) 无阻断时,按 user_status 给系统说明文案
const s = String(props.userStatus || '').trim() as ReviewCurrentUserStatus | '';
if (s === 'running') {
return t('chat.shippingOrderReview.currentTask.nextStepRunning');
}
if (s === 'completed') {
return t('chat.shippingOrderReview.currentTask.nextStepCompleted');
}
if (s === 'cancelled') {
return t('chat.shippingOrderReview.currentTask.nextStepCancelled');
}
if (s === 'failed' && !props.retryable) {
return t('chat.shippingOrderReview.currentTask.nextStepFailedNoRetry');
}
if (s === 'waiting_human') {
return t('chat.shippingOrderReview.currentTask.nextStepWaitingHumanDefault');
}
if (s === 'retryable') {
return t('chat.shippingOrderReview.currentTask.nextStepRetryableDefault');
}
return t('chat.shippingOrderReview.currentTask.nextStepUnknown');
});
/** 已完成/已取消时没有后续业务动作,不渲染“下一步”区,避免制造未完成错觉。 */
const showNextStep = computed(() => {
const status = String(props.userStatus || '').trim().toLowerCase();
return !['completed', 'cancelled'].includes(status);
});
/**
* 判断当前工作台是否应隐藏后端下发的纯导航动作。
* 批次中心可用它打开工作台;进入工作台后必须复用注册表规则,避免当前阶段再次显示
* 「进入订单复核」或「编辑正式任务」等自跳转入口。
*/
function isHiddenWorkbenchNavigationAction(code: string): boolean {
const entry = lookupWorkbenchAction(code);
return Boolean(entry && !shouldRenderWorkbenchAction(entry, {
actionsExecutable: true,
surface: 'review',
actionCode: code,
}));
}
/**
* 当前任务卡只承载正式 Gate 的可执行业务动作。
*
* 草稿编辑/建草稿是页面能力,保存校验是底栏唯一提交;它们即使出现在历史响应中,
* 也不能升级为右栏 CTA,更不能因缺失文案泄漏内部动作码。
*/
function isNonTaskCapabilityAction(code: string): boolean {
return new Set(['edit_draft', 'create_draft', 'validate']).has(code.trim().toLowerCase());
}
/**
* 业务动作按钮只消费 primary_action;retryable 是状态,不是授权。
*/
const showBusinessAction = computed(() => {
if (props.loading) return false;
if (props.taskMissing) return false;
// [STEP] 自动处理期间没有人工业务动作;只保留外层的刷新进度入口。
// 防止正式任务编辑等历史 primary_action 穿透到库存获取运行态。
if (props.userStatus === 'running') return false;
const code = String(props.primaryAction?.code || '').trim();
if (isInternalInventoryAction(code)) return false;
if (!code) return false;
if (isNonTaskCapabilityAction(code)) return false;
if (isHiddenWorkbenchNavigationAction(code)) return false;
// 无对象边界的泛化 retry 永不展示。
if (code === 'retry') return false;
return true;
});
const businessActionLabel = computed(() => {
const code = String(props.primaryAction?.code || '').trim();
const inventoryKey = inventoryActionLabelKey(code);
if (inventoryKey && te(inventoryKey)) return t(inventoryKey);
const pa = props.primaryAction;
if (!pa) return '';
if (isNonTaskCapabilityAction(String(pa.code || ''))) return '';
// Gate action presentation uses label_key; normalize it at the shared card boundary
// so every gate renders its business label instead of exposing the action code.
const i18nKey = String(
pa.i18nKey
|| (pa as ShippingProcessingPrimaryAction & { label_key?: string | null }).label_key
|| '',
).trim();
if (i18nKey && te(i18nKey)) {
return t(i18nKey);
}
// 当前任务按钮没有受控文案时 fail-closed,禁止泄漏内部 action code。
return '';
});
const businessActionTitle = computed(() => {
const retryingFlag = Boolean(props.retrying);
if (retryingFlag) {
return t('chat.shippingOrderReview.currentTask.actionRetryRunningTooltip');
}
return '';
});
const actionIsRetry = computed(() => String(props.primaryAction?.code || '').trim().startsWith('retry_'));
const actionIsInventoryRpa = computed(() => String(props.primaryAction?.code || '').trim() === 'retry_inventory_preparation');
const recoveryActions = computed(() => (props.recoveryActions || []).filter((action) => {
const code = String(action.code || '').trim();
if (!code || isNonTaskCapabilityAction(code) || isInternalInventoryAction(code)) return false;
if (code === String(props.primaryAction?.code || '').trim()) return false;
const key = String(
action.i18nKey
|| action.label_key
|| `workspace.shippingNotice.processGate.actionCodes.${code}`,
).trim();
return Boolean(key && te(key));
}));
function recoveryActionLabel(action: (typeof recoveryActions.value)[number]): string {
const inventoryKey = inventoryActionLabelKey(action.code);
if (inventoryKey && te(inventoryKey)) return t(inventoryKey);
const key = String(
action.i18nKey
|| action.label_key
|| `workspace.shippingNotice.processGate.actionCodes.${action.code}`,
).trim();
return key && te(key) ? t(key) : '';
}
function handleBusinessActionClick() {
const primaryActionCode = String(props.primaryAction?.code || '').trim();
if (!primaryActionCode || primaryActionCode === 'retry') return;
emit('action', primaryActionCode, props.primaryAction?.parameters ?? {});
}
/**
* 辅助导航「定位明细」:仅当后端在 primary_action.parameters 里提供 line_key 或 field_id 才显示。
*/
const showLocateAction = computed(() => {
if (props.loading) return false;
if (props.taskMissing) return false;
const params = (props.primaryAction?.parameters ?? {}) as Record<string, unknown>;
const hasLineKey = typeof params.line_key === 'string' && params.line_key.length > 0;
const hasFieldId = typeof params.field_id === 'string' && params.field_id.length > 0;
return hasLineKey || hasFieldId;
});
const locateTargetLineKey = computed(() => {
const params = (props.primaryAction?.parameters ?? {}) as Record<string, unknown>;
return typeof params.line_key === 'string' ? params.line_key : null;
});
const locateTargetFieldId = computed(() => {
const params = (props.primaryAction?.parameters ?? {}) as Record<string, unknown>;
return typeof params.field_id === 'string' ? params.field_id : null;
});
function handleLocateClick() {
emit('locate', locateTargetLineKey.value, locateTargetFieldId.value);
}
type ReviewCurrentUserStatus =
| 'running'
| 'waiting_human'
| 'retryable'
| 'failed'
| 'completed'
| 'cancelled';
</script>
<template>
<section
class="rounded-xl border border-sky-200 bg-sky-50/80 p-3 shadow-sm dark:border-sky-900 dark:bg-sky-950/30"
data-testid="review-current-processing-card"
:data-user-status="String(userStatus || '')"
:data-task-missing="taskMissing ? '1' : '0'"
:data-loading="loading ? '1' : '0'"
>
<header class="mb-3">
<h2 class="text-sm font-semibold text-sky-950 dark:text-sky-100">
{{ t('chat.shippingOrderReview.currentTask.title') }}
</h2>
</header>
<dl class="space-y-1 text-xs text-sky-950 dark:text-sky-100">
<div class="flex flex-wrap gap-x-2">
<dt class="text-muted">{{ t('chat.shippingOrderReview.currentTask.labelStage') }}</dt>
<dd data-testid="review-current-task-stage" :class="loading ? 'animate-pulse' : ''">{{ stageLabel }}</dd>
</div>
<div class="flex flex-wrap gap-x-2">
<dt class="text-muted">{{ t('chat.shippingOrderReview.currentProcessing.status') }}</dt>
<dd
class="inline-flex items-center gap-1"
data-testid="review-current-task-status"
:class="loading ? 'animate-pulse' : ''"
>
<RefreshCw
v-if="userStatus === 'running' && !loading"
class="h-3 w-3 animate-spin"
aria-hidden="true"
/>
{{ statusLabel }}
</dd>
</div>
<div
v-if="hasFormalOt && shippingNoticeNo"
class="flex flex-wrap gap-x-2"
>
<dt class="text-muted">{{ t('chat.shippingOrderReview.currentTask.labelFormalSn') }}</dt>
<dd
class="font-mono"
data-testid="review-current-processing-ot"
>{{ shippingNoticeNo }}</dd>
</div>
</dl>
<p
v-if="taskMissing"
class="mt-2 text-[11px] text-rose-800 dark:text-rose-200"
data-testid="review-current-processing-task-missing"
>
{{ t('chat.shippingOrderReview.currentProcessing.taskMissingHint') }}
</p>
<aside
v-if="taskMissing && showAdminDiagnosis"
class="mt-2 rounded border border-rose-300 bg-rose-50/80 p-2 text-[11px] text-rose-950 dark:border-rose-800 dark:bg-rose-950/40 dark:text-rose-100"
data-testid="review-current-processing-admin-diagnosis"
>
<p class="font-medium">{{ t('chat.shippingOrderReview.currentProcessing.adminDiagnosisTitle') }}</p>
<p
v-if="confirmedTaskId != null"
class="mt-1 font-mono"
>
{{ t('chat.shippingOrderReview.currentProcessing.confirmedTaskId', { id: confirmedTaskId }) }}
</p>
<p class="mt-1">
{{ t('chat.shippingOrderReview.currentProcessing.adminDiagnosisStatus') }}
</p>
<p class="mt-1 text-muted">
{{ t('chat.shippingOrderReview.currentProcessing.adminDiagnosisHint') }}
</p>
</aside>
<div
v-if="showNextStep"
class="mt-3 border-t border-sky-200/70 pt-3 dark:border-sky-800/60"
data-testid="review-current-task-next-step-section"
>
<p class="text-[11px] font-medium uppercase tracking-wide text-sky-900/70 dark:text-sky-200/70">
{{ t('chat.shippingOrderReview.currentTask.nextStepTitle') }}
</p>
<p
class="mt-1 text-xs text-sky-950 dark:text-sky-100"
data-testid="review-current-task-next-step-text"
:class="loading ? 'animate-pulse' : ''"
>{{ nextStepText }}</p>
</div>
<div
v-if="showBusinessAction || showLocateAction"
class="mt-3 flex flex-wrap items-center gap-2"
data-testid="review-current-task-actions"
>
<button
v-if="showBusinessAction"
type="button"
class="inline-flex items-center gap-1 rounded-md bg-sky-700 px-3 py-1.5 text-xs font-medium text-white shadow-sm transition hover:bg-sky-800 disabled:opacity-50 dark:bg-sky-600 dark:hover:bg-sky-500"
:data-testid="actionIsRetry ? 'review-current-processing-retry' : 'review-current-task-primary-action'"
:disabled="retrying || locating"
:title="businessActionTitle"
@click="handleBusinessActionClick"
>
<Bot v-if="actionIsInventoryRpa" class="h-3.5 w-3.5" />
<RefreshCw
v-else-if="actionIsRetry"
class="h-3.5 w-3.5"
:class="{ 'animate-spin': Boolean(retrying) }"
/>
{{ businessActionLabel }}
</button>
<button
v-for="action in recoveryActions"
:key="action.code"
type="button"
class="inline-flex items-center gap-1 rounded-md border border-sky-300 bg-white px-2.5 py-1.5 text-xs font-medium text-sky-800 shadow-sm transition hover:bg-sky-50 disabled:opacity-50 dark:border-sky-700 dark:bg-sky-900 dark:text-sky-100 dark:hover:bg-sky-800"
:data-testid="`review-current-task-recovery-${action.code}`"
:disabled="retrying || locating"
@click="$emit('action', action.code, action.parameters || {})"
>
{{ recoveryActionLabel(action) }}
</button>
<button
v-if="showLocateAction"
type="button"
class="inline-flex items-center gap-1 rounded-md border border-sky-300 bg-white px-2.5 py-1.5 text-xs font-medium text-sky-800 shadow-sm transition hover:bg-sky-50 disabled:opacity-50 dark:border-sky-700 dark:bg-sky-900 dark:text-sky-100 dark:hover:bg-sky-800"
data-testid="review-current-task-locate-action"
:disabled="locating"
@click="handleLocateClick"
>
<Crosshair class="h-3.5 w-3.5" />
{{ t('chat.shippingOrderReview.currentTask.actionLocateLine') }}
</button>
</div>
</section>
</template>