feat(common problems fuzzy query): 增加常用问题模糊查询兜底

This commit is contained in:
HTEWJ\26070045 committed 2026-10-22 17:25:01 +08:00
1 parent b69c725992
commit 5a269f940d
18 files changed
+411 -58

No files matched your search

@@ -3,10 +3,11 @@
* 用途:常用问题 / FAQ 缓存的创建与编辑对话框。字段多,宽 680px,两列短字段。
* 依赖:element-plus 对话框和表单、QuestionFormState、AdminAgentOption。
* 逻辑:QuestionsPage 打开本组件。提交时 emit save 或 review,由 useQuestionsAdmin 调接口。样式跟页面已引入的 Element 皮肤走。
* is_enabled 仅控制工作台首页入口;cache_enabled 单独控制聊天是否跳过 Dify。
* is_enabled 仅控制工作台首页入口;cache_enabled 单独控制聊天是否跳过 Dify;
* fuzzy_enabled 在精确未命中时按阈值兜底直答,以 cache_enabled 为前提(关闭缓存时联动取消勾选)。
*/
<script setup lang="ts">
import { computed } from 'vue';
import { computed, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import {
ElAlert,
@@ -43,6 +44,19 @@ const { t } = useI18n();
/** 启用 FAQ 缓存时标准答案为必填。 */
const answerRequired = computed(() => props.form.cache_enabled);
/** 模糊匹配只在 FAQ 缓存开启时有意义,控制阈值输入的显隐与开关可用态。 */
const fuzzyAvailable = computed(() => props.form.cache_enabled && props.form.fuzzy_enabled);
/**
* 关闭 FAQ 缓存时联动取消模糊匹配,避免提交出「缓存关、模糊开」的无效组合。
*/
watch(
() => props.form.cache_enabled,
(enabled) => {
if (!enabled) props.form.fuzzy_enabled = false;
},
);
/** 是否处于 KB 更新后的待复审状态。 */
const isStale = computed(() => Boolean(props.form.stale_at));
@@ -143,6 +157,23 @@ function submitForm(): void {
<ElFormItem class="question-form-span">
<ElCheckbox v-model="form.cache_enabled">{{ t('admin.question.fields.cacheEnabled') }}</ElCheckbox>
</ElFormItem>
<ElFormItem class="question-form-span">
<ElCheckbox v-model="form.fuzzy_enabled" :disabled="!form.cache_enabled">
<span class="question-check-label">{{ t('admin.question.fields.fuzzyEnabled') }}</span>
<span class="hx-element-hint question-check-hint">{{ t('admin.question.fields.fuzzyEnabledHelp') }}</span>
</ElCheckbox>
</ElFormItem>
<ElFormItem v-if="fuzzyAvailable" class="question-form-span" :label="t('admin.question.fields.fuzzyThreshold')">
<ElInputNumber
v-model="form.fuzzy_threshold"
:min="0.5"
:max="1"
:step="0.05"
:precision="2"
controls-position="right"
/>
<p class="hx-element-hint">{{ t('admin.question.fields.fuzzyThresholdHelp') }}</p>
</ElFormItem>
<p class="question-section-label question-form-span">{{ t('admin.question.sections.matching') }}</p>
<ElFormItem class="question-form-span" :label="t('admin.question.fields.content')" required>
@@ -108,6 +108,8 @@ export function useQuestionsAdmin() {
aliasesText: aliasesToText(q.aliases),
cache_enabled: q.cache_enabled,
is_enabled: q.is_enabled,
fuzzy_enabled: Boolean(q.fuzzy_enabled),
fuzzy_threshold: typeof q.fuzzy_threshold === 'number' ? q.fuzzy_threshold : 0.8,
agent_id: q.agent_id,
sort_order: q.sort_order,
expires_at: q.expires_at ? q.expires_at.slice(0, 16) : '',
@@ -11,6 +11,8 @@ export interface AdminQuickQuestionRow {
aliases?: string[];
cache_enabled: boolean;
is_enabled: boolean;
fuzzy_enabled?: boolean;
fuzzy_threshold?: number | null;
hit_count: number;
agent_id: number;
agent_name?: string;
@@ -32,6 +34,8 @@ export interface QuestionFormState {
aliasesText: string;
cache_enabled: boolean;
is_enabled: boolean;
fuzzy_enabled: boolean;
fuzzy_threshold: number;
agent_id?: number;
sort_order: number;
expires_at: string;
@@ -47,6 +51,8 @@ export const createEmptyQuestionForm = (): QuestionFormState => ({
aliasesText: '',
cache_enabled: false,
is_enabled: true,
fuzzy_enabled: false,
fuzzy_threshold: 0.8,
agent_id: undefined,
sort_order: 0,
expires_at: '',
@@ -70,7 +76,7 @@ export const textToAliases = (text: string): string[] => {
return result;
};
/** 构建提交 API 的 payload。 */
/** 构建提交 API 的 payload。模糊匹配以 FAQ 缓存为前提,缓存关闭时一并提交关闭。 */
export const buildQuestionPayload = (
form: QuestionFormState,
options?: { clearStale?: boolean },
@@ -81,6 +87,8 @@ export const buildQuestionPayload = (
aliases: textToAliases(form.aliasesText),
cache_enabled: form.cache_enabled,
is_enabled: form.is_enabled,
fuzzy_enabled: form.cache_enabled && form.fuzzy_enabled,
fuzzy_threshold: form.fuzzy_threshold,
agent_id: form.agent_id,
sort_order: form.sort_order,
expires_at: form.expires_at || null,