Files
lcb/pages/audioPlay/index.js
T
小鱼开发 3bf5c948d8 Initial commit
2024-05-24 14:16:05 +08:00

131 lines
4.0 KiB
JavaScript

const innerAudioContext = wx.createInnerAudioContext();
let interval = null
Page({
data: {
currentime:0,
currentx:'00:00'
},
onLoad: function (options) {
let res = {"code":200,"data":{"list":[{"content":"【帆神】拨打电话","record_url":"https:\/\/media.liche.cn\/liche\/xz_video_b0f8821632330b5f\/1f06c26a0da82604.mp3","second":5,"imgs":[],"c_time":"2021.07.27"},{"content":"【老叶】拨打电话","record_url":"https:\/\/media.liche.cn\/liche\/xz_video_65efc63e86180ab0\/12c3837809e69d57.mp3","second":5,"imgs":[],"c_time":"2021.07.27"},{"content":"【老叶】拨打电话","record_url":"https:\/\/img.liche.cn\/liche\/xz_video_e41408d91a337343\/3177bd021db3c7cd.mp3","second":5,"imgs":[],"c_time":"2021.07.27"},{"content":"【老叶】拨打电话(未接通)","record_url":"","second":0,"imgs":[],"c_time":"2021.07.27"},{"content":"【老叶】拨打电话(未接通)","record_url":"","second":0,"imgs":[],"c_time":"2021.07.27"},{"content":"【lccsw】【lccsw】分配客户","record_url":"","second":0,"imgs":[],"c_time":"2021.07.22"},{"content":"【admin】后台分配","record_url":"","second":0,"imgs":[],"c_time":"2021.07.22"}],"total":7,"statistics":[{"name":"去电","val":5,"color":"#f3f6fc"},{"name":"短信","val":0,"color":"#fffaeb"},{"name":"到店","val":"0","color":"#f1f9f8"},{"name":"试驾","val":"0","color":"#fff6f8"}]},"msg":""}
let list = res.data.list
list.forEach(item => {
if(item.record_url){
item.alltime=this.format(item.second)
}
})
this.setData({
logslist:list,
})
innerAudioContext.onEnded(() => {
this.offaudio()
})
},
//生命周期函数--监听页面隐藏
onHide: function () {
this.offaudio()
},
//生命周期函数--监听页面卸载
onUnload: function () {
this.offaudio()
},
onShow(){
this.offaudio()
},
//时间格式话
format(t) {
let time = Math.floor(t / 60) >= 10 ? Math.floor(t / 60) : '0' + Math.floor(t / 60)
t = time + ':' + ((t % 60) / 100).toFixed(2).slice(-2)
return t
},
//点击
handle_slider_move_start(e){
clearTimeout(interval)
innerAudioContext.stop()
this.setData({
currentIndex:e.currentTarget.dataset.index,
play:false,
})
},
//拖动中
hanle_slider_changing(e){
clearTimeout(interval)
innerAudioContext.stop()
this.setData({
currentime:e.detail.value,
currentx:this.format(parseInt(e.detail.value))
})
innerAudioContext.src = this.data.logslist[e.currentTarget.dataset.index].record_url
},
//拖动结束
hanle_slider_change(e){
clearTimeout(interval)
innerAudioContext.stop()
this.setData({
currentime:e.detail.value,
currentx:this.format(parseInt(e.detail.value))
})
innerAudioContext.src = this.data.logslist[e.currentTarget.dataset.index].record_url
innerAudioContext.seek(parseInt(this.data.currentime))
},
//离开页面
offaudio() {
this.setData({
currentIndex:'-1',
play: false,
currentime:0,
currentx:'00:00'
})
innerAudioContext.stop()
clearTimeout(interval)
},
//操作录音
audioPlay: function (e) {
clearTimeout(interval)
if(this.data.currentIndex != e.currentTarget.dataset.index){
innerAudioContext.stop()
this.setData({
currentIndex:e.currentTarget.dataset.index,
currentime:0,
play:true,
})
innerAudioContext.src = this.data.logslist[e.currentTarget.dataset.index].record_url
innerAudioContext.play()
this.countDown()
}else{
if(this.data.play){
this.setData({
play:false,
})
innerAudioContext.pause()
}else{
this.setData({
play:true,
})
innerAudioContext.play()
this.countDown()
}
}
},
//播放录音时间
countDown:function () {
interval = setInterval(res => {
this.setData({
currentime:this.data.currentime + 1,
currentx:this.format(this.data.currentime + 1)
})
}, 1000)
},
})