fix: 优化一些配置

This commit is contained in:
sophie committed 2026-07-30 16:49:27 +08:00
1 parent ac7b53a523
commit eb21af5949
17 files changed
+117 -208

No files matched your search

@@ -1,7 +1,7 @@
/**
* features/chat/components/ChatInputBar.vue
* 聊天输入栏:文本框、附件、语音、知识库与采购合同双文件输入控件。
* 逻辑:附件卡片和快捷操作显示在文字输入区上方;采购合同审查隐藏企业知识库,模板比对明确上传双方合同。
* 聊天输入栏:文本框、附件、语音与采购合同双文件输入控件。
* 逻辑:底部左区放附件/合同等工具;右区语音与发送并排。采购合同审查用专用上传按钮,不展示通用回形针附件入口。
*/
<script setup lang="ts">
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
@@ -9,8 +9,6 @@ import { useI18n } from 'vue-i18n';
import type { Ref } from 'vue';
import {
Check,
ChevronDown,
Database,
FileText,
Link2,
Loader2,
@@ -37,14 +35,11 @@ export interface ChatInputAttachmentPolicy {
}
const inputValue = defineModel<string>({ required: true });
const selectedKb = defineModel<string>('selectedKb', { required: true });
const procurementReviewMode = defineModel<ContractReviewMode>('procurementReviewMode', { default: 'compare' });
const props = defineProps<{
attachments: PendingAttachment[];
attachmentPolicy: ChatInputAttachmentPolicy;
availableKbOptions: string[];
kbDropdownDisabled: boolean;
isThinking: boolean;
isVoiceRecording: boolean;
isVoiceTranscribing: boolean;
@@ -61,7 +56,6 @@ const props = defineProps<{
/** 用对象包裹 Ref,避免 template 自动解包 */
shippingPickerRefHolder: { pickerRef: Ref<HTMLInputElement | null> };
shippingNoticePickerRefHolder: { pickerRef: Ref<HTMLInputElement | null> };
getKbLabel: (kb: string) => string;
}>();
const emit = defineEmits<{
@@ -87,11 +81,9 @@ const originalContractPickerRef = ref<HTMLInputElement | null>(null);
const { t } = useI18n();
const textareaRef = ref<HTMLTextAreaElement | 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 hasProcurementContractAttachment = computed(() =>
@@ -227,20 +219,6 @@ const selectAttachmentUrl = async () => {
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;
@@ -271,12 +249,12 @@ const bindAttachmentPickerRef = (el: unknown) => {
bindShippingNoticePickerRef(el);
};
/**
* 点击输入栏外部时收起附件菜单。
*/
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();
}
@@ -539,21 +517,13 @@ watch(
@keydown.enter.prevent="emit('send')"
/>
<div class="mt-1.5 flex items-center justify-between px-1.5 pb-0.5">
<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')"
<div class="mt-1.5 flex items-center justify-between gap-2 px-1.5 pb-0.5">
<div class="flex min-w-0 flex-1 flex-wrap items-center gap-2">
<div
v-if="attachmentPolicy.anyEnabled && !isProcurementContractAgent"
ref="attachmentMenuRef"
class="relative"
>
<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"
@@ -658,34 +628,6 @@ watch(
</span>
</div>
<div v-else-if="!isMaintenanceAgent" 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>
<div
v-if="isMaintenanceAgent && canManageMaintenance"
class="flex flex-wrap items-center gap-2"
@@ -708,29 +650,47 @@ watch(
</div>
</div>
<button
v-if="isThinking && !isUploadingAttachments"
type="button"
class="flex h-10 w-10 items-center justify-center rounded-full border border-rose-300 bg-rose-50 text-rose-600 shadow-sm transition-all duration-200 hover:scale-105 hover:bg-rose-100 active:scale-95"
:title="$t('chat.stopGenerating')"
:aria-label="$t('chat.stopGenerating')"
@click="emit('stop')"
>
<Square class="h-4 w-4 fill-current" />
</button>
<button
v-else
type="button"
:disabled="!canSendMessage"
class="flex h-10 w-10 shrink-0 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 class="flex shrink-0 items-center gap-1.5">
<button
type="button"
:disabled="isThinking || isVoiceTranscribing"
:title="isVoiceRecording ? $t('chat.voiceStop') : isVoiceTranscribing ? $t('chat.voiceTranscribing') : $t('chat.voiceFeature')"
class="flex h-10 w-10 items-center justify-center rounded-full transition-colors disabled:cursor-not-allowed disabled:opacity-50"
:class="isVoiceRecording
? 'animate-pulse bg-rose-50 text-red-500'
: isVoiceTranscribing
? 'bg-brand-50 text-brand-500'
: 'text-muted hover:bg-surface-soft 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>
<button
v-if="isThinking && !isUploadingAttachments"
type="button"
class="flex h-10 w-10 items-center justify-center rounded-full border border-rose-300 bg-rose-50 text-rose-600 shadow-sm transition-all duration-200 hover:scale-105 hover:bg-rose-100 active:scale-95"
:title="$t('chat.stopGenerating')"
:aria-label="$t('chat.stopGenerating')"
@click="emit('stop')"
>
<Square class="h-4 w-4 fill-current" />
</button>
<button
v-else
type="button"
:disabled="!canSendMessage"
class="flex h-10 w-10 shrink-0 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>
<div class="mt-3 text-center text-[11px] text-muted">
@@ -263,12 +263,9 @@ watch(() => page.currentAgentId, () => {
v-show="!isTrainingWorkspaceExpanded"
:key="`${page.currentAgentId}-${page.conversationId || 'draft'}-${page.messages.length}`"
v-model="page.input"
v-model:selected-kb="page.selectedKb"
v-model:procurement-review-mode="page.procurementReviewMode"
: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"
@@ -284,7 +281,6 @@ watch(() => page.currentAgentId, () => {
:shipping-focus-reason="page.shippingFocusReason"
:shipping-picker-ref-holder="page.shippingPickerRefHolder"
:shipping-notice-picker-ref-holder="page.shippingNoticePickerRefHolder"
:get-kb-label="page.getKbLabel"
@send="page.handleSend()"
@stop="page.stopActiveGeneration()"
@voice-click="page.handleVoiceFeatureClick"
@@ -1,16 +1,15 @@
/**
* features/chat/composables/useChatAgent.ts
* 当前 Agent 元数据、知识库选项、推荐问题与用户可切换 Agent 列表。
* 当前 Agent 元数据、发送时默认知识库类型、推荐问题与用户可切换 Agent 列表。
* 依赖:user API、agent-registry / agent-category utils、training 题库工具、ChatDeps。
* 逻辑:Chat 页面通过 useChatPage 调用;selectedKb 固定为企业知识库供发消息透传,输入栏不再展示知识库下拉。
*/
import { computed, ref, watch, type ComputedRef } from 'vue';
import { computed, ref, type ComputedRef } from 'vue';
import { BusinessError } from '@/shared/api/client';
import { getUserAgent, listUserAgents } from '@/features/user';
import { setLastChatAgentId } from '@/shared/utils/lastChatAgent';
import { sortAgentsByCategory } from '@/shared/utils/agent-category.utils';
import {
agentHasErpKb,
type AgentRegistryFields,
} from '@/shared/utils/agent-registry.utils';
import type { AgentRegistryFields } from '@/shared/utils/agent-registry.utils';
import { matchesTrainingAgent } from '../training/trainingWorkspace.utils';
import { resolveTrainingRoleChatQuestions } from '../training/trainingChatQuestions';
import type { ChatDeps } from './chat.deps';
@@ -21,8 +20,8 @@ export type AgentSuggestedQuestionItem = {
group: string;
};
/** 发消息时透传给后端的默认 kb_type;聊天输入栏已不再提供切换入口 */
const DEFAULT_KB = '企业知识库';
const ERP_KB = 'ERP知识库';
const normalizeAgentSuggestedQuestions = (value: unknown): AgentSuggestedQuestionItem[] => {
if (!Array.isArray(value)) return [];
@@ -77,36 +76,11 @@ export function useChatAgent(options: UseChatAgentOptions) {
const userAgents = ref<ChatAgentOption[]>([]);
const showAgentPanel = ref(true);
const selectedKb = ref(DEFAULT_KB);
const kbOptions = [DEFAULT_KB, ERP_KB];
const getKbLabel = (kb: string) => {
if (kb === DEFAULT_KB) return t('chat.kb.enterprise');
if (kb === ERP_KB) return t('chat.kb.erp');
return kb;
};
const canSelectErpKnowledgeBase = computed(() => agentHasErpKb(currentAgent.value));
const availableKbOptions = computed(() => (
canSelectErpKnowledgeBase.value
? kbOptions
: kbOptions.filter((option) => option !== ERP_KB)
));
const kbDropdownDisabled = computed(() => availableKbOptions.value.length <= 1);
const isTrainingAdminViewer = computed(() => Boolean(
(currentUser.value as { feature_permissions?: { training_hr_manage?: boolean } } | null)
?.feature_permissions?.training_hr_manage,
));
watch(canSelectErpKnowledgeBase, (allowed) => {
if (allowed) {
selectedKb.value = DEFAULT_KB;
return;
}
if (selectedKb.value === ERP_KB) {
selectedKb.value = DEFAULT_KB;
}
}, { immediate: true });
const agentDescription = computed(() => {
const welcome = String(currentAgent.value?.welcome_message || '').trim();
if (welcome) return welcome;
@@ -200,9 +174,6 @@ export function useChatAgent(options: UseChatAgentOptions) {
userAgents,
showAgentPanel,
selectedKb,
getKbLabel,
availableKbOptions,
kbDropdownDisabled,
agentDescription,
suggestedQuestionsStyle,
agentSuggestedQuestions,