Files
hht-ximenzi-uni/main.js
2024-09-20 11:24:16 +08:00

72 lines
1.6 KiB
JavaScript

import App from './App'
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
Vue.directive('enterNumber', {
inserted: function (el) {
el.addEventListener("keypress",function(e){
e = e || window.event;
let charcode = typeof e.charCode == 'number' ? e.charCode : e.keyCode;
// if (parseInt(e.target.value) == 0) {
// e.preventDefault();
// }
parseInt(e.target.value) == 0 && e.preventDefault();
let re = /\d/;
if(!re.test(String.fromCharCode(charcode)) && charcode > 9 && !e.ctrlKey){
if(e.preventDefault){
e.preventDefault();
}else{
e.returnValue = false;
}
}
});
}
});
// 全局计时
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;
}
}
};
import store from '@/vuex/store.js'
const app = new Vue({
...App,
store
})
app.$mount()