接收消息合并
This commit is contained in:
		| @@ -193,8 +193,11 @@ export default class Chat { | ||||
|         this.send({ name, text, time, type }) | ||||
|     } | ||||
|     收到消息(data) { | ||||
|         const { name, text, time, type } = data | ||||
|         this.add({ name, text, time, type }) | ||||
|         console.log('收到消息', data) | ||||
|         const time = new Date().toLocaleString() | ||||
|         const { name, text, type } = data | ||||
|         this.添加元素({ name, text, time, type }) | ||||
|         this.存储消息({ name, text, time, type }) | ||||
|     } | ||||
|     // 退出 | ||||
|     exit() { | ||||
|   | ||||
| @@ -157,7 +157,7 @@ clientList.setChannel('chat', { | ||||
|     const data = JSON.parse(event.data) | ||||
|     if (data.type === 'message') { | ||||
|       console.log(client.name, '发来消息:', data) | ||||
|       chat.add({ name: client.name, text: data.text, time: new Date().toLocaleTimeString() }) | ||||
|       chat.收到消息({ name: client.name, ...data.text }) | ||||
|       return | ||||
|     } | ||||
|     if (data.type === 'image') { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user