From e9cfdbc3c412bfe53f8ceb7fd97db31a1855b7e8 Mon Sep 17 00:00:00 2001 From: xwenliang Date: Sun, 6 Nov 2022 04:59:46 +0800 Subject: [PATCH] fix: action by id instead of index --- app.js | 9 ++++++--- pages/result/result.js | 12 ++++++------ pages/result/result.wxml | 6 +++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app.js b/app.js index 2a3db26..f87c389 100644 --- a/app.js +++ b/app.js @@ -65,7 +65,7 @@ App({ }, /** * @param {(add|delete)} action - 增或删 - * @param {object|number} [param] - 增加时是 audio 描述,删除时是索引 + * @param {object|number} [param] - 增加时是 audio 描述,删除时是唯一特征 path 值 */ setAudioList(action, param){ const storageKey = 'audioList'; @@ -75,8 +75,11 @@ App({ wx.setStorageSync(storageKey, list); } if(action === 'delete' && String(param)){ - list.splice(param, 1); - wx.setStorageSync(storageKey, list); + const index = list.findIndex(v => v.path === param); + if(index > -1){ + list.splice(index, 1); + wx.setStorageSync(storageKey, list); + } } return list; } diff --git a/pages/result/result.js b/pages/result/result.js index 620d748..1f1544c 100644 --- a/pages/result/result.js +++ b/pages/result/result.js @@ -24,16 +24,16 @@ Page({ }); }, play(e){ - const { index } = e.target.dataset; - const target = app.globalData.getAudioList()[index]; + const { path } = e.target.dataset; + const target = app.globalData.getAudioList().find(v => v.path === path); audio && audio.destroy(); audio = wx.createInnerAudioContext({useWebAudioImplement: true}); audio.autoplay = true; audio.src = target.path; }, download(e){ - const { index } = e.target.dataset; - const target = app.globalData.getAudioList()[index]; + const { path } = e.target.dataset; + const target = app.globalData.getAudioList().find(v => v.path === path); const ext = target.path.split('.').pop(); wx.shareFileMessage({ filePath: target.path, @@ -41,7 +41,7 @@ Page({ }); }, delete(e){ - const { index } = e.target.dataset; + const { path } = e.target.dataset; wx.showModal({ title: '提示', content: '确认删除吗?', @@ -49,7 +49,7 @@ Page({ if(!res.confirm){ return; } - const newList = app.globalData.setAudioList('delete', index); + const newList = app.globalData.setAudioList('delete', path); this.setData({ audioList: formateDate(newList) }); diff --git a/pages/result/result.wxml b/pages/result/result.wxml index e336c22..e19fe67 100644 --- a/pages/result/result.wxml +++ b/pages/result/result.wxml @@ -10,8 +10,8 @@ {{item.date}} - - - + + + \ No newline at end of file -- libgit2 0.22.2