110 lines
3.4 KiB
TypeScript
110 lines
3.4 KiB
TypeScript
import { ref, computed } from 'vue'
|
|
|
|
export interface ChatMessage {
|
|
id: number
|
|
title: string
|
|
content: string
|
|
time: string
|
|
pending?: boolean
|
|
avatar?: string
|
|
}
|
|
|
|
export interface ChatBubble {
|
|
id: number
|
|
content: string
|
|
time: string
|
|
isSelf: boolean
|
|
}
|
|
|
|
export type FilterType = 'all' | 'pending' | 'processed'
|
|
|
|
export function useChat() {
|
|
const selectedChatId = ref<number | null>(null)
|
|
|
|
// 模拟对话列表数据
|
|
const chats = ref<ChatMessage[]>([
|
|
{ id: 1, title: '系统助手', content: '欢迎使用角色管理系统,祝您工作顺利!', time: '10:00', pending: false, avatar: '系统' },
|
|
{ id: 2, title: '任务提醒', content: '您有一个待处理的任务需要在今天完成。', time: '11:30', pending: true, avatar: '任务' },
|
|
{ id: 3, title: '审批助手', content: '新的流程审批等待您的处理,请及时查看。', time: '14:20', pending: true, avatar: '审批' },
|
|
{ id: 4, title: '会议助手', content: '明天上午 10 点召开项目进度会议,请准时参加。', time: '15:00', pending: false, avatar: '会议' },
|
|
])
|
|
|
|
// 模拟聊天泡泡数据
|
|
const chatBubbles = ref<Record<number, ChatBubble[]>>({
|
|
1: [
|
|
{ id: 1, content: '欢迎使用角色管理系统,祝您工作顺利!', time: '10:00', isSelf: false },
|
|
{ id: 2, content: '谢谢,我该如何开始?', time: '10:01', isSelf: true },
|
|
{ id: 3, content: '您可以从左侧菜单开始探索各项功能', time: '10:02', isSelf: false },
|
|
],
|
|
2: [
|
|
{ id: 1, content: '您有一个待处理的任务需要在今天完成。', time: '11:30', isSelf: false },
|
|
],
|
|
3: [
|
|
{ id: 1, content: '新的流程审批等待您的处理,请及时查看。', time: '14:20', isSelf: false },
|
|
{ id: 2, content: '好的,我马上处理', time: '14:25', isSelf: true },
|
|
],
|
|
4: [
|
|
{ id: 1, content: '明天上午 10 点召开项目进度会议,请准时参加。', time: '15:00', isSelf: false },
|
|
],
|
|
})
|
|
|
|
// 计算属性:获取当前选中的对话
|
|
const selectedChat = computed(() =>
|
|
chats.value.find(c => c.id === selectedChatId.value)
|
|
)
|
|
|
|
// 计算属性:获取当前对话的泡泡列表
|
|
const currentBubbles = computed(() =>
|
|
selectedChatId.value ? (chatBubbles.value[selectedChatId.value] || []) : []
|
|
)
|
|
|
|
// 选择对话
|
|
const selectChat = (id: number) => {
|
|
selectedChatId.value = id
|
|
// 标记为已处理
|
|
const chat = chats.value.find(c => c.id === id)
|
|
if (chat) chat.pending = false
|
|
}
|
|
|
|
// 发送消息
|
|
const sendMessage = (content: string) => {
|
|
if (!selectedChatId.value || !content.trim()) return
|
|
|
|
const newBubble: ChatBubble = {
|
|
id: Date.now(),
|
|
content: content.trim(),
|
|
time: new Date().toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' }),
|
|
isSelf: true,
|
|
}
|
|
|
|
if (!chatBubbles.value[selectedChatId.value]) {
|
|
chatBubbles.value[selectedChatId.value] = []
|
|
}
|
|
chatBubbles.value[selectedChatId.value].push(newBubble)
|
|
}
|
|
|
|
// 操作处理函数
|
|
const handleChatAction = (action: string, chatId: number) => {
|
|
console.log(`处理对话 ${chatId}: ${action}`)
|
|
// TODO: 实现具体业务逻辑
|
|
}
|
|
|
|
return {
|
|
// 状态
|
|
selectedChatId,
|
|
|
|
// 数据
|
|
chats,
|
|
chatBubbles,
|
|
|
|
// 计算属性
|
|
selectedChat,
|
|
currentBubbles,
|
|
|
|
// 方法
|
|
selectChat,
|
|
sendMessage,
|
|
handleChatAction,
|
|
}
|
|
}
|