feat: add index management interface #24
@@ -24,7 +24,7 @@ async function send(){const q=question.value.trim();if(!q||busy.value)return;mes
|
||||
function validUrl(value:string){try{if(value)new URL(value);return true}catch{return false}}
|
||||
async function save(){error.value='';notice.value='';if(!form.value.title.trim()||!form.value.content.trim()){error.value='请填写知识标题和正文。';return}if(!validUrl(form.value.source_url)){error.value='来源网址必须是有效的 http(s) 地址。';return}try{await createKnowledge({...form.value,title:form.value.title.trim(),content:form.value.content.trim(),...(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:'保存失败'}}
|
||||
</script>
|
||||
<template><div class="shell"><aside class="sidebar"><div class="brand"><div class="mark"><Bot :size="23"/></div><div><b>边疆红驿</b><small>NALATI KNOWLEDGE HUB</small></div></div><p class="muted label">功能列表</p><nav><button v-for="n in visibleNav" :key="n.id" :class="{active:page===n.id}" @click="page=n.id"><component :is="n.icon" :size="18"/>{{n.label}}<ChevronRight v-if="page===n.id" class="chev" :size="15"/></button><button @click="router.push('/profile')"><ShieldCheck :size="18"/>个人中心</button><button v-if="currentUser?.role==='admin'" @click="router.push('/admin')"><Activity :size="18"/>用户管理</button></nav><div class="quick-actions"><p class="muted label">快捷操作</p><button v-if="page==='knowledge'" class="side-action" @click="showForm=true"><Plus :size="16"/>新增知识</button><button v-if="page==='sources'" class="side-action" @click="showSourceForm=true"><Plus :size="16"/>新增来源</button><p v-if="page==='chat'" class="side-hint">选择示例问题,或直接开始提问。</p><p v-if="page==='evaluation'" class="side-hint">实验结果只展示真实运行数据。</p></div><div class="side-bottom"><div class="tip"><ShieldCheck :size="17"/><div><b>{{currentUser?.role==='admin'?'管理员':'已登录用户'}}</b><p>{{currentUser?.nickname||currentUser?.username||'正在载入账户'}}</p></div></div><p class="api">● API {{apiStatus}} <span>v0.1.0</span></p></div></aside><main><header><span>边疆红驿 / {{nav.find(n=>n.id===page)?.label}}</span><div><span class="pill">● {{currentUser?.role==='admin'?'管理员':'用户'}}</span><i>研</i></div></header><section class="content">
|
||||
<template><div class="shell"><aside class="sidebar"><div class="brand"><div class="mark"><Bot :size="23"/></div><div><b>边疆红驿</b><small>NALATI KNOWLEDGE HUB</small></div></div><p class="muted label">功能列表</p><nav><button v-for="n in visibleNav" :key="n.id" :class="{active:page===n.id}" @click="page=n.id"><component :is="n.icon" :size="18"/>{{n.label}}<ChevronRight v-if="page===n.id" class="chev" :size="15"/></button><button @click="router.push('/profile')"><ShieldCheck :size="18"/>个人中心</button><button v-if="currentUser?.role==='admin'" @click="router.push('/indexes')"><Database :size="18"/>索引管理</button><button v-if="currentUser?.role==='admin'" @click="router.push('/admin')"><Activity :size="18"/>用户管理</button></nav><div class="quick-actions"><p class="muted label">快捷操作</p><button v-if="page==='knowledge'" class="side-action" @click="showForm=true"><Plus :size="16"/>新增知识</button><button v-if="page==='sources'" class="side-action" @click="showSourceForm=true"><Plus :size="16"/>新增来源</button><p v-if="page==='chat'" class="side-hint">选择示例问题,或直接开始提问。</p><p v-if="page==='evaluation'" class="side-hint">实验结果只展示真实运行数据。</p></div><div class="side-bottom"><div class="tip"><ShieldCheck :size="17"/><div><b>{{currentUser?.role==='admin'?'管理员':'已登录用户'}}</b><p>{{currentUser?.nickname||currentUser?.username||'正在载入账户'}}</p></div></div><p class="api">● API {{apiStatus}} <span>v0.1.0</span></p></div></aside><main><header><span>边疆红驿 / {{nav.find(n=>n.id===page)?.label}}</span><div><span class="pill">● {{currentUser?.role==='admin'?'管理员':'用户'}}</span><i>研</i></div></header><section class="content">
|
||||
<div v-if="page==='chat'"><div class="heading"><div><small class="eyebrow"><Sparkles :size="14"/> LOCAL KNOWLEDGE ASSISTANT</small><h1>文旅知识,问得明白</h1><p>面向那拉提文旅与民宿服务的知识问答原型</p></div><span class="chip"><ShieldCheck :size="15"/> 来源可追溯 · 设计目标</span></div><div class="chat-layout"><div class="card chat"><div class="chat-head"><div class="mark"><Bot :size="20"/></div><div><b>边疆红驿助手</b><small>问答服务原型</small></div></div><div class="messages"><div v-for="(m,i) in messages" :key="i" class="message" :class="m.role"><small>{{m.role==='assistant'?'智能助手':'你'}}</small><p>{{m.content}}</p><div v-if="m.sources?.length" class="sources"><b><Link2 :size="14"/> 参考来源</b><a v-for="s in m.sources" :key="s.title" :href="s.source_url ?? undefined" target="_blank">{{s.title}}</a></div></div><p v-if="busy">正在请求后端…</p></div><form class="composer" @submit.prevent="send"><textarea v-model="question" placeholder="输入你想了解的文旅问题…" rows="2" @keydown.enter.exact.prevent="send"/><div><small>当前为基础接口,尚未接入真实检索</small><button class="primary" :disabled="busy||!question.trim()"><Send :size="15"/> 发送</button></div></form></div><aside class="suggest"><b><Sparkles :size="16"/> 你可以这样问</b><button @click="question='那拉提有哪些值得了解的旅游资源?'"><Globe2/>旅游资源 <ChevronRight/></button><button @click="question='有哪些经过核验的红色文化资料?'"><BookOpen/>红色文化 <ChevronRight/></button><button @click="question='民宿服务信息应如何核验?'"><ShieldCheck/>民宿服务 <ChevronRight/></button><div class="notice"><b><AlertCircle :size="15"/> 信息说明</b><p>本项目仍处于原型阶段。演示内容不代表已核验的地方文旅事实。</p></div></aside></div></div>
|
||||
<div v-else-if="page==='knowledge'"><div class="heading"><div><small class="eyebrow"><Database :size="14"/> KNOWLEDGE MANAGEMENT</small><h1>知识库管理</h1><p>集中管理领域知识、来源和审核状态。</p></div><button class="primary" @click="showForm=!showForm"><Plus :size="16"/> 新增知识</button></div><div v-if="showForm" class="card form-card"><b>新增知识条目</b><form class="knowledge-form" @submit.prevent="save"><label>标题<input v-model="form.title" required maxlength="250"/></label><label>分类<select v-model="form.category"><option>红色文化</option><option>旅游资源</option><option>民宿服务</option><option>交通出行</option><option>其他</option></select></label><label class="wide">正文<textarea v-model="form.content" required rows="3"/></label><label class="wide">来源网址(可选)<input v-model="form.source_url" type="url" placeholder="https://..."/></label><div class="wide actions"><button type="button" class="secondary" @click="showForm=false">取消</button><button class="primary">保存条目</button></div></form></div><div class="stats"><div class="card stat"><small>知识条目</small><strong>{{items.length}}</strong><span>来自当前数据库</span></div><div class="card stat"><small>已核验</small><strong>{{items.filter(x=>x.verification_status==='verified').length}}</strong><span>需经过真实审核</span></div><div class="card stat"><small>待审核</small><strong>{{items.filter(x=>x.verification_status==='pending').length}}</strong><span>尚未进入检索索引</span></div></div><p v-if="notice" class="success">{{notice}}</p><p v-if="error" class="error">{{error}}</p><div class="card table-card"><div class="table-head"><div><b>知识条目</b><p>列表来自后端接口,不含预设真实资料。</p></div><label class="search"><Search :size="15"/><input v-model="search" placeholder="搜索知识"/></label></div><div class="scroll"><table><thead><tr><th>标题</th><th>分类</th><th>来源</th><th>状态</th><th>创建时间</th></tr></thead><tbody><tr v-for="x in filtered" :key="x.id"><td><b>{{x.title}}</b><small>{{x.content.slice(0,45)}}</small></td><td>{{x.category}}</td><td><a v-if="x.source_url" :href="x.source_url" target="_blank">打开来源</a><span v-else>未填写</span></td><td><em>{{x.verification_status==='pending'?'待审核':x.verification_status}}</em></td><td>{{new Date(x.created_at).toLocaleDateString()}}</td></tr><tr v-if="!filtered.length"><td colspan="5" class="empty">暂无条目,点击“新增知识”添加。</td></tr></tbody></table></div></div></div>
|
||||
<div v-else-if="page==='sources'"><div class="heading"><div><small class="eyebrow"><Globe2 :size="14"/> SOURCE OPERATIONS</small><h1>来源与更新</h1><p>登记可追溯来源,为文档采集和知识审核建立基础。</p></div><button class="primary" @click="showSourceForm=!showSourceForm"><Plus :size="16"/> 新增来源</button></div><div v-if="showSourceForm" class="card form-card"><b>登记来源</b><form class="knowledge-form" @submit.prevent="saveSource"><label>来源名称<input v-model="sourceForm.name" required maxlength="250" placeholder="例如:那拉提景区官网"/></label><label>来源网址(可选)<input v-model="sourceForm.source_url" type="url" placeholder="https://..."/></label><label class="wide">备注<textarea v-model="sourceForm.notes" rows="3" placeholder="记录来源用途、可靠性判断或待核验事项"/></label><div class="wide actions"><button type="button" class="secondary" @click="showSourceForm=false">取消</button><button class="primary">保存来源</button></div></form></div><p v-if="notice" class="success">{{notice}}</p><p v-if="error" class="error">{{error}}</p><div class="stats"><div class="card stat"><small>来源总数</small><strong>{{sources.length}}</strong><span>来自当前数据库</span></div><div class="card stat"><small>关联文档</small><strong>—</strong><span>文档工作台待接入</span></div><div class="card stat"><small>自动更新</small><strong class="pending">未启用</strong><span>当前不会自动抓取网页</span></div></div><div class="card table-card"><div class="table-head"><div><b>已登记来源</b><p>来源不是审核通过的证明,关键事实仍需交叉核验。</p></div><label class="search"><Search :size="15"/><input v-model="sourceSearch" placeholder="搜索名称或备注" @keyup.enter="refreshSources"/></label></div><div class="scroll"><table><thead><tr><th>名称</th><th>网址</th><th>备注</th><th>登记时间</th></tr></thead><tbody><tr v-for="source in sources" :key="source.id"><td><b>{{source.name}}</b></td><td><a v-if="source.source_url" :href="source.source_url" target="_blank" rel="noreferrer">打开来源</a><span v-else>未填写</span></td><td>{{source.notes||'—'}}</td><td>{{new Date(source.created_at).toLocaleDateString()}}</td></tr><tr v-if="!sources.length"><td colspan="4" class="empty">暂无来源,点击“新增来源”登记。</td></tr></tbody></table></div></div><div class="card roadmap"><b>来源处理边界</b><div><span>01 登记来源</span><ChevronRight/><span>02 人工核验</span><ChevronRight/><span>03 关联文档</span><ChevronRight/><span>04 后续检索</span></div></div></div>
|
||||
|
||||
@@ -10,6 +10,7 @@ const router=createRouter({history:createWebHistory(),routes:[
|
||||
{path:'/register',component:()=>import('./views/RegisterView.vue'),meta:{public:true}},
|
||||
{path:'/profile',component:()=>import('./views/ProfileView.vue')},
|
||||
{path:'/settings',component:()=>import('./views/AccountSettingsView.vue')},
|
||||
{path:'/indexes',component:()=>import('./views/IndexManagementView.vue'),meta:{role:'admin'}},
|
||||
{path:'/admin',component:()=>import('./views/AdminView.vue'),meta:{role:'admin'}},
|
||||
]})
|
||||
router.beforeEach(async to=>{if(to.meta.public)return true;try{role=(await getCurrentUser()).role}catch{return {path:'/login',query:{redirect:to.fullPath}}}if(to.meta.role&&role!==to.meta.role)return {path:'/profile',query:{forbidden:'1'}};return true})
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { buildIndex, getActiveIndex, getIndexVersions, publishIndex, type ActiveIndex, type IndexVersion } from '../services/indexes'
|
||||
import { buildVectorIndex, getActiveVectors, getVectorVersions, publishVectorIndex, type ActiveVectors, type VectorVersion } from '../services/vectors'
|
||||
|
||||
const textActive = ref<ActiveIndex>()
|
||||
const vectorActive = ref<ActiveVectors>()
|
||||
const textVersions = ref<IndexVersion[]>([])
|
||||
const vectorVersions = ref<VectorVersion[]>([])
|
||||
const loading = ref(true)
|
||||
const buildingText = ref(false)
|
||||
const buildingVector = ref<string>()
|
||||
const publishing = ref<string>()
|
||||
const error = ref('')
|
||||
const notice = ref('')
|
||||
const config = ref({ chunk_size: 800, overlap: 120 })
|
||||
|
||||
async function refresh() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const [text, texts, vectors, vectorList] = await Promise.all([getActiveIndex(), getIndexVersions(), getActiveVectors(), getVectorVersions()])
|
||||
textActive.value = text
|
||||
textVersions.value = texts.items
|
||||
vectorActive.value = vectors
|
||||
vectorVersions.value = vectorList.items
|
||||
} catch (cause) {
|
||||
error.value = cause instanceof Error ? cause.message : '无法读取索引状态'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function buildText() {
|
||||
error.value = ''; notice.value = ''
|
||||
if (config.value.chunk_size <= 0 || config.value.overlap < 0 || config.value.overlap >= config.value.chunk_size) {
|
||||
error.value = '切分长度必须大于 0,且重叠长度必须小于切分长度。'
|
||||
return
|
||||
}
|
||||
buildingText.value = true
|
||||
try {
|
||||
const version = await buildIndex(config.value)
|
||||
notice.value = `文本索引 ${version.id} 已构建为 ready,需确认后再发布。`
|
||||
await refresh()
|
||||
} catch (cause) { error.value = cause instanceof Error ? cause.message : '构建文本索引失败' } finally { buildingText.value = false }
|
||||
}
|
||||
|
||||
async function publishText(version: IndexVersion) {
|
||||
publishing.value = `text:${version.id}`; error.value = ''; notice.value = ''
|
||||
try { await publishIndex(version.id, textActive.value?.generation ?? 0); notice.value = '文本索引已发布。'; await refresh() }
|
||||
catch (cause) { error.value = cause instanceof Error ? cause.message : '发布文本索引失败' } finally { publishing.value = undefined }
|
||||
}
|
||||
|
||||
async function buildVector(version: IndexVersion) {
|
||||
buildingVector.value = version.id; error.value = ''; notice.value = ''
|
||||
try { const created = await buildVectorIndex(version.id); notice.value = `向量索引 ${created.id} 已构建为 ready。`; await refresh() }
|
||||
catch (cause) { error.value = cause instanceof Error ? cause.message : '构建向量索引失败' } finally { buildingVector.value = undefined }
|
||||
}
|
||||
|
||||
async function publishVector(version: VectorVersion) {
|
||||
publishing.value = `vector:${version.id}`; error.value = ''; notice.value = ''
|
||||
try { await publishVectorIndex(version.id, vectorActive.value?.generation ?? 0); notice.value = '向量索引已发布。'; await refresh() }
|
||||
catch (cause) { error.value = cause instanceof Error ? cause.message : '发布向量索引失败' } finally { publishing.value = undefined }
|
||||
}
|
||||
|
||||
onMounted(refresh)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main>
|
||||
<RouterLink to="/">返回工作台</RouterLink>
|
||||
<h1>索引管理</h1>
|
||||
<p>操作直接调用管理员受保护接口;构建与发布会以服务端当前审核语料和代数校验为准。</p>
|
||||
<p v-if="error" role="alert">{{ error }}</p><p v-if="notice" role="status">{{ notice }}</p>
|
||||
<p v-if="loading">正在读取索引状态…</p>
|
||||
<template v-else>
|
||||
<section><h2>文本索引</h2><p>当前版本:{{ textActive?.active_version?.id || '未发布' }};代数:{{ textActive?.generation ?? 0 }}</p>
|
||||
<form @submit.prevent="buildText"><label>切分长度<input v-model.number="config.chunk_size" type="number" min="1" required /></label><label>重叠长度<input v-model.number="config.overlap" type="number" min="0" required /></label><button :disabled="buildingText">{{ buildingText ? '构建中…' : '构建文本索引' }}</button></form>
|
||||
<table><thead><tr><th>版本</th><th>状态</th><th>条目/片段</th><th>创建时间</th><th>操作</th></tr></thead><tbody><tr v-for="version in textVersions" :key="version.id"><td>{{ version.id }}</td><td>{{ version.status }}</td><td>{{ version.item_count }} / {{ version.chunk_count }}</td><td>{{ new Date(version.created_at).toLocaleString() }}</td><td><button v-if="version.status==='ready'" :disabled="publishing===`text:${version.id}`" @click="publishText(version)">发布</button><button v-if="version.status==='published'" :disabled="buildingVector===version.id" @click="buildVector(version)">{{ buildingVector===version.id?'构建中…':'构建向量索引' }}</button></td></tr><tr v-if="!textVersions.length"><td colspan="5">暂无文本索引。</td></tr></tbody></table>
|
||||
</section>
|
||||
<section><h2>向量索引</h2><p>当前版本:{{ vectorActive?.active_version?.id || '未发布' }};代数:{{ vectorActive?.generation ?? 0 }}</p>
|
||||
<table><thead><tr><th>版本</th><th>文本版本</th><th>状态</th><th>片段数</th><th>操作</th></tr></thead><tbody><tr v-for="version in vectorVersions" :key="version.id"><td>{{ version.id }}</td><td>{{ version.text_index_version_id }}</td><td>{{ version.status }}</td><td>{{ version.chunk_count }}</td><td><button v-if="version.status==='ready'" :disabled="publishing===`vector:${version.id}`" @click="publishVector(version)">发布</button></td></tr><tr v-if="!vectorVersions.length"><td colspan="5">暂无向量索引;需先发布文本索引并启用本地 Embedding。</td></tr></tbody></table>
|
||||
</section>
|
||||
</template>
|
||||
</main>
|
||||
</template>
|
||||
Reference in New Issue
Block a user