result.js
2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { convertDate } from '../../utils/util.js';
//获取应用实例
const app = getApp();
const type = app.globalData.getTypeList();
let audio = null;
let formateDate = function (audioList) {
return audioList.map(audio => {
return {
...audio,
date: convertDate(audio.time)
};
}).reverse();
};
Page({
data: {
audioList: formateDate(app.globalData.getAudioList())
},
onLoad (options) {
this.setData({
audioList: formateDate(app.globalData.getAudioList())
});
},
play(e){
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;
// 播放失败要移除缓存内容
audio.onError(err => {
wx.showModal({
title: '提示',
content: '该语音缓存失效,点击确定删除',
success: res => {
if(!res.confirm){
return;
}
const newList = app.globalData.setAudioList('delete', target.path);
this.setData({
audioList: formateDate(newList)
});
}
});
});
},
download(e){
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,
fileName: `${target.text.slice(0, 8)}.${ext}`
});
},
delete(e){
const { path } = e.target.dataset;
wx.showModal({
title: '提示',
content: '确认删除吗?',
success: res => {
if(!res.confirm){
return;
}
const newList = app.globalData.setAudioList('delete', path);
this.setData({
audioList: formateDate(newList)
});
}
});
}
});