为消息添加id
This commit is contained in:
parent
e96b319a85
commit
77fd29efb4
25
src/chat.js
25
src/chat.js
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user