From 25d79011dc1ea2101114da40af22528ca642a891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=94=A1=E7=8E=B2?= <8702040+cai-ling@user.noreply.gitee.com> Date: Fri, 20 Sep 2024 13:28:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BB=B6=E6=97=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 73 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/main.js b/main.js index e55b130..ad594bf 100644 --- a/main.js +++ b/main.js @@ -26,37 +26,64 @@ Vue.directive('enterNumber', { }); // 全局计时 +// Vue.prototype.$globalData = { +// timer: null, +// timerDuration: 20, // 假设是60秒 +// startTimer: function() { +// const self = this; +// self.timer = setInterval(function() { +// self.timerDuration--; +// console.log('剩余时间:' + self.timerDuration + '秒'); +// if (self.timerDuration <= 0) { +// clearInterval(self.timer); +// self.timerDuration = 20; +// console.log('计时器结束1'); +// uni.showModal({ +// title: '提示', +// showCancel: false, +// content: '路线锁定未释放,请操作完成再退出!', +// success: (res) => { +// if (res.confirm) { +// Vue.prototype.$globalData.startTimer() +// } +// } +// }) +// } +// }, 1000); +// }, +// stopTimer: function() { +// if (this.timer) { +// clearInterval(this.timer); +// console.log('计时器结束2'); +// this.timer = null; +// this.timerDuration = 20; +// } +// } +// }; Vue.prototype.$globalData = { timer: null, - timerDuration: 20, // 假设是60秒 startTimer: function() { const self = this; - self.timer = setInterval(function() { - self.timerDuration--; - console.log('剩余时间:' + self.timerDuration + '秒'); - if (self.timerDuration <= 0) { - clearInterval(self.timer); - self.timerDuration = 20; - console.log('计时器结束1'); - uni.showModal({ - title: '提示', - showCancel: false, - content: '路线锁定未释放,请操作完成再退出!', - success: (res) => { - if (res.confirm) { - Vue.prototype.$globalData.startTimer() - } - } - }) - } - }, 1000); + self.timer = setTimeout(function() { + clearTimeout(self.timer); + // console.log('延时器结束1'); + uni.showModal({ + title: '提示', + showCancel: false, + content: '路线锁定未释放,请操作完成再退出!', + success: (res) => { + if (res.confirm) { + Vue.prototype.$globalData.startTimer() + } + } + }) + }, 10000); }, stopTimer: function() { if (this.timer) { - clearInterval(this.timer); - console.log('计时器结束2'); + clearTimeout(this.timer); + // console.log('延时器结束2'); this.timer = null; - this.timerDuration = 20; } } };