feat: add avatar chat and knowledge workflow
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
<template>
|
||||
<div class="chat-page">
|
||||
<header class="chat-header">
|
||||
<button class="back-btn" @click="router.back()">‹</button>
|
||||
<div class="avatar-heading">
|
||||
<div class="avatar-mark">{{ avatar?.emoji || '🤖' }}</div>
|
||||
<div>
|
||||
<h1>{{ avatar?.displayName || avatar?.name || '数字分身' }}</h1>
|
||||
<span class="online-state">● 随时可以和我聊聊</span>
|
||||
</div>
|
||||
</div>
|
||||
<button class="settings-btn" title="编辑分身" @click="router.push(`/avatar/edit/${avatarId}`)">⚙</button>
|
||||
</header>
|
||||
|
||||
<main ref="messageList" class="message-list">
|
||||
<div v-if="!messages.length" class="welcome-card">
|
||||
<div class="welcome-icon">✦</div>
|
||||
<h2>你好,我是{{ avatar?.displayName || '你的数字分身' }}</h2>
|
||||
<p>我会优先参考标准问答和知识库,再结合自己的理解回答你。</p>
|
||||
<div class="starter-list">
|
||||
<button v-for="starter in starters" :key="starter" @click="sendMessage(starter)">{{ starter }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<article v-for="(message, index) in messages" :key="`${message.role}-${index}`" class="message-row" :class="message.role">
|
||||
<div v-if="message.role === 'assistant'" class="message-avatar">{{ avatar?.emoji || '🤖' }}</div>
|
||||
<div class="message-column">
|
||||
<div class="message-bubble">{{ message.content }}</div>
|
||||
<div v-if="message.source || message.references?.length" class="message-source">
|
||||
{{ sourceLabel(message.source) }}
|
||||
<span v-if="message.references?.length"> · {{ message.references.map((item) => item.filename).filter(Boolean).join('、') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<div v-if="sending" class="message-row assistant">
|
||||
<div class="message-avatar">{{ avatar?.emoji || '🤖' }}</div>
|
||||
<div class="message-bubble typing"><i></i><i></i><i></i></div>
|
||||
</div>
|
||||
<p v-if="errorMessage" class="chat-error">{{ errorMessage }} <button @click="retryLast">重试</button></p>
|
||||
</main>
|
||||
|
||||
<form class="composer" @submit.prevent="sendMessage(inputText)">
|
||||
<textarea v-model="inputText" rows="1" :disabled="sending" placeholder="输入你想聊的内容…" @keydown.enter.exact.prevent="sendMessage(inputText)"></textarea>
|
||||
<button class="send-btn" type="submit" :disabled="sending || !inputText.trim()">发送</button>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { nextTick, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { getAvatarDetail, sendAvatarChat, type ChatMessage } from '@/api'
|
||||
import { useAvatarStore } from '@/store/avatar'
|
||||
|
||||
type DisplayMessage = ChatMessage & {
|
||||
source?: 'qa' | 'knowledge' | 'qwen'
|
||||
references?: Array<{ filename?: string }>
|
||||
}
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const store = useAvatarStore()
|
||||
const avatarId = String(route.params.id || '')
|
||||
const avatar = ref<any>(null)
|
||||
const messages = ref<DisplayMessage[]>([])
|
||||
const inputText = ref('')
|
||||
const sending = ref(false)
|
||||
const errorMessage = ref('')
|
||||
const lastQuestion = ref('')
|
||||
const messageList = ref<HTMLElement | null>(null)
|
||||
const starters = ['介绍一下你自己', '你能帮我做什么?', '请根据我的知识库回答一个问题']
|
||||
|
||||
const sourceLabel = (source?: DisplayMessage['source']) => ({
|
||||
qa: '标准问答对',
|
||||
knowledge: '参考文件知识库',
|
||||
qwen: 'Qwen 智能回答'
|
||||
}[source || ''] || '')
|
||||
|
||||
const scrollToBottom = async () => {
|
||||
await nextTick()
|
||||
if (messageList.value) messageList.value.scrollTop = messageList.value.scrollHeight
|
||||
}
|
||||
|
||||
const loadAvatar = async () => {
|
||||
avatar.value = store.avatars.find((item) => String(item.id) === avatarId)
|
||||
if (!avatar.value) avatar.value = await getAvatarDetail(avatarId)
|
||||
}
|
||||
|
||||
const sendMessage = async (value: string) => {
|
||||
const question = value.trim()
|
||||
if (!question || sending.value) return
|
||||
lastQuestion.value = question
|
||||
inputText.value = ''
|
||||
errorMessage.value = ''
|
||||
messages.value.push({ role: 'user', content: question })
|
||||
sending.value = true
|
||||
await scrollToBottom()
|
||||
try {
|
||||
const response = await sendAvatarChat(avatarId, {
|
||||
message: question,
|
||||
history: messages.value.slice(-10).map(({ role, content }) => ({ role, content }))
|
||||
})
|
||||
messages.value.push({ role: 'assistant', content: response.answer, source: response.source, references: response.references })
|
||||
await scrollToBottom()
|
||||
} catch (error: any) {
|
||||
errorMessage.value = error?.message || '暂时无法回答,请稍后重试'
|
||||
} finally {
|
||||
sending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const retryLast = () => {
|
||||
if (!lastQuestion.value || sending.value) return
|
||||
const last = messages.value[messages.value.length - 1]
|
||||
if (last?.role === 'user') messages.value.pop()
|
||||
sendMessage(lastQuestion.value)
|
||||
}
|
||||
|
||||
onMounted(loadAvatar)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.chat-page { min-height: 100dvh; display: flex; flex-direction: column; background: #FFF8F1; color: #3B2417; }
|
||||
.chat-header { flex: 0 0 auto; display: flex; align-items: center; gap: 12px; padding: 14px 18px; color: white; background: linear-gradient(135deg, #F97316, #FB923C); box-shadow: 0 5px 18px rgba(249, 115, 22, .2); }
|
||||
.back-btn, .settings-btn { border: 0; background: transparent; color: white; cursor: pointer; font-size: 25px; padding: 2px 6px; }
|
||||
.settings-btn { font-size: 20px; margin-left: auto; }
|
||||
.avatar-heading { display: flex; align-items: center; gap: 10px; }
|
||||
.avatar-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 13px; background: rgba(255,255,255,.24); font-size: 23px; }
|
||||
.avatar-heading h1 { margin: 0; font-size: 17px; }
|
||||
.online-state { display: block; margin-top: 3px; font-size: 11px; opacity: .86; }
|
||||
.message-list { flex: 1 1 auto; width: min(760px, 100%); box-sizing: border-box; margin: 0 auto; padding: 24px 18px 120px; overflow-y: auto; }
|
||||
.welcome-card { padding: 28px 20px; text-align: center; background: rgba(255,255,255,.72); border: 1px solid #FFE1C2; border-radius: 22px; box-shadow: 0 10px 28px rgba(181, 99, 35, .08); }
|
||||
.welcome-icon { color: #F97316; font-size: 30px; }
|
||||
.welcome-card h2 { margin: 9px 0 8px; font-size: 20px; }
|
||||
.welcome-card p { margin: 0 auto 20px; max-width: 420px; color: #8B6B58; line-height: 1.6; font-size: 14px; }
|
||||
.starter-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
|
||||
.starter-list button { border: 1px solid #FFD1A8; color: #C15F18; background: #FFF4E8; border-radius: 20px; padding: 8px 12px; cursor: pointer; }
|
||||
.message-row { display: flex; gap: 9px; margin: 18px 0; align-items: flex-end; }
|
||||
.message-row.user { justify-content: flex-end; }
|
||||
.message-avatar { flex: 0 0 auto; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 10px; background: #FFE4C7; }
|
||||
.message-column { max-width: min(78%, 560px); }
|
||||
.message-bubble { padding: 12px 14px; white-space: pre-wrap; line-height: 1.6; font-size: 15px; border-radius: 16px 16px 16px 4px; background: white; box-shadow: 0 3px 12px rgba(96, 52, 21, .07); }
|
||||
.user .message-bubble { color: white; border-radius: 16px 16px 4px 16px; background: #F97316; }
|
||||
.message-source { margin: 5px 4px 0; font-size: 11px; color: #A77A5B; }
|
||||
.typing { display: flex; gap: 4px; padding: 14px 16px; }
|
||||
.typing i { width: 5px; height: 5px; border-radius: 50%; background: #F97316; animation: blink 1s infinite alternate; }
|
||||
.typing i:nth-child(2) { animation-delay: .2s; }.typing i:nth-child(3) { animation-delay: .4s; }
|
||||
@keyframes blink { from { opacity: .25; } to { opacity: 1; } }
|
||||
.chat-error { margin: 4px auto; color: #B42318; font-size: 13px; }.chat-error button { border: 0; background: none; color: #C15F18; cursor: pointer; text-decoration: underline; }
|
||||
.composer { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 10px; padding: 12px max(18px, calc((100vw - 760px) / 2 + 18px)); background: rgba(255,255,255,.92); border-top: 1px solid #F4DCC7; backdrop-filter: blur(12px); }
|
||||
.composer textarea { flex: 1; resize: none; min-height: 22px; max-height: 100px; padding: 11px 13px; border: 1px solid #EED8C5; border-radius: 13px; font: inherit; color: #3B2417; outline: none; }.composer textarea:focus { border-color: #F97316; }
|
||||
.send-btn { align-self: flex-end; padding: 11px 18px; border: 0; border-radius: 12px; color: white; background: #F97316; cursor: pointer; }.send-btn:disabled { opacity: .45; cursor: not-allowed; }
|
||||
</style>
|
||||
@@ -0,0 +1,533 @@
|
||||
<template>
|
||||
<div class="edit-avatar-page">
|
||||
<!-- 顶部导航 -->
|
||||
<header class="page-header">
|
||||
<button class="back-btn" @click="goBack">‹</button>
|
||||
<h1 class="page-title">形象微调编辑</h1>
|
||||
<button class="save-btn" :disabled="loading || saving" @click="saveChanges">
|
||||
{{ saving ? '保存中...' : '保存' }}
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<div v-if="loading" class="status-banner">加载中...</div>
|
||||
<div v-else-if="errorMsg" class="status-banner error">{{ errorMsg }}</div>
|
||||
|
||||
<!-- 头像预览 -->
|
||||
<section class="photo-section">
|
||||
<div class="photo-container">
|
||||
<div class="photo-preview">
|
||||
<img v-if="formData.photoUrl" :src="formData.photoUrl" alt="" class="photo-image" referrerpolicy="no-referrer" />
|
||||
<div v-else class="photo-placeholder">🤖</div>
|
||||
</div>
|
||||
<span class="photo-hint">可直接修改下方头像链接</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 基本信息表单 -->
|
||||
<section class="form-section">
|
||||
<h3 class="section-title">基本信息</h3>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">分身名称</label>
|
||||
<input
|
||||
v-model="formData.name"
|
||||
class="form-input"
|
||||
placeholder="请输入分身名称"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">显示名称</label>
|
||||
<input
|
||||
v-model="formData.displayName"
|
||||
class="form-input"
|
||||
placeholder="请输入显示名称"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">分身描述</label>
|
||||
<textarea
|
||||
v-model="formData.description"
|
||||
class="form-textarea"
|
||||
placeholder="描述你的数字分身的功能和特点"
|
||||
rows="3"
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">头像链接</label>
|
||||
<input
|
||||
v-model="formData.photoUrl"
|
||||
class="form-input"
|
||||
placeholder="请输入头像图片 URL"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">状态</label>
|
||||
<div class="status-selector">
|
||||
<button
|
||||
class="status-option"
|
||||
:class="{ active: formData.status === 'active' }"
|
||||
@click="formData.status = 'active'"
|
||||
>
|
||||
活跃中
|
||||
</button>
|
||||
<button
|
||||
class="status-option"
|
||||
:class="{ active: formData.status === 'inactive' }"
|
||||
@click="formData.status = 'inactive'"
|
||||
>
|
||||
未激活
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 高级设置 -->
|
||||
<section class="form-section">
|
||||
<h3 class="section-title">高级设置</h3>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">回复风格</label>
|
||||
<select v-model="formData.replyStyle" class="form-select">
|
||||
<option value="professional">专业正式</option>
|
||||
<option value="casual">轻松随意</option>
|
||||
<option value="friendly">友好亲切</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<div class="slider-head"><label class="form-label">创造力</label><b>{{ formData.creativity }}</b></div>
|
||||
<input v-model.number="formData.creativity" type="range" min="0" max="100" class="range" />
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<div class="slider-head"><label class="form-label">严谨度</label><b>{{ formData.rigor }}</b></div>
|
||||
<input v-model.number="formData.rigor" type="range" min="0" max="100" class="range" />
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<div class="slider-head"><label class="form-label">幽默感</label><b>{{ formData.humor }}</b></div>
|
||||
<input v-model.number="formData.humor" type="range" min="0" max="100" class="range" />
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">回复长度</label>
|
||||
<div class="choice-row">
|
||||
<button v-for="item in responseLengths" :key="item.value" type="button" class="choice-btn" :class="{ active: formData.responseLength === item.value }" @click="formData.responseLength = item.value">{{ item.label }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">系统提示词</label>
|
||||
<textarea v-model="formData.systemPrompt" class="form-textarea" rows="4" placeholder="给分身的额外指令,例如语气、禁用内容或回答边界"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">自动回复</label>
|
||||
<div class="toggle-container">
|
||||
<span class="toggle-label">{{ formData.autoReply ? '开启' : '关闭' }}</span>
|
||||
<button
|
||||
class="toggle-btn"
|
||||
:class="{ active: formData.autoReply }"
|
||||
@click="formData.autoReply = !formData.autoReply"
|
||||
>
|
||||
<span class="toggle-dot"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 危险操作 -->
|
||||
<section class="danger-section">
|
||||
<button class="delete-btn" :disabled="loading || deleting" @click="deleteAvatar">
|
||||
{{ deleting ? '删除中...' : '删除数字分身' }}
|
||||
</button>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { deleteAvatar as apiDeleteAvatar, getAvatarDetail, updateAvatar } from '@/api'
|
||||
import { useAvatarStore } from '@/store/avatar'
|
||||
import { buildAvatarUpdatePayload, normalizeAvatarEditForm } from '@/utils/avatar-page-data.js'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const avatarStore = useAvatarStore()
|
||||
const avatarId = route.params.id as string
|
||||
|
||||
// 表单数据
|
||||
const formData = reactive({
|
||||
name: '',
|
||||
displayName: '',
|
||||
description: '',
|
||||
status: 'active' as 'active' | 'inactive',
|
||||
photoUrl: '',
|
||||
replyStyle: 'professional',
|
||||
creativity: 50,
|
||||
rigor: 50,
|
||||
humor: 30,
|
||||
responseLength: 'medium',
|
||||
systemPrompt: '',
|
||||
autoReply: true
|
||||
})
|
||||
|
||||
const responseLengths = [
|
||||
{ value: 'short', label: '简短' },
|
||||
{ value: 'medium', label: '适中' },
|
||||
{ value: 'long', label: '详细' }
|
||||
]
|
||||
|
||||
const loading = ref(true)
|
||||
const saving = ref(false)
|
||||
const deleting = ref(false)
|
||||
const errorMsg = ref('')
|
||||
|
||||
const loadAvatar = async () => {
|
||||
loading.value = true
|
||||
errorMsg.value = ''
|
||||
try {
|
||||
const avatar: any = await getAvatarDetail(avatarId)
|
||||
Object.assign(formData, normalizeAvatarEditForm(avatar))
|
||||
} catch (e: any) {
|
||||
errorMsg.value = e?.message || '分身加载失败'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 保存修改
|
||||
const saveChanges = async () => {
|
||||
if (loading.value || saving.value) return
|
||||
if (!formData.name.trim()) {
|
||||
errorMsg.value = '请输入分身名称'
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
errorMsg.value = ''
|
||||
try {
|
||||
await updateAvatar(avatarId, buildAvatarUpdatePayload(formData))
|
||||
await avatarStore.loadAvatars()
|
||||
router.replace('/avatar/manage')
|
||||
} catch (e: any) {
|
||||
errorMsg.value = e?.message || '保存失败,请重试'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 删除分身
|
||||
const deleteAvatar = async () => {
|
||||
if (loading.value || deleting.value) return
|
||||
if (confirm('确定要删除这个数字分身吗?此操作不可恢复。')) {
|
||||
deleting.value = true
|
||||
errorMsg.value = ''
|
||||
try {
|
||||
await apiDeleteAvatar(avatarId)
|
||||
await avatarStore.loadAvatars()
|
||||
router.replace('/avatar/manage')
|
||||
} catch (e: any) {
|
||||
errorMsg.value = e?.message || '删除失败,请重试'
|
||||
} finally {
|
||||
deleting.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 返回
|
||||
const goBack = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadAvatar()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.edit-avatar-page {
|
||||
min-height: 100vh;
|
||||
background: #F8F9FA;
|
||||
padding-bottom: 40px;
|
||||
}
|
||||
|
||||
/* 顶部导航 */
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 16px 20px;
|
||||
background: white;
|
||||
border-bottom: 1px solid #EDEEF1;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
padding: 4px 8px;
|
||||
color: #18191C;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
font-size: 17px;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
color: #18191C;
|
||||
}
|
||||
|
||||
.status-banner {
|
||||
margin: 16px 20px 0;
|
||||
padding: 12px 14px;
|
||||
border-radius: 10px;
|
||||
background: #FFF7ED;
|
||||
color: #9A3412;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.status-banner.error {
|
||||
background: #FEF2F2;
|
||||
color: #B91C1C;
|
||||
}
|
||||
|
||||
.save-btn {
|
||||
background: #F97316;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 20px;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* 头像上传 */
|
||||
.photo-section {
|
||||
padding: 30px 20px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.photo-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.photo-preview {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, #F97316 0%, #FB923C 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
|
||||
}
|
||||
|
||||
.photo-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.photo-placeholder {
|
||||
font-size: 48px;
|
||||
}
|
||||
|
||||
.photo-hint {
|
||||
font-size: 13px;
|
||||
color: #F97316;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 表单区域 */
|
||||
.form-section {
|
||||
padding: 20px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 16px;
|
||||
color: #18191C;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #18191C;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.form-input {
|
||||
width: 100%;
|
||||
padding: 12px 16px;
|
||||
border: 1px solid #EDEEF1;
|
||||
border-radius: 10px;
|
||||
font-size: 15px;
|
||||
color: #18191C;
|
||||
background: white;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.form-input:focus {
|
||||
outline: none;
|
||||
border-color: #F97316;
|
||||
}
|
||||
|
||||
.form-textarea {
|
||||
width: 100%;
|
||||
padding: 12px 16px;
|
||||
border: 1px solid #EDEEF1;
|
||||
border-radius: 10px;
|
||||
font-size: 15px;
|
||||
color: #18191C;
|
||||
background: white;
|
||||
resize: vertical;
|
||||
font-family: inherit;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.form-textarea:focus {
|
||||
outline: none;
|
||||
border-color: #F97316;
|
||||
}
|
||||
|
||||
.form-select {
|
||||
width: 100%;
|
||||
padding: 12px 16px;
|
||||
border: 1px solid #EDEEF1;
|
||||
border-radius: 10px;
|
||||
font-size: 15px;
|
||||
color: #18191C;
|
||||
background: white;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.slider-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.slider-head .form-label { margin-bottom: 0; }
|
||||
.slider-head b { color: #F97316; font-size: 14px; }
|
||||
.range { width: 100%; accent-color: #F97316; }
|
||||
|
||||
.choice-row { display: flex; gap: 8px; }
|
||||
.choice-btn {
|
||||
flex: 1; padding: 10px 8px; border: 1px solid #EDEEF1; border-radius: 10px;
|
||||
background: white; color: #6B7280; cursor: pointer;
|
||||
}
|
||||
.choice-btn.active { border-color: #F97316; color: #F97316; background: #FFF0E6; }
|
||||
|
||||
/* 状态选择器 */
|
||||
.status-selector {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.status-option {
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
border: 2px solid #EDEEF1;
|
||||
border-radius: 10px;
|
||||
background: white;
|
||||
font-size: 14px;
|
||||
color: #9398AE;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.status-option.active {
|
||||
border-color: #F97316;
|
||||
color: #F97316;
|
||||
background: #FFF0E6;
|
||||
}
|
||||
|
||||
/* 开关切换 */
|
||||
.toggle-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 12px 16px;
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #EDEEF1;
|
||||
}
|
||||
|
||||
.toggle-label {
|
||||
font-size: 15px;
|
||||
color: #18191C;
|
||||
}
|
||||
|
||||
.toggle-btn {
|
||||
width: 48px;
|
||||
height: 28px;
|
||||
border-radius: 14px;
|
||||
border: none;
|
||||
background: #D1D5DB;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
transition: background 0.3s;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.toggle-btn.active {
|
||||
background: #F97316;
|
||||
}
|
||||
|
||||
.toggle-dot {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 2px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 50%;
|
||||
background: white;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.toggle-btn.active .toggle-dot {
|
||||
transform: translateX(20px);
|
||||
}
|
||||
|
||||
/* 危险操作 */
|
||||
.danger-section {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
background: white;
|
||||
color: #EF4444;
|
||||
border: 2px solid #EF4444;
|
||||
border-radius: 10px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.delete-btn:hover {
|
||||
background: #EF4444;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,840 @@
|
||||
<template>
|
||||
<div class="avatar-manage-page">
|
||||
<!-- 顶部导航 -->
|
||||
<header class="page-header">
|
||||
<div class="header-left">
|
||||
<button class="back-btn" @click="goBack">‹</button>
|
||||
<h1 class="page-title">数字分身管理</h1>
|
||||
</div>
|
||||
<!-- 右上角创建入口 -->
|
||||
<div class="header-right">
|
||||
<button class="icon-btn" @click="goCreate" title="创建数字分身">➕</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 用户资料头(会会登录账号的头像 / 昵称) -->
|
||||
<section class="profile-section">
|
||||
<div class="profile-avatar">
|
||||
<img v-if="me?.avatarUrl" :src="me.avatarUrl" alt="头像" referrerpolicy="no-referrer" />
|
||||
<span v-else class="profile-avatar-fallback">🤖</span>
|
||||
</div>
|
||||
<div class="profile-meta">
|
||||
<span class="profile-name">{{ me?.nickname || '会会用户' }}</span>
|
||||
<span class="profile-sub">{{ me?.phone ? '手机 ' + me.phone : '已登录 · 会会账号' }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Token 余额条 -->
|
||||
<section class="token-section">
|
||||
<div class="token-card">
|
||||
<div class="token-info">
|
||||
<span class="token-label">Token 余额</span>
|
||||
<span class="token-amount">{{ tokenBalance.toLocaleString() }}</span>
|
||||
</div>
|
||||
<button class="recharge-btn" @click="goToRecharge">充值</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 数字分身列表(只放分身相关) -->
|
||||
<section class="avatar-list-section">
|
||||
<div class="section-head">
|
||||
<h3 class="section-title">我的数字分身</h3>
|
||||
<span class="count-badge">{{ avatars.length }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="avatars.length" class="avatar-list">
|
||||
<div class="avatar-card" v-for="a in avatars" :key="a.id">
|
||||
<div class="avatar-photo">
|
||||
<img v-if="a.photoUrl" :src="a.photoUrl" alt="" referrerpolicy="no-referrer" class="avatar-img" />
|
||||
<div v-else class="avatar-placeholder">{{ a.emoji || '🤖' }}</div>
|
||||
</div>
|
||||
<div class="avatar-details">
|
||||
<h2 class="avatar-name">{{ a.displayName || a.name }}</h2>
|
||||
<p class="avatar-desc">{{ a.description || '暂无描述' }}</p>
|
||||
<div class="avatar-status">
|
||||
<span class="status-dot" :class="a.status"></span>
|
||||
<span class="status-text">{{ statusText(a.status) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="avatar-actions">
|
||||
<button class="chat-link" @click="goToChat(a.id)">对话</button>
|
||||
<button class="edit-link" @click="goToEdit(a.id)">编辑</button>
|
||||
<button class="del-link" @click="askDelete(a)">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="empty-state">
|
||||
<span class="empty-icon">🤖</span>
|
||||
<p class="empty-text">还没有数字分身</p>
|
||||
<button class="empty-create-btn" @click="goCreate">立即创建一个</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 分身工具入口 -->
|
||||
<section class="tools-section">
|
||||
<h3 class="section-title">分身工具</h3>
|
||||
<div class="tools-grid">
|
||||
<div class="tool-card" @click="goToKnowledge">
|
||||
<div class="tool-icon">📚</div>
|
||||
<div class="tool-info">
|
||||
<span class="tool-name">知识库管理</span>
|
||||
<span class="tool-desc">上传文档与标准问答</span>
|
||||
</div>
|
||||
<span class="tool-arrow">›</span>
|
||||
</div>
|
||||
<div class="tool-card" @click="goToAvatarCard">
|
||||
<div class="tool-icon">🪪</div>
|
||||
<div class="tool-info">
|
||||
<span class="tool-name">分身名片</span>
|
||||
<span class="tool-desc">生成并分享名片</span>
|
||||
</div>
|
||||
<span class="tool-arrow">›</span>
|
||||
</div>
|
||||
<div class="tool-card" @click="goToAvatarContacts">
|
||||
<div class="tool-icon">🤝</div>
|
||||
<div class="tool-info">
|
||||
<span class="tool-name">分身人脉</span>
|
||||
<span class="tool-desc">管理社交关系</span>
|
||||
</div>
|
||||
<span class="tool-arrow">›</span>
|
||||
</div>
|
||||
<div class="tool-card" @click="goToMyProjects">
|
||||
<div class="tool-icon">📁</div>
|
||||
<div class="tool-info">
|
||||
<span class="tool-name">我的项目</span>
|
||||
<span class="tool-desc">查看参与项目</span>
|
||||
</div>
|
||||
<span class="tool-arrow">›</span>
|
||||
</div>
|
||||
<div class="tool-card" @click="goToCreateOrg">
|
||||
<div class="tool-icon">🏢</div>
|
||||
<div class="tool-info">
|
||||
<span class="tool-name">创建组织</span>
|
||||
<span class="tool-desc">新建组织团队</span>
|
||||
</div>
|
||||
<span class="tool-arrow">›</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 分身动态列表 -->
|
||||
<section class="activities-section">
|
||||
<h3 class="section-title">分身动态</h3>
|
||||
<div class="activity-list" v-if="activities.length > 0">
|
||||
<div class="activity-item" v-for="activity in activities" :key="activity.id">
|
||||
<div class="activity-icon" :class="activity.type">{{ activityIcon(activity.type) }}</div>
|
||||
<div class="activity-content">
|
||||
<p class="activity-text">{{ activity.text }}</p>
|
||||
<span class="activity-time">{{ formatTime(activity.createdAt) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="empty-state" v-else>
|
||||
<span class="empty-icon">📭</span>
|
||||
<p class="empty-text">暂无动态</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 删除确认弹窗 -->
|
||||
<div v-if="showDelete" class="modal-mask" @click.self="cancelDelete">
|
||||
<div class="modal">
|
||||
<div class="modal-icon">⚠️</div>
|
||||
<h3 class="modal-title">删除数字分身</h3>
|
||||
<p class="modal-text">
|
||||
确认删除「{{ pendingDelete?.displayName || pendingDelete?.name }}」?<br />
|
||||
其知识库、问答对、授权等关联数据将一并清除,且<b>不可恢复</b>。
|
||||
</p>
|
||||
<div class="modal-actions">
|
||||
<button class="modal-cancel" @click="cancelDelete">取消</button>
|
||||
<button class="modal-confirm" :disabled="deleting" @click="confirmDelete">
|
||||
{{ deleting ? '删除中...' : '确认删除' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useAvatarStore } from '@/store/avatar'
|
||||
import { useUserStore } from '@/store/user'
|
||||
|
||||
const router = useRouter()
|
||||
const avatarStore = useAvatarStore()
|
||||
const userStore = useUserStore()
|
||||
|
||||
// 当前登录会会用户的资料(头像 / 昵称)
|
||||
const me = computed(() => userStore.user)
|
||||
|
||||
// 状态(来自 store / 后端)
|
||||
const tokenBalance = computed(() => avatarStore.tokenBalance)
|
||||
const avatars = computed(() => avatarStore.avatars)
|
||||
|
||||
// 删除确认弹窗状态
|
||||
const showDelete = ref(false)
|
||||
const pendingDelete = ref<any>(null)
|
||||
const deleting = ref(false)
|
||||
|
||||
const activities = ref<Array<{ id: string; type: string; text: string; createdAt: string }>>([
|
||||
{ id: '1', type: 'create', text: '数字分身创建成功', createdAt: new Date(Date.now() - 86400000).toISOString() },
|
||||
{ id: '2', type: 'edit', text: '更新了分身描述', createdAt: new Date(Date.now() - 43200000).toISOString() },
|
||||
{ id: '3', type: 'authorize', text: '授权微信小程序访问', createdAt: new Date(Date.now() - 3600000).toISOString() }
|
||||
])
|
||||
|
||||
// 状态文本
|
||||
const statusText = (status: string) => {
|
||||
const map: Record<string, string> = {
|
||||
'active': '活跃中',
|
||||
'inactive': '未激活',
|
||||
'training': '训练中'
|
||||
}
|
||||
return map[status] || status
|
||||
}
|
||||
|
||||
// 活动图标
|
||||
const activityIcon = (type: string) => {
|
||||
const map: Record<string, string> = {
|
||||
'create': '✨',
|
||||
'edit': '✏️',
|
||||
'authorize': '🔑',
|
||||
'interact': '💬'
|
||||
}
|
||||
return map[type] || '📌'
|
||||
}
|
||||
|
||||
// 格式化时间
|
||||
const formatTime = (time: string) => {
|
||||
const date = new Date(time)
|
||||
const now = new Date()
|
||||
const diff = now.getTime() - date.getTime()
|
||||
const minutes = Math.floor(diff / 60000)
|
||||
const hours = Math.floor(diff / 3600000)
|
||||
const days = Math.floor(diff / 86400000)
|
||||
|
||||
if (minutes < 60) return `${minutes}分钟前`
|
||||
if (hours < 24) return `${hours}小时前`
|
||||
return `${days}天前`
|
||||
}
|
||||
|
||||
// 删除流程
|
||||
const askDelete = (a: any) => {
|
||||
pendingDelete.value = a
|
||||
showDelete.value = true
|
||||
}
|
||||
const cancelDelete = () => {
|
||||
if (deleting.value) return
|
||||
showDelete.value = false
|
||||
pendingDelete.value = null
|
||||
}
|
||||
const confirmDelete = async () => {
|
||||
if (!pendingDelete.value || deleting.value) return
|
||||
deleting.value = true
|
||||
try {
|
||||
await avatarStore.removeAvatar(pendingDelete.value.id)
|
||||
showDelete.value = false
|
||||
pendingDelete.value = null
|
||||
} catch (e: any) {
|
||||
alert(e?.message || '删除失败,请稍后重试')
|
||||
} finally {
|
||||
deleting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 导航
|
||||
const goBack = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
const goToRecharge = () => {
|
||||
router.push('/token/charge')
|
||||
}
|
||||
|
||||
const goCreate = () => {
|
||||
router.push('/')
|
||||
}
|
||||
|
||||
const goToKnowledge = () => {
|
||||
router.push('/knowledge')
|
||||
}
|
||||
|
||||
const goToEdit = (id: string) => {
|
||||
router.push(`/avatar/edit/${id}`)
|
||||
}
|
||||
|
||||
const goToChat = (id: string) => {
|
||||
router.push(`/avatar/chat/${id}`)
|
||||
}
|
||||
|
||||
const goToAvatarCard = () => {
|
||||
router.push('/avatar/card')
|
||||
}
|
||||
|
||||
const goToAvatarContacts = () => {
|
||||
router.push('/avatar/contacts')
|
||||
}
|
||||
|
||||
const goToMyProjects = () => {
|
||||
router.push('/avatar/projects')
|
||||
}
|
||||
|
||||
const goToCreateOrg = () => {
|
||||
router.push('/avatar/org/create')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
userStore.loadFromStorage()
|
||||
avatarStore.loadAvatars()
|
||||
avatarStore.loadTokenBalance()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.avatar-manage-page {
|
||||
min-height: 100vh;
|
||||
background: #F8F9FA;
|
||||
padding-bottom: 80px;
|
||||
}
|
||||
|
||||
/* 顶部导航 */
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 16px 20px;
|
||||
background: linear-gradient(135deg, #F97316 0%, #FB923C 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.header-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* 用户资料头 */
|
||||
.profile-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
padding: 18px 20px 8px;
|
||||
background: #F8F9FA;
|
||||
}
|
||||
.profile-avatar {
|
||||
width: 54px;
|
||||
height: 54px;
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
background: linear-gradient(135deg, #FFB36B, #FF7A1A);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 4px 12px rgba(249, 115, 22, 0.28);
|
||||
border: 2px solid #fff;
|
||||
}
|
||||
.profile-avatar img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
.profile-avatar-fallback {
|
||||
font-size: 28px;
|
||||
}
|
||||
.profile-meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
min-width: 0;
|
||||
}
|
||||
.profile-name {
|
||||
font-size: 17px;
|
||||
font-weight: 700;
|
||||
color: #18191C;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.profile-sub {
|
||||
font-size: 12px;
|
||||
color: #9398AE;
|
||||
}
|
||||
|
||||
.icon-btn {
|
||||
background: rgba(255, 255, 255, 0.18);
|
||||
border: none;
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.icon-btn:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
/* Token 余额条 */
|
||||
.token-section {
|
||||
padding: 16px 20px;
|
||||
}
|
||||
|
||||
.token-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 16px 20px;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.token-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.token-label {
|
||||
font-size: 13px;
|
||||
color: #6B7280;
|
||||
}
|
||||
|
||||
.token-amount {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: #F97316;
|
||||
}
|
||||
|
||||
.recharge-btn {
|
||||
padding: 8px 16px;
|
||||
background: #F97316;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.recharge-btn:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
/* 分身列表 */
|
||||
.avatar-list-section {
|
||||
padding: 0 20px 8px;
|
||||
}
|
||||
|
||||
.section-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 8px 0 12px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
color: #18191C;
|
||||
}
|
||||
|
||||
.count-badge {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: #F97316;
|
||||
background: #FFF0E6;
|
||||
border-radius: 999px;
|
||||
padding: 2px 10px;
|
||||
}
|
||||
|
||||
.avatar-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.avatar-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
padding: 16px;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.avatar-photo {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
background: #F3F4F6;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.avatar-placeholder {
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.avatar-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.avatar-details {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.avatar-name {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 4px;
|
||||
color: #18191C;
|
||||
}
|
||||
|
||||
.avatar-desc {
|
||||
font-size: 13px;
|
||||
color: #9398AE;
|
||||
margin: 0 0 8px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.avatar-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.status-dot.active {
|
||||
background: #22C55E;
|
||||
}
|
||||
|
||||
.status-dot.inactive {
|
||||
background: #9398AE;
|
||||
}
|
||||
|
||||
.status-dot.training {
|
||||
background: #F59E0B;
|
||||
}
|
||||
|
||||
.status-text {
|
||||
font-size: 12px;
|
||||
color: #9398AE;
|
||||
}
|
||||
|
||||
.avatar-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.chat-link {
|
||||
padding: 7px 14px;
|
||||
background: #FFF0E6;
|
||||
color: #F97316;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.edit-link {
|
||||
padding: 7px 14px;
|
||||
background: #F3F4F6;
|
||||
color: #6B7280;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.edit-link:hover {
|
||||
background: #E5E7EB;
|
||||
}
|
||||
|
||||
.del-link {
|
||||
padding: 7px 14px;
|
||||
background: #FEF2F2;
|
||||
color: #EF4444;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.del-link:hover {
|
||||
background: #FEE2E2;
|
||||
}
|
||||
|
||||
/* 空状态 */
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 20px;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 48px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 14px;
|
||||
color: #9398AE;
|
||||
margin: 0 0 16px;
|
||||
}
|
||||
|
||||
.empty-create-btn {
|
||||
padding: 10px 24px;
|
||||
background: linear-gradient(135deg, #F97316, #FB923C);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
|
||||
}
|
||||
|
||||
/* 分身工具入口 */
|
||||
.tools-section {
|
||||
padding: 8px 20px 16px;
|
||||
}
|
||||
|
||||
.tools-grid {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.tool-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 16px;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.tool-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.tool-icon {
|
||||
font-size: 24px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.tool-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.tool-name {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #18191C;
|
||||
}
|
||||
|
||||
.tool-desc {
|
||||
font-size: 12px;
|
||||
color: #9398AE;
|
||||
}
|
||||
|
||||
.tool-arrow {
|
||||
font-size: 18px;
|
||||
color: #C9CDD2;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* 分身动态列表 */
|
||||
.activities-section {
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
.activity-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.activity-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
padding: 14px 16px;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.activity-icon {
|
||||
font-size: 20px;
|
||||
flex-shrink: 0;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 10px;
|
||||
background: #FFF0E6;
|
||||
}
|
||||
|
||||
.activity-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.activity-text {
|
||||
font-size: 14px;
|
||||
color: #18191C;
|
||||
margin: 0 0 4px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.activity-time {
|
||||
font-size: 12px;
|
||||
color: #9398AE;
|
||||
}
|
||||
|
||||
/* 删除确认弹窗 */
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
z-index: 50;
|
||||
animation: fade 0.2s ease;
|
||||
}
|
||||
|
||||
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
|
||||
|
||||
.modal {
|
||||
width: 100%;
|
||||
max-width: 320px;
|
||||
background: white;
|
||||
border-radius: 18px;
|
||||
padding: 24px 22px 18px;
|
||||
text-align: center;
|
||||
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
|
||||
animation: pop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
|
||||
}
|
||||
|
||||
@keyframes pop { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: none; } }
|
||||
|
||||
.modal-icon {
|
||||
font-size: 36px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
font-size: 17px;
|
||||
font-weight: 700;
|
||||
color: #18191C;
|
||||
margin: 0 0 10px;
|
||||
}
|
||||
|
||||
.modal-text {
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
color: #6B7280;
|
||||
margin: 0 0 20px;
|
||||
}
|
||||
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.modal-cancel {
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
background: #F3F4F6;
|
||||
color: #6B7280;
|
||||
border: none;
|
||||
border-radius: 12px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.modal-confirm {
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
background: #EF4444;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 12px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.modal-confirm:hover {
|
||||
opacity: 0.92;
|
||||
}
|
||||
|
||||
.modal-confirm:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,703 @@
|
||||
<template>
|
||||
<div class="knowledge-page">
|
||||
<!-- 顶部导航 -->
|
||||
<header class="page-header">
|
||||
<div class="header-left">
|
||||
<button class="back-btn" @click="goBack">‹</button>
|
||||
<h1 class="page-title">知识库管理</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div v-if="!avatarId" class="empty-state">
|
||||
<span class="empty-icon">🤖</span>
|
||||
<p class="empty-text">请先创建数字分身后再管理知识库</p>
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="tab-switcher" role="tablist" aria-label="知识库类型">
|
||||
<button class="tab-btn" :class="{ active: activeTab === 'docs' }" role="tab" :aria-selected="activeTab === 'docs'" @click="activeTab = 'docs'">文档知识库 <b>{{ docs.length }}</b></button>
|
||||
<button class="tab-btn" :class="{ active: activeTab === 'qa' }" role="tab" :aria-selected="activeTab === 'qa'" @click="activeTab = 'qa'">标准问答对 <b>{{ qaPairs.length }}</b></button>
|
||||
</div>
|
||||
|
||||
<section v-if="activeTab === 'docs'" class="knowledge-panel">
|
||||
<div class="upload-section">
|
||||
<div class="upload-zone" :class="{ 'drag-over': dragOver }" @click="triggerFile" @dragover.prevent="dragOver = true" @dragleave.prevent="dragOver = false" @drop.prevent="onDrop">
|
||||
<div class="upload-icon">📥</div>
|
||||
<p class="upload-title">拖拽文件到此处,或<span class="upload-link">点击上传</span></p>
|
||||
<p class="upload-hint">支持 MD / TXT / PDF / DOC / DOCX / XLSX,上传后自动向量化</p>
|
||||
<input ref="fileInput" type="file" accept=".md,.txt,.pdf,.doc,.docx,.xlsx" class="hidden-input" @change="onFileChange" />
|
||||
</div>
|
||||
<p v-if="uploading" class="uploading-text">上传并向量化中…</p>
|
||||
<p v-if="uploadError" class="error-text">{{ uploadError }}</p>
|
||||
</div>
|
||||
|
||||
<div class="table-scroll">
|
||||
<table class="knowledge-table">
|
||||
<thead><tr><th>文档</th><th>类型</th><th>大小</th><th>状态</th><th>上传时间</th><th>操作</th></tr></thead>
|
||||
<tbody v-if="docs.length">
|
||||
<tr v-for="doc in docs" :key="doc.id">
|
||||
<td><div class="file-cell"><span class="doc-icon">{{ fileEmoji(doc.fileType) }}</span><strong>{{ doc.filename }}</strong></div></td>
|
||||
<td>{{ doc.fileType.toUpperCase() }}</td>
|
||||
<td>{{ formatSize(doc.fileSize) }}</td>
|
||||
<td><span class="status-pill" :class="{ pending: !doc.vectorized }">{{ doc.vectorized ? `已向量化 · ${doc.chunkCount || 0} 段` : '处理中' }}</span></td>
|
||||
<td>{{ formatDate(doc.createdAt) }}</td>
|
||||
<td><button class="table-delete" @click="removeDoc(doc.id)">删除</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div v-if="!docs.length" class="table-empty">📂 暂无文档,先上传一个知识文件</div>
|
||||
</div>
|
||||
|
||||
<section class="search-section">
|
||||
<h3 class="section-title">向量检索测试</h3>
|
||||
<div class="search-bar"><input v-model="query" class="search-input" placeholder="输入检索词,测试文档向量召回" @keyup.enter="doSearch" /><button class="search-btn" :disabled="searching" @click="doSearch">检索</button></div>
|
||||
<div v-if="searchResults.length" class="search-results"><div class="search-item" v-for="(r, i) in searchResults" :key="i"><div class="search-head"><span class="search-name">{{ r.filename }}</span><span class="search-score">相似度 {{ r.score }}</span></div><p class="search-snippet">{{ r.snippet }}</p></div></div>
|
||||
<p v-if="searched && !searchResults.length" class="empty-sub-text">未检索到相关内容,先上传文档试试</p>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section v-else class="knowledge-panel">
|
||||
<div class="panel-heading"><div><h3 class="section-title">标准问答对</h3><p>命中后优先使用标准答案,不调用 Qwen。</p></div><button class="add-qa-btn" @click="goAddQa">+ 添加</button></div>
|
||||
<div class="table-scroll">
|
||||
<table class="knowledge-table qa-table">
|
||||
<thead><tr><th>问题</th><th>标准答案</th><th>状态</th><th>更新时间</th><th>操作</th></tr></thead>
|
||||
<tbody v-if="qaPairs.length">
|
||||
<tr v-for="qa in qaPairs" :key="qa.id" :class="{ 'qa-disabled': qa.enabled === false }">
|
||||
<td class="question-cell">{{ qa.question }}</td><td class="answer-cell">{{ qa.answer }}</td>
|
||||
<td><label class="switch" :title="qa.enabled === false ? '已停用' : '已启用'"><input type="checkbox" :checked="qa.enabled !== false" @change="toggleQa(qa, $event)" /><span class="slider"></span></label></td>
|
||||
<td>{{ formatDate(qa.updatedAt || qa.createdAt) }}</td>
|
||||
<td><div class="row-actions"><button class="qa-edit" @click="goEditQa(qa)">编辑</button><button class="qa-del" @click="removeQa(qa.id)">删除</button></div></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div v-if="!qaPairs.length" class="table-empty">💡 暂无问答对,添加后分身会优先按此作答</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, computed } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useAvatarStore } from '@/store/avatar'
|
||||
import { pickAvatarId, unwrapListData } from '@/utils/avatar-page-data.js'
|
||||
import {
|
||||
getKnowledgeDocs,
|
||||
uploadKnowledgeDoc,
|
||||
deleteKnowledgeDoc,
|
||||
getQAPairs,
|
||||
deleteQAPair,
|
||||
searchKnowledge,
|
||||
setQaEnabled
|
||||
} from '@/api'
|
||||
|
||||
const router = useRouter()
|
||||
const store = useAvatarStore()
|
||||
|
||||
const avatarId = computed(() => pickAvatarId(store.currentAvatarId, store.avatars))
|
||||
const activeTab = ref<'docs' | 'qa'>('docs')
|
||||
|
||||
const docs = ref<any[]>([])
|
||||
const qaPairs = ref<any[]>([])
|
||||
const uploading = ref(false)
|
||||
const uploadError = ref('')
|
||||
const dragOver = ref(false)
|
||||
const fileInput = ref<HTMLInputElement | null>(null)
|
||||
|
||||
const query = ref('')
|
||||
const searching = ref(false)
|
||||
const searched = ref(false)
|
||||
const searchResults = ref<any[]>([])
|
||||
|
||||
const loadDocs = async () => {
|
||||
if (!avatarId.value) return
|
||||
try {
|
||||
const res: any = await getKnowledgeDocs(avatarId.value)
|
||||
docs.value = unwrapListData(res)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
const loadQA = async () => {
|
||||
if (!avatarId.value) return
|
||||
try {
|
||||
const res: any = await getQAPairs(avatarId.value)
|
||||
qaPairs.value = unwrapListData(res)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
const triggerFile = () => fileInput.value?.click()
|
||||
|
||||
const onFileChange = (e: Event) => {
|
||||
const f = (e.target as HTMLInputElement).files?.[0]
|
||||
if (f) doUpload(f)
|
||||
;(e.target as HTMLInputElement).value = ''
|
||||
}
|
||||
|
||||
const onDrop = (e: DragEvent) => {
|
||||
dragOver.value = false
|
||||
const f = e.dataTransfer?.files?.[0]
|
||||
if (f) doUpload(f)
|
||||
}
|
||||
|
||||
const doUpload = async (file: File) => {
|
||||
uploadError.value = ''
|
||||
const ext = '.' + (file.name.split('.').pop() || '').toLowerCase()
|
||||
if (!['.md', '.txt', '.pdf', '.doc', '.docx', '.xlsx'].includes(ext)) {
|
||||
uploadError.value = `不支持的类型:${ext},仅支持 md/txt/pdf/doc/docx/xlsx`
|
||||
return
|
||||
}
|
||||
if (!avatarId.value) {
|
||||
uploadError.value = '请先创建数字分身'
|
||||
return
|
||||
}
|
||||
uploading.value = true
|
||||
try {
|
||||
await uploadKnowledgeDoc(avatarId.value, file)
|
||||
await loadDocs()
|
||||
} catch (e: any) {
|
||||
uploadError.value = e?.message || '上传失败'
|
||||
} finally {
|
||||
uploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const removeDoc = async (id: string) => {
|
||||
if (!avatarId.value) return
|
||||
await deleteKnowledgeDoc(avatarId.value, id)
|
||||
await loadDocs()
|
||||
}
|
||||
|
||||
const doSearch = async () => {
|
||||
if (!avatarId.value || !query.value.trim()) return
|
||||
searching.value = true
|
||||
searched.value = true
|
||||
try {
|
||||
const res: any = await searchKnowledge(avatarId.value, query.value.trim(), 5)
|
||||
searchResults.value = unwrapListData(res)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
searchResults.value = []
|
||||
} finally {
|
||||
searching.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const toggleQa = async (qa: any, e: Event) => {
|
||||
const enabled = (e.target as HTMLInputElement).checked
|
||||
qa.enabled = enabled
|
||||
if (!avatarId.value) return
|
||||
try {
|
||||
await setQaEnabled(avatarId.value, qa.id, enabled)
|
||||
} catch (err) {
|
||||
qa.enabled = !enabled
|
||||
;(e.target as HTMLInputElement).checked = !enabled
|
||||
console.error('切换启用状态失败', err)
|
||||
}
|
||||
}
|
||||
|
||||
const goAddQa = () => router.push('/knowledge/qa/create')
|
||||
|
||||
const goEditQa = (qa: any) => router.push(`/knowledge/qa/${qa.id}/edit`)
|
||||
|
||||
const removeQa = async (id: string) => {
|
||||
if (!avatarId.value) return
|
||||
await deleteQAPair(avatarId.value, id)
|
||||
await loadQA()
|
||||
}
|
||||
|
||||
const goBack = () => router.back()
|
||||
|
||||
const formatSize = (n: number) => {
|
||||
if (n < 1024) return n + ' B'
|
||||
if (n < 1024 * 1024) return (n / 1024).toFixed(1) + ' KB'
|
||||
return (n / 1024 / 1024).toFixed(1) + ' MB'
|
||||
}
|
||||
|
||||
const formatDate = (value?: string) => value ? new Date(value).toLocaleDateString('zh-CN') : '-'
|
||||
|
||||
const fileEmoji = (t: string) => (['xlsx'].includes(t) ? '📊' : '📄')
|
||||
|
||||
onMounted(async () => {
|
||||
if (!store.avatars.length) {
|
||||
await store.loadAvatars()
|
||||
}
|
||||
await Promise.all([loadDocs(), loadQA()])
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.knowledge-page {
|
||||
min-height: 100vh;
|
||||
background: #F8F9FA;
|
||||
padding-bottom: 80px;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.tab-switcher {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
padding: 16px 20px 0;
|
||||
}
|
||||
|
||||
.tab-btn {
|
||||
flex: 1;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #F4D8BE;
|
||||
border-radius: 12px 12px 0 0;
|
||||
background: #FFF8F1;
|
||||
color: #8B6B58;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.tab-btn b { margin-left: 4px; font-size: 12px; color: #B0896C; }
|
||||
.tab-btn.active { background: white; border-color: #F97316; color: #F97316; font-weight: 700; }
|
||||
.tab-btn.active b { color: #F97316; }
|
||||
.knowledge-panel { padding: 0 20px; }
|
||||
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 0 12px; }
|
||||
.panel-heading p { margin: -5px 0 0; color: #9398AE; font-size: 12px; }
|
||||
.table-scroll { max-height: 420px; overflow: auto; border: 1px solid #F1E1D3; border-radius: 14px; background: white; }
|
||||
.knowledge-table { width: 100%; min-width: 720px; border-collapse: collapse; text-align: left; font-size: 13px; }
|
||||
.knowledge-table th { position: sticky; top: 0; z-index: 1; padding: 12px 14px; background: #FFF8F1; color: #8B6B58; font-weight: 600; white-space: nowrap; }
|
||||
.knowledge-table td { padding: 13px 14px; border-top: 1px solid #F5EEE7; color: #6B7280; vertical-align: middle; }
|
||||
.knowledge-table tr.qa-disabled { opacity: .55; }
|
||||
.file-cell { display: flex; align-items: center; gap: 9px; min-width: 190px; color: #27201C; }.file-cell strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.status-pill { display: inline-flex; padding: 4px 8px; border-radius: 999px; color: #15803D; background: #ECFDF3; font-size: 11px; white-space: nowrap; }.status-pill.pending { color: #B45309; background: #FFFBEB; }
|
||||
.table-delete { border: 0; color: #EF4444; background: #FEF2F2; border-radius: 7px; padding: 6px 10px; cursor: pointer; }
|
||||
.table-empty { padding: 48px 20px; color: #9398AE; text-align: center; }
|
||||
.question-cell { min-width: 190px; max-width: 280px; color: #27201C !important; font-weight: 600; }.answer-cell { min-width: 240px; max-width: 360px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.row-actions { display: flex; gap: 6px; white-space: nowrap; }
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 16px 20px;
|
||||
background: linear-gradient(135deg, #F97316 0%, #FB923C 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.header-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* 上传区 */
|
||||
.upload-section {
|
||||
padding: 16px 20px;
|
||||
}
|
||||
|
||||
.upload-zone {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
padding: 28px 20px;
|
||||
background: white;
|
||||
border: 2px dashed #FCD9B6;
|
||||
border-radius: 12px;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.2s, background 0.2s;
|
||||
}
|
||||
|
||||
.upload-zone.drag-over {
|
||||
border-color: #F97316;
|
||||
background: #FFF7EF;
|
||||
}
|
||||
|
||||
.upload-icon {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.upload-title {
|
||||
font-size: 14px;
|
||||
color: #18191C;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.upload-link {
|
||||
color: #F97316;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.upload-hint {
|
||||
font-size: 12px;
|
||||
color: #9398AE;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.hidden-input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.uploading-text {
|
||||
font-size: 13px;
|
||||
color: #F97316;
|
||||
text-align: center;
|
||||
margin: 10px 0 0;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
font-size: 13px;
|
||||
color: #EF4444;
|
||||
text-align: center;
|
||||
margin: 10px 0 0;
|
||||
}
|
||||
|
||||
/* 文档列表 */
|
||||
.docs-section,
|
||||
.qa-section,
|
||||
.search-section {
|
||||
padding: 0 20px 16px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 12px;
|
||||
color: #18191C;
|
||||
}
|
||||
|
||||
.doc-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.doc-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 16px;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.doc-icon {
|
||||
font-size: 22px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.doc-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.doc-name {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #18191C;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.doc-meta {
|
||||
font-size: 12px;
|
||||
color: #9398AE;
|
||||
}
|
||||
|
||||
.badge-vec {
|
||||
align-self: flex-start;
|
||||
margin-top: 2px;
|
||||
font-size: 11px;
|
||||
color: #16A34A;
|
||||
background: #ECFDF3;
|
||||
border-radius: 6px;
|
||||
padding: 2px 8px;
|
||||
}
|
||||
|
||||
.badge-vec.pending {
|
||||
color: #D97706;
|
||||
background: #FFFAEB;
|
||||
}
|
||||
|
||||
.doc-del {
|
||||
padding: 6px 12px;
|
||||
background: #FEF2F2;
|
||||
color: #EF4444;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* 检索测试 */
|
||||
.search-bar {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
border: 1px solid #E5E7EB;
|
||||
border-radius: 8px;
|
||||
padding: 10px 12px;
|
||||
font-size: 14px;
|
||||
color: #18191C;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.search-input:focus {
|
||||
outline: none;
|
||||
border-color: #F97316;
|
||||
}
|
||||
|
||||
.search-btn {
|
||||
width: 72px;
|
||||
height: 38px;
|
||||
background: #F97316;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.search-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.search-results {
|
||||
margin-top: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.search-item {
|
||||
padding: 12px 14px;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.search-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.search-name {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #18191C;
|
||||
}
|
||||
|
||||
.search-score {
|
||||
font-size: 12px;
|
||||
color: #F97316;
|
||||
}
|
||||
|
||||
.search-snippet {
|
||||
font-size: 12px;
|
||||
color: #6B7280;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
/* 问答对 */
|
||||
.qa-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.qa-head .section-title {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.add-qa-btn {
|
||||
width: 72px;
|
||||
height: 38px;
|
||||
background: #F97316;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.qa-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.qa-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
padding: 14px 16px;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.qa-item.qa-disabled {
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.qa-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.qa-question {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #18191C;
|
||||
margin: 0 0 6px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.qa-answer {
|
||||
font-size: 13px;
|
||||
color: #6B7280;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.qa-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: 6px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.qa-edit {
|
||||
padding: 5px 12px;
|
||||
background: #FFF0E6;
|
||||
color: #F97316;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.qa-del {
|
||||
padding: 5px 12px;
|
||||
background: #FEF2F2;
|
||||
color: #EF4444;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* 开关 */
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 40px;
|
||||
height: 22px;
|
||||
}
|
||||
|
||||
.switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
inset: 0;
|
||||
background: #E5E7EB;
|
||||
border-radius: 22px;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.slider::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
left: 3px;
|
||||
top: 3px;
|
||||
background: white;
|
||||
border-radius: 50%;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.switch input:checked + .slider {
|
||||
background: #F97316;
|
||||
}
|
||||
|
||||
.switch input:checked + .slider::before {
|
||||
transform: translateX(18px);
|
||||
}
|
||||
|
||||
/* 空状态 */
|
||||
.empty-state,
|
||||
.empty-sub {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 20px;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
margin: 16px 20px;
|
||||
}
|
||||
|
||||
.docs-section .empty-sub,
|
||||
.qa-section .empty-sub {
|
||||
margin: 16px 0 0;
|
||||
}
|
||||
|
||||
/* 上传区空态无需额外 margin,.upload-zone 已占满 section content 宽度 */
|
||||
.empty-icon,
|
||||
.empty-sub-icon {
|
||||
font-size: 44px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.empty-text,
|
||||
.empty-sub-text {
|
||||
font-size: 14px;
|
||||
color: #9398AE;
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user