This commit is contained in:
2026-03-27 16:56:26 +08:00
parent ffb4deefb9
commit 09d0113569
4 changed files with 30 additions and 12 deletions

View File

@@ -43,4 +43,23 @@ const router = new VueRouter({
routes 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 export default router

View File

@@ -43,20 +43,19 @@ export default {
getAisle({user_id:JSON.parse(localStorage.getItem('info')).ID}).then(res => { getAisle({user_id:JSON.parse(localStorage.getItem('info')).ID}).then(res => {
if(res.code === 0){ if(res.code === 0){
this.list = res.data.list this.list = res.data.list
console.log(this.list)
} }
}) })
}, },
formatDate (dateString){ formatDate (dateString){
if (!dateString) return ''; if (!dateString) return ''
const date = new Date(dateString); const date = new Date(dateString)
const year = date.getFullYear(); const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0'); const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0')
const hours = String(date.getHours()).padStart(2, '0'); const hours = String(date.getHours()).padStart(2, '0')
const minutes = String(date.getMinutes()).padStart(2, '0'); const minutes = String(date.getMinutes()).padStart(2, '0')
const seconds = String(date.getSeconds()).padStart(2, '0'); const seconds = String(date.getSeconds()).padStart(2, '0')
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
} }
} }
} }

View File

@@ -49,7 +49,7 @@ export default {
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.$message.success('退出登录成功'); this.$message.success('退出登录成功');
localStorage.setItem('info',{}) localStorage.setItem('info','')
this.$router.replace('/login') this.$router.replace('/login')
}).catch(() => { }).catch(() => {
// 取消退出 // 取消退出

View File

@@ -51,8 +51,8 @@ export default {
login({...params}).then((res) => { login({...params}).then((res) => {
if(res.code === 0){ if(res.code === 0){
this.$message.success('登录成功'); this.$message.success('登录成功');
this.$router.replace('/index')
localStorage.setItem('info',JSON.stringify(res.data)) localStorage.setItem('info',JSON.stringify(res.data))
this.$router.replace('/index')
}else { }else {
this.$message.error(res.msg || '请求失败'); this.$message.error(res.msg || '请求失败');
} }