Page({
/**
* 页面的初始数据
*/
data: {
picPath: '',
videoPath: '',
recordPath: '',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
picPath: options.url,
videoPath: options.video,
recordPath: decodeURIComponent(options.record),
})
},
/**
* 播放录音
*/
playVoice(){
wx.playVoice({
filePath: this.data.recordPath,
complete(res) {
console.log(res)
}
})
},
/**
* 保存到相册
*/
save2Album() {
if (this.data.videoPath != ''){
wx.saveVideoToPhotosAlbum({
filePath: this.data.videoPath,
success: function(data){
wx.showToast({
title: '保存成功',
icon: 'success'
})
},
fail: function (err) {
console.log(err);
if (err.errMsg === "saveVideoToPhotosAlbum:fail auth deny") {
console.log('再次发起授权')
// 申请相册授权
wx.openSetting({
success(suc) {
console.log(suc)
if (suc.authSetting['scope.writePhotosAlbum']) {
console.log('获取授权成功')
} else {
console.log('获取授权失败')
}
}
})
}
}
})
} else if (this.data.picPath != ''){
wx.saveImageToPhotosAlbum({
filePath: this.data.picPath,
success: function (data) {
wx.showToast({
title: '保存成功',
icon: 'success',
duration: 2000
})
},
fail: function (err) {
console.log(err);
if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
console.log('再次发起授权')
// 申请相册授权
wx.openSetting({
success(suc) {
console.log(suc)
if (suc.authSetting['scope.writePhotosAlbum']) {
console.log('获取授权成功')
} else {
console.log('获取授权失败')
}
}
})
}
}
})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})