Compare commits

..

No commits in common. "ea397c735bade03dd1691e0ffbdcd1a40bb9053b" and "df3500f6c56fe253d303c7eb9501feef58f5d0d4" have entirely different histories.

2 changed files with 10 additions and 11 deletions

View File

@ -1,6 +1,7 @@
import { get, set, del, update, createStore, values } from 'idb-keyval' import { get, set, del, update, createStore, values } from 'idb-keyval'
import { Span, Button, List, ListItem, TextArea, createElement } from './weigets.js' import { Span, Button, List, ListItem, Input, createElement } from './weigets.js'
// 先不划分频道, 只有一个公共聊天室
export default class Chat { export default class Chat {
constructor({ name, EventListeners = {}, onsend, onexit }) { constructor({ name, EventListeners = {}, onsend, onexit }) {
this.event = { onsend, onexit } this.event = { onsend, onexit }
@ -10,7 +11,7 @@ export default class Chat {
document.body.appendChild(createElement({ document.body.appendChild(createElement({
children: [ children: [
this.ul, this.ul,
TextArea({ createElement({
type: 'text', type: 'text',
placeholder: '输入聊天内容', placeholder: '输入聊天内容',
style: { style: {
@ -27,7 +28,7 @@ export default class Chat {
event.target.value = '' event.target.value = ''
} }
} }
}), }, 'textarea'),
Button({ Button({
textContent: '发送(ctrl+Enter)', textContent: '发送(ctrl+Enter)',
onclick: event => { onclick: event => {
@ -47,8 +48,9 @@ export default class Chat {
}), }),
] ]
})) }))
document.head.appendChild(createElement({ // 写入 css 样式到 head
innerText: ` const style = document.createElement('style')
style.innerText = `
ul.chat-list { ul.chat-list {
max-height: 70vh; max-height: 70vh;
overflow-y: auto; overflow-y: auto;
@ -66,8 +68,9 @@ export default class Chat {
} }
ul.chat-list > li.disable { ul.chat-list > li.disable {
color: #888; color: #888;
}` }
}, 'style')) `
document.head.appendChild(style)
this.载入消息() this.载入消息()
} }
// 收到应答(对方确认消息已被接收) // 收到应答(对方确认消息已被接收)

View File

@ -35,10 +35,6 @@ export function Input(options) {
return createElement(options, 'input') return createElement(options, 'input')
} }
export function TextArea(options) {
return createElement(options, 'textarea')
}
export function Avatar(options) { export function Avatar(options) {
const element = createElement(options, 'img') const element = createElement(options, 'img')
element.onerror = () => element.src = '/favicon.ico' element.onerror = () => element.src = '/favicon.ico'