vue-pro/yudao-vue-ui/App.vue

80 lines
1.7 KiB
Vue
Raw Normal View History

2021-11-24 23:33:06 +08:00
<script>
2021-11-26 09:47:23 +08:00
import Vue from 'vue'
import { getAuthToken } from '@/common/js/util.js'
let __timerId = 0;
2021-11-24 23:33:06 +08:00
export default {
2021-11-26 09:47:23 +08:00
onLaunch() {
uni.getSystemInfo({
success: e=> {
this.initSize(e);
}
})
this.initLogin();
2021-11-24 23:33:06 +08:00
},
2021-11-26 09:47:23 +08:00
methods: {
// 初始化登陆状态
async initLogin(){
const token = getAuthToken()
if (!token) {
return;
}
// 通过设置 Token 的方式,触发加载用户信息
this.$store.commit('setToken', {
token
});
},
/**
* 存储设备信息 参考colorUI
* @param {Object}
*/
initSize(e){
const systemInfo = e;
let navigationBarHeight;
let custom = {};
// #ifndef MP
custom = {height: 36,width: 88};
navigationBarHeight = 44;
// #endif
// #ifdef MP
custom = wx.getMenuButtonBoundingClientRect();
navigationBarHeight = custom.bottom + custom.top - e.statusBarHeight * 2;
// #endif
systemInfo.custom = custom;
systemInfo.navigationBarHeight = navigationBarHeight;
Vue.prototype.systemInfo = systemInfo;
},
//打开全局定时器
openTimer(){
this.closeTimer();
__timerId = setInterval(()=>{
this.$store.commit('setStateAttr', {
key: 'timerIdent',
val: !this.$store.state.timerIdent
})
}, 1000)
},
//关闭定时器
closeTimer(){
if(__timerId != 0){
clearInterval(__timerId);
__timerId = 0;
}
},
2021-11-24 23:33:06 +08:00
},
2021-11-26 09:47:23 +08:00
onShow() {
console.log('app show');
this.openTimer();
},
onHide() {
this.closeTimer();
2021-11-24 23:33:06 +08:00
}
}
</script>
2021-11-26 09:47:23 +08:00
<style lang="scss">
2021-11-24 23:33:06 +08:00
/*每个页面公共css */
2021-11-27 23:45:09 +08:00
@import "@/uni_modules/uview-ui/index.scss";
2021-11-24 23:33:06 +08:00
@import url("./common/css/common.css");
@import url("./common/css/icon.css");
2021-11-26 09:47:23 +08:00
</style>