tangshi300/pages/record-history/record-history.js

124 lines
3.7 KiB
JavaScript

var t = require("../../miniprogram_npm/@vant/weapp/dialog/dialog"), e = require("../../lib/aes.js"), a = getApp(), o = wx.getFileSystemManager();
Page({
data: {
poetryList: void 0,
recordList: void 0,
showDelete: !1,
playing: !1,
currentId: 0
},
onLoad: function() {
this.audio = wx.createInnerAudioContext(), this.handleAutoPlay(), this.getPoetryList();
},
onShow: function() {},
handleAutoPlay: function() {
var t = this;
t.audio.onEnded(function(e) {
t.setData({
playing: !1
});
}), t.audio.onPause(function(e) {
t.setData({
playing: !1
});
}), t.audio.onPlay(function(e) {
t.setData({
playing: !0
});
}), t.audio.onError(function(e) {
t.setData({
playing: !1
});
});
},
getPoetryList: function() {
var t = this, o = (t.data.poetryId, a.globalData.API_URL + "/h5/api/textbook/poetry/voice/list"), i = {
openId: a.globalData.openid
};
wx.request({
url: o,
data: i,
success: function(o) {
var i = e.decrypt(o.data, a.globalData.key), r = JSON.parse(i);
t.setData({
poetryList: r
});
}
});
},
getLocalRecord: function() {
var t = wx.env.USER_DATA_PATH + "/poetry";
if (!this.isFileExit(t)) try {
o.mkdirSync(t, !0);
} catch (t) {
// t = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(t);
// console.error(t);
}
var e = [];
try {
var a = o.readdirSync(t);
if (a && a.length > 0) for (var i = 0; i < a.length; i++) {
var r = a[i].split("#"), n = {
id: i,
name: r[0],
poetryId: r[1],
date: r[2],
path: t + "/" + a[i]
};
e.push(n);
}
} catch (t) {
// t = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(t);
// console.error(t);
}
this.setData({
recordList: e
});
},
isFileExit: function(t) {
try {
return o.accessSync(t), !0;
} catch (t) {
// t = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(t);
// return console.error(t), !1;
}
},
deleteRecord: function(e) {
var a = this, o = e.currentTarget.dataset.item;
a.audio.stop(), t.confirm({
title: "删除",
message: "确认删除本条朗诵吗?"
}).then(function() {
a.deleteVoice(o.id);
}).catch(function() {});
},
deleteVoice: function(t) {
var e = this, o = a.globalData.API_URL + "/h5/api/textbook/poetry/voice/delete", i = {
openId: a.globalData.openid,
id: t
};
wx.request({
url: o,
data: i,
success: function(t) {
e.getPoetryList();
}
});
},
toRecord: function(t) {
var e = t.currentTarget.dataset.item;
this.audio.stop(), wx.navigateTo({
url: "../record/record?id=" + e.poetryId
});
},
shareRecord: function(t) {
var e = t.currentTarget.dataset.item;
wx.shareFileMessage({
filePath: e.path,
fileName: e.name + "-朗诵.mp3",
success: function() {},
fail: console.error
});
}
});