From 0fc8dc3f67b35abf873854b7eec452fa625570db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=89?= Date: Mon, 2 Oct 2023 06:30:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E9=92=AE=E5=8A=9F=E8=83=BD=E5=90=88?= =?UTF-8?q?=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/music.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/public/music.js b/public/music.js index c341597..32b8c31 100644 --- a/public/music.js +++ b/public/music.js @@ -97,17 +97,18 @@ export default class MusicList { } }), Button({ - innerText: '移除', + innerText: item.arrayBuffer ? '移除' : '喜欢', onclick: event => { event.stopPropagation() - this.remove(item) - } - }), - Button({ - innerText: '喜欢', - onclick: event => { - event.stopPropagation() - this.like(item) + if (item.arrayBuffer) { + event.target.innerText = '喜欢' + this.unlike(item) + this.remove(item) + } else { + event.target.innerText = '移除' + this.ul.querySelector(`#${item.id}`).classList.add('cache') + this.like(item) + } } }), Button({ @@ -130,7 +131,7 @@ export default class MusicList { } async remove(item) { this.ul.querySelector(`#${item.id}`)?.remove() - this.stop() // 停止播放 + if (this.playing) this.stop() // 停止播放 this.event.onremove(item) } async load(item) { @@ -149,6 +150,7 @@ export default class MusicList { this.audio.pause() this.audio.src = '' this.event.onstop(this.playing) + this.playing = null } async like(item) { if (!item.arrayBuffer) {