From c0bd382e30ca3bb1e350b889421acafa543f40e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=89?= Date: Tue, 3 Oct 2023 00:28:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=A6=BB=E5=BC=80=E6=97=B6?= =?UTF-8?q?=E4=BB=8E=E7=A7=BB=E9=99=A4=E5=85=B6=E9=9F=B3=E4=B9=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.html | 24 +++++++++++++----------- public/music.js | 1 + 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/public/index.html b/public/index.html index e899155..e8a668c 100644 --- a/public/index.html +++ b/public/index.html @@ -44,17 +44,19 @@ console.log(client.name, '离开频道', client) // 从列表中移除未缓存的此用户的音乐, 但可能多人都有此音乐且未缓存 // 因此每条音乐都要检查是否有其他用户也有此音乐, 如果有则不移除 - //musicList.list.filter(item => !item.arrayBuffer).forEach(item => { - // const client = clientList.clientlist.find(client => { - // return client.musicList.find(x => x.id === item.id) - // }) - // if (!client) { - // console.log('没有用户存留此音乐了, 移除记录', item.name) - // musicList.remove(item) - // } else { - // console.log(client.name, '中还有此音乐, 保留记录', item.name) - // } - //}) + const 此用户音乐 = client.musicList.map(item => item.id) + const 无数据音乐 = musicList.list.filter(item => !item.arrayBuffer) + 无数据音乐.forEach(item => { + const client = clientList.clientlist.find(client => { + return client.musicList.find(x => x.id === item.id) + }) + if (!client) { + console.log('没有用户存留此音乐了, 移除记录', item.name) + musicList.remove(item) + } else { + console.log(client.name, '中还有此音乐, 保留记录', item.name) + } + }) } }) diff --git a/public/music.js b/public/music.js index 8ad7d09..ad309fd 100644 --- a/public/music.js +++ b/public/music.js @@ -126,6 +126,7 @@ export default class MusicList { async remove(item) { this.ul.querySelector(`#${item.id}`)?.remove() if (!this.audio.paused) this.stop() // 停止播放 + this.list = this.list.filter(i => i.id !== item.id) this.event.onremove(item) } async load(item) {