feat(应用管理):增加应用管理介绍描述及自定义常见问题
refactor(chat):chat页面接口获取应用管理中的应用介绍及常见问题
This commit is contained in:
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,
|
||||
|
||||
Reference in new issue
Block a user