219 lines
4.7 KiB
TypeScript
219 lines
4.7 KiB
TypeScript
// 聊天相关接口定义
|
|
|
|
export interface ChatConversation {
|
|
id: number
|
|
name: string
|
|
avatar: string
|
|
lastMessage: string
|
|
time: string
|
|
unreadCount?: number
|
|
}
|
|
|
|
export interface ChatMessage {
|
|
id: number
|
|
type: 'user' | 'ai'
|
|
content: string
|
|
time: string
|
|
isAudio?: boolean
|
|
audioDuration?: string
|
|
}
|
|
|
|
export interface Character {
|
|
id: number
|
|
name: string
|
|
description: string
|
|
icon: string
|
|
}
|
|
|
|
// Mock 数据 - 会话列表
|
|
const mockConversations: ChatConversation[] = [
|
|
{
|
|
id: 1,
|
|
name: '阳光知心伴伴',
|
|
avatar: '🎤',
|
|
lastMessage: '因为太阳光里面其实藏着七种颜色呀...',
|
|
time: '14:31',
|
|
unreadCount: 2
|
|
},
|
|
{
|
|
id: 2,
|
|
name: '智慧小博士',
|
|
avatar: '📚',
|
|
lastMessage: '好的,我来给你讲一个关于恐龙的故事...',
|
|
time: '昨天'
|
|
},
|
|
{
|
|
id: 3,
|
|
name: '音乐小精灵',
|
|
avatar: '🎵',
|
|
lastMessage: '《拔萝卜》已经唱完啦,还要听别的吗?',
|
|
time: '昨天'
|
|
},
|
|
{
|
|
id: 4,
|
|
name: '故事大王',
|
|
avatar: '📖',
|
|
lastMessage: '从前有一只勇敢的小兔子...',
|
|
time: '周一'
|
|
},
|
|
{
|
|
id: 5,
|
|
name: '英语小老师',
|
|
avatar: '🔤',
|
|
lastMessage: 'Apple, A-P-P-L-E, apple!',
|
|
time: '周一'
|
|
}
|
|
]
|
|
|
|
// Mock 数据 - 消息列表
|
|
const mockMessages: Record<number, ChatMessage[]> = {
|
|
1: [
|
|
{
|
|
id: 1,
|
|
type: 'user',
|
|
content: '天空为什么是蓝色的呀?',
|
|
time: '今天 14:30'
|
|
},
|
|
{
|
|
id: 2,
|
|
type: 'ai',
|
|
content: '因为太阳光里面其实藏着七种颜色呀。当光穿过大气层的时候,蓝色的光最调皮,到处乱跑,所以我们看到的天空就是蓝色的啦!',
|
|
time: '今天 14:31'
|
|
},
|
|
{
|
|
id: 3,
|
|
type: 'user',
|
|
content: '给我唱一首拔萝卜吧!',
|
|
time: '今天 15:15'
|
|
},
|
|
{
|
|
id: 4,
|
|
type: 'ai',
|
|
content: '',
|
|
time: '今天 15:15',
|
|
isAudio: true,
|
|
audioDuration: '01:45'
|
|
}
|
|
],
|
|
2: [
|
|
{
|
|
id: 1,
|
|
type: 'user',
|
|
content: '你知道恐龙吗?',
|
|
time: '昨天 10:30'
|
|
},
|
|
{
|
|
id: 2,
|
|
type: 'ai',
|
|
content: '当然知道!恐龙是生活在很久很久以前的大型爬行动物,有的恐龙比房子还要大呢!',
|
|
time: '昨天 10:31'
|
|
},
|
|
{
|
|
id: 3,
|
|
type: 'user',
|
|
content: '那给我讲一个恐龙的故事吧',
|
|
time: '昨天 10:32'
|
|
},
|
|
{
|
|
id: 4,
|
|
type: 'ai',
|
|
content: '好的,我来给你讲一个关于恐龙的故事...',
|
|
time: '昨天 10:33'
|
|
}
|
|
],
|
|
3: [
|
|
{
|
|
id: 1,
|
|
type: 'user',
|
|
content: '我想听拔萝卜',
|
|
time: '昨天 16:00'
|
|
},
|
|
{
|
|
id: 2,
|
|
type: 'ai',
|
|
content: '',
|
|
time: '昨天 16:01',
|
|
isAudio: true,
|
|
audioDuration: '02:30'
|
|
},
|
|
{
|
|
id: 3,
|
|
type: 'ai',
|
|
content: '《拔萝卜》已经唱完啦,还要听别的吗?',
|
|
time: '昨天 16:04'
|
|
}
|
|
],
|
|
4: [
|
|
{
|
|
id: 1,
|
|
type: 'user',
|
|
content: '给我讲个故事吧',
|
|
time: '周一 20:00'
|
|
},
|
|
{
|
|
id: 2,
|
|
type: 'ai',
|
|
content: '从前有一只勇敢的小兔子...',
|
|
time: '周一 20:01'
|
|
}
|
|
],
|
|
5: [
|
|
{
|
|
id: 1,
|
|
type: 'user',
|
|
content: '苹果用英语怎么说?',
|
|
time: '周一 18:00'
|
|
},
|
|
{
|
|
id: 2,
|
|
type: 'ai',
|
|
content: 'Apple, A-P-P-L-E, apple!',
|
|
time: '周一 18:01'
|
|
}
|
|
]
|
|
}
|
|
|
|
// Mock 数据 - 角色信息
|
|
const mockCharacters: Record<number, Character> = {
|
|
1: { id: 1, name: '阳光知心伴伴', description: '温柔音色 / 开朗耐心', icon: '🎤' },
|
|
2: { id: 2, name: '智慧小博士', description: '博学多才 / 爱讲故事', icon: '📚' },
|
|
3: { id: 3, name: '音乐小精灵', description: '歌声甜美 / 会唱儿歌', icon: '🎵' },
|
|
4: { id: 4, name: '故事大王', description: '故事丰富 / 生动有趣', icon: '📖' },
|
|
5: { id: 5, name: '英语小老师', description: '英语启蒙 / 发音标准', icon: '🔤' }
|
|
}
|
|
|
|
/**
|
|
* 获取会话列表
|
|
*/
|
|
export function getConversations(): Promise<ChatConversation[]> {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
resolve([...mockConversations])
|
|
}, 300)
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 获取会话消息列表
|
|
* @param conversationId 会话ID
|
|
*/
|
|
export function getMessages(conversationId: number): Promise<ChatMessage[]> {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
resolve(mockMessages[conversationId] || [])
|
|
}, 300)
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 获取角色信息
|
|
* @param characterId 角色ID
|
|
*/
|
|
export function getCharacter(characterId: number): Promise<Character | null> {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
resolve(mockCharacters[characterId] || null)
|
|
}, 300)
|
|
})
|
|
}
|