answer
This commit is contained in:
15
src/chat.js
15
src/chat.js
@@ -8,6 +8,9 @@ export default class Chat {
|
||||
this.EventListeners = EventListeners
|
||||
document.body.appendChild(this.ul) // 元素加入页面
|
||||
|
||||
// 使用一个有序列表来存储消息
|
||||
const messageBox = new Map()
|
||||
|
||||
// 添加输入框
|
||||
const input = createElement({
|
||||
type: 'text',
|
||||
@@ -55,15 +58,23 @@ export default class Chat {
|
||||
`
|
||||
document.head.appendChild(style)
|
||||
}
|
||||
// 收到应答(对方确认消息已被接收)
|
||||
answer(data) {
|
||||
const { name, text, time, type } = data
|
||||
const item = this.add({ name, text, time, type })
|
||||
item.classList.add('disable')
|
||||
}
|
||||
// 添加一条消息
|
||||
add({ name, text, time, type }) {
|
||||
this.ul.appendChild(ListItem({
|
||||
const item = ListItem({
|
||||
classList: [type],
|
||||
children: [
|
||||
Span({ innerText: `${name} ${time} ${text}` })
|
||||
]
|
||||
}))
|
||||
})
|
||||
this.ul.appendChild(item)
|
||||
this.ul.scrollTop = this.ul.scrollHeight
|
||||
return item
|
||||
}
|
||||
// 发送消息
|
||||
send(text) {
|
||||
|
||||
Reference in New Issue
Block a user