完善
This commit is contained in:
@@ -43,4 +43,23 @@ const router = new VueRouter({
|
||||
routes
|
||||
})
|
||||
|
||||
// 路由守卫
|
||||
router.beforeEach((to, from, next) => {
|
||||
// 登录页面不需要验证
|
||||
if (to.path === '/login') {
|
||||
next()
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否已登录
|
||||
const userInfo = localStorage.getItem('info')
|
||||
if (userInfo) {
|
||||
// 已登录,继续导航
|
||||
next()
|
||||
} else {
|
||||
// 未登录,重定向到登录页面
|
||||
next('/login')
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -43,20 +43,19 @@ export default {
|
||||
getAisle({user_id:JSON.parse(localStorage.getItem('info')).ID}).then(res => {
|
||||
if(res.code === 0){
|
||||
this.list = res.data.list
|
||||
console.log(this.list)
|
||||
}
|
||||
})
|
||||
},
|
||||
formatDate (dateString){
|
||||
if (!dateString) return '';
|
||||
const date = new Date(dateString);
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
if (!dateString) return ''
|
||||
const date = new Date(dateString)
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
const hours = String(date.getHours()).padStart(2, '0')
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0')
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0')
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ export default {
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
this.$message.success('退出登录成功');
|
||||
localStorage.setItem('info',{})
|
||||
localStorage.setItem('info','')
|
||||
this.$router.replace('/login')
|
||||
}).catch(() => {
|
||||
// 取消退出
|
||||
|
||||
@@ -51,8 +51,8 @@ export default {
|
||||
login({...params}).then((res) => {
|
||||
if(res.code === 0){
|
||||
this.$message.success('登录成功');
|
||||
this.$router.replace('/index')
|
||||
localStorage.setItem('info',JSON.stringify(res.data))
|
||||
this.$router.replace('/index')
|
||||
}else {
|
||||
this.$message.error(res.msg || '请求失败');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user