You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.4 KiB
Vue

2 years ago
<script>
import {
mapState,
mapActions
} from 'vuex';
2 years ago
// import {
// amsGetPort,
// } from '@/common/js/api/vas/ams.js'
2 years ago
export default {
globalData: {
latitude: '',
longitude: '',
version: '',
city:'',
cityCode:'',
isLogin: true,
safeAreaBottom: '',
2 years ago
safeAreaWidth: uni.getSystemInfoSync().safeArea.width,
2 years ago
},
onLaunch: function() {
this.checkToken();
2 years ago
// this.amsGetPort();
2 years ago
console.log('App Launch')
},
onShow: function() {
this.$scope.globalData.safeAreaBottom = uni.getSystemInfoSync().safeArea.bottom - uni.getSystemInfoSync().safeArea.height - 20;
2 years ago
},
onHide: function() {
console.log('App Hide')
},
methods:{
...mapActions([
2 years ago
'setUserInfo',
'setDischargePort',
'setDischargePortVal',
]),
checkToken(){
2 years ago
const tokenStartTime = uni.getStorageSync('tokenStartTime');
const userToken = uni.getStorageSync('userToken');
let date = new Date().getTime()
2 years ago
if(date - tokenStartTime >= 0 || !tokenStartTime || !userToken) {
2 years ago
console.log('token已过期');
this.$scope.globalData.isLogin = false;
uni.removeStorageSync('userToken')
uni.removeStorageSync('tokenStartTime');
this.loginReset();
}else{
this.getUserInfo();
}
2 years ago
},
loginReset(){
let LoginName = uni.getStorageSync('LoginName');
let Password = uni.getStorageSync('Password');
if(LoginName && Password){
LoginName = this.Base64deCode(LoginName)
Password = this.Base64deCode(Password)
2 years ago
this.$util.loginFun(LoginName,Password).then(res=>{
let time = new Date().getTime() + res.data.expiresIn*1000
uni.setStorageSync('userToken', res.data.token);
uni.setStorageSync('tokenStartTime', time);
this.getUserInfo(LoginName,Password);
})
}
},
getUserInfo(LoginName,Password){
this.$util.getUserInfoFun(LoginName,Password).then(res=>{
getApp().globalData.isLogin = true;
this.setUserInfo(res.data);
})
},
Base64deCode(text){
let Base64 = require('@/js_sdk/js-base64').Base64
return Base64.decode(text)
},
2 years ago
2 years ago
// amsGetPort(){
// amsGetPort().then(res =>{
// if(res.code == 200){
// this.setDischargePort(res.result);
// let arr = res.result.map((item,index)=>{return item.value});
// this.setDischargePortVal(arr)
// }
// })
// },
2 years ago
},
2 years ago
}
</script>
2 years ago
<style lang="less">
@import "common/css/common.less";
2 years ago
@import url('@/common/css/font/iconfont.css');
2 years ago
</style>