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,9 +1,9 @@
/**
* features/admin/modules/agents/components/AgentFormModal.vue
*
* 用途:应用管理新增/编辑弹窗,集中承载 Agent 基础信息、Dify/Iframe 配置和常见问题表单。
* 用途:应用管理新增/编辑弹窗,集中承载 Agent 基础信息(含启用状态)、Dify/Iframe 配置和常见问题表单。
* 依赖:agent.types AgentFormState、schedule.types ScheduleTask、AgentToolRunProgressConfig、vue-i18n。
* 逻辑:父组件控制 visible/isEditing/isSaving 与保存;本组件直接编辑传入的 form,并通过事件通知关闭、保存、增删常见问题。
* 逻辑:父组件控制 visible/isEditing/isSaving 与保存;本组件直接编辑传入的 form(含 is_active),并通过事件通知关闭、保存、增删常见问题。
*/
<script setup lang="ts">
@@ -340,6 +340,23 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
</div>
</template>
<div class="col-span-1 md:col-span-2 space-y-2">
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.fields.isActive') }}</label>
<div class="flex flex-col gap-2 rounded-xl border border-default bg-surface-soft/40 px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
<p class="text-sm leading-6 text-secondary">
{{ form.is_active ? t('admin.agent.fields.isActiveHintOn') : t('admin.agent.fields.isActiveHintOff') }}
</p>
<label class="inline-flex shrink-0 items-center gap-2 rounded-xl border border-default bg-white px-3 py-2 text-sm text-secondary">
<input
v-model="form.is_active"
type="checkbox"
class="accent-brand-600"
/>
<span>{{ t('admin.agent.fields.isActiveEnable') }}</span>
</label>
</div>
</div>
<div class="col-span-1 md:col-span-2 space-y-2">
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.fields.description') }}</label>
<input
@@ -74,7 +74,6 @@ const {
getApplicationSortMark,
handleApplicationSearchChange,
openApplicationChatLogs,
openApplicationPermissionRequests,
isLoading,
currentTable,
tableData,
@@ -139,7 +138,6 @@ const applicationSortableKeys: ApplicationSortKey[] = [
'unique_users',
'last_active_at',
'authorized_users',
'pending_requests',
'avg_score',
];
@@ -531,7 +529,7 @@ onBeforeUnmount(() => {
</div>
</div>
<div v-if="applicationSummary" class="grid grid-cols-2 gap-3 md:grid-cols-4">
<div v-if="applicationSummary" class="grid grid-cols-1 gap-3 sm:grid-cols-3">
<button type="button" class="rounded-xl border border-default bg-surface p-4 text-left" @click="setApplicationUsageFilter('all')">
<div class="text-sm text-muted">{{ t('admin.report.appOps.summaryActive') }}</div>
<div class="mt-2 text-2xl font-bold text-primary">{{ applicationSummary.active_agents }}</div>
@@ -545,25 +543,20 @@ onBeforeUnmount(() => {
<div class="text-sm text-muted">{{ t('admin.report.appOps.summaryUnused') }}</div>
<div class="mt-2 text-2xl font-bold text-primary">{{ applicationSummary.unused_agents }}</div>
</button>
<div class="rounded-xl border border-default bg-surface p-4">
<div class="text-sm text-muted">{{ t('admin.report.appOps.summaryPending') }}</div>
<div class="mt-2 text-2xl font-bold text-primary">{{ applicationSummary.pending_permission_total }}</div>
</div>
</div>
<div class="admin-report-table-wrap">
<table class="admin-report-table admin-report-table--app-ops w-full table-fixed border-collapse">
<colgroup>
<col class="w-[14%]" />
<col class="w-[7%]" />
<col class="w-[7%]" />
<col class="w-[16%]" />
<col class="w-[7%]" />
<col class="w-[7%]" />
<col class="w-[8%]" />
<col class="w-[8%]" />
<col class="w-[8%]" />
<col class="w-[18%]" />
<col class="w-[8%]" />
<col class="w-[10%]" />
<col class="w-[10%]" />
<col class="w-[10%]" />
<col class="w-[12%]" />
</colgroup>
<thead>
<tr>
@@ -588,7 +581,7 @@ onBeforeUnmount(() => {
</thead>
<tbody>
<tr v-if="applicationItems.length === 0">
<td colspan="10" class="text-center text-muted py-12">
<td colspan="9" class="text-center text-muted py-12">
{{ t('admin.report.appOps.empty') }}
</td>
</tr>
@@ -600,7 +593,6 @@ onBeforeUnmount(() => {
{{ row.last_active_at ? formatLocalDateTime(row.last_active_at) : '-' }}
</td>
<td class="px-3 py-3 text-left align-middle font-mono tabular-nums">{{ row.authorized_users }}</td>
<td class="px-3 py-3 text-left align-middle font-mono tabular-nums">{{ row.pending_requests }}</td>
<td class="px-3 py-3 text-left align-middle font-mono tabular-nums whitespace-nowrap">
{{ row.avg_score == null ? '-' : row.avg_score }}
<span v-if="row.feedback_count" class="text-xs text-muted">({{ row.feedback_count }})</span>
@@ -612,14 +604,9 @@ onBeforeUnmount(() => {
</span>
</td>
<td class="px-3 py-3 text-left align-middle">
<div class="flex flex-wrap gap-1">
<button type="button" class="btn-secondary text-xs px-2 py-1" @click="openApplicationChatLogs(row)">
{{ t('admin.report.appOps.actionLogs') }}
</button>
<button type="button" class="btn-secondary text-xs px-2 py-1" @click="openApplicationPermissionRequests(row)">
{{ t('admin.report.appOps.actionRequests') }}
</button>
</div>
<button type="button" class="btn-secondary text-xs px-2 py-1" @click="openApplicationChatLogs(row)">
{{ t('admin.report.appOps.actionLogs') }}
</button>
</td>
</tr>
</tbody>
@@ -207,18 +207,6 @@ export function useReportsAdmin() {
});
};
/**
* 下钻到权限申请列表,按 agent_id 精确过滤。
* @param row - 应用运营行
*/
const openApplicationPermissionRequests = (row: ApplicationReportItem): void => {
void router.push({
name: 'AdminReports',
params: { table: 'permission_requests' },
query: { agent_id: String(row.agent_id) },
});
};
/**
* 导出应用运营报表 Excel(仅运营字段)。
*/
@@ -237,7 +225,6 @@ export function useReportsAdmin() {
? formatLocalDateTime(row.last_active_at)
: '-',
[t('admin.report.appOps.columns.authorized_users')]: row.authorized_users,
[t('admin.report.appOps.columns.pending_requests')]: row.pending_requests,
[t('admin.report.appOps.columns.avg_score')]: row.avg_score ?? '-',
[t('admin.report.appOps.columns.feedback_count')]: row.feedback_count,
[t('admin.report.appOps.columns.tokens_used')]: row.tokens_used,
@@ -405,7 +392,7 @@ const dataSourceTable = computed<Exclude<AdminReportTableId, 'usage_analysis'>>(
});
/**
* 从路由 query 灌入列筛选(用于应用运营下钻到聊天日志 / 权限申请)。
* 从路由 query 灌入列筛选(用于应用运营下钻到聊天日志)。
*/
const applyRouteQueryFilters = (): void => {
const next: Record<string, string> = {};
@@ -1218,7 +1205,6 @@ watch([reportPageSize, sortedTableData], () => {
getApplicationSortMark,
handleApplicationSearchChange,
openApplicationChatLogs,
openApplicationPermissionRequests,
isLoading,
currentTable,
tableData,
@@ -45,7 +45,6 @@ export type ApplicationSortKey =
| 'unique_users'
| 'last_active_at'
| 'authorized_users'
| 'pending_requests'
| 'avg_score'
| 'tokens_used';
@@ -58,7 +57,8 @@ export interface ApplicationReportItem {
unique_users: number;
last_active_at: string | null;
authorized_users: number;
pending_requests: number;
/** 后端仍返回;应用运营页已不再展示待审列 */
pending_requests?: number;
avg_score: number | null;
feedback_count: number;
tokens_used: number;
@@ -70,7 +70,8 @@ export interface ApplicationReportSummary {
active_agents: number;
used_agents: number;
unused_agents: number;
pending_permission_total: number;
/** 后端仍返回;应用运营页已不再展示待审摘要卡 */
pending_permission_total?: number;
}
export interface ApplicationReport {
@@ -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,