为消息添加id

This commit is contained in:
2023-10-21 15:48:01 +08:00
parent e96b319a85
commit 77fd29efb4
1 changed files with 7 additions and 18 deletions

View File

@ -168,10 +168,7 @@ export default class Chat {
}))
}
存储消息(data) {
const { name, text, time, type } = data
const id = window.crypto.randomUUID()
const item = { id, name, text, time, type }
set(id, item, this.store)
set(data.id, data, this.store)
}
载入消息() {
values(this.store).then(items => {
@ -185,24 +182,16 @@ export default class Chat {
}
发送消息(text) {
const name = '我'
const id = window.crypto.randomUUID()
const time = new Date().toLocaleString()
console.log('发送消息', { name, text, time })
const type = 'text'
this.添加元素({ name, text, time, type })
this.存储消息({ name, text, time, type })
this.send({ name, text, time, type })
this.添加元素({ id, name, text, time, type })
this.存储消息({ id, name, text, time, type })
this.send({ id, name, text, time, type })
}
收到消息(data) {
console.log('收到消息', data)
const time = new Date().toLocaleString()
const { name, text, type } = data
this.添加元素({ name, text, time, type })
this.存储消息({ name, text, time, type })
}
// 退出
exit() {
if (this.event.onexit) {
this.event.onexit()
}
this.添加元素(data)
this.存储消息(data)
}
}