refactor(frontend): 重构前端第二版
This commit is contained in:
1 parent
2631f78b00
commit
4b562cfa82
205 files changed
+15399
-12015
No files matched your search
@@ -0,0 +1,398 @@
|
||||
/**
|
||||
* features/chat/components/messages/ChatMessageBubble.vue
|
||||
* 单条聊天消息:用户气泡、助手 Markdown、请假/出货子组件、来源引用与操作栏。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { Check, Copy, Edit2, LayoutGrid, MessageSquareText, RotateCw } from 'lucide-vue-next';
|
||||
import LeaveMessageBlock, { type LeaveMessageHandlers } from './LeaveMessageBlock.vue';
|
||||
import ShippingInventoryMappingMessage, { type ShippingMappingHandlers } from './ShippingInventoryMappingMessage.vue';
|
||||
import type { ChatMessage, SourceFileLink } from '../../types/chat.types';
|
||||
import type { ShippingInventoryMappingFormPayload } from '../../types/shipping.types';
|
||||
|
||||
export interface ChatMessageBubbleHandlers {
|
||||
renderMarkdown: (text: string) => string;
|
||||
onMarkdownClick: (event: MouseEvent) => void;
|
||||
getShippingInventoryMappingPayload: (msg: ChatMessage) => ShippingInventoryMappingFormPayload | null;
|
||||
canOpenQueryPreview: (msg: ChatMessage) => boolean;
|
||||
getQueryPreviewSummary: (msg: ChatMessage) => string;
|
||||
openQueryPreviewDialog: (msg: ChatMessage) => void;
|
||||
shippingActionButtonClass: (variant?: string) => string;
|
||||
onShippingActionClick: (msg: ChatMessage, action: NonNullable<ChatMessage['shipping_actions']>[number]) => void;
|
||||
getDisplayRetrieverResources: (msg: ChatMessage) => Array<Record<string, unknown>>;
|
||||
getSourceLinks: (resources: Array<Record<string, unknown>>) => SourceFileLink[];
|
||||
shouldExpandSourceDetails: (msg: ChatMessage) => boolean;
|
||||
getSourceTitle: (doc: Record<string, unknown>) => string;
|
||||
getSourceMeta: (doc: Record<string, unknown>) => string;
|
||||
getSourceBrief: (doc: Record<string, unknown>) => string;
|
||||
openPreview: (file: SourceFileLink) => void;
|
||||
}
|
||||
|
||||
const {
|
||||
message,
|
||||
index,
|
||||
messageCount,
|
||||
isThinking,
|
||||
showChatRating,
|
||||
copiedIndex,
|
||||
isShippingNoticeAgent,
|
||||
handlers,
|
||||
leaveHandlers,
|
||||
shippingHandlers,
|
||||
} = defineProps<{
|
||||
message: ChatMessage;
|
||||
index: number;
|
||||
messageCount: number;
|
||||
isThinking: boolean;
|
||||
showChatRating: boolean;
|
||||
copiedIndex: number | null;
|
||||
isShippingNoticeAgent: boolean;
|
||||
handlers: ChatMessageBubbleHandlers;
|
||||
leaveHandlers: LeaveMessageHandlers;
|
||||
shippingHandlers: ShippingMappingHandlers;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
copy: [];
|
||||
edit: [content: string];
|
||||
resend: [content: string];
|
||||
regenerate: [];
|
||||
'open-feedback': [];
|
||||
}>();
|
||||
|
||||
const isLeaveMessage = computed(() =>
|
||||
message.type === 'leave-form'
|
||||
|| message.type === 'leave-confirmation'
|
||||
|| message.type === 'leave-result',
|
||||
);
|
||||
|
||||
const retrieverResources = computed(() => handlers.getDisplayRetrieverResources(message));
|
||||
const sourceLinks = computed(() => handlers.getSourceLinks(retrieverResources.value));
|
||||
|
||||
const showSourceSection = computed(() => {
|
||||
if (message.role !== 'assistant' || isLeaveMessage.value) return false;
|
||||
return retrieverResources.value.length > 0
|
||||
|| (message.attribution_parts?.length ?? 0) > 0
|
||||
|| sourceLinks.value.length > 0;
|
||||
});
|
||||
|
||||
const showActions = computed(() => message.type !== 'leave-form');
|
||||
const isLastMessage = computed(() => index === messageCount - 1);
|
||||
const isCopied = computed(() => copiedIndex === index);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
:data-msg-index="index"
|
||||
class="group mx-auto mb-6 flex w-full max-w-4xl animate-slide-up"
|
||||
:class="message.role === 'user' ? 'justify-end' : 'justify-start'"
|
||||
>
|
||||
<div
|
||||
class="flex flex-col"
|
||||
:class="message.role === 'user' ? 'max-w-[88%] md:max-w-[74%] items-end' : 'w-full'"
|
||||
>
|
||||
<div
|
||||
class="text-[15px] leading-relaxed"
|
||||
:class="message.role === 'user'
|
||||
? 'rounded-2xl rounded-tr-sm bg-brand-600 px-5 py-2.5 text-white shadow-sm shadow-brand-500/15'
|
||||
: 'chat-msg-assistant'"
|
||||
>
|
||||
<div v-if="message.role === 'user'" class="whitespace-pre-wrap">{{ message.content }}</div>
|
||||
<div v-else>
|
||||
<LeaveMessageBlock
|
||||
v-if="isLeaveMessage"
|
||||
:message="message"
|
||||
:index="index"
|
||||
:handlers="leaveHandlers"
|
||||
/>
|
||||
<ShippingInventoryMappingMessage
|
||||
v-else-if="message.type === 'shipping-inventory-mapping' && handlers.getShippingInventoryMappingPayload(message)"
|
||||
:message="message"
|
||||
:handlers="shippingHandlers"
|
||||
/>
|
||||
<div
|
||||
v-else
|
||||
class="chat-markdown prose prose-sm max-w-none leading-7 text-primary prose-a:text-blue-600 prose-p:my-1 prose-li:my-0.5 prose-ol:my-2 prose-ul:my-2 prose-headings:my-2 prose-hr:my-3 prose-code:rounded prose-code:bg-slate-100 prose-code:px-1 prose-code:text-blue-700 prose-pre:my-3 prose-pre:border prose-pre:border-slate-700 prose-pre:bg-slate-900 prose-pre:text-slate-100 prose-th:border prose-th:border-slate-200 prose-th:bg-slate-50 prose-th:px-3 prose-th:py-2 prose-th:text-left prose-td:border prose-td:border-slate-200 prose-td:px-3 prose-td:py-2"
|
||||
@click="handlers.onMarkdownClick"
|
||||
v-html="handlers.renderMarkdown(message.content)"
|
||||
/>
|
||||
|
||||
<div
|
||||
v-if="message.role === 'assistant' && handlers.canOpenQueryPreview(message)"
|
||||
class="mt-4"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-2 rounded-xl border border-brand-200 bg-brand-50 px-3 py-2 text-xs font-medium text-brand-700 transition hover:bg-brand-100"
|
||||
@click="handlers.openQueryPreviewDialog(message)"
|
||||
>
|
||||
<LayoutGrid class="h-3.5 w-3.5" />
|
||||
{{ handlers.getQueryPreviewSummary(message) }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="isShippingNoticeAgent && message.shipping_actions?.length"
|
||||
class="mt-4 space-y-2 border-t border-default pt-4"
|
||||
>
|
||||
<div class="text-xs font-medium text-muted">{{ $t('chat.shippingNoticeActionsHint') }}</div>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<button
|
||||
v-for="(action, actionIndex) in message.shipping_actions"
|
||||
:key="`${message.local_id || index}-shipping-action-${action.id}-${actionIndex}`"
|
||||
type="button"
|
||||
:class="handlers.shippingActionButtonClass(action.variant)"
|
||||
:disabled="isThinking || message.shipping_actions_used"
|
||||
@click="handlers.onShippingActionClick(message, action)"
|
||||
>
|
||||
{{ action.label }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="showSourceSection" class="mt-2 space-y-2">
|
||||
<div v-if="sourceLinks.length > 0" class="flex flex-wrap gap-2">
|
||||
<button
|
||||
v-for="(file, linkIndex) in sourceLinks"
|
||||
:key="`src-link-top-${linkIndex}-${file.url}`"
|
||||
type="button"
|
||||
class="break-all rounded-lg border border-brand-200 bg-brand-50 px-2.5 py-1.5 text-xs text-brand-700 transition-colors hover:bg-brand-100"
|
||||
@click="handlers.openPreview(file)"
|
||||
>
|
||||
{{ file.name }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<details
|
||||
v-if="retrieverResources.length > 0"
|
||||
class="rounded-xl border border-default bg-surface-soft/90 px-4 py-3"
|
||||
:open="handlers.shouldExpandSourceDetails(message)"
|
||||
>
|
||||
<summary class="cursor-pointer text-xs font-semibold uppercase tracking-wide text-secondary">
|
||||
{{ $t('chat.sourceDocs') }} ({{ retrieverResources.length }})
|
||||
</summary>
|
||||
<div class="mt-3 space-y-2">
|
||||
<div
|
||||
v-for="(doc, docIndex) in retrieverResources"
|
||||
:key="`${doc.document_name || 'doc'}-${doc.segment_id || docIndex}`"
|
||||
class="rounded-lg border border-default bg-surface p-3"
|
||||
>
|
||||
<div class="break-all text-sm font-semibold text-primary">{{ handlers.getSourceTitle(doc) }}</div>
|
||||
<div v-if="handlers.getSourceMeta(doc)" class="mt-1 text-xs text-muted">{{ handlers.getSourceMeta(doc) }}</div>
|
||||
<div v-if="handlers.getSourceBrief(doc)" class="mt-2 whitespace-pre-wrap break-all text-xs text-secondary">
|
||||
{{ handlers.getSourceBrief(doc) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<details
|
||||
v-if="message.attribution_parts && message.attribution_parts.length > 0"
|
||||
class="rounded-xl border border-default bg-surface-soft/90 px-4 py-3"
|
||||
open
|
||||
>
|
||||
<summary class="cursor-pointer text-xs font-semibold uppercase tracking-wide text-secondary">
|
||||
{{ $t('chat.attributionParts') }}
|
||||
</summary>
|
||||
<ul class="mt-3 space-y-2">
|
||||
<li
|
||||
v-for="(part, partIndex) in message.attribution_parts"
|
||||
:key="`attr-${partIndex}`"
|
||||
class="rounded-lg border border-default bg-surface p-3 text-xs text-secondary"
|
||||
>
|
||||
{{ part }}
|
||||
</li>
|
||||
</ul>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="showActions"
|
||||
class="mt-1 flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100"
|
||||
:class="message.role === 'user' ? 'justify-end text-muted' : 'justify-start text-muted'"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-md p-1.5 text-xs transition-colors hover-surface-soft"
|
||||
:title="$t('chat.actions.copy')"
|
||||
@click.stop="emit('copy')"
|
||||
>
|
||||
<Check v-if="isCopied" class="h-3.5 w-3.5 text-emerald-500" />
|
||||
<Copy v-else class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
|
||||
<template v-if="message.role === 'user'">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-md p-1.5 text-xs transition-colors hover-surface-soft"
|
||||
:title="$t('chat.actions.edit')"
|
||||
@click.stop="emit('edit', message.content)"
|
||||
>
|
||||
<Edit2 class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-md p-1.5 text-xs transition-colors hover-surface-soft"
|
||||
:title="$t('chat.actions.resend')"
|
||||
@click.stop="emit('resend', message.content)"
|
||||
>
|
||||
<RotateCw class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<button
|
||||
v-if="isLastMessage && !isThinking"
|
||||
type="button"
|
||||
class="rounded-md p-1.5 text-xs transition-colors hover-surface-soft"
|
||||
:title="$t('chat.actions.regenerate')"
|
||||
@click="emit('regenerate')"
|
||||
>
|
||||
<RotateCw class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
<button
|
||||
v-if="showChatRating && !isThinking && !message.rated"
|
||||
type="button"
|
||||
class="rounded-md p-1.5 text-xs transition-colors hover-surface-soft"
|
||||
:title="$t('chat.rate')"
|
||||
@click="emit('open-feedback')"
|
||||
>
|
||||
<MessageSquareText class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
:deep(.chat-markdown) {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
:deep(.chat-markdown .chat-table-scroll) {
|
||||
max-width: 100%;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
margin: 0.75rem 0;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
|
||||
:deep(.chat-markdown .chat-table-inner) {
|
||||
width: max-content;
|
||||
min-width: 100%;
|
||||
}
|
||||
|
||||
:deep(.chat-markdown table) {
|
||||
width: max-content;
|
||||
min-width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 0;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
:deep(.chat-markdown th),
|
||||
:deep(.chat-markdown td) {
|
||||
border: 1px solid rgb(226 232 240);
|
||||
padding: 0.5rem 0.75rem;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
:deep(.chat-markdown th) {
|
||||
background: rgb(248 250 252);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
:deep(.dark .chat-markdown th),
|
||||
:deep(.dark .chat-markdown td) {
|
||||
border-color: rgb(51 65 85);
|
||||
}
|
||||
|
||||
:deep(.dark .chat-markdown th) {
|
||||
background: rgb(30 41 59);
|
||||
}
|
||||
|
||||
:deep(.chat-markdown details) {
|
||||
margin-top: 1rem;
|
||||
border: 1px solid rgb(226 232 240);
|
||||
border-radius: 0.75rem;
|
||||
background: rgb(248 250 252 / 0.9);
|
||||
padding: 0.75rem 1rem;
|
||||
}
|
||||
|
||||
:deep(.dark .chat-markdown details) {
|
||||
border-color: rgb(51 65 85);
|
||||
background: rgb(30 41 59 / 0.65);
|
||||
}
|
||||
|
||||
:deep(.chat-markdown details summary) {
|
||||
cursor: pointer;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.08em;
|
||||
color: rgb(71 85 105);
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
:deep(.dark .chat-markdown details summary) {
|
||||
color: rgb(203 213 225);
|
||||
}
|
||||
|
||||
:deep(.chat-markdown details[open] summary) {
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
:deep(.chat-markdown details pre) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
:deep(.chat-markdown .leave-action-trigger) {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0 0.2rem;
|
||||
padding: 0.1rem 0.6rem;
|
||||
border-radius: 9999px;
|
||||
border: 1px solid rgb(59 130 246 / 0.28);
|
||||
background: rgb(239 246 255);
|
||||
color: rgb(29 78 216);
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
:deep(.chat-markdown .leave-action-trigger:hover) {
|
||||
background: rgb(219 234 254);
|
||||
border-color: rgb(59 130 246 / 0.4);
|
||||
}
|
||||
|
||||
:deep(.chat-markdown .leave-intent-highlight) {
|
||||
display: inline-block;
|
||||
margin: 0 0.2rem;
|
||||
padding: 0.05rem 0.4rem;
|
||||
border-radius: 0.5rem;
|
||||
background: rgb(254 249 195);
|
||||
color: rgb(161 98 7);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
:deep(.dark .chat-markdown .leave-action-trigger) {
|
||||
border-color: rgb(96 165 250 / 0.35);
|
||||
background: rgb(30 41 59);
|
||||
color: rgb(147 197 253);
|
||||
}
|
||||
|
||||
:deep(.dark .chat-markdown .leave-action-trigger:hover) {
|
||||
background: rgb(30 64 175 / 0.25);
|
||||
}
|
||||
|
||||
:deep(.dark .chat-markdown .leave-intent-highlight) {
|
||||
background: rgb(113 63 18 / 0.45);
|
||||
color: rgb(253 224 71);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,272 @@
|
||||
/**
|
||||
* features/chat/components/messages/LeaveMessageBlock.vue
|
||||
* 请假 OA 消息 UI(表单/确认/结果)。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { Search } from 'lucide-vue-next';
|
||||
import { LEAVE_TYPES } from '../../constants/leave';
|
||||
import type { ChatMessage } from '../../types/chat.types';
|
||||
import type {
|
||||
LeaveConfirmationPayload,
|
||||
LeaveFormPayload,
|
||||
LeaveRequestFormData,
|
||||
LeaveResultPayload,
|
||||
} from '../../types/leave.types';
|
||||
|
||||
export interface LeaveMessageHandlers {
|
||||
getLeaveFormPayload: (msg: ChatMessage) => LeaveFormPayload | null;
|
||||
getLeaveConfirmationPayload: (msg: ChatMessage) => LeaveConfirmationPayload | null;
|
||||
getLeaveResultPayload: (msg: ChatMessage) => LeaveResultPayload | null;
|
||||
getLeaveAgentDisplayValue: (form: LeaveRequestFormData) => string;
|
||||
getLeaveTypeLabel: (val: string) => string;
|
||||
formatDurationLabel: (hours: number, leaveType?: string) => string;
|
||||
formatYesNoLabel: (value: 0 | 1 | null) => string;
|
||||
syncLeaveDuration: (form: LeaveRequestFormData) => void;
|
||||
openLeaveAgentDialog: (msg: ChatMessage, role?: 'agent' | 'applicant') => void;
|
||||
openOALeaveRequestDirectly: () => void;
|
||||
openOARequestDirectly: (requestId: string) => void;
|
||||
submitLeaveForm: (msg: ChatMessage) => void;
|
||||
editLeaveConfirmation: (msg: ChatMessage, index: number) => void;
|
||||
confirmLeaveSubmission: (msg: ChatMessage) => void;
|
||||
}
|
||||
|
||||
const { message, index, handlers } = defineProps<{
|
||||
message: ChatMessage;
|
||||
index: number;
|
||||
handlers: LeaveMessageHandlers;
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="message.type === 'leave-form'" class="space-y-4">
|
||||
<div class="text-sm font-medium text-secondary">
|
||||
{{ $t('chat.leaveFormIntro') }} <a href="#" @click.prevent="handlers.openOALeaveRequestDirectly" class="text-brand-600 font-bold hover:underline">{{ $t('chat.oaLeaveDirectLink') }}</a>
|
||||
</div>
|
||||
<div v-if="handlers.getLeaveFormPayload(message)" class="grid gap-4 md:grid-cols-2">
|
||||
<label class="space-y-1.5">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.leaveFiller') }}</span>
|
||||
<input
|
||||
v-model="handlers.getLeaveFormPayload(message)!.form.fillerName"
|
||||
type="text"
|
||||
class="w-full rounded-xl border border-default bg-surface-soft px-3 py-2 text-sm text-muted outline-none"
|
||||
disabled
|
||||
/>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.employeeId') }}</span>
|
||||
<input
|
||||
v-model="handlers.getLeaveFormPayload(message)!.form.employeeId"
|
||||
type="text"
|
||||
class="w-full rounded-xl border border-default bg-surface-soft px-3 py-2 text-sm text-muted outline-none"
|
||||
disabled
|
||||
/>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.createdAt') }}</span>
|
||||
<input
|
||||
:value="handlers.getLeaveFormPayload(message)!.form.applyTime.replace('T', ' ')"
|
||||
type="text"
|
||||
class="w-full rounded-xl border border-default bg-surface-soft px-3 py-2 text-sm text-muted outline-none"
|
||||
disabled
|
||||
/>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.leaveType') }}</span>
|
||||
<select
|
||||
v-model="handlers.getLeaveFormPayload(message)!.form.leaveType"
|
||||
class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400"
|
||||
:disabled="handlers.getLeaveFormPayload(message)!.submitting || handlers.getLeaveFormPayload(message)!.confirmationGenerated"
|
||||
@change="handlers.syncLeaveDuration(handlers.getLeaveFormPayload(message)!.form)"
|
||||
>
|
||||
<option value="" disabled>{{ $t('chat.selectLeaveType') }}</option>
|
||||
<option v-for="leaveType in LEAVE_TYPES" :key="leaveType.value" :value="leaveType.value">{{ leaveType.label }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.leaveApplicant') }}</span>
|
||||
<div class="relative">
|
||||
<input
|
||||
:value="handlers.getLeaveFormPayload(message)!.form.applicantName ? `${handlers.getLeaveFormPayload(message)!.form.applicantName} / ${handlers.getLeaveFormPayload(message)!.form.employeeId}` : ''"
|
||||
type="text"
|
||||
:placeholder="$t('chat.selectLeaveApplicant')"
|
||||
readonly
|
||||
class="w-full rounded-xl border border-default bg-surface px-3 py-2 pr-11 text-sm text-secondary outline-none transition focus:border-blue-400"
|
||||
:disabled="handlers.getLeaveFormPayload(message)!.submitting || handlers.getLeaveFormPayload(message)!.confirmationGenerated"
|
||||
@click="handlers.openLeaveAgentDialog(message, 'applicant')"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="absolute inset-y-0 right-0 flex w-11 items-center justify-center text-muted transition hover:text-brand-600 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
:disabled="handlers.getLeaveFormPayload(message)!.submitting || handlers.getLeaveFormPayload(message)!.confirmationGenerated"
|
||||
@click="handlers.openLeaveAgentDialog(message, 'applicant')"
|
||||
:title="$t('chat.pickLeaveApplicant')"
|
||||
>
|
||||
<Search class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.leaveAgent') }}</span>
|
||||
<div class="relative">
|
||||
<input
|
||||
:value="handlers.getLeaveAgentDisplayValue(handlers.getLeaveFormPayload(message)!.form)"
|
||||
type="text"
|
||||
:placeholder="$t('chat.selectLeaveAgent')"
|
||||
readonly
|
||||
class="w-full rounded-xl border border-default bg-surface px-3 py-2 pr-11 text-sm text-secondary outline-none transition focus:border-blue-400"
|
||||
:disabled="handlers.getLeaveFormPayload(message)!.submitting || handlers.getLeaveFormPayload(message)!.confirmationGenerated"
|
||||
@click="handlers.openLeaveAgentDialog(message)"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="absolute inset-y-0 right-0 flex w-11 items-center justify-center text-muted transition hover:text-brand-600 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
:disabled="handlers.getLeaveFormPayload(message)!.submitting || handlers.getLeaveFormPayload(message)!.confirmationGenerated"
|
||||
@click="handlers.openLeaveAgentDialog(message)"
|
||||
:title="$t('chat.pickLeaveAgent')"
|
||||
>
|
||||
<Search class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.startTime') }}</span>
|
||||
<input
|
||||
v-model="handlers.getLeaveFormPayload(message)!.form.startTime"
|
||||
type="datetime-local"
|
||||
class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400"
|
||||
:disabled="handlers.getLeaveFormPayload(message)!.submitting || handlers.getLeaveFormPayload(message)!.confirmationGenerated"
|
||||
@input="handlers.syncLeaveDuration(handlers.getLeaveFormPayload(message)!.form)"
|
||||
/>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.endTime') }}</span>
|
||||
<input
|
||||
v-model="handlers.getLeaveFormPayload(message)!.form.endTime"
|
||||
type="datetime-local"
|
||||
class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400"
|
||||
:disabled="handlers.getLeaveFormPayload(message)!.submitting || handlers.getLeaveFormPayload(message)!.confirmationGenerated"
|
||||
@input="handlers.syncLeaveDuration(handlers.getLeaveFormPayload(message)!.form)"
|
||||
/>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.duration') }}</span>
|
||||
<input
|
||||
:value="handlers.formatDurationLabel(handlers.getLeaveFormPayload(message)!.form.durationHours, handlers.getLeaveFormPayload(message)!.form.leaveType)"
|
||||
type="text"
|
||||
class="w-full rounded-xl border border-default bg-surface-soft px-3 py-2 text-sm text-muted outline-none"
|
||||
disabled
|
||||
/>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.isOutOfOffice') }}</span>
|
||||
<select
|
||||
v-model="handlers.getLeaveFormPayload(message)!.form.isOutOfOffice"
|
||||
class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400"
|
||||
:disabled="handlers.getLeaveFormPayload(message)!.submitting || handlers.getLeaveFormPayload(message)!.confirmationGenerated"
|
||||
>
|
||||
<option :value="1">{{ $t('chat.no') }}</option>
|
||||
<option :value="0">{{ $t('chat.yes') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-1.5 md:col-span-2">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.isWorkInjury') }}</span>
|
||||
<select
|
||||
v-model="handlers.getLeaveFormPayload(message)!.form.isWorkInjury"
|
||||
class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400"
|
||||
:disabled="handlers.getLeaveFormPayload(message)!.submitting || handlers.getLeaveFormPayload(message)!.confirmationGenerated"
|
||||
>
|
||||
<option :value="1">{{ $t('chat.no') }}</option>
|
||||
<option :value="0">{{ $t('chat.yes') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div v-if="handlers.getLeaveFormPayload(message)?.confirmationGenerated" class="rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-xs text-amber-700">
|
||||
{{ $t('chat.leaveConfirmGenerated') }}
|
||||
</div>
|
||||
<div class="flex justify-end">
|
||||
<button
|
||||
@click="handlers.submitLeaveForm(message)"
|
||||
:disabled="handlers.getLeaveFormPayload(message)?.submitting || handlers.getLeaveFormPayload(message)?.confirmationGenerated"
|
||||
class="btn-primary btn-sm disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
{{ handlers.getLeaveFormPayload(message)?.submitting ? $t('chat.submitting') : $t('chat.submit') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="message.type === 'leave-confirmation' && handlers.getLeaveConfirmationPayload(message)" class="space-y-4">
|
||||
<div class="text-sm font-medium text-secondary">{{ message.content }}</div>
|
||||
<div class="rounded-2xl border border-default bg-surface-soft/90 p-4">
|
||||
<div class="mb-3 text-xs font-bold uppercase tracking-wider text-muted">{{ $t('chat.leaveFillerInfo') }}</div>
|
||||
<div class="grid gap-3 text-sm md:grid-cols-2">
|
||||
<div><span class="text-muted">{{ $t('chat.leaveFiller') }}:</span>{{ handlers.getLeaveConfirmationPayload(message)!.form.fillerName || $t('chat.noData') }}</div>
|
||||
<div><span class="text-muted">{{ $t('chat.createdAt') }}:</span>{{ handlers.getLeaveConfirmationPayload(message)!.form.applyTime.replace('T', ' ') }}</div>
|
||||
<div v-if="handlers.getLeaveConfirmationPayload(message)!.form.fillerJobTitleName || handlers.getLeaveConfirmationPayload(message)!.form.fillerJobTitle"><span class="text-muted">{{ $t('chat.leaveFillerTitle') }}:</span>{{ handlers.getLeaveConfirmationPayload(message)!.form.fillerJobTitleName || handlers.getLeaveConfirmationPayload(message)!.form.fillerJobTitle }}</div>
|
||||
<div v-if="handlers.getLeaveConfirmationPayload(message)!.form.fillerDepartmentName || handlers.getLeaveConfirmationPayload(message)!.form.fillerDepartmentId"><span class="text-muted">{{ $t('chat.leaveFillerDept') }}:</span>{{ handlers.getLeaveConfirmationPayload(message)!.form.fillerDepartmentName || handlers.getLeaveConfirmationPayload(message)!.form.fillerDepartmentId }}</div>
|
||||
<div v-if="handlers.getLeaveConfirmationPayload(message)!.form.fillerSubCompanyName || handlers.getLeaveConfirmationPayload(message)!.form.fillerSubCompanyId1"><span class="text-muted">{{ $t('chat.leaveFillerCompany') }}:</span>{{ handlers.getLeaveConfirmationPayload(message)!.form.fillerSubCompanyName || handlers.getLeaveConfirmationPayload(message)!.form.fillerSubCompanyId1 }}</div>
|
||||
</div>
|
||||
<div class="my-3 border-t border-default"></div>
|
||||
<div class="mb-3 text-xs font-bold uppercase tracking-wider text-muted">{{ $t('chat.leaveApplicantInfo') }}</div>
|
||||
<div class="grid gap-3 text-sm md:grid-cols-2">
|
||||
<div><span class="text-muted">{{ $t('chat.leaveApplicant') }}:</span>{{ handlers.getLeaveConfirmationPayload(message)!.form.applicantName }}({{ handlers.getLeaveConfirmationPayload(message)!.form.employeeId }})</div>
|
||||
<div v-if="handlers.getLeaveConfirmationPayload(message)!.form.applicantJobTitleName || handlers.getLeaveConfirmationPayload(message)!.form.applicantJobTitle"><span class="text-muted">{{ $t('chat.leaveApplicantTitle') }}:</span>{{ handlers.getLeaveConfirmationPayload(message)!.form.applicantJobTitleName || handlers.getLeaveConfirmationPayload(message)!.form.applicantJobTitle }}</div>
|
||||
<div v-if="handlers.getLeaveConfirmationPayload(message)!.form.applicantDepartmentName || handlers.getLeaveConfirmationPayload(message)!.form.applicantDepartmentId"><span class="text-muted">{{ $t('chat.leaveApplicantDept') }}:</span>{{ handlers.getLeaveConfirmationPayload(message)!.form.applicantDepartmentName || handlers.getLeaveConfirmationPayload(message)!.form.applicantDepartmentId }}</div>
|
||||
<div v-if="handlers.getLeaveConfirmationPayload(message)!.form.applicantSubCompanyName || handlers.getLeaveConfirmationPayload(message)!.form.applicantSubCompanyId1"><span class="text-muted">{{ $t('chat.leaveApplicantCompany') }}:</span>{{ handlers.getLeaveConfirmationPayload(message)!.form.applicantSubCompanyName || handlers.getLeaveConfirmationPayload(message)!.form.applicantSubCompanyId1 }}</div>
|
||||
</div>
|
||||
<div class="my-3 border-t border-default"></div>
|
||||
<div class="mb-3 text-xs font-bold uppercase tracking-wider text-muted">{{ $t('chat.leaveInfo') }}</div>
|
||||
<div class="grid gap-3 text-sm md:grid-cols-2">
|
||||
<div><span class="text-muted">{{ $t('chat.leaveAgent') }}:</span>{{ handlers.getLeaveAgentDisplayValue(handlers.getLeaveConfirmationPayload(message)!.form) || $t('chat.notSelected') }}</div>
|
||||
<div v-if="handlers.getLeaveConfirmationPayload(message)!.form.agentJobTitleName || handlers.getLeaveConfirmationPayload(message)!.form.agentJobTitle"><span class="text-muted">{{ $t('chat.leaveAgentTitle') }}:</span>{{ handlers.getLeaveConfirmationPayload(message)!.form.agentJobTitleName || handlers.getLeaveConfirmationPayload(message)!.form.agentJobTitle }}</div>
|
||||
<div v-if="handlers.getLeaveConfirmationPayload(message)!.form.agentDepartmentName || handlers.getLeaveConfirmationPayload(message)!.form.agentDepartmentId"><span class="text-muted">{{ $t('chat.leaveAgentDept') }}:</span>{{ handlers.getLeaveConfirmationPayload(message)!.form.agentDepartmentName || handlers.getLeaveConfirmationPayload(message)!.form.agentDepartmentId }}</div>
|
||||
<div v-if="handlers.getLeaveConfirmationPayload(message)!.form.agentSubCompanyName || handlers.getLeaveConfirmationPayload(message)!.form.agentSubCompanyId1"><span class="text-muted">{{ $t('chat.leaveAgentCompany') }}:</span>{{ handlers.getLeaveConfirmationPayload(message)!.form.agentSubCompanyName || handlers.getLeaveConfirmationPayload(message)!.form.agentSubCompanyId1 }}</div>
|
||||
<div><span class="text-muted">{{ $t('chat.leaveType') }}:</span>{{ handlers.getLeaveTypeLabel(handlers.getLeaveConfirmationPayload(message)!.form.leaveType) }}</div>
|
||||
<div><span class="text-muted">{{ $t('chat.duration') }}:</span>{{ handlers.formatDurationLabel(handlers.getLeaveConfirmationPayload(message)!.form.durationHours, handlers.getLeaveConfirmationPayload(message)!.form.leaveType) }}</div>
|
||||
<div><span class="text-muted">{{ $t('chat.startTime') }}:</span>{{ handlers.getLeaveConfirmationPayload(message)!.form.startTime.replace('T', ' ') }}</div>
|
||||
<div><span class="text-muted">{{ $t('chat.endTime') }}:</span>{{ handlers.getLeaveConfirmationPayload(message)!.form.endTime.replace('T', ' ') }}</div>
|
||||
<div><span class="text-muted">{{ $t('chat.isOutOfOffice') }}:</span>{{ handlers.formatYesNoLabel(handlers.getLeaveConfirmationPayload(message)!.form.isOutOfOffice) }}</div>
|
||||
<div><span class="text-muted">{{ $t('chat.isWorkInjury') }}:</span>{{ handlers.formatYesNoLabel(handlers.getLeaveConfirmationPayload(message)!.form.isWorkInjury) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-end gap-3">
|
||||
<button
|
||||
v-if="!handlers.getLeaveConfirmationPayload(message)?.submitting && !handlers.getLeaveConfirmationPayload(message)?.confirmed"
|
||||
@click="handlers.editLeaveConfirmation(message, index)"
|
||||
class="rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
{{ $t('chat.backToEdit') }}
|
||||
</button>
|
||||
<button
|
||||
@click="handlers.confirmLeaveSubmission(message)"
|
||||
:disabled="handlers.getLeaveConfirmationPayload(message)?.submitting || handlers.getLeaveConfirmationPayload(message)?.confirmed"
|
||||
class="rounded-xl bg-emerald-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-emerald-700 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
{{ handlers.getLeaveConfirmationPayload(message)?.submitting ? $t('chat.confirming') : (handlers.getLeaveConfirmationPayload(message)?.confirmed ? $t('chat.confirmed') : $t('chat.confirm')) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="message.type === 'leave-result' && handlers.getLeaveResultPayload(message)" class="space-y-3">
|
||||
<div
|
||||
class="rounded-2xl border px-4 py-4"
|
||||
:class="handlers.getLeaveResultPayload(message)!.success
|
||||
? 'border-emerald-200 bg-emerald-50 text-emerald-800'
|
||||
: 'border-rose-200 bg-rose-50 text-rose-800'"
|
||||
>
|
||||
<div class="text-sm font-semibold">{{ handlers.getLeaveResultPayload(message)!.success ? $t('chat.oaSubmitResult') : $t('chat.oaSubmitFailed') }}</div>
|
||||
<div v-if="handlers.getLeaveResultPayload(message)!.success" class="mt-2 whitespace-pre-wrap text-sm leading-7">
|
||||
{{ $t('chat.leaveResultPrefix') }}
|
||||
<a
|
||||
href="#"
|
||||
@click.prevent="handlers.openOARequestDirectly(handlers.getLeaveResultPayload(message)!.referenceNo)"
|
||||
class="ml-1 inline-flex items-center rounded-full border border-brand-200 bg-brand-50 px-3 py-0.5 font-bold text-brand-700 transition hover:bg-brand-100 hover:underline"
|
||||
>
|
||||
{{ $t('chat.leaveResultLinkText') }}
|
||||
</a>
|
||||
</div>
|
||||
<div v-else class="mt-2 whitespace-pre-wrap text-sm leading-7">{{ message.content }}</div>
|
||||
<div class="mt-3 text-xs opacity-80">{{ $t('chat.requestNo') }}:{{ handlers.getLeaveResultPayload(message)!.referenceNo }}</div>
|
||||
<div class="mt-1 text-xs opacity-80">{{ $t('chat.submitTime') }}:{{ handlers.getLeaveResultPayload(message)!.submittedAt }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* features/chat/components/messages/ShippingInventoryMappingMessage.vue
|
||||
* 出货 Agent:库存 Excel 列映射表单消息 UI。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import type { ChatMessage } from '../../types/chat.types';
|
||||
import type { ShippingInventoryMappingFormPayload } from '../../types/shipping.types';
|
||||
|
||||
export interface ShippingMappingHandlers {
|
||||
getPayload: (msg: ChatMessage) => ShippingInventoryMappingFormPayload | null;
|
||||
normalizeHeader: (header: string) => string;
|
||||
hasSampleRows: (msg: ChatMessage) => boolean;
|
||||
getSampleRowText: (msg: ChatMessage) => string;
|
||||
reupload: (msg: ChatMessage) => void;
|
||||
apply: (msg: ChatMessage) => void;
|
||||
}
|
||||
|
||||
const { message, handlers } = defineProps<{
|
||||
message: ChatMessage;
|
||||
handlers: ShippingMappingHandlers;
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="handlers.getPayload(message)" class="space-y-4">
|
||||
<div class="whitespace-pre-wrap text-sm font-medium text-secondary">{{ message.content }}</div>
|
||||
<div class="space-y-4 rounded-2xl border border-default bg-surface-soft/90 p-4">
|
||||
<div class="space-y-2">
|
||||
<div class="text-xs font-bold uppercase tracking-wider text-muted">{{ $t('chat.shippingNoticeMapping.inventoryHeaders') }}</div>
|
||||
<div class="text-xs text-muted">
|
||||
{{ $t('chat.shippingNoticeMapping.headerRow', { row: handlers.getPayload(message)!.schema_preview.header_row_index || 1 }) }}
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<span
|
||||
v-for="h in (handlers.getPayload(message)!.schema_preview.headers || [])"
|
||||
:key="`inv-h-${h}`"
|
||||
class="rounded-full border border-default bg-surface px-3 py-1 text-xs text-secondary"
|
||||
>{{ handlers.normalizeHeader(h) || $t('chat.shippingNoticeMapping.empty') }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="handlers.hasSampleRows(message)"
|
||||
class="whitespace-pre-wrap text-xs text-muted"
|
||||
>
|
||||
{{ $t('chat.shippingNoticeMapping.sample') }}:{{ handlers.getSampleRowText(message) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<div class="text-xs font-bold uppercase tracking-wider text-muted">{{ $t('chat.shippingNoticeMapping.orderDetails') }}</div>
|
||||
<div class="text-xs text-muted">
|
||||
{{ $t('chat.shippingNoticeMapping.orderRowCount', { count: handlers.getPayload(message)!.order.line_count }) }};{{ $t('chat.shippingNoticeMapping.orderSkuPreview', { count: handlers.getPayload(message)!.order.skus.length, skus: handlers.getPayload(message)!.order.skus.join(',') || $t('chat.shippingNoticeMapping.unrecognized') }) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<label class="space-y-1.5">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.shippingNoticeMapping.skuColumnRequired') }}</span>
|
||||
<select
|
||||
v-model="handlers.getPayload(message)!.form.sku"
|
||||
class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400"
|
||||
:disabled="handlers.getPayload(message)!.applying"
|
||||
>
|
||||
<option value="" disabled>{{ $t('chat.shippingNoticeMapping.selectHeader') }}</option>
|
||||
<option v-for="h in (handlers.getPayload(message)!.schema_preview.headers || [])" :key="`sku-${h}`" :value="h">{{ handlers.normalizeHeader(h) }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.shippingNoticeMapping.availableQtyColumnRequired') }}</span>
|
||||
<select
|
||||
v-model="handlers.getPayload(message)!.form.available_qty"
|
||||
class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400"
|
||||
:disabled="handlers.getPayload(message)!.applying"
|
||||
>
|
||||
<option value="" disabled>{{ $t('chat.shippingNoticeMapping.selectHeader') }}</option>
|
||||
<option v-for="h in (handlers.getPayload(message)!.schema_preview.headers || [])" :key="`qty-${h}`" :value="h">{{ handlers.normalizeHeader(h) }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-1.5 md:col-span-2">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.shippingNoticeMapping.reservationIdColumnOptional') }}</span>
|
||||
<select
|
||||
v-model="handlers.getPayload(message)!.form.reservation_id"
|
||||
class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400"
|
||||
:disabled="handlers.getPayload(message)!.applying"
|
||||
>
|
||||
<option value="">{{ $t('chat.shippingNoticeMapping.reservationIdNotUsed') }}</option>
|
||||
<option v-for="h in (handlers.getPayload(message)!.schema_preview.headers || [])" :key="`rid-${h}`" :value="h">{{ handlers.normalizeHeader(h) }}</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-3">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="handlers.getPayload(message)!.applying"
|
||||
@click="handlers.reupload(message)"
|
||||
>
|
||||
{{ $t('chat.shippingNoticeMapping.reupload') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-xl bg-emerald-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-emerald-700 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="handlers.getPayload(message)!.applying"
|
||||
@click="handlers.apply(message)"
|
||||
>
|
||||
{{ handlers.getPayload(message)!.applying ? $t('chat.shippingNoticeMapping.applying') : $t('chat.shippingNoticeMapping.applyAndParse') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user