diff --git a/main.js b/main.js index 1abc647..e55b130 100644 --- a/main.js +++ b/main.js @@ -25,6 +25,42 @@ 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; + } + } +}; + import store from '@/vuex/store.js' const app = new Vue({ diff --git a/pages/home/home.vue b/pages/home/home.vue index bd23e43..f360ecb 100644 --- a/pages/home/home.vue +++ b/pages/home/home.vue @@ -64,10 +64,19 @@ }) }, Quit () { - this.$store.dispatch('delUserInfo', '') - uni.redirectTo({ - url: '/pages/login/login' - }) + if (this.$store.getters.routeStatus) { + uni.showModal({ + title: '提示', + showCancel: false, + content: '路线锁定未释放,请操作完成再退出!' + }) + return + } + this.$store.dispatch('delUserInfo', '') + this.$globalData.stopTimer() + uni.redirectTo({ + url: '/pages/login/login' + }) } } } diff --git a/pages/login/login.vue b/pages/login/login.vue index ad0aa59..7503cb5 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -53,6 +53,7 @@ this.versionCode = info.versionCode ; }) //#endif + this.$globalData.stopTimer() }, methods: { isUpdate () { diff --git a/pages/manage/route-lock.vue b/pages/manage/route-lock.vue index f1c06aa..d157405 100644 --- a/pages/manage/route-lock.vue +++ b/pages/manage/route-lock.vue @@ -28,6 +28,7 @@ import NavBar from '@/components/NavBar.vue' import SearchBox from '@/components/SearchBox.vue' import {updateRouteStatus} from '@/utils/getData2.js' + // import {updateRouteStatus} from '@/utils/mork2.js' export default { components: { NavBar, @@ -78,6 +79,14 @@ title: res.message, icon: 'none' }) + this.$globalData.stopTimer() + if (type === '1') { + this.$store.dispatch('setRouteStatus', true) + this.$globalData.startTimer() + } else { + this.$store.dispatch('delRouteStatus', false) + this.$globalData.stopTimer() + } } catch (e) { this.disabled = false } diff --git a/utils/mork2.js b/utils/mork2.js index 5b31319..27b9eef 100644 --- a/utils/mork2.js +++ b/utils/mork2.js @@ -19,4 +19,10 @@ export const fabOrders = (data) => { {order_code: '111'} ] return res +} +export const updateRouteStatus = (data) => { + let res = { + message: 'ok' + } + return res } \ No newline at end of file diff --git a/vuex/modules/data.js b/vuex/modules/data.js index e2914f9..48b6e11 100644 --- a/vuex/modules/data.js +++ b/vuex/modules/data.js @@ -1,11 +1,13 @@ import * as types from '../types' const state = { publicObj: '', - publicArr: '' + publicArr: '', + routeStatus: uni.getStorageSync('routeStatus') || false } const getters = { publicObj: state => state.publicObj, - publicArr: state => state.publicArr + publicArr: state => state.publicArr, + routeStatus: state => state.routeStatus } const actions = { setPublicObj ({commit}, res) { @@ -13,7 +15,15 @@ const actions = { }, setPublicArr ({commit}, res) { commit(types.PUBLIC_ARR, res) - } + }, + setRouteStatus ({commit}, res) { + uni.setStorageSync('routeStatus', res) + commit(types.SET_ROUTE_STATUS, res) + }, + delRouteStatus ({commit}, res) { + uni.removeStorageSync('routeStatus', res) + commit(types.DEL_ROUTE_STATUS, res) + }, } const mutations = { [types.PUBLIC_OBJ] (state, res) { @@ -21,6 +31,12 @@ const mutations = { }, [types.PUBLIC_ARR] (state, res) { state.publicArr = res + }, + [types.SET_ROUTE_STATUS] (state, res) { + state.routeStatus = res + }, + [types.DEL_ROUTE_STATUS] (state, res) { + state.routeStatus = res } } export default { diff --git a/vuex/types.js b/vuex/types.js index ee8a8f3..2b0d08d 100644 --- a/vuex/types.js +++ b/vuex/types.js @@ -12,4 +12,6 @@ export const SAVE_TOKEN = 'SAVE_TOKEN' * data */ export const PUBLIC_OBJ = 'PUBLIC_OBJ' -export const PUBLIC_ARR = 'PUBLIC_ARR' \ No newline at end of file +export const PUBLIC_ARR = 'PUBLIC_ARR' +export const SET_ROUTE_STATUS = 'SET_ROUTE_STATUS' +export const DEL_ROUTE_STATUS = 'DEL_ROUTE_STATUS' \ No newline at end of file