2026-08-03 858df78951d5c29e8d4217cffcf81d2cc4fabcd4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<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>