277bada3 by 任超

session

1 parent 6fa7dc2d
......@@ -21,25 +21,25 @@
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
import { getSession } from '@/utils/session'
// import { getSession } from '@/utils/session'
export default {
components: {
Breadcrumb,
Hamburger
},
created () {
this.init();
// this.init();
},
computed: {
...mapGetters(['sidebar', 'avatar', 'name'])
},
methods: {
init () {
let userInfo = getSession('userInfo');
if (userInfo && userInfo.userValid === 0) {
this.userValid = 0;
}
},
// init () {
// let userInfo = getSession('userInfo');
// if (userInfo && userInfo.userValid === 0) {
// this.userValid = 0;
// }
// },
toggleSideBar () {
this.$store.dispatch('app/toggleSideBar')
},
......
// setSession
export function setSession (key, value, time) {
time = time ? Date.parse(new Date()) + time * 1000 * 60 : null
let params = {
value: value,
time: time ? time : null
}
window.sessionStorage.setItem(key, JSON.stringify(params))
}
// getSession
export function getSession (key) {
let params = window.sessionStorage.getItem(key)
if (!params) return null
params = JSON.parse(params)
if (params.time) {
if (params.time > Date.parse(new Date)) {
return params.value
}
window.sessionStorage.removeItem(key)
return null
}
return params.value
}
export function removeSession (key) {
return sessionStorage.removeItem(key)
}
\ No newline at end of file