# 06-AI对话页面(原型) ## 目标 实现 Web 端 AI 健康问诊对话功能,使用模拟数据模拟多轮对话效果。 --- ## 前置要求 - 路由配置完成 - 模拟数据服务已创建 --- ## 实施步骤 ### 步骤 1:创建对话状态 Store 创建 `src/stores/chat.ts`: ```typescript import { defineStore } from 'pinia' import { ref } from 'vue' import type { Conversation, Message } from '@/types' export const useChatStore = defineStore('chat', () => { const conversations = ref([]) function addConversation(conv: Conversation) { conversations.value.unshift(conv) saveToStorage() } function deleteConversation(id: string) { conversations.value = conversations.value.filter(c => c.id !== id) saveToStorage() } function addMessage(convId: string, message: Message) { const conv = conversations.value.find(c => c.id === convId) if (conv) { conv.messages.push(message) conv.updatedAt = new Date().toISOString() // 更新标题为第一条用户消息 if (message.role === 'user' && conv.messages.filter(m => m.role === 'user').length === 1) { conv.title = message.content.slice(0, 20) + (message.content.length > 20 ? '...' : '') } saveToStorage() } } function saveToStorage() { localStorage.setItem('conversations', JSON.stringify(conversations.value)) } function init() { const saved = localStorage.getItem('conversations') if (saved) { conversations.value = JSON.parse(saved) } } init() return { conversations, addConversation, deleteConversation, addMessage } }) ``` ### 步骤 2:对话列表页面 创建 `src/views/chat/ChatListView.vue`: ```vue ``` ### 步骤 3:对话详情页面 创建 `src/views/chat/ChatDetailView.vue`: ```vue ``` --- ## 验收标准 - [ ] 对话列表正常显示 - [ ] 新建对话正常 - [ ] 删除对话正常 - [ ] 消息发送和模拟回复正常 - [ ] 快捷问题点击正常 - [ ] 免责声明显示 --- ## 预计耗时 40-50 分钟 --- ## 下一步 完成后进入 `03-Web原型开发/07-个人中心页面.md`