feat: improve source search interaction

This commit is contained in:
2026-10-15 20:09:48 +08:00
parent a8b2160ac1
commit 60c1e9b45a
3 changed files with 5 additions and 1 deletions
+3 -1
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { computed, onMounted, ref, watch } from 'vue'
import { Activity, BookOpen, Bot, CheckCircle2, ChevronRight, Database, FileText, Globe2, Link2, MessageSquareText, Plus, Search, Send, ShieldCheck, Sparkles, AlertCircle } from 'lucide-vue-next'
import { askQuestion, createKnowledge, createSource, getHealth, getKnowledge, getSources, type SourceItem } from './api'
type Page='chat'|'knowledge'|'sources'|'evaluation'
@@ -12,6 +12,8 @@ const filtered=computed(()=>items.value.filter(x=>`${x.title} ${x.category} ${x.
async function refresh(){try{items.value=await getKnowledge();error.value=''}catch{error.value='无法读取后端知识库,请确认 API 和 PostgreSQL 已启动。'}}
async function refreshSources(){try{sources.value=(await getSources(sourceSearch.value)).items;error.value=''}catch{error.value='无法读取来源列表,请确认 API 和 PostgreSQL 已启动。'}}
async function saveSource(){error.value='';notice.value='';try{await createSource({...sourceForm.value,...(sourceForm.value.source_url?{source_url:sourceForm.value.source_url}:{})});sourceForm.value={name:'',source_url:'',notes:''};showSourceForm.value=false;notice.value='来源已登记,可继续创建关联文档和知识条目。';await refreshSources()}catch(e){error.value=e instanceof Error?e.message:'保存失败'}}
let sourceSearchTimer:number|undefined
watch(sourceSearch,()=>{window.clearTimeout(sourceSearchTimer);sourceSearchTimer=window.setTimeout(refreshSources,260)})
onMounted(async()=>{try{await getHealth();apiStatus.value='已连接'}catch{apiStatus.value='未连接'}await Promise.all([refresh(),refreshSources()])})
async function send(){const q=question.value.trim();if(!q||busy.value)return;messages.value.push({role:'user',content:q});question.value='';busy.value=true;try{const r=await askQuestion(q);messages.value.push({role:'assistant',content:r.answer,sources:r.sources})}catch{messages.value.push({role:'assistant',content:'暂时无法连接后端 API。请确认 FastAPI 已启动。'})}finally{busy.value=false}}
async function save(){error.value='';notice.value='';try{await createKnowledge({...form.value,...(form.value.source_url?{source_url:form.value.source_url}:{})});form.value={title:'',category:'旅游资源',content:'',source_url:''};showForm.value=false;notice.value='已保存为待审核条目,尚未进入检索索引。';await refresh()}catch(e){error.value=e instanceof Error?e.message:'保存失败'}}
+1
View File
@@ -0,0 +1 @@
.search:focus-within{border-color:#8eaa91;box-shadow:0 0 0 3px #dcebdc}.knowledge-form input:focus,.knowledge-form select:focus,.knowledge-form textarea:focus{border-color:#7e9f83;box-shadow:0 0 0 3px #e4f0e4}.table-card tbody tr{transition:background .15s ease}.table-card tbody tr:hover{background:#fafbf7}.success,.error{animation:feedback-in .2s ease-out}@keyframes feedback-in{from{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:translateY(0)}}
+1
View File
@@ -1,4 +1,5 @@
import { createApp } from 'vue'
import './style.css'
import './enhancements.css'
import App from './App.vue'
createApp(App).mount('#app')