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,116 @@
|
||||
/**
|
||||
* features/chat/components/ChatBrowserPanel.vue
|
||||
* 内置浏览器侧栏 UI:移动端遮罩、拖拽分隔条与 iframe 预览区。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { ExternalLink, Globe, RotateCw, X } from 'lucide-vue-next';
|
||||
|
||||
const open = defineModel<boolean>('open', { required: true });
|
||||
const draftUrl = defineModel<string>('draftUrl', { required: true });
|
||||
|
||||
defineProps<{
|
||||
currentUrl: string;
|
||||
frameKey: number;
|
||||
panelStyle: { width: string } | undefined;
|
||||
isResizing: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
load: [];
|
||||
refresh: [];
|
||||
'open-new-tab': [];
|
||||
'url-enter': [event: KeyboardEvent];
|
||||
'start-resize': [event: MouseEvent];
|
||||
close: [];
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-if="open">
|
||||
<div
|
||||
class="fixed inset-0 z-40 bg-overlay backdrop-blur-sm lg:hidden"
|
||||
@click="emit('close')"
|
||||
/>
|
||||
|
||||
<div
|
||||
class="relative z-10 hidden w-2 shrink-0 cursor-col-resize bg-transparent lg:block"
|
||||
@mousedown="emit('start-resize', $event)"
|
||||
>
|
||||
<div
|
||||
class="absolute inset-y-0 left-1/2 w-px -translate-x-1/2 transition-colors"
|
||||
:class="isResizing ? 'bg-brand-500' : 'bg-slate-200'"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<aside
|
||||
class="fixed inset-y-0 right-0 z-50 flex w-full max-w-[100vw] flex-col border-l border-default bg-surface shadow-2xl sm:w-[420px] lg:static lg:z-0 lg:w-[420px] lg:shadow-none"
|
||||
:style="panelStyle"
|
||||
>
|
||||
<div class="flex items-center justify-between border-b border-default px-4 py-3">
|
||||
<div class="flex items-center gap-2 text-sm font-semibold text-secondary">
|
||||
<Globe class="h-4 w-4 text-brand-500" />
|
||||
{{ $t('chat.browser') }}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-md p-1.5 text-muted transition-colors hover-surface-soft hover:text-secondary"
|
||||
:title="$t('chat.closeBrowser')"
|
||||
@click="emit('close')"
|
||||
>
|
||||
<X class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2 border-b border-default px-3 py-3">
|
||||
<input
|
||||
v-model="draftUrl"
|
||||
type="text"
|
||||
:placeholder="$t('chat.browserInputPlaceholder')"
|
||||
class="flex-1 rounded-xl border border-default bg-surface-soft px-3 py-2 text-sm text-primary outline-none transition focus:border-brand-400 focus:bg-surface"
|
||||
@keydown="emit('url-enter', $event)"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-xl bg-brand-600 px-3 py-2 text-xs font-medium text-white transition-colors hover:bg-brand-500"
|
||||
@click="emit('load')"
|
||||
>
|
||||
{{ $t('chat.open') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-xl border border-default p-2 text-muted transition-colors hover:bg-surface-soft hover:text-secondary"
|
||||
:title="$t('chat.refresh')"
|
||||
@click="emit('refresh')"
|
||||
>
|
||||
<RotateCw class="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-xl border border-default p-2 text-muted transition-colors hover:bg-surface-soft hover:text-secondary"
|
||||
:title="$t('chat.openInNewTab')"
|
||||
@click="emit('open-new-tab')"
|
||||
>
|
||||
<ExternalLink class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="min-h-0 flex-1 bg-slate-100">
|
||||
<div
|
||||
v-if="!currentUrl"
|
||||
class="flex h-full flex-col items-center justify-center gap-3 px-8 text-center text-sm text-muted"
|
||||
>
|
||||
<Globe class="h-8 w-8 text-brand-500" />
|
||||
<div>{{ $t('chat.browserHint1') }}</div>
|
||||
<div class="text-xs">{{ $t('chat.browserHint2') }}</div>
|
||||
</div>
|
||||
<iframe
|
||||
v-else
|
||||
:key="frameKey"
|
||||
:src="currentUrl"
|
||||
class="h-full w-full border-0 bg-surface"
|
||||
allow="clipboard-read; clipboard-write"
|
||||
/>
|
||||
</div>
|
||||
</aside>
|
||||
</template>
|
||||
</template>
|
||||
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* features/chat/components/ChatGuideModal.vue
|
||||
* Agent 学习之窗:指南目录与视频 / PDF / 图片预览。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { BookOpen, FileText, Image as ImageIcon, PanelLeftClose, PanelLeftOpen, Play, X } from 'lucide-vue-next';
|
||||
import type { AgentGuide } from '../composables/useChatGuides';
|
||||
|
||||
const open = defineModel<boolean>('open', { required: true });
|
||||
const activeGuideId = defineModel<number | null>('activeGuideId', { required: true });
|
||||
const showSidebar = defineModel<boolean>('showSidebar', { required: true });
|
||||
|
||||
defineProps<{
|
||||
agentName: string;
|
||||
guides: AgentGuide[];
|
||||
activeGuide: AgentGuide | undefined;
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="open"
|
||||
class="fixed inset-0 z-[9999] flex items-center justify-center bg-black/50 p-4 backdrop-blur-sm"
|
||||
>
|
||||
<div class="flex h-[85vh] w-full max-w-4xl flex-col overflow-hidden rounded-2xl bg-surface shadow-xl">
|
||||
<div class="flex shrink-0 items-center justify-between border-b border-default bg-surface px-6 py-4">
|
||||
<h3 class="flex items-center gap-2 text-lg font-bold text-primary">
|
||||
<BookOpen class="h-5 w-5 text-brand-600" />
|
||||
{{ agentName }} - 学习之窗
|
||||
</h3>
|
||||
<div class="flex items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-1.5 rounded-lg border border-transparent px-3 py-1.5 text-sm font-medium text-brand-600 transition-colors hover:border-brand-100 hover:bg-brand-50 hover:text-brand-700"
|
||||
@click="showSidebar = !showSidebar"
|
||||
>
|
||||
<component :is="showSidebar ? PanelLeftClose : PanelLeftOpen" class="h-4 w-4" />
|
||||
{{ showSidebar ? '收起目录' : '展开目录' }}
|
||||
</button>
|
||||
<div class="h-5 w-px bg-default" />
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg p-1 text-muted transition-colors hover:bg-surface-soft hover:text-primary"
|
||||
@click="open = false"
|
||||
>
|
||||
<X class="h-6 w-6" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="relative flex min-h-0 flex-1 overflow-hidden">
|
||||
<div
|
||||
v-show="showSidebar"
|
||||
class="absolute z-10 h-full w-64 shrink-0 space-y-2 overflow-y-auto border-r border-default bg-surface-soft p-4 shadow-xl transition-transform duration-300 md:relative md:shadow-none"
|
||||
:class="showSidebar ? 'translate-x-0' : '-translate-x-full absolute'"
|
||||
>
|
||||
<button
|
||||
v-for="guide in guides"
|
||||
:key="guide.id"
|
||||
type="button"
|
||||
class="w-full rounded-xl border px-4 py-3 text-left transition-all"
|
||||
:class="activeGuideId === guide.id ? 'border-brand-200 bg-brand-50 text-brand-700 shadow-sm' : 'border-transparent bg-surface hover:border-default hover:shadow-sm'"
|
||||
@click="activeGuideId = guide.id"
|
||||
>
|
||||
<div class="mb-1 flex items-center gap-2">
|
||||
<component
|
||||
:is="guide.file_type === 'video' ? Play : (guide.file_type === 'pdf' ? FileText : ImageIcon)"
|
||||
class="h-4 w-4 shrink-0"
|
||||
/>
|
||||
<span class="truncate text-sm font-medium">{{ guide.file_name }}</span>
|
||||
</div>
|
||||
<p
|
||||
v-if="guide.remark"
|
||||
class="truncate text-xs opacity-70"
|
||||
:class="activeGuideId === guide.id ? 'text-brand-600' : 'text-muted'"
|
||||
>
|
||||
{{ guide.remark }}
|
||||
</p>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="relative flex flex-1 items-center justify-center overflow-hidden bg-[#ebedf0] dark:bg-gray-900">
|
||||
<template v-if="activeGuide">
|
||||
<video
|
||||
v-if="activeGuide.file_type === 'video'"
|
||||
:key="'video-' + activeGuide.id"
|
||||
:src="activeGuide.file_url || activeGuide.file_path"
|
||||
controls
|
||||
class="h-full w-full bg-black object-contain"
|
||||
/>
|
||||
<iframe
|
||||
v-else-if="activeGuide.file_type === 'pdf'"
|
||||
:key="'pdf-' + activeGuide.id"
|
||||
:src="activeGuide.file_url || activeGuide.file_path"
|
||||
class="h-full w-full border-none bg-white"
|
||||
/>
|
||||
<img
|
||||
v-else
|
||||
:key="'img-' + activeGuide.id"
|
||||
:src="activeGuide.file_url || activeGuide.file_path"
|
||||
class="max-h-full max-w-full object-contain"
|
||||
/>
|
||||
</template>
|
||||
<div v-else class="flex flex-col items-center gap-3 text-muted">
|
||||
<BookOpen class="h-12 w-12 opacity-20" />
|
||||
<p class="text-sm">请选择左侧指南进行查阅</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
@@ -0,0 +1,346 @@
|
||||
/**
|
||||
* features/chat/components/ChatInputBar.vue
|
||||
* 聊天输入栏:文本框、附件、语音、知识库选择与发送按钮。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import type { Ref } from 'vue';
|
||||
import {
|
||||
Check,
|
||||
ChevronDown,
|
||||
Database,
|
||||
Globe,
|
||||
Link2,
|
||||
Loader2,
|
||||
Mic,
|
||||
Paperclip,
|
||||
Send,
|
||||
X,
|
||||
} from 'lucide-vue-next';
|
||||
import type { PendingAttachment } from '../types/shipping.types';
|
||||
|
||||
export interface ChatInputAttachmentPolicy {
|
||||
anyEnabled: boolean;
|
||||
canLocal: boolean;
|
||||
canRemote: boolean;
|
||||
accept: string;
|
||||
}
|
||||
|
||||
const inputValue = defineModel<string>({ required: true });
|
||||
const selectedKb = defineModel<string>('selectedKb', { required: true });
|
||||
|
||||
const props = defineProps<{
|
||||
attachments: PendingAttachment[];
|
||||
attachmentPolicy: ChatInputAttachmentPolicy;
|
||||
availableKbOptions: string[];
|
||||
kbDropdownDisabled: boolean;
|
||||
isThinking: boolean;
|
||||
isVoiceRecording: boolean;
|
||||
isVoiceTranscribing: boolean;
|
||||
isUploadingAttachments: boolean;
|
||||
canSendMessage: boolean;
|
||||
isShippingNoticeAgent: boolean;
|
||||
shippingSuggestedPrompt: string;
|
||||
/** 用对象包裹 Ref,避免 template 自动解包 */
|
||||
shippingPickerRefHolder: { pickerRef: Ref<HTMLInputElement | null> };
|
||||
getKbLabel: (kb: string) => string;
|
||||
browserPanelOpen: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
send: [];
|
||||
'toggle-browser': [];
|
||||
'voice-click': [];
|
||||
'remove-attachment': [id: string];
|
||||
'local-files-selected': [event: Event];
|
||||
'add-remote-url': [url: string];
|
||||
'shipping-inventory-selected': [event: Event];
|
||||
'use-shipping-suggested-prompt': [];
|
||||
}>();
|
||||
|
||||
const filePickerRef = ref<HTMLInputElement | null>(null);
|
||||
const attachmentMenuRef = ref<HTMLElement | null>(null);
|
||||
const kbMenuRef = ref<HTMLElement | null>(null);
|
||||
const attachmentUrlInputRef = ref<HTMLInputElement | null>(null);
|
||||
const showAttachmentMenu = ref(false);
|
||||
const showAttachmentUrlPanel = ref(false);
|
||||
const showKbDropdown = ref(false);
|
||||
const attachmentUrlInput = ref('');
|
||||
|
||||
const closeAttachmentMenu = () => {
|
||||
showAttachmentMenu.value = false;
|
||||
showAttachmentUrlPanel.value = false;
|
||||
attachmentUrlInput.value = '';
|
||||
};
|
||||
|
||||
const toggleAttachmentMenu = () => {
|
||||
if (props.isThinking || props.isUploadingAttachments) return;
|
||||
showAttachmentMenu.value = !showAttachmentMenu.value;
|
||||
if (!showAttachmentMenu.value) {
|
||||
showAttachmentUrlPanel.value = false;
|
||||
attachmentUrlInput.value = '';
|
||||
}
|
||||
};
|
||||
|
||||
const selectAttachmentLocal = () => {
|
||||
if (!props.attachmentPolicy.canLocal) return;
|
||||
closeAttachmentMenu();
|
||||
filePickerRef.value?.click();
|
||||
};
|
||||
|
||||
const selectAttachmentUrl = async () => {
|
||||
if (!props.attachmentPolicy.canRemote) return;
|
||||
showAttachmentMenu.value = true;
|
||||
showAttachmentUrlPanel.value = true;
|
||||
await nextTick();
|
||||
attachmentUrlInputRef.value?.focus();
|
||||
};
|
||||
|
||||
const toggleKbDropdown = () => {
|
||||
if (props.kbDropdownDisabled) {
|
||||
showKbDropdown.value = false;
|
||||
return;
|
||||
}
|
||||
showKbDropdown.value = !showKbDropdown.value;
|
||||
};
|
||||
|
||||
const selectKb = (option: string) => {
|
||||
if (!props.availableKbOptions.includes(option)) return;
|
||||
selectedKb.value = option;
|
||||
showKbDropdown.value = false;
|
||||
};
|
||||
|
||||
const submitRemoteUrl = () => {
|
||||
const raw = attachmentUrlInput.value.trim();
|
||||
if (!raw) return;
|
||||
emit('add-remote-url', raw);
|
||||
closeAttachmentMenu();
|
||||
};
|
||||
|
||||
const bindShippingPickerRef = (el: unknown) => {
|
||||
props.shippingPickerRefHolder.pickerRef.value = (el as HTMLInputElement | null) ?? null;
|
||||
};
|
||||
|
||||
const handleDocumentPointerDown = (event: MouseEvent | TouchEvent) => {
|
||||
const target = event.target as Node | null;
|
||||
if (!target) return;
|
||||
if (showKbDropdown.value && kbMenuRef.value && !kbMenuRef.value.contains(target)) {
|
||||
showKbDropdown.value = false;
|
||||
}
|
||||
if (showAttachmentMenu.value && attachmentMenuRef.value && !attachmentMenuRef.value.contains(target)) {
|
||||
closeAttachmentMenu();
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('mousedown', handleDocumentPointerDown);
|
||||
document.addEventListener('touchstart', handleDocumentPointerDown, { passive: true });
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('mousedown', handleDocumentPointerDown);
|
||||
document.removeEventListener('touchstart', handleDocumentPointerDown);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<footer class="safe-bottom sticky bottom-0 z-20 bg-transparent p-3 md:p-6">
|
||||
<div class="relative mx-auto max-w-4xl">
|
||||
<div class="flex flex-col rounded-2xl bg-surface p-2 shadow-[0_0_15px_rgba(0,0,0,0.05)] transition-all">
|
||||
<textarea
|
||||
v-model="inputValue"
|
||||
rows="1"
|
||||
:placeholder="isVoiceTranscribing ? $t('chat.voiceTranscribing') : isVoiceRecording ? $t('chat.voiceListening') : $t('chat.askAnything')"
|
||||
class="w-full resize-none border-none bg-transparent px-3 py-2 text-[15px] leading-relaxed text-primary placeholder-slate-400 focus:border-transparent focus:outline-none focus:ring-0"
|
||||
style="min-height: 44px; max-height: 220px;"
|
||||
:disabled="isThinking || isVoiceTranscribing"
|
||||
spellcheck="false"
|
||||
autocorrect="off"
|
||||
autocapitalize="off"
|
||||
@keydown.enter.prevent="emit('send')"
|
||||
/>
|
||||
|
||||
<input
|
||||
:ref="bindShippingPickerRef"
|
||||
type="file"
|
||||
class="hidden"
|
||||
accept=".xlsx,.xls,.csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,text/csv"
|
||||
@change="emit('shipping-inventory-selected', $event)"
|
||||
/>
|
||||
|
||||
<input
|
||||
ref="filePickerRef"
|
||||
type="file"
|
||||
multiple
|
||||
class="hidden"
|
||||
:accept="attachmentPolicy.accept || undefined"
|
||||
@change="emit('local-files-selected', $event)"
|
||||
/>
|
||||
|
||||
<div v-if="attachments.length > 0" class="flex flex-wrap gap-2 px-3 pb-1">
|
||||
<div
|
||||
v-for="a in attachments"
|
||||
:key="a.id"
|
||||
class="flex items-center gap-2 rounded-lg border border-default bg-surface-soft px-2 py-1 text-xs text-secondary"
|
||||
>
|
||||
<span class="max-w-[220px] truncate">
|
||||
{{ a.kind === 'local' ? a.file.name : a.url }}
|
||||
</span>
|
||||
<button type="button" class="text-muted hover:text-red-500" @click="emit('remove-attachment', a.id)">
|
||||
<X class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="isShippingNoticeAgent && attachments.length > 0"
|
||||
class="flex flex-wrap items-center gap-2 px-3 pb-1 text-xs text-muted"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-full border border-default bg-surface-soft px-3 py-1 font-medium text-secondary transition-colors hover:bg-surface-soft/70"
|
||||
@click="emit('use-shipping-suggested-prompt')"
|
||||
>
|
||||
{{ shippingSuggestedPrompt || '推荐问题' }}
|
||||
</button>
|
||||
<span>点发送开始处理</span>
|
||||
</div>
|
||||
|
||||
<div class="mt-2 flex items-center justify-between px-2 pb-1">
|
||||
<div class="flex items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
:disabled="isThinking || isVoiceTranscribing"
|
||||
:title="isVoiceRecording ? $t('chat.voiceStop') : isVoiceTranscribing ? $t('chat.voiceTranscribing') : $t('chat.voiceFeature')"
|
||||
class="transition-colors disabled:cursor-not-allowed disabled:opacity-50"
|
||||
:class="isVoiceRecording ? 'animate-pulse text-red-500' : isVoiceTranscribing ? 'text-brand-500' : 'text-muted hover:text-brand-600'"
|
||||
@click="emit('voice-click')"
|
||||
>
|
||||
<Loader2 v-if="isVoiceTranscribing" class="h-5 w-5 animate-spin" />
|
||||
<Mic v-else class="h-5 w-5" />
|
||||
</button>
|
||||
|
||||
<div v-if="attachmentPolicy.anyEnabled" ref="attachmentMenuRef" class="relative">
|
||||
<button
|
||||
type="button"
|
||||
:disabled="isThinking || isUploadingAttachments"
|
||||
title="附件"
|
||||
class="flex h-9 w-9 items-center justify-center rounded-lg text-muted transition-colors hover:text-brand-600 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
@click="toggleAttachmentMenu"
|
||||
>
|
||||
<Paperclip class="h-5 w-5" />
|
||||
</button>
|
||||
<div
|
||||
v-if="showAttachmentMenu"
|
||||
class="absolute bottom-full left-0 mb-2 w-72 animate-fade-in overflow-hidden rounded-xl border border-subtle bg-surface py-1 shadow-xl"
|
||||
>
|
||||
<button
|
||||
v-if="attachmentPolicy.canLocal"
|
||||
type="button"
|
||||
class="flex w-full items-center gap-2 px-3 py-2 text-xs text-secondary transition-colors hover:bg-surface-soft"
|
||||
@click="selectAttachmentLocal"
|
||||
>
|
||||
<Paperclip class="h-4 w-4 text-brand-500" />
|
||||
上传本地文件
|
||||
</button>
|
||||
<button
|
||||
v-if="attachmentPolicy.canRemote"
|
||||
type="button"
|
||||
class="flex w-full items-center gap-2 px-3 py-2 text-xs text-secondary transition-colors hover:bg-surface-soft"
|
||||
@click="selectAttachmentUrl"
|
||||
>
|
||||
<Link2 class="h-4 w-4 text-brand-500" />
|
||||
粘贴 URL
|
||||
</button>
|
||||
<div v-if="showAttachmentUrlPanel" class="px-3 py-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<input
|
||||
ref="attachmentUrlInputRef"
|
||||
v-model="attachmentUrlInput"
|
||||
:disabled="isThinking || isUploadingAttachments"
|
||||
placeholder="粘贴附件 URL(http/https)"
|
||||
class="flex-1 rounded-lg border border-default bg-surface-soft px-3 py-2 text-xs text-secondary placeholder-slate-400 focus:outline-none focus:ring-0"
|
||||
@keydown.enter.prevent="submitRemoteUrl"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="isThinking || isUploadingAttachments"
|
||||
class="flex h-9 w-9 items-center justify-center rounded-lg border border-default text-muted transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
|
||||
title="添加"
|
||||
@click="submitRemoteUrl"
|
||||
>
|
||||
<Check class="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="isThinking || isUploadingAttachments"
|
||||
class="flex h-9 w-9 items-center justify-center rounded-lg border border-default text-muted transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
|
||||
title="取消"
|
||||
@click="closeAttachmentMenu"
|
||||
>
|
||||
<X class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ref="kbMenuRef" class="relative">
|
||||
<button
|
||||
type="button"
|
||||
:disabled="kbDropdownDisabled"
|
||||
class="flex items-center gap-1 rounded-lg border border-default px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
|
||||
@click="toggleKbDropdown"
|
||||
>
|
||||
<Database class="h-3.5 w-3.5 text-brand-500" />
|
||||
{{ getKbLabel(selectedKb) }} <ChevronDown class="h-3 w-3" />
|
||||
</button>
|
||||
<div
|
||||
v-if="showKbDropdown && !kbDropdownDisabled"
|
||||
class="absolute bottom-full left-0 mb-2 w-36 animate-fade-in overflow-hidden rounded-xl border border-subtle bg-surface py-1 shadow-xl"
|
||||
>
|
||||
<button
|
||||
v-for="option in availableKbOptions"
|
||||
:key="option"
|
||||
type="button"
|
||||
class="flex w-full items-center justify-between px-3 py-2 text-xs text-secondary transition-colors hover:bg-surface-soft"
|
||||
:class="{ 'font-bold text-brand-700': selectedKb === option }"
|
||||
@click="selectKb(option)"
|
||||
>
|
||||
{{ getKbLabel(option) }}
|
||||
<Check v-if="selectedKb === option" class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
:disabled="isThinking"
|
||||
class="flex items-center gap-1 rounded-lg border border-default px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
|
||||
@click="emit('toggle-browser')"
|
||||
>
|
||||
<Globe class="h-3.5 w-3.5 text-brand-500" />
|
||||
{{ browserPanelOpen ? $t('chat.collapseBrowser') : $t('chat.openBrowser') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
:disabled="!canSendMessage"
|
||||
class="flex h-10 w-10 items-center justify-center rounded-full border shadow-sm transition-all duration-200 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
:class="!canSendMessage
|
||||
? 'border-default bg-slate-100 text-muted'
|
||||
: 'border-brand-500 bg-brand-500 text-white shadow-[0_0_0_4px_rgba(59,130,246,0.18)] hover:scale-105 hover:bg-brand-600 hover:shadow-[0_0_0_6px_rgba(59,130,246,0.24)] active:scale-95'"
|
||||
@click="emit('send')"
|
||||
>
|
||||
<Loader2 v-if="isUploadingAttachments" class="h-4 w-4 animate-spin" />
|
||||
<Send v-else class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-3 text-center text-[11px] text-muted">
|
||||
{{ $t('chat.disclaimer') }}
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</template>
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* features/chat/components/ChatLeaveAgentDialog.vue
|
||||
* 请假 OA:选择代理人 / 申请人弹窗。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { Loader2, Search, X } from 'lucide-vue-next';
|
||||
import type { LeaveAgentOption } from '../types/leave.types';
|
||||
|
||||
const open = defineModel<boolean>('open', { required: true });
|
||||
const keyword = defineModel<string>('keyword', { required: true });
|
||||
|
||||
defineProps<{
|
||||
selectRole: 'agent' | 'applicant';
|
||||
options: LeaveAgentOption[];
|
||||
loading: boolean;
|
||||
page: number;
|
||||
hasMore: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
search: [];
|
||||
'load-more': [];
|
||||
'load-all': [];
|
||||
select: [option: LeaveAgentOption];
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="open"
|
||||
class="dialog-overlay z-[100] items-center"
|
||||
@click.self="emit('close')"
|
||||
>
|
||||
<div class="dialog-panel flex max-h-[80vh] max-w-2xl flex-col">
|
||||
<div class="dialog-header">
|
||||
<div>
|
||||
<h3 class="section-title">
|
||||
{{ $t('chat.selectWho', { role: selectRole === 'agent' ? $t('chat.leaveAgent') : $t('chat.leaveApplicant') }) }}
|
||||
</h3>
|
||||
<p class="section-desc mt-1">{{ $t('chat.oaDataConnected') }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds" :aria-label="$t('admin.close')" @click="emit('close')">
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="dialog-body space-y-4 border-t-0 pt-4">
|
||||
<div class="relative shrink-0">
|
||||
<input
|
||||
v-model="keyword"
|
||||
type="text"
|
||||
:placeholder="$t('chat.searchByNameOrEmployeeId')"
|
||||
class="input-field pr-10"
|
||||
@keydown.enter="emit('search')"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="absolute inset-y-0 right-0 flex w-10 items-center justify-center text-muted hover:text-brand-600"
|
||||
@click="emit('search')"
|
||||
>
|
||||
<Search class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="max-h-[50vh] flex-1 space-y-3 overflow-y-auto pr-2 scrollbar-thin">
|
||||
<div v-if="loading && page === 1" class="flex justify-center py-8">
|
||||
<Loader2 class="h-6 w-6 animate-spin text-brand-500" />
|
||||
</div>
|
||||
<div v-else-if="options.length === 0" class="py-8 text-center text-sm text-muted">
|
||||
{{ $t('chat.noData') }}
|
||||
</div>
|
||||
<template v-else>
|
||||
<button
|
||||
v-for="option in options"
|
||||
:key="option.uid"
|
||||
type="button"
|
||||
class="flex w-full items-center justify-between rounded-2xl border border-default px-4 py-4 text-left transition hover:border-brand-300 hover:bg-brand-50/50"
|
||||
@click="emit('select', option)"
|
||||
>
|
||||
<div class="space-y-1">
|
||||
<div class="text-sm font-semibold text-primary">{{ option.name }}</div>
|
||||
<div class="text-xs text-muted">UID:{{ option.uid }}</div>
|
||||
</div>
|
||||
<div class="text-right text-xs text-muted">
|
||||
<div>{{ $t('chat.employeeId') }}:{{ option.employeeId }}</div>
|
||||
<div>{{ $t('chat.name') }}:{{ option.name }}</div>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<div v-if="hasMore" class="flex items-center justify-center space-x-6 py-4">
|
||||
<button
|
||||
type="button"
|
||||
class="text-xs text-muted hover:text-secondary disabled:opacity-50"
|
||||
:disabled="loading"
|
||||
@click="emit('load-all')"
|
||||
>
|
||||
{{ $t('chat.loadAll') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="text-xs text-brand-600 hover:text-brand-700 disabled:opacity-50"
|
||||
:disabled="loading"
|
||||
@click="emit('load-more')"
|
||||
>
|
||||
{{ loading ? $t('chat.loading') : $t('chat.loadMore') }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-else class="py-4 text-center text-xs text-muted">{{ $t('chat.noMoreData') }}</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* features/chat/components/ChatMessageList.vue
|
||||
* 消息列表主区域:滚动容器、欢迎页、消息气泡与思考中占位。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import type { Ref } from 'vue';
|
||||
import ChatWelcomePanel, { type WelcomeQuestionItem, type WelcomeQuestionSection } from './ChatWelcomePanel.vue';
|
||||
import ChatThinkingBubble from './ChatThinkingBubble.vue';
|
||||
import ChatMessageBubble, { type ChatMessageBubbleHandlers } from './messages/ChatMessageBubble.vue';
|
||||
import type { LeaveMessageHandlers } from './messages/LeaveMessageBlock.vue';
|
||||
import type { ShippingMappingHandlers } from './messages/ShippingInventoryMappingMessage.vue';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
|
||||
const {
|
||||
messages,
|
||||
shouldRenderMessage,
|
||||
scrollContainerHolder,
|
||||
} = defineProps<{
|
||||
messages: ChatMessage[];
|
||||
agentName: string;
|
||||
suggestedQuestionsStyle: 'plain' | 'styled';
|
||||
styledSections: WelcomeQuestionSection[];
|
||||
suggestedQuestions: WelcomeQuestionItem[];
|
||||
showThinkingBubble: boolean;
|
||||
isThinking: boolean;
|
||||
showChatRating: boolean;
|
||||
copiedIndex: number | null;
|
||||
isShippingNoticeAgent: boolean;
|
||||
handlers: ChatMessageBubbleHandlers;
|
||||
leaveHandlers: LeaveMessageHandlers;
|
||||
shippingHandlers: ShippingMappingHandlers;
|
||||
shouldRenderMessage: (msg: ChatMessage) => boolean;
|
||||
/** 供父级滚动逻辑绑定 main 元素 */
|
||||
scrollContainerHolder: { el: Ref<HTMLElement | null> };
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
copy: [payload: { message: ChatMessage; index: number }];
|
||||
edit: [content: string];
|
||||
resend: [content: string];
|
||||
regenerate: [];
|
||||
'open-feedback': [index: number];
|
||||
'select-question': [question: string];
|
||||
}>();
|
||||
|
||||
const bindScrollContainer = (node: unknown) => {
|
||||
scrollContainerHolder.el.value = (node as HTMLElement | null) ?? null;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main
|
||||
:ref="bindScrollContainer"
|
||||
class="flex-1 p-3 md:p-8"
|
||||
:class="messages.length === 0 ? 'overflow-hidden md:overflow-y-auto' : 'overflow-y-auto scrollbar-thin'"
|
||||
>
|
||||
<div :class="messages.length === 0 ? 'h-full' : 'flex min-h-full flex-col justify-end'">
|
||||
<ChatWelcomePanel
|
||||
v-if="messages.length === 0"
|
||||
:agent-name="agentName"
|
||||
:suggested-questions-style="suggestedQuestionsStyle"
|
||||
:styled-sections="styledSections"
|
||||
:suggested-questions="suggestedQuestions"
|
||||
@select-question="emit('select-question', $event)"
|
||||
/>
|
||||
|
||||
<template v-for="(msg, index) in messages" :key="index">
|
||||
<ChatMessageBubble
|
||||
v-if="shouldRenderMessage(msg)"
|
||||
:message="msg"
|
||||
:index="index"
|
||||
:message-count="messages.length"
|
||||
:is-thinking="isThinking"
|
||||
:show-chat-rating="showChatRating"
|
||||
:copied-index="copiedIndex"
|
||||
:is-shipping-notice-agent="isShippingNoticeAgent"
|
||||
:handlers="handlers"
|
||||
:leave-handlers="leaveHandlers"
|
||||
:shipping-handlers="shippingHandlers"
|
||||
@copy="emit('copy', { message: msg, index })"
|
||||
@edit="emit('edit', $event)"
|
||||
@resend="emit('resend', $event)"
|
||||
@regenerate="emit('regenerate')"
|
||||
@open-feedback="emit('open-feedback', index)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<ChatThinkingBubble v-if="showThinkingBubble" />
|
||||
<div v-if="messages.length > 0" class="h-2 md:h-3" />
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* features/chat/components/ChatMobileHeader.vue
|
||||
* 移动端顶栏:Agent 名称、学习之窗与 Agent 切换弹层。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { BookOpen, History, LayoutGrid } from 'lucide-vue-next';
|
||||
|
||||
export interface ChatMobileHeaderAgent {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
defineProps<{
|
||||
agentName: string;
|
||||
hasAgentGuides: boolean;
|
||||
userAgents: ChatMobileHeaderAgent[];
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
'open-guide': [];
|
||||
'go-history': [];
|
||||
'open-agent-popover': [];
|
||||
'switch-agent': [agent: ChatMobileHeaderAgent];
|
||||
}>();
|
||||
|
||||
const showAgentPopover = ref(false);
|
||||
const popoverRef = ref<HTMLElement | null>(null);
|
||||
|
||||
const toggleAgentPopover = () => {
|
||||
showAgentPopover.value = !showAgentPopover.value;
|
||||
if (showAgentPopover.value) {
|
||||
emit('open-agent-popover');
|
||||
}
|
||||
};
|
||||
|
||||
const handleClickOutside = (event: MouseEvent | TouchEvent) => {
|
||||
const target = event.target as Node | null;
|
||||
if (!target) return;
|
||||
if (showAgentPopover.value && popoverRef.value && !popoverRef.value.contains(target)) {
|
||||
showAgentPopover.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const onSwitchAgent = (agent: ChatMobileHeaderAgent) => {
|
||||
showAgentPopover.value = false;
|
||||
emit('switch-agent', agent);
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
document.addEventListener('touchstart', handleClickOutside, { passive: true });
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('mousedown', handleClickOutside);
|
||||
document.removeEventListener('touchstart', handleClickOutside);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<header class="relative flex items-center justify-between border-b border-default bg-surface px-4 py-2.5">
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="flex h-7 w-7 items-center justify-center rounded-lg bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-xs font-bold text-white shadow-sm shadow-brand-500/20">
|
||||
AI
|
||||
</div>
|
||||
<span class="text-sm font-semibold text-primary">{{ agentName }}</span>
|
||||
<button
|
||||
v-if="hasAgentGuides"
|
||||
type="button"
|
||||
class="ml-1 flex items-center gap-1.5 rounded-lg border border-brand-300 bg-brand-100 px-3 py-1.5 text-xs font-bold text-brand-700 shadow-sm transition-all hover:border-brand-400 hover:bg-brand-200"
|
||||
@click="emit('open-guide')"
|
||||
>
|
||||
<BookOpen class="h-4 w-4" />
|
||||
学习之窗
|
||||
</button>
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<button
|
||||
type="button"
|
||||
class="flex h-9 w-9 items-center justify-center rounded-full text-muted transition-colors hover-surface-soft"
|
||||
:title="$t('chat.agents')"
|
||||
@click="toggleAgentPopover"
|
||||
>
|
||||
<LayoutGrid class="h-5 w-5" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="flex h-9 w-9 items-center justify-center rounded-full text-muted transition-colors hover-surface-soft"
|
||||
:title="$t('chat.history')"
|
||||
@click="emit('go-history')"
|
||||
>
|
||||
<History class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
v-if="showAgentPopover"
|
||||
ref="popoverRef"
|
||||
class="absolute right-4 top-12 z-50 w-72 rounded-2xl border border-default bg-surface p-3 shadow-xl"
|
||||
>
|
||||
<div class="mb-2 text-xs font-medium text-muted">{{ $t('chat.agents') }}</div>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<button
|
||||
v-for="agent in userAgents"
|
||||
:key="agent.id"
|
||||
type="button"
|
||||
class="flex flex-col items-center gap-1.5 rounded-xl px-2 py-3 text-center transition-colors hover-surface-soft"
|
||||
@click="onSwitchAgent(agent)"
|
||||
>
|
||||
<div class="flex h-9 w-9 items-center justify-center rounded-lg bg-brand-50 text-sm font-bold text-brand-600">
|
||||
{{ agent.name.charAt(0) }}
|
||||
</div>
|
||||
<span class="w-full truncate text-xs font-medium text-secondary">{{ agent.name }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="userAgents.length === 0" class="py-3 text-center text-xs text-muted">{{ $t('chat.noOtherAgents') }}</div>
|
||||
</div>
|
||||
</header>
|
||||
</template>
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* features/chat/components/ChatOALoginDialog.vue
|
||||
* 请假 OA 系统登录弹窗。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
const open = defineModel<boolean>('open', { required: true });
|
||||
const employeeId = defineModel<string>('employeeId', { required: true });
|
||||
const password = defineModel<string>('password', { required: true });
|
||||
|
||||
const emit = defineEmits<{
|
||||
confirm: [];
|
||||
cancel: [];
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="open"
|
||||
class="dialog-overlay z-[9999] items-center"
|
||||
@click.self="emit('cancel')"
|
||||
>
|
||||
<div class="dialog-panel max-w-sm">
|
||||
<div class="dialog-header dialog-header--compact justify-center border-0 pb-2">
|
||||
<h3 class="section-title text-center">{{ $t('chat.loginOaSystem') }}</h3>
|
||||
</div>
|
||||
<div class="dialog-body space-y-4 border-t-0 pt-0">
|
||||
<label class="block space-y-1.5">
|
||||
<span class="label-field">{{ $t('chat.employeeId') }}</span>
|
||||
<input
|
||||
v-model="employeeId"
|
||||
type="text"
|
||||
disabled
|
||||
class="input-field bg-surface-soft"
|
||||
/>
|
||||
</label>
|
||||
<label class="block space-y-1.5">
|
||||
<span class="label-field">{{ $t('login.password') }}</span>
|
||||
<input
|
||||
v-model="password"
|
||||
type="password"
|
||||
:placeholder="$t('chat.enterOaPassword')"
|
||||
class="input-field"
|
||||
@keyup.enter="emit('confirm')"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button type="button" class="btn-secondary" @click="emit('cancel')">
|
||||
{{ $t('profile.cancel') }}
|
||||
</button>
|
||||
<button type="button" class="btn-primary btn-sm" @click="emit('confirm')">
|
||||
{{ $t('chat.confirmLogin') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* features/chat/components/ChatQueryPreviewDialog.vue
|
||||
* Text2SQL 查询结果全量预览弹窗 UI。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { Loader2, X } from 'lucide-vue-next';
|
||||
import type { QueryPreviewState } from '../composables/useChatQueryPreview';
|
||||
|
||||
const open = defineModel<boolean>('open', { required: true });
|
||||
|
||||
const props = defineProps<{
|
||||
loading: boolean;
|
||||
error: string;
|
||||
state: QueryPreviewState;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
'change-page': [delta: number];
|
||||
}>();
|
||||
|
||||
const totalPages = computed(() =>
|
||||
Math.max(1, Math.ceil((props.state.total || 0) / (props.state.pageSize || 100))),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="open"
|
||||
class="dialog-overlay z-[120] items-center"
|
||||
@click.self="emit('close')"
|
||||
>
|
||||
<div class="dialog-panel flex max-h-[88vh] w-[min(96vw,1280px)] max-w-[1280px] flex-col">
|
||||
<div class="dialog-header">
|
||||
<div>
|
||||
<h3 class="section-title">查询结果全量预览</h3>
|
||||
<p class="section-desc mt-1">{{ state.query || state.title }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds" aria-label="关闭" @click="emit('close')">
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="dialog-body flex min-h-0 flex-1 flex-col gap-4 border-t-0 pt-4">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3 rounded-xl border border-default bg-surface-soft px-4 py-3 text-sm text-secondary">
|
||||
<div>共 {{ state.total || 0 }} 条,当前第 {{ state.page }} / {{ totalPages }} 页</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg border border-default px-3 py-1.5 text-xs transition-colors hover:bg-surface disabled:cursor-not-allowed disabled:opacity-50"
|
||||
:disabled="loading || state.page <= 1"
|
||||
@click="emit('change-page', -1)"
|
||||
>
|
||||
上一页
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg border border-default px-3 py-1.5 text-xs transition-colors hover:bg-surface disabled:cursor-not-allowed disabled:opacity-50"
|
||||
:disabled="loading || state.page >= totalPages"
|
||||
@click="emit('change-page', 1)"
|
||||
>
|
||||
下一页
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="error" class="rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">
|
||||
{{ error }}
|
||||
</div>
|
||||
<div class="min-h-0 flex-1 overflow-auto rounded-2xl border border-default bg-surface">
|
||||
<div v-if="loading" class="flex h-56 items-center justify-center">
|
||||
<Loader2 class="h-6 w-6 animate-spin text-brand-500" />
|
||||
</div>
|
||||
<div v-else-if="!state.columns.length" class="flex h-56 items-center justify-center text-sm text-muted">
|
||||
暂无可预览数据
|
||||
</div>
|
||||
<table v-else class="min-w-full border-collapse text-sm">
|
||||
<thead class="sticky top-0 z-10 bg-slate-50">
|
||||
<tr>
|
||||
<th
|
||||
v-for="column in state.columns"
|
||||
:key="`query-preview-col-${column}`"
|
||||
class="border border-slate-200 px-3 py-2 text-left font-semibold text-primary"
|
||||
>
|
||||
{{ column }}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="(row, rowIndex) in state.rows"
|
||||
:key="`query-preview-row-${rowIndex}`"
|
||||
class="odd:bg-white even:bg-slate-50/50"
|
||||
>
|
||||
<td
|
||||
v-for="(cell, cellIndex) in row"
|
||||
:key="`query-preview-cell-${rowIndex}-${cellIndex}`"
|
||||
class="max-w-[320px] border border-slate-200 px-3 py-2 align-top text-secondary"
|
||||
>
|
||||
<div class="whitespace-pre-wrap break-all">{{ cell ?? '-' }}</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,332 @@
|
||||
/**
|
||||
* features/chat/components/ChatSidebar.vue
|
||||
* 桌面端聊天侧栏:Agent 信息、会话历史、Agent 切换面板与底部用户菜单。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import {
|
||||
BookOpen,
|
||||
Briefcase,
|
||||
LayoutGrid,
|
||||
LogOut,
|
||||
MessageSquareText,
|
||||
Moon,
|
||||
PanelLeftClose,
|
||||
PanelLeftOpen,
|
||||
Plus,
|
||||
Settings,
|
||||
Sparkles,
|
||||
Sun,
|
||||
X,
|
||||
} from 'lucide-vue-next';
|
||||
import LocaleToggleButton from '@/shared/components/LocaleToggleButton.vue';
|
||||
import type { DisplayHistoryItem } from '../types/chat.types';
|
||||
|
||||
export interface ChatSidebarAgent {
|
||||
id: number;
|
||||
name: string;
|
||||
icon_url?: string;
|
||||
}
|
||||
|
||||
const collapsed = defineModel<boolean>('collapsed', { required: true });
|
||||
const agentPanelOpen = defineModel<boolean>('agentPanelOpen', { required: true });
|
||||
|
||||
const { currentUser } = defineProps<{
|
||||
isOpen: boolean;
|
||||
currentAgent: { name?: string } | null;
|
||||
agentDescription: string;
|
||||
hasAgentGuides: boolean;
|
||||
displayHistory: DisplayHistoryItem[];
|
||||
activeHistoryKey: string;
|
||||
userAgents: ChatSidebarAgent[];
|
||||
currentUser: Record<string, unknown> | null;
|
||||
appliedTheme: string;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
'new-chat': [];
|
||||
'open-guide': [];
|
||||
'history-select': [item: DisplayHistoryItem];
|
||||
'clear-all-history': [];
|
||||
'delete-history-item': [id: string, event: Event];
|
||||
'switch-agent': [agent: ChatSidebarAgent];
|
||||
'toggle-theme': [];
|
||||
'open-feedback': [];
|
||||
'go-workspace': [];
|
||||
'go-admin': [];
|
||||
logout: [];
|
||||
}>();
|
||||
|
||||
const showUserDropdown = ref(false);
|
||||
const userMenuRef = ref<HTMLElement | null>(null);
|
||||
|
||||
const handleDocumentPointerDown = (event: MouseEvent | TouchEvent) => {
|
||||
const target = event.target as Node | null;
|
||||
if (!target) return;
|
||||
if (showUserDropdown.value && userMenuRef.value && !userMenuRef.value.contains(target)) {
|
||||
showUserDropdown.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('mousedown', handleDocumentPointerDown);
|
||||
document.addEventListener('touchstart', handleDocumentPointerDown, { passive: true });
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('mousedown', handleDocumentPointerDown);
|
||||
document.removeEventListener('touchstart', handleDocumentPointerDown);
|
||||
});
|
||||
|
||||
const onNewChat = () => {
|
||||
emit('new-chat');
|
||||
};
|
||||
|
||||
const onLogout = () => {
|
||||
showUserDropdown.value = false;
|
||||
emit('logout');
|
||||
};
|
||||
|
||||
const onGoAdmin = () => {
|
||||
showUserDropdown.value = false;
|
||||
emit('go-admin');
|
||||
};
|
||||
|
||||
const userInitial = (fallback: string) => {
|
||||
const name = String(currentUser?.username ?? '').trim();
|
||||
return (name || fallback).charAt(0).toUpperCase();
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside
|
||||
class="glass-panel fixed inset-y-0 left-0 z-50 flex h-full flex-col border-r border-default bg-surface transition-all duration-300 ease-in-out md:relative md:translate-x-0"
|
||||
:class="[
|
||||
isOpen ? 'translate-x-0 w-[86vw] max-w-[300px]' : '-translate-x-full w-[86vw] max-w-[300px]',
|
||||
collapsed ? 'md:w-[72px]' : 'md:w-80',
|
||||
]"
|
||||
>
|
||||
<template v-if="collapsed">
|
||||
<div class="flex h-full w-full flex-col items-center py-4">
|
||||
<button type="button" class="mb-6 text-muted transition-colors hover:text-secondary" @click="collapsed = false">
|
||||
<PanelLeftOpen class="h-5 w-5" />
|
||||
</button>
|
||||
|
||||
<div class="mb-4 flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-white shadow-sm shadow-brand-500/25">
|
||||
<Sparkles class="h-5 w-5" />
|
||||
</div>
|
||||
|
||||
<button type="button" class="chat-sidebar-btn-icon" :title="$t('chat.createNewChat')" @click="onNewChat">
|
||||
<Plus class="h-5 w-5" />
|
||||
</button>
|
||||
|
||||
<div class="mt-auto flex flex-col items-center gap-6 pb-2 text-muted">
|
||||
<button type="button" class="transition-colors hover:text-secondary"><Sparkles class="h-5 w-5" /></button>
|
||||
<div class="flex h-8 w-8 items-center justify-center rounded-full bg-brand-600 text-sm font-bold text-white shadow-sm shadow-brand-500/20">
|
||||
{{ userInitial('I') }}
|
||||
</div>
|
||||
<LocaleToggleButton variant="sidebar" icon-size="md" />
|
||||
<button type="button" class="transition-colors hover:text-secondary" :title="$t('chat.generalFeedback')" @click="emit('open-feedback')">
|
||||
<MessageSquareText class="h-5 w-5" />
|
||||
</button>
|
||||
<button type="button" class="transition-colors hover:text-secondary" :title="$t('workspace.title')" @click="emit('go-workspace')">
|
||||
<Briefcase class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="flex items-center justify-between p-4">
|
||||
<div class="flex w-full min-w-0 items-center gap-3">
|
||||
<div class="flex h-8 w-8 shrink-0 items-center justify-center rounded-xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-sm font-bold text-white shadow-sm shadow-brand-500/25">
|
||||
{{ currentAgent?.name === '人事规章' ? 'HR' : 'AI' }}
|
||||
</div>
|
||||
<div class="group relative flex min-w-0 flex-1 flex-col justify-center">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="truncate font-bold text-primary">{{ currentAgent?.name || 'AI' }}</span>
|
||||
<button
|
||||
v-if="hasAgentGuides"
|
||||
type="button"
|
||||
class="flex items-center gap-1.5 rounded-lg border border-brand-300 bg-brand-100 px-3 py-1.5 text-xs font-bold text-brand-700 shadow-sm transition-all hover:border-brand-400 hover:bg-brand-200"
|
||||
@click="emit('open-guide')"
|
||||
>
|
||||
<BookOpen class="h-4 w-4" />
|
||||
学习之窗
|
||||
</button>
|
||||
</div>
|
||||
<span v-if="agentDescription" class="mt-1 block cursor-help truncate text-[11px] text-muted">
|
||||
{{ agentDescription }}
|
||||
</span>
|
||||
|
||||
<div
|
||||
v-if="agentDescription"
|
||||
class="pointer-events-none invisible absolute left-0 top-[calc(100%+0.25rem)] z-[100] w-[20rem] rounded-xl border border-default bg-surface p-3 opacity-0 shadow-xl transition-all duration-200 group-hover:visible group-hover:opacity-100"
|
||||
>
|
||||
<div class="text-[11px] leading-relaxed text-secondary">
|
||||
{{ agentDescription }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="ml-2 shrink-0 text-muted transition-colors hover:text-secondary" @click="collapsed = true">
|
||||
<PanelLeftClose class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="px-4 pb-4">
|
||||
<button type="button" class="chat-sidebar-btn" @click="onNewChat">
|
||||
<Plus class="h-4 w-4" /> {{ $t('chat.createNewChat') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between px-4 py-2">
|
||||
<span class="text-xs font-semibold text-slate-500 dark:text-slate-400">{{ $t('chat.history') }}</span>
|
||||
<button
|
||||
v-if="displayHistory.length > 0"
|
||||
type="button"
|
||||
class="text-xs text-slate-400 transition-colors hover:text-slate-600 dark:hover:text-slate-200"
|
||||
@click="emit('clear-all-history')"
|
||||
>
|
||||
{{ $t('chat.clearAll') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="scrollbar-thin flex-1 overflow-y-auto px-2">
|
||||
<div v-if="displayHistory.length === 0" class="py-8 text-center text-sm italic text-slate-400">
|
||||
{{ $t('chat.noHistory') }}
|
||||
</div>
|
||||
<div v-else class="space-y-0.5">
|
||||
<div
|
||||
v-for="item in displayHistory"
|
||||
:key="item.conversation_id"
|
||||
class="group relative flex w-full items-center justify-between rounded-lg transition-colors"
|
||||
:class="activeHistoryKey === item.conversation_id ? 'bg-brand-50 dark:bg-brand-900/20' : 'hover:bg-slate-50 dark:hover:bg-slate-800/50'"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="flex-1 truncate px-3 py-2.5 pr-8 text-left text-sm"
|
||||
:class="activeHistoryKey === item.conversation_id
|
||||
? 'font-medium text-brand-700 dark:text-brand-300'
|
||||
: 'text-slate-600 dark:text-slate-300'"
|
||||
@click="emit('history-select', item)"
|
||||
>
|
||||
{{ item.title || $t('chat.newChat') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="!item.__runId"
|
||||
type="button"
|
||||
class="absolute right-2 p-1.5 text-muted opacity-0 transition-opacity hover:text-red-500 group-hover:opacity-100"
|
||||
:title="$t('chat.clearOneRecord')"
|
||||
@click="emit('delete-history-item', item.conversation_id, $event)"
|
||||
>
|
||||
<X class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-auto flex flex-col p-4">
|
||||
<div v-if="userAgents.length > 0 && agentPanelOpen" class="chat-agent-panel">
|
||||
<div class="mb-2 flex items-center gap-1.5 text-xs font-semibold text-muted">
|
||||
<LayoutGrid class="h-3.5 w-3.5" /> {{ $t('chat.agents') }}
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-x-2 gap-y-1.5">
|
||||
<button
|
||||
v-for="agent in userAgents"
|
||||
:key="agent.id"
|
||||
type="button"
|
||||
class="grid w-full min-w-0 grid-cols-[1rem_1fr] items-center gap-1.5 rounded-xl px-2 py-2 text-left text-xs font-medium text-secondary transition-colors hover-surface-soft hover:shadow-sm"
|
||||
@click="emit('switch-agent', agent)"
|
||||
>
|
||||
<div
|
||||
v-if="agent.icon_url"
|
||||
class="h-4 w-4 shrink-0 rounded bg-contain bg-center bg-no-repeat"
|
||||
:style="{ backgroundImage: `url(${agent.icon_url})` }"
|
||||
/>
|
||||
<div v-else class="flex h-4 w-4 shrink-0 items-center justify-center rounded bg-brand-100 text-[9px] font-bold text-brand-600">
|
||||
{{ agent.name.charAt(0) }}
|
||||
</div>
|
||||
<span class="min-w-0 truncate">{{ agent.name }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ref="userMenuRef" class="relative flex items-center justify-between text-muted">
|
||||
<button
|
||||
type="button"
|
||||
class="flex h-10 min-w-[2.5rem] items-center justify-center rounded-full bg-brand-600 px-3 text-sm font-bold text-white shadow-sm shadow-brand-500/20 transition-colors hover:bg-brand-700"
|
||||
@click="showUserDropdown = !showUserDropdown"
|
||||
>
|
||||
退出
|
||||
</button>
|
||||
|
||||
<div
|
||||
v-if="showUserDropdown"
|
||||
class="absolute bottom-full left-0 z-50 mb-2 w-56 animate-fade-in rounded-xl border border-subtle bg-surface py-1 shadow-xl"
|
||||
>
|
||||
<div class="flex items-center gap-3 border-b border-subtle px-4 py-3">
|
||||
<div class="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-brand-600 text-lg font-bold text-white shadow-sm shadow-brand-500/20">
|
||||
{{ userInitial('U') }}
|
||||
</div>
|
||||
<div class="overflow-hidden">
|
||||
<div class="truncate text-sm font-bold text-primary">{{ currentUser?.username || 'User' }}</div>
|
||||
<div v-if="(currentUser as any)?.employee_id" class="truncate text-xs text-muted">
|
||||
{{ $t('chat.employeeId') }}: {{ (currentUser as any).employee_id }}
|
||||
</div>
|
||||
<div v-else class="truncate text-xs text-muted">{{ currentUser?.role }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
v-if="currentUser?.role === 'admin'"
|
||||
type="button"
|
||||
class="flex w-full items-center gap-2 px-4 py-2 text-left text-sm text-secondary transition-colors hover:bg-surface-soft"
|
||||
@click="onGoAdmin"
|
||||
>
|
||||
<Settings class="h-4 w-4" />
|
||||
{{ $t('workspace.nav.admin') }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full items-center gap-2 border-t border-subtle px-4 py-2 text-left text-sm text-red-600 transition-colors hover:bg-red-50"
|
||||
@click="onLogout"
|
||||
>
|
||||
<LogOut class="h-4 w-4" />
|
||||
{{ $t('chat.logout') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-3">
|
||||
<button
|
||||
type="button"
|
||||
:class="agentPanelOpen && userAgents.length > 0 ? 'text-brand-600' : ''"
|
||||
class="transition-colors hover:text-secondary"
|
||||
:title="userAgents.length === 0 ? $t('chat.noAvailableAgents') : (agentPanelOpen ? $t('chat.collapseAgents') : $t('chat.expandAgents'))"
|
||||
@click="userAgents.length === 0 ? undefined : (agentPanelOpen = !agentPanelOpen)"
|
||||
>
|
||||
<LayoutGrid class="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="transition-colors hover:text-secondary"
|
||||
:title="appliedTheme === 'dark' ? ($t('theme.switchToLight') || 'Switch to light mode') : ($t('theme.switchToDark') || 'Switch to dark mode')"
|
||||
@click="emit('toggle-theme')"
|
||||
>
|
||||
<Sun v-if="appliedTheme === 'dark'" class="h-4 w-4" />
|
||||
<Moon v-else class="h-4 w-4" />
|
||||
</button>
|
||||
<LocaleToggleButton variant="sidebar" />
|
||||
<button type="button" class="transition-colors hover:text-secondary" :title="$t('chat.generalFeedback')" @click="emit('open-feedback')">
|
||||
<MessageSquareText class="h-4 w-4" />
|
||||
</button>
|
||||
<button type="button" class="transition-colors hover:text-secondary" :title="$t('workspace.title')" @click="emit('go-workspace')">
|
||||
<Briefcase class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</aside>
|
||||
</template>
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* features/chat/components/ChatThinkingBubble.vue
|
||||
* Agent 思考中占位气泡。
|
||||
*/
|
||||
<template>
|
||||
<div class="mx-auto flex w-full max-w-4xl justify-start">
|
||||
<div class="flex items-center gap-3 rounded-2xl rounded-tl-md border border-default bg-surface/95 px-5 py-3 shadow-md">
|
||||
<div class="flex gap-1">
|
||||
<span class="h-2 w-2 animate-bounce rounded-full bg-brand-400" />
|
||||
<span class="h-2 w-2 animate-bounce rounded-full bg-brand-400 delay-75" />
|
||||
<span class="h-2 w-2 animate-bounce rounded-full bg-brand-400 delay-150" />
|
||||
</div>
|
||||
<span class="text-sm font-medium text-muted">{{ $t('chat.thinking') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
* features/chat/components/ChatViewContent.vue
|
||||
* 对话页主区域:侧栏、消息列表、输入栏与内置浏览器。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { Loader2 } from 'lucide-vue-next';
|
||||
import ChatShell from '@/shared/layouts/ChatShell.vue';
|
||||
import ChatSidebar from '@/features/chat/components/ChatSidebar.vue';
|
||||
import ChatInputBar from '@/features/chat/components/ChatInputBar.vue';
|
||||
import ChatMessageList from '@/features/chat/components/ChatMessageList.vue';
|
||||
import ChatMobileHeader from '@/features/chat/components/ChatMobileHeader.vue';
|
||||
import ChatBrowserPanel from '@/features/chat/components/ChatBrowserPanel.vue';
|
||||
import { useChatPageContext } from '@/features/chat/composables/chat.context';
|
||||
|
||||
const page = useChatPageContext();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ChatShell>
|
||||
<template #overlay>
|
||||
<div
|
||||
v-if="page.isSidebarOpen && !page.isMobile"
|
||||
class="fixed inset-0 z-40 bg-overlay backdrop-blur-sm transition-opacity md:hidden"
|
||||
@click="page.isSidebarOpen = false"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #sidebar>
|
||||
<ChatSidebar
|
||||
v-if="!page.isMobile"
|
||||
v-model:collapsed="page.sidebarCollapsed"
|
||||
v-model:agent-panel-open="page.showAgentPanel"
|
||||
:is-open="page.isSidebarOpen"
|
||||
:current-agent="page.currentAgent"
|
||||
:agent-description="page.agentDescription"
|
||||
:has-agent-guides="page.agentGuides.length > 0"
|
||||
:display-history="page.displayHistory"
|
||||
:active-history-key="page.activeHistoryKey"
|
||||
:user-agents="page.userAgents"
|
||||
:current-user="page.currentUser"
|
||||
:applied-theme="page.appliedTheme"
|
||||
@new-chat="page.handleSidebarNewChat"
|
||||
@open-guide="page.openGuideModal"
|
||||
@history-select="page.handleHistorySelect"
|
||||
@clear-all-history="page.clearAllHistory"
|
||||
@delete-history-item="page.deleteHistoryItem"
|
||||
@switch-agent="page.switchToAgent"
|
||||
@toggle-theme="page.toggleLightDark"
|
||||
@open-feedback="page.showGeneralFeedbackDialog = true"
|
||||
@go-workspace="page.goToWorkspace()"
|
||||
@go-admin="page.goToAdmin"
|
||||
@logout="page.handleLogout"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<ChatMobileHeader
|
||||
v-if="page.isMobile && page.currentAgent"
|
||||
:agent-name="page.currentAgent?.name || 'AI'"
|
||||
:has-agent-guides="page.agentGuides.length > 0"
|
||||
:user-agents="page.userAgents"
|
||||
@open-guide="page.openGuideModal"
|
||||
@go-history="page.goToWorkspace('history')"
|
||||
@open-agent-popover="page.loadUserAgents"
|
||||
@switch-agent="page.switchToAgent"
|
||||
/>
|
||||
|
||||
<div v-if="!page.currentAgent" class="flex flex-1 flex-col items-center justify-center space-y-4">
|
||||
<Loader2 class="h-10 w-10 animate-spin text-brand-500" />
|
||||
<p class="text-sm animate-pulse text-muted">{{ $t('chat.loadingAgent') }}</p>
|
||||
</div>
|
||||
|
||||
<div v-else-if="page.currentAgent.type === 'iframe'" class="relative h-full w-full flex-1">
|
||||
<iframe
|
||||
:src="page.currentAgent.extra_config?.iframe_url"
|
||||
class="h-full w-full border-0 bg-surface"
|
||||
allow="microphone; camera; clipboard-read; clipboard-write"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="flex min-h-0 flex-1">
|
||||
<div class="flex min-h-0 flex-1 flex-col">
|
||||
<ChatMessageList
|
||||
:messages="page.messages"
|
||||
:agent-name="page.currentAgent?.name || 'AI'"
|
||||
:suggested-questions-style="page.suggestedQuestionsStyle"
|
||||
:styled-sections="page.styledSuggestedQuestionSections"
|
||||
:suggested-questions="page.agentSuggestedQuestions"
|
||||
:show-thinking-bubble="page.shouldShowThinkingBubble"
|
||||
:is-thinking="page.isThinking"
|
||||
:show-chat-rating="page.showChatRating"
|
||||
:copied-index="page.copiedIndex"
|
||||
:is-shipping-notice-agent="page.isShippingNoticeAgent"
|
||||
:handlers="page.messageBubbleHandlers"
|
||||
:leave-handlers="page.leaveMessageHandlers"
|
||||
:shipping-handlers="page.shippingMappingHandlers"
|
||||
:should-render-message="page.shouldRenderMessage"
|
||||
:scroll-container-holder="page.scrollContainerHolder"
|
||||
@copy="page.copyToClipboard($event.message, $event.index)"
|
||||
@edit="page.input = $event"
|
||||
@resend="page.handleSend($event)"
|
||||
@regenerate="page.regenerate"
|
||||
@open-feedback="page.handleOpenFeedback($event)"
|
||||
@select-question="page.handleSend"
|
||||
/>
|
||||
|
||||
<ChatInputBar
|
||||
v-model="page.input"
|
||||
v-model:selected-kb="page.selectedKb"
|
||||
:attachments="page.attachments"
|
||||
:attachment-policy="page.attachmentPolicy"
|
||||
:available-kb-options="page.availableKbOptions"
|
||||
:kb-dropdown-disabled="page.kbDropdownDisabled"
|
||||
:is-thinking="page.isThinking"
|
||||
:is-voice-recording="page.isVoiceRecording"
|
||||
:is-voice-transcribing="page.isVoiceTranscribing"
|
||||
:is-uploading-attachments="page.isUploadingAttachments"
|
||||
:can-send-message="page.canSendMessage"
|
||||
:is-shipping-notice-agent="page.isShippingNoticeAgent"
|
||||
:shipping-suggested-prompt="page.shippingSuggestedPrompt"
|
||||
:shipping-picker-ref-holder="page.shippingPickerRefHolder"
|
||||
:get-kb-label="page.getKbLabel"
|
||||
:browser-panel-open="page.browserPanelOpen"
|
||||
@toggle-browser="page.toggleBrowserPanel"
|
||||
@send="page.handleSend()"
|
||||
@voice-click="page.handleVoiceFeatureClick"
|
||||
@remove-attachment="page.removeAttachment"
|
||||
@local-files-selected="page.handleLocalFilesSelected"
|
||||
@add-remote-url="page.addRemoteUrlAttachment"
|
||||
@shipping-inventory-selected="page.handleShippingInventorySelected"
|
||||
@use-shipping-suggested-prompt="page.useShippingSuggestedPrompt"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ChatBrowserPanel
|
||||
v-model:open="page.browserPanelOpen"
|
||||
v-model:draft-url="page.browserDraftUrl"
|
||||
:current-url="page.browserCurrentUrl"
|
||||
:frame-key="page.browserFrameKey"
|
||||
:panel-style="page.browserPanelStyle"
|
||||
:is-resizing="page.isBrowserResizing"
|
||||
@load="page.browser.loadPage"
|
||||
@refresh="page.browser.refreshPage"
|
||||
@open-new-tab="page.browser.openInNewTab"
|
||||
@url-enter="page.browser.onUrlEnter"
|
||||
@start-resize="page.browser.startResize"
|
||||
@close="page.browser.close"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</ChatShell>
|
||||
</template>
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* features/chat/components/ChatViewOverlays.vue
|
||||
* 对话页全局弹窗:文件预览、反馈、查询预览、请假 OA、删除确认、学习之窗。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import FilePreviewModal from '@/shared/components/FilePreviewModal.vue';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import GeneralFeedbackDialog from '@/shared/components/GeneralFeedbackDialog.vue';
|
||||
import ChatQueryPreviewDialog from '@/features/chat/components/ChatQueryPreviewDialog.vue';
|
||||
import ChatLeaveAgentDialog from '@/features/chat/components/ChatLeaveAgentDialog.vue';
|
||||
import ChatOALoginDialog from '@/features/chat/components/ChatOALoginDialog.vue';
|
||||
import ChatGuideModal from '@/features/chat/components/ChatGuideModal.vue';
|
||||
import { useChatPageContext } from '@/features/chat/composables/chat.context';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
|
||||
const page = useChatPageContext();
|
||||
|
||||
function onFeedbackSubmitted() {
|
||||
const idx = page.activeFeedbackMessageIndex;
|
||||
const target = idx !== null ? page.messages[idx] : undefined;
|
||||
if (target) target.rated = true;
|
||||
page.msg.success(page.t('chat.feedbackSubmitSuccess'));
|
||||
page.showGeneralFeedbackDialog = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FilePreviewModal
|
||||
v-model="page.filePreviewVisible"
|
||||
:file="page.previewFile"
|
||||
:agent-id="page.currentAgentId"
|
||||
:auth-headers="getAuthHeaders()"
|
||||
/>
|
||||
<GeneralFeedbackDialog
|
||||
v-model="page.showGeneralFeedbackDialog"
|
||||
:auth-headers="getAuthHeaders()"
|
||||
source-page="chat"
|
||||
:chat-log-id="page.currentGeneralFeedbackChatLogId"
|
||||
@submitted="onFeedbackSubmitted"
|
||||
/>
|
||||
<ChatQueryPreviewDialog
|
||||
v-model:open="page.showQueryPreviewDialog"
|
||||
:loading="page.queryPreviewLoading"
|
||||
:error="page.queryPreviewError"
|
||||
:state="page.queryPreviewState"
|
||||
@close="page.queryPreview.close"
|
||||
@change-page="page.queryPreview.changePage"
|
||||
/>
|
||||
<ChatLeaveAgentDialog
|
||||
v-model:open="page.showLeaveAgentDialog"
|
||||
v-model:keyword="page.leaveAgentKeyword"
|
||||
:select-role="page.leaveUserSelectRole"
|
||||
:options="page.leaveAgentOptions"
|
||||
:loading="page.leaveAgentLoading"
|
||||
:page="page.leaveAgentPage"
|
||||
:has-more="page.leaveAgentHasMore"
|
||||
@close="page.closeLeaveAgentDialog"
|
||||
@search="page.handleAgentSearch"
|
||||
@load-more="page.loadMoreAgents"
|
||||
@load-all="page.loadAllAgents"
|
||||
@select="page.selectLeaveAgent"
|
||||
/>
|
||||
<ChatOALoginDialog
|
||||
v-model:open="page.showOALoginDialog"
|
||||
v-model:employee-id="page.oaLoginEmployeeId"
|
||||
v-model:password="page.oaLoginPassword"
|
||||
@confirm="page.confirmOALogin"
|
||||
@cancel="page.cancelOALogin"
|
||||
/>
|
||||
<DeleteConfirmDialog
|
||||
v-model="page.showDeleteConfirmDialog"
|
||||
:message="page.deleteConfirmMessage"
|
||||
@confirm="page.handleDeleteConfirm"
|
||||
@cancel="page.closeDeleteConfirmDialog"
|
||||
/>
|
||||
<ChatGuideModal
|
||||
v-model:open="page.showGuideModal"
|
||||
v-model:active-guide-id="page.activeGuideId"
|
||||
v-model:show-sidebar="page.showGuideSidebar"
|
||||
:agent-name="page.currentAgent?.name || 'AI'"
|
||||
:guides="page.agentGuides"
|
||||
:active-guide="page.activeGuide"
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* features/chat/components/ChatWelcomePanel.vue
|
||||
* 无消息时的欢迎区:Agent 头像、标题与预设问题快捷入口。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Building, CalendarDays } from 'lucide-vue-next';
|
||||
|
||||
export interface WelcomeQuestionItem {
|
||||
question: string;
|
||||
group: string;
|
||||
}
|
||||
|
||||
export interface WelcomeQuestionSection {
|
||||
title: string;
|
||||
questions: WelcomeQuestionItem[];
|
||||
iconType: 'calendar' | 'building';
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
agentName: string;
|
||||
suggestedQuestionsStyle: 'plain' | 'styled';
|
||||
styledSections: WelcomeQuestionSection[];
|
||||
suggestedQuestions: WelcomeQuestionItem[];
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
'select-question': [question: string];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const avatarLabel = computed(() => (props.agentName === '人事规章' ? 'HR' : 'AI'));
|
||||
|
||||
const welcomeTitle = computed(() => (
|
||||
props.agentName === '人事规章'
|
||||
? '你好,我是人事规章 AI 助手'
|
||||
: t('chat.welcomeTitle')
|
||||
));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex h-full min-h-0 w-full flex-col items-center px-4 pb-2 pt-2 md:pb-3">
|
||||
<template v-if="suggestedQuestionsStyle === 'styled' && styledSections.length > 0">
|
||||
<div class="mb-6 mt-2 flex h-16 w-16 shrink-0 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
|
||||
{{ avatarLabel }}
|
||||
</div>
|
||||
<h2 class="mb-6 shrink-0 text-center text-xl font-bold text-primary md:text-2xl">
|
||||
{{ welcomeTitle }}
|
||||
</h2>
|
||||
|
||||
<div class="min-h-0 w-full flex-1 overflow-y-auto pb-2">
|
||||
<div class="mx-auto grid w-full max-w-4xl grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div
|
||||
v-for="(section, sectionIndex) in styledSections"
|
||||
:key="`${section.title}-${sectionIndex}`"
|
||||
class="w-full rounded-2xl border border-default bg-surface p-5 shadow-sm transition-colors hover:border-brand-300"
|
||||
>
|
||||
<div class="mb-3 flex items-center gap-2">
|
||||
<div class="rounded-lg bg-brand-50 p-1.5 text-brand-600">
|
||||
<CalendarDays v-if="section.iconType === 'calendar'" class="h-4 w-4" />
|
||||
<Building v-else class="h-4 w-4" />
|
||||
</div>
|
||||
<h3 class="font-semibold text-secondary">{{ section.title }}</h3>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<button
|
||||
v-for="(item, questionIndex) in section.questions"
|
||||
:key="`${section.title}-${questionIndex}`"
|
||||
type="button"
|
||||
class="w-full truncate rounded-lg bg-surface-soft px-3 py-2 text-left text-xs text-secondary transition-colors hover:bg-brand-50 hover:text-brand-600 md:text-sm"
|
||||
@click="emit('select-question', item.question)"
|
||||
>
|
||||
"{{ item.question }}"
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="suggestedQuestions.length > 0">
|
||||
<div class="mb-6 mt-2 flex h-16 w-16 shrink-0 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
|
||||
AI
|
||||
</div>
|
||||
<h2 class="mb-6 shrink-0 text-center text-xl font-medium text-primary md:text-2xl">
|
||||
{{ $t('chat.welcomeTitle') }}
|
||||
</h2>
|
||||
|
||||
<div class="min-h-0 w-full flex-1 overflow-y-auto pb-2">
|
||||
<div class="mx-auto mt-2 flex w-full max-w-3xl flex-wrap justify-center gap-3">
|
||||
<button
|
||||
v-for="(item, index) in suggestedQuestions"
|
||||
:key="`${item.question}-${index}`"
|
||||
type="button"
|
||||
class="rounded-full border border-default bg-surface px-4 py-2 text-sm text-secondary shadow-sm transition-all hover:border-brand-300 hover:bg-brand-50 hover:text-brand-600"
|
||||
@click="emit('select-question', item.question)"
|
||||
>
|
||||
"{{ item.question }}"
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="mb-6 mt-2 flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
|
||||
AI
|
||||
</div>
|
||||
<h2 class="text-center text-xl font-medium text-primary md:text-2xl">
|
||||
{{ $t('chat.welcomeTitle') }}
|
||||
</h2>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -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