合并组件

This commit is contained in:
2023-10-19 00:21:45 +08:00
parent 1cdfc924d2
commit 247e3e532d
1 changed files with 18 additions and 23 deletions

View File

@ -12,8 +12,6 @@ export default class MusicList {
this.audio = new Audio() this.audio = new Audio()
this.audio.autoplay = true this.audio.autoplay = true
this.audio.controls = true this.audio.controls = true
this.audio.style.width = '100%'
this.audio.style.height = '5rem'
this.audio.style.margin = '1rem 2rem' this.audio.style.margin = '1rem 2rem'
this.audio.addEventListener('play', () => { this.audio.addEventListener('play', () => {
this.event.onplay(this.playing) this.event.onplay(this.playing)
@ -30,20 +28,15 @@ export default class MusicList {
// 收起到右上角, 音乐播放器基于浮窗定位, 不再占用页面空间 // 收起到右上角, 音乐播放器基于浮窗定位, 不再占用页面空间
const element = createElement({ const element = createElement({
textContent: '音乐', //textContent: '音乐',
style: { position: 'fixed', top: '5rem', right: '1rem', backgroundColor: '#eee', padding: '.5rem', borderRadius: '1rem', cursor: 'pointer' }, style: { position: 'fixed', top: '5rem', right: '1rem', backgroundColor: '#eee', padding: '.5rem', borderRadius: '1rem', cursor: 'pointer' },
onclick: event => { onclick: event => {
this.ul.classList.toggle('disable') this.ul.classList.toggle('disable')
}, },
children: [ children: [
this.audio, this.audio,
this.ul this.ul,
] UploadMusic({
})
document.body.appendChild(element)
// 本地添加音乐按钮
document.body.appendChild(UploadMusic({
style: { width: '20rem', height: '5rem', margin: '1rem 2rem' }, style: { width: '20rem', height: '5rem', margin: '1rem 2rem' },
onchange: files => { onchange: files => {
for (const file of files) { for (const file of files) {
@ -58,8 +51,10 @@ export default class MusicList {
reader.readAsArrayBuffer(file) reader.readAsArrayBuffer(file)
} }
} }
})) })
]
})
document.body.appendChild(element)
// 写入 css 样式到 head // 写入 css 样式到 head
const style = document.createElement('style') const style = document.createElement('style')