下一章 上一章 目录 设置
6、第 6 章 uniap ...
-
onLoad(option) {
this.name = option.name // 页面跳转带来的来电人姓名
this.city = option.city // 来电人城市
this.calling()
this.playLs();
},
onUnload() {
console.log(\"销毁页面\")
clearInterval(this.timer) // 清除来电震动定时器
clearInterval(this.phoneJs); // 清除通话时间定时器
this.ringToneContext.stop(); // 停止来电铃声
},
methods:{
// 挂电话
toback() {
console.log(\"拒绝\")
clearInterval(this.timer)
this.ringToneContext.stop()
uni.navigateBack()
},
// 接听电话
answerPhone() {
var n = this;
clearInterval(n.timer)
n.ringToneContext.stop()
n.callFlg = false
// n.timeJiShi()
n.phoneJs = setInterval(() => {
n.timerPhone++;
}, 1000);
},
// 结束通话
endCall() {
clearInterval(this.phoneJs);
uni.navigateBack()
},
// 调用微信震动
calling() {
this.timer = setInterval(function() {
uni.vibrateLong()
}, 2000);
},
// 播放铃声
playLs() {
var n = this;
n.ringToneContext = uni.createInnerAudioContext()
n.ringToneContext.src = n.ringSrc
n.ringToneContext.play()
n.ringToneContext.onEnded(function() {
n.playLs();
});
},
// 停止方法
stop() {
clearInterval(n);
},
}