OfficeApp/store/modules/config.js

61 lines
1.3 KiB
JavaScript
Raw Normal View History

import Cache from '@/utils/cache';
const state = {
2023-08-11 13:51:58 +08:00
eyeType: Cache.get('eyeType') || true, // 小眼睛
request: Cache.get('request') || true, // 网络请求
timer: [{
id: -1,
time: 60,
timer: null
}], //
};
const mutations = {
SET_EYE_TYPE(state){
state.eyeType=!state.eyeType;
Cache.set('eyeType', state.eyeType);
2023-08-05 15:16:05 +08:00
},
SET_REQUEST(state, data=true){
state.request = data;
Cache.set('request', state.request);
2023-08-11 13:51:58 +08:00
},
clearTimer(state, id){
let time = state.timer.find(item=>item.id==id);
clearInterval(time.timer);
time.timer = null;
time.time = 0;
}
};
const actions = {
2023-08-11 13:51:58 +08:00
startTimer({state, commit}, data){
let time = state.timer.find(item=>item.id==data.id);
if(time){
time.timer = setInterval(() => {
time.time--;
if (time.time <= 0) {
commit('clearTimer', data.id);
}
})
}else {
state.timer.push({
id: data.id,
time: data.time,
timer: null
})
let new_time = state.timer.find(item=>item.id==data.id);
new_time.timer = setInterval(() => {
new_time.time--;
if (new_time.time <= 0) {
commit('clearTimer', data.id);
}
}, 1000)
}
}
};
export default {
state,
mutations,
actions
};