feat(web): add login, auth store and router guard

This commit is contained in:
2026-07-07 15:25:47 +08:00
parent bcef04a8cc
commit e731ee7a2e
9 changed files with 227 additions and 1 deletions

View File

@@ -8,8 +8,19 @@ import Person from '../views/Person.vue'
import Tag from '../views/Tag.vue'
import SendRecord from '../views/SendRecord.vue'
import InboundFlow from '../views/InboundFlow.vue'
import FlowTrace from '../views/FlowTrace.vue'
import MessageTest from '../views/MessageTest.vue'
import TenantManagement from '../views/TenantManagement.vue'
import UserManagement from '../views/UserManagement.vue'
import Login from '../views/Login.vue'
import { useAuthStore } from '../stores/auth'
const routes = [
{
path: '/login',
component: Login,
meta: { public: true },
},
{
path: '/',
component: Layout,
@@ -23,6 +34,10 @@ const routes = [
{ path: 'tag', component: Tag, meta: { title: '标签' } },
{ path: 'send-record', component: SendRecord, meta: { title: '发送记录' } },
{ path: 'inbound-flow', component: InboundFlow, meta: { title: '入站流程' } },
{ path: 'flow-trace', component: FlowTrace, meta: { title: '流程追踪' } },
{ path: 'message-test', component: MessageTest, meta: { title: '消息测试' } },
{ path: 'tenant-management', component: TenantManagement, meta: { title: '租户管理' } },
{ path: 'user-management', component: UserManagement, meta: { title: '用户管理' } },
],
},
]
@@ -32,4 +47,17 @@ const router = createRouter({
routes,
})
router.beforeEach((to, from, next) => {
const authStore = useAuthStore()
const isPublic = to.meta?.public === true
if (!isPublic && !authStore.isLoggedIn) {
next('/login')
} else if (to.path === '/login' && authStore.isLoggedIn) {
next('/dashboard')
} else {
next()
}
})
export default router