feat: 功能1 - 新建机器人 (v0.9.6)

- 添加 CreateBotModal.vue 新建机器人模态框
- 实现12个预设头像选择
- 实现名称/显示名称/描述表单
- HomeView 添加「新建机器人」按钮
- Store 添加 createBot 方法
- Store 添加 fetchAgents 方法
- 表单验证和错误提示
This commit is contained in:
2026-03-15 11:54:36 +08:00
parent cb2bb5ec35
commit 15b001bab5
3 changed files with 433 additions and 5 deletions

View File

@@ -1,13 +1,16 @@
<script setup lang="ts">
import { onMounted } from 'vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import { useChatStore } from '@/stores/chat'
import CreateBotModal from '@/components/chat/CreateBotModal.vue'
const router = useRouter()
const authStore = useAuthStore()
const chatStore = useChatStore()
const showCreateBot = ref(false)
onMounted(async () => {
await chatStore.fetchBots()
await chatStore.fetchSessions()
@@ -24,6 +27,10 @@ function startChat(botId: string) {
function resumeChat(sessionId: string) {
router.push({ name: 'chat', params: { sessionId } })
}
function handleBotCreated(bot: any) {
chatStore.bots.push(bot)
}
</script>
<template>
@@ -31,9 +38,14 @@ function resumeChat(sessionId: string) {
<header class="header">
<div class="header-content">
<h1>🐕 智队中枢</h1>
<div class="user-info">
<span>{{ authStore.user?.nickname || authStore.user?.username }}</span>
<button class="logout-btn" @click="authStore.logout">退出</button>
<div class="user-actions">
<button class="new-bot-btn" @click="showCreateBot = true">
+ 新建机器人
</button>
<div class="user-info">
<span>{{ authStore.user?.nickname || authStore.user?.username }}</span>
<button class="logout-btn" @click="authStore.logout">退出</button>
</div>
</div>
</div>
</header>
@@ -92,6 +104,12 @@ function resumeChat(sessionId: string) {
</div>
</section>
</main>
<CreateBotModal
v-if="showCreateBot"
@close="showCreateBot = false"
@created="handleBotCreated"
/>
</div>
</template>
@@ -120,6 +138,28 @@ function resumeChat(sessionId: string) {
color: var(--primary-color);
}
.user-actions {
display: flex;
align-items: center;
gap: var(--spacing-md);
}
.new-bot-btn {
padding: var(--spacing-xs) var(--spacing-md);
background: var(--primary-color);
color: white;
border: none;
border-radius: var(--border-radius);
font-size: var(--font-size-sm);
font-weight: 500;
cursor: pointer;
transition: background 0.2s;
}
.new-bot-btn:hover {
background: var(--primary-dark);
}
.user-info {
display: flex;
align-items: center;