From 6b986de6d6c288972a9d309c0cd772cb7e1afe48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=89?= Date: Mon, 2 Oct 2023 05:38:44 +0800 Subject: [PATCH] =?UTF-8?q?like=20=E6=97=B6=E6=8E=A8=E9=80=81=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.html | 19 +++++++++++++------ public/music.js | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/public/index.html b/public/index.html index 4dd7559..5c3bd73 100644 --- a/public/index.html +++ b/public/index.html @@ -36,18 +36,25 @@ onstop: item => { console.log('停止音乐', item.name) }, - onlike: item => { + onlike: (item, list) => { console.log('喜欢音乐', item) if (item.arrayBuffer) { database.add(item) - // clientList.send('base', JSON.stringify({ - // type: 'set_music_list', - // list: list.map(({ id, name, size, type }) => ({ id, name, size, type })) - // })) + clientList.send('base', JSON.stringify({ + type: 'set_music_list', + list: list.map(({ id, name, size, type }) => ({ id, name, size, type })) + })) } }, - onunlike: item => { + onunlike: (item, list) => { console.log('取消喜欢', item) + if (item.arrayBuffer) { + database.delete(item.id) + clientList.send('base', JSON.stringify({ + type: 'set_music_list', + list: list.map(({ id, name, size, type }) => ({ id, name, size, type })) + })) + } }, onban: item => { console.log('禁止音乐', item) diff --git a/public/music.js b/public/music.js index c72b1bc..c341597 100644 --- a/public/music.js +++ b/public/music.js @@ -154,10 +154,10 @@ export default class MusicList { if (!item.arrayBuffer) { await this.load(item) } - this.event.onlike(item) + this.event.onlike(item, this.list) } async unlike(item) { - this.event.onunlike(item) + this.event.onunlike(item, this.list) } async ban(item) { this.event.onban(item)