按钮功能合并

This commit is contained in:
2023-10-02 06:30:20 +08:00
parent 6b986de6d6
commit 0fc8dc3f67
1 changed files with 12 additions and 10 deletions

View File

@ -97,17 +97,18 @@ export default class MusicList {
} }
}), }),
Button({ Button({
innerText: '移除', innerText: item.arrayBuffer ? '移除' : '喜欢',
onclick: event => { onclick: event => {
event.stopPropagation() event.stopPropagation()
this.remove(item) if (item.arrayBuffer) {
} event.target.innerText = '喜欢'
}), this.unlike(item)
Button({ this.remove(item)
innerText: '喜欢', } else {
onclick: event => { event.target.innerText = '移除'
event.stopPropagation() this.ul.querySelector(`#${item.id}`).classList.add('cache')
this.like(item) this.like(item)
}
} }
}), }),
Button({ Button({
@ -130,7 +131,7 @@ export default class MusicList {
} }
async remove(item) { async remove(item) {
this.ul.querySelector(`#${item.id}`)?.remove() this.ul.querySelector(`#${item.id}`)?.remove()
this.stop() // 停止播放 if (this.playing) this.stop() // 停止播放
this.event.onremove(item) this.event.onremove(item)
} }
async load(item) { async load(item) {
@ -149,6 +150,7 @@ export default class MusicList {
this.audio.pause() this.audio.pause()
this.audio.src = '' this.audio.src = ''
this.event.onstop(this.playing) this.event.onstop(this.playing)
this.playing = null
} }
async like(item) { async like(item) {
if (!item.arrayBuffer) { if (!item.arrayBuffer) {