修改token保存方式

This commit is contained in:
2021-10-06 13:11:11 +08:00
parent d21f63d8f3
commit 28110bd884
5 changed files with 12 additions and 12 deletions
+3 -3
View File
@@ -75,14 +75,14 @@ export default class Home extends Vue{
this.openMenuNames.push(result[1])
}
}
if(!localStorage.getItem('login_token')) {
if(!this.$store.state.loginInfo.token) {
this.$router.push('/login')
return
}
const data = await this.$http.post<{token: null | string}, any>('/api/common/verifyToken', {token: localStorage.getItem('login_token')})
const data = await this.$http.post<{token: string}, any>('/api/common/verifyToken', {token: this.$store.state.loginInfo.token})
if(data.status) {
// 如果是已过期的token 服务端会签发新的token
this.$store.commit('login', {token: data.newToken || localStorage.getItem('login_token'), userInfo: data.userInfo})
this.$store.commit('login', {token: data.newToken || this.$store.state.loginInfo.token, userInfo: data.userInfo})
} else {
this.$router.push('/login')
}
+1 -1
View File
@@ -143,7 +143,7 @@ export default class SystemConfig extends Vue {
* @param dateStr 日期时间
*/
datetimeFormat(dateStr: string) {
return moment(dateStr).format('YYYY-MM-DD HH:mm:ss')
return dateStr ? moment(dateStr).format('YYYY-MM-DD HH:mm:ss') : null
}
}
</script>