From 77fd29efb4929f5fd85e346739baff30ddf2fb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=89?= Date: Sat, 21 Oct 2023 15:48:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E6=B6=88=E6=81=AF=E6=B7=BB=E5=8A=A0id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat.js | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/chat.js b/src/chat.js index 722cde8..3734432 100644 --- a/src/chat.js +++ b/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) } } \ No newline at end of file