<script lang="ts" setup>
|
import { ref } from 'vue';
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
import { Empty, Input, Spin } from 'ant-design-vue';
|
|
import { searchKnowledgeSegment } from '#/api/ai/knowledge/segment';
|
|
defineOptions({ name: 'MesQcAiAssistant' });
|
|
const knowledgeId = 1; // 质检标准知识库 ID,需根据实际配置修改
|
|
const keyword = ref('');
|
const loading = ref(false);
|
const segments = ref<
|
Array<{ id: number; content: string; score: number; documentName: string }>
|
>([]);
|
|
async function handleSearch() {
|
if (!keyword.value.trim()) return;
|
loading.value = true;
|
try {
|
const data = await searchKnowledgeSegment({
|
knowledgeId,
|
content: keyword.value,
|
topK: 5,
|
similarityThreshold: 0.5,
|
});
|
segments.value = (data || []) as typeof segments.value;
|
} finally {
|
loading.value = false;
|
}
|
}
|
|
function handleKeywordChange(e: Event) {
|
keyword.value = (e.target as HTMLInputElement).value;
|
}
|
|
const [AssistantModal, modalApi] = useVbenModal({
|
footer: false,
|
});
|
</script>
|
|
<template>
|
<a-button type="default" @click="modalApi.open()">
|
质检助手
|
</a-button>
|
|
<AssistantModal title="质检助手" class="w-1/3">
|
<div class="mb-4">
|
<a-textarea
|
:value="keyword"
|
placeholder="输入问题,如:外观检验标准是什么?"
|
:rows="3"
|
@change="handleKeywordChange"
|
/>
|
</div>
|
<div class="mb-4 flex justify-end">
|
<a-button type="primary" :loading="loading" @click="handleSearch">
|
搜索
|
</a-button>
|
</div>
|
|
<Spin :spinning="loading" tip="检索中...">
|
<template v-if="segments.length === 0 && !loading">
|
<Empty description="未找到相关标准,请尝试其他关键词" />
|
</template>
|
<div v-else class="space-y-3">
|
<div
|
v-for="segment in segments"
|
:key="segment.id"
|
class="rounded border border-gray-200 p-3"
|
>
|
<div class="mb-1 text-xs text-gray-500">
|
来源:{{ segment.documentName || '未知文档' }}
|
</div>
|
<div class="text-sm leading-relaxed">
|
{{ segment.content }}
|
</div>
|
<div class="mt-1 text-xs text-gray-400">
|
相似度 {{ ((segment.score ?? 0) * 100).toFixed(0) }}%
|
</div>
|
</div>
|
</div>
|
</Spin>
|
</AssistantModal>
|
</template>
|