feat(应用管理):增加应用管理介绍描述及自定义常见问题

refactor(chat):chat页面接口获取应用管理中的应用介绍及常见问题
This commit is contained in:
runny committed 2026-06-06 10:42:10 +08:00
1 parent 01173e0a0e
commit a3123cd602
4 files changed
+241 -47

No files matched your search

@@ -37,6 +37,8 @@ const {
resetForm,
selectAgent,
submitAgent,
addSuggestedQuestion,
removeSuggestedQuestion,
deleteAgent,
openTestModal,
runAgentTest,
@@ -133,6 +135,66 @@ onMounted(() => {
:placeholder="t('admin.agent.fields.descPlaceholder')"
/>
</div>
<div class="col-span-1 md:col-span-2 space-y-3">
<div class="flex items-center justify-between gap-3">
<label class="text-xs font-bold text-muted uppercase tracking-wider">常见问题</label>
<button
type="button"
class="inline-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"
@click="addSuggestedQuestion"
>
<Plus class="h-4 w-4" />
添加问题
</button>
</div>
<div class="flex items-center gap-3 text-sm">
<label class="inline-flex items-center gap-2 text-secondary">
<input v-model="form.suggested_questions_style" type="radio" value="plain" class="accent-brand-600" />
<span>无样式</span>
</label>
<label class="inline-flex items-center gap-2 text-secondary">
<input v-model="form.suggested_questions_style" type="radio" value="styled" class="accent-brand-600" />
<span>有样式</span>
</label>
</div>
<div v-if="form.suggested_questions.length === 0" class="rounded-xl border border-dashed border-default px-4 py-5 text-sm text-muted">
暂未配置常见问题,点击“添加问题”后会同步到对应 Agent 的 Chat 欢迎页。
</div>
<div v-else class="space-y-3">
<div
v-for="(item, index) in form.suggested_questions"
:key="index"
class="rounded-2xl border border-default bg-surface-soft/50 p-4"
>
<div class="grid grid-cols-1 gap-3 md:grid-cols-[1fr_220px_auto]">
<input
v-model="item.question"
type="text"
class="w-full input-field"
placeholder="请输入常见问题,例如:查询我有多少假期?"
/>
<input
v-model="item.group"
type="text"
class="w-full input-field"
:disabled="form.suggested_questions_style !== 'styled'"
:placeholder="form.suggested_questions_style === 'styled' ? '可选:分组标题,例如:考勤与休假' : '无样式下无需分组'"
/>
<button
type="button"
class="inline-flex items-center justify-center rounded-xl border border-red-200 bg-red-50 px-3 py-2 text-red-600 transition-colors hover:bg-red-100"
@click="removeSuggestedQuestion(index)"
>
<Trash2 class="h-4 w-4" />
</button>
</div>
</div>
</div>
</div>
</div>
<div class="flex justify-end">
<button type="button" class="btn-primary btn-lg" @click="submitAgent">
@@ -18,9 +18,25 @@ import {
} from '@/api/admin';
import { useMessage } from '@/composables/useMessage';
import type { AdminUserRow } from '@/features/admin/types/admin.types';
import type { AgentFormState, AgentRow, AgentTestResult } from '@/features/admin/types/agent.types';
import type { AgentFormState, AgentRow, AgentSuggestedQuestionItem, AgentTestResult } from '@/features/admin/types/agent.types';
import { createEmptyAgentForm } from '@/features/admin/types/agent.types';
const normalizeSuggestedQuestions = (value: unknown): AgentSuggestedQuestionItem[] => {
if (!Array.isArray(value)) return [];
return value
.map((item) => {
if (typeof item === 'string') {
return { question: item.trim(), group: '' };
}
if (!item || typeof item !== 'object') return null;
const question = String((item as Record<string, unknown>).question || (item as Record<string, unknown>).text || '').trim();
const group = String((item as Record<string, unknown>).group || '').trim();
if (!question) return null;
return { question, group };
})
.filter((item): item is AgentSuggestedQuestionItem => !!item);
};
export function useAgentsAdmin() {
const { t } = useI18n();
const msg = useMessage();
@@ -90,6 +106,8 @@ export function useAgentsAdmin() {
dify_app_type: agent.extra_config?.dify_app_type === 'workflow' ? 'workflow' : 'chatflow',
api_base_url: agent.api_base_url || '',
iframe_url: String(agent.extra_config?.iframe_url || ''),
suggested_questions_style: agent.extra_config?.suggested_questions_style === 'styled' ? 'styled' : 'plain',
suggested_questions: normalizeSuggestedQuestions(agent.extra_config?.suggested_questions),
is_active: agent.is_active,
};
isEditing.value = true;
@@ -132,6 +150,13 @@ export function useAgentsAdmin() {
if (form.value.type === 'api') {
extra_config.dify_app_type = form.value.dify_app_type === 'workflow' ? 'workflow' : 'chatflow';
}
extra_config.suggested_questions_style = form.value.suggested_questions_style === 'styled' ? 'styled' : 'plain';
extra_config.suggested_questions = form.value.suggested_questions
.map((item) => ({
question: String(item.question || '').trim(),
group: String(item.group || '').trim(),
}))
.filter((item) => item.question);
try {
const editingId = isEditing.value ? Number(form.value.id) : null;
@@ -149,6 +174,7 @@ export function useAgentsAdmin() {
payload.dify_api_key = form.value.dify_api_key;
}
await updateAdminAgent(form.value.id, payload);
msg.success('应用更新成功');
} else {
await createAdminAgent({
name: form.value.name,
@@ -159,6 +185,7 @@ export function useAgentsAdmin() {
api_base_url: form.value.api_base_url,
extra_config,
});
msg.success('应用创建成功');
}
await loadAgents();
@@ -176,6 +203,14 @@ export function useAgentsAdmin() {
}
};
const addSuggestedQuestion = (): void => {
form.value.suggested_questions.push({ question: '', group: '' });
};
const removeSuggestedQuestion = (index: number): void => {
form.value.suggested_questions.splice(index, 1);
};
const deleteAgent = async (id: number): Promise<void> => {
openDeleteConfirm(t('admin.agent.confirmDelete'), async () => {
try {
@@ -293,6 +328,8 @@ export function useAgentsAdmin() {
resetForm,
selectAgent,
submitAgent,
addSuggestedQuestion,
removeSuggestedQuestion,
deleteAgent,
openTestModal,
runAgentTest,
@@ -19,6 +19,11 @@ export interface AgentRow {
iframe_url?: string;
}
export interface AgentSuggestedQuestionItem {
question: string;
group: string;
}
export interface AgentTestResult {
success: boolean;
request_url: string;
@@ -38,6 +43,8 @@ export interface AgentFormState {
dify_app_type: 'chatflow' | 'workflow';
api_base_url: string;
iframe_url: string;
suggested_questions_style: 'plain' | 'styled';
suggested_questions: AgentSuggestedQuestionItem[];
is_active: boolean;
}
@@ -50,5 +57,7 @@ export const createEmptyAgentForm = (): AgentFormState => ({
dify_app_type: 'chatflow',
api_base_url: '',
iframe_url: '',
suggested_questions_style: 'plain',
suggested_questions: [],
is_active: true,
});
+132 -46
View File
@@ -705,6 +705,92 @@ const showGeneralFeedbackDialog = ref(false);
const LEAVE_FEATURE_AGENT_NAMES = new Set(['通用入口', '人事规章']);
const canUseLeaveFeature = computed(() => LEAVE_FEATURE_AGENT_NAMES.has(String(currentAgent.value?.name || '').trim()));
type AgentSuggestedQuestionItem = {
question: string;
group: string;
};
const DEFAULT_AGENT_DESCRIPTIONS: Record<string, string> = {
人事规章: '我是你的7x24小时专属HR政策助手。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的规章制度中,为你精准提取并总结答案。',
通用入口: '我是你的7x24小时专属AI数字人。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的人事规章制度中,为你精准提取并总结答案。',
};
const DEFAULT_AGENT_SUGGESTED_QUESTIONS: Record<string, { style: 'plain' | 'styled'; questions: AgentSuggestedQuestionItem[] }> = {
人事规章: {
style: 'styled',
questions: [
{ question: '查询我有多少假期?', group: '考勤与休假' },
{ question: '如何进行请假?', group: '考勤与休假' },
{ question: '查公司法定节假日?', group: '考勤与休假' },
{ question: '新员工入职须知', group: '规章与日常' },
{ question: '怎么开具在职证明?', group: '规章与日常' },
{ question: '查公司薪酬及福利待遇怎么样?', group: '规章与日常' },
],
},
通用入口: {
style: 'plain',
questions: [
{ question: '新员工入职须知', group: '' },
{ question: '查询我有多少假期?', group: '' },
{ question: '如何进行请假?', group: '' },
{ question: '查公司法定节假日?', group: '' },
{ question: '查公司薪酬及福利待遇怎么样?', group: '' },
],
},
};
const normalizeAgentSuggestedQuestions = (value: unknown): AgentSuggestedQuestionItem[] => {
if (!Array.isArray(value)) return [];
return value
.map((item) => {
if (typeof item === 'string') {
const question = item.trim();
return question ? { question, group: '' } : null;
}
if (!item || typeof item !== 'object') return null;
const record = item as Record<string, unknown>;
const question = String(record.question || record.text || '').trim();
const group = String(record.group || '').trim();
return question ? { question, group } : null;
})
.filter((item): item is AgentSuggestedQuestionItem => !!item);
};
const currentAgentName = computed(() => String(currentAgent.value?.name || '').trim());
const agentDescription = computed(() => {
const text = String(currentAgent.value?.description || '').trim();
return text || DEFAULT_AGENT_DESCRIPTIONS[currentAgentName.value] || '';
});
const suggestedQuestionsStyle = computed<'plain' | 'styled'>(() => {
const style = String(currentAgent.value?.extra_config?.suggested_questions_style || '').trim().toLowerCase();
if (style === 'styled') return 'styled';
if (style === 'plain') return 'plain';
return DEFAULT_AGENT_SUGGESTED_QUESTIONS[currentAgentName.value]?.style || 'plain';
});
const agentSuggestedQuestions = computed<AgentSuggestedQuestionItem[]>(() => {
const configured = normalizeAgentSuggestedQuestions(
currentAgent.value?.suggested_questions ?? currentAgent.value?.extra_config?.suggested_questions,
);
if (configured.length > 0) return configured;
return DEFAULT_AGENT_SUGGESTED_QUESTIONS[currentAgentName.value]?.questions || [];
});
const styledSuggestedQuestionSections = computed(() => {
const groups = new Map<string, AgentSuggestedQuestionItem[]>();
for (const item of agentSuggestedQuestions.value) {
const groupName = String(item.group || '').trim() || '常见问题';
if (!groups.has(groupName)) {
groups.set(groupName, []);
}
groups.get(groupName)?.push(item);
}
const iconTypes: Array<'calendar' | 'building'> = ['calendar', 'building'];
return Array.from(groups.entries()).map(([title, questions], index) => ({
title,
questions,
iconType: iconTypes[index % iconTypes.length],
}));
});
const agentGuides = ref<any[]>([]);
const showGuideModal = ref(false);
const activeGuideId = ref<number | null>(null);
@@ -2698,17 +2784,14 @@ const showChatRating = ref(false);
学习之窗
</button>
</div>
<span v-if="currentAgent?.name === '人事规章'" class="block text-[11px] text-muted mt-1 truncate cursor-help">
我是你的7x24小时专属HR政策助手。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的规章制度中,为你精准提取并总结答案。
</span>
<span v-else-if="currentAgent?.name === '通用入口'" class="block text-[11px] text-muted mt-1 truncate cursor-help">
我是你的7x24小时专属AI数字人。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的人事规章制度中,为你精准提取并总结答案。
<span v-if="agentDescription" class="block text-[11px] text-muted mt-1 truncate cursor-help">
{{ agentDescription }}
</span>
<!-- 气泡提示 -->
<div v-if="currentAgent?.name === '人事规章' || currentAgent?.name === '通用入口'" class="absolute left-0 top-[calc(100%+0.25rem)] w-[20rem] p-3 bg-surface border border-default rounded-xl opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-[100] shadow-xl pointer-events-none">
<div v-if="agentDescription" class="absolute left-0 top-[calc(100%+0.25rem)] w-[20rem] p-3 bg-surface border border-default rounded-xl opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-[100] shadow-xl pointer-events-none">
<div class="leading-relaxed text-[11px] text-secondary">
{{ currentAgent?.name === '人事规章' ? '我是你的7x24小时专属HR政策助手。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的规章制度中,为你精准提取并总结答案。' : '我是你的7x24小时专属AI数字人。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的人事规章制度中,为你精准提取并总结答案。' }}
{{ agentDescription }}
</div>
</div>
</div>
@@ -2887,61 +2970,64 @@ const showChatRating = ref(false);
<div
:class="messages.length === 0 ? 'h-full' : 'flex min-h-full flex-col justify-end'"
>
<div v-if="messages.length === 0" class="flex h-full flex-col items-center justify-center py-2 md:pb-16 w-full px-4">
<template v-if="currentAgent?.name === '人事规章'">
<div class="mb-6 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">
HR
<div v-if="messages.length === 0" class="flex h-full min-h-0 w-full flex-col items-center px-4 pt-2 pb-2 md:pb-3">
<template v-if="suggestedQuestionsStyle === 'styled' && styledSuggestedQuestionSections.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">
{{ currentAgent?.name === '人事规章' ? 'HR' : 'AI' }}
</div>
<h2 class="text-center text-xl font-bold text-primary md:text-2xl mb-8">你好,我是人事规章 AI 助手</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 w-full max-w-4xl mx-auto">
<!-- 考勤与休假 -->
<div class="bg-surface border border-default rounded-2xl p-5 hover:border-brand-300 transition-colors shadow-sm">
<div class="flex items-center gap-2 mb-3">
<div class="p-1.5 bg-brand-50 rounded-lg text-brand-600">
<CalendarDays class="h-4 w-4" />
</div>
<h3 class="font-semibold text-secondary">考勤与休假</h3>
</div>
<div class="space-y-2">
<button @click="handleSend('查询我有多少假期?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"查询我有多少假期?"</button>
<button @click="handleSend('如何进行请假?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"如何进行请假?"</button>
<button @click="handleSend('查公司法定节假日?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"查公司法定节假日?"</button>
</div>
</div>
<h2 class="mb-6 shrink-0 text-center text-xl font-bold text-primary md:text-2xl">
{{ currentAgent?.name === '人事规章' ? '你好,我是人事规章 AI 助手' : t('chat.welcomeTitle') }}
</h2>
<!-- 规章与日常 -->
<div class="bg-surface border border-default rounded-2xl p-5 hover:border-brand-300 transition-colors shadow-sm">
<div class="w-full flex-1 min-h-0 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 styledSuggestedQuestionSections"
:key="`${section.title}-${sectionIndex}`"
class="w-full bg-surface border border-default rounded-2xl p-5 hover:border-brand-300 transition-colors shadow-sm"
>
<div class="flex items-center gap-2 mb-3">
<div class="p-1.5 bg-brand-50 rounded-lg text-brand-600">
<Building class="h-4 w-4" />
<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">规章与日常</h3>
<h3 class="font-semibold text-secondary">{{ section.title }}</h3>
</div>
<div class="space-y-2">
<button @click="handleSend('新员工入职须知')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"新员工入职须知"</button>
<button @click="handleSend('怎么开具在职证明?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"怎么开具在职证明?"</button>
<button @click="handleSend('查公司薪酬及福利待遇怎么样?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"查公司薪酬及福利待遇怎么样?"</button>
<button
v-for="(item, questionIndex) in section.questions"
:key="`${section.title}-${questionIndex}`"
@click="handleSend(item.question)"
class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate"
>
"{{ item.question }}"
</button>
</div>
</div>
</div>
</div>
</template>
<template v-else-if="currentAgent?.name === '通用入口'">
<div class="mb-6 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">
<template v-else-if="agentSuggestedQuestions.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="text-center text-xl font-medium text-primary md:text-2xl mb-8">{{ $t('chat.welcomeTitle') }}</h2>
<div class="flex flex-wrap justify-center gap-3 w-full max-w-3xl mx-auto mt-2">
<button @click="handleSend('新员工入职须知')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"新员工入职须知"</button>
<button @click="handleSend('查询我有多少假期?')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"查询我有多少假期?"</button>
<button @click="handleSend('如何进行请假?')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"如何进行请假?"</button>
<button @click="handleSend('查公司法定节假日?')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"查公司法定节假日?"</button>
<button @click="handleSend('查公司薪酬及福利待遇怎么样?')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"查公司薪酬及福利待遇怎么样?"</button>
<h2 class="mb-6 shrink-0 text-center text-xl font-medium text-primary md:text-2xl">{{ $t('chat.welcomeTitle') }}</h2>
<div class="w-full flex-1 min-h-0 overflow-y-auto pb-2">
<div class="flex flex-wrap justify-center gap-3 w-full max-w-3xl mx-auto mt-2">
<button
v-for="(item, index) in agentSuggestedQuestions"
:key="`${item.question}-${index}`"
@click="handleSend(item.question)"
class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm"
>
"{{ item.question }}"
</button>
</div>
</div>
</template>
<template v-else>
<div class="mb-6 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">
<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>