20260810172235
This commit is contained in:
1 parent
c4891538a7
commit
ed5ab3885d
35 files changed
+1314
-653
No files matched your search
@@ -1,14 +1,11 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import NProgress from 'nprogress'
|
||||
import 'nprogress/nprogress.css'
|
||||
import DefaultLayout from '@/layouts/DefaultLayout.vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { usePermissionStore } from '@/stores/permissions'
|
||||
|
||||
const PlaceholderPage = () => import('@/views/base/PlaceholderPage.vue')
|
||||
|
||||
// Demo pages
|
||||
const TablePage = () => import('@/views/demo/TableDemo.vue')
|
||||
const FormPage = () => import('@/views/demo/FormDemo.vue')
|
||||
const CardPage = () => import('@/views/demo/CardDemo.vue')
|
||||
const SettingsPage = () => import('@/views/demo/SettingsDemo.vue')
|
||||
NProgress.configure({ showSpinner: false })
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
@@ -16,7 +13,7 @@ const router = createRouter({
|
||||
{
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
component: () => import('@/views/login/LoginView.vue'),
|
||||
component: () => import('@/views/login/index.vue'),
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
@@ -30,73 +27,49 @@ const router = createRouter({
|
||||
component: () => import('@/views/dashboard/index.vue'),
|
||||
meta: { title: '工作台' },
|
||||
},
|
||||
// Demo pages
|
||||
{
|
||||
path: '/demo/table',
|
||||
name: 'demo-table',
|
||||
component: TablePage,
|
||||
meta: { title: '表格示例', section: 'Demo 页面' },
|
||||
},
|
||||
{
|
||||
path: '/demo/form',
|
||||
name: 'demo-form',
|
||||
component: FormPage,
|
||||
meta: { title: '表单示例', section: 'Demo 页面' },
|
||||
},
|
||||
{
|
||||
path: '/demo/cards',
|
||||
name: 'demo-cards',
|
||||
component: CardPage,
|
||||
meta: { title: '卡片示例', section: 'Demo 页面' },
|
||||
},
|
||||
{
|
||||
path: '/demo/settings',
|
||||
name: 'demo-settings',
|
||||
component: SettingsPage,
|
||||
meta: { title: '设置示例', section: 'Demo 页面' },
|
||||
},
|
||||
// Business pages
|
||||
// Base
|
||||
{
|
||||
path: '/base/othercompany',
|
||||
name: 'base-othercompany',
|
||||
component: PlaceholderPage,
|
||||
meta: { title: '合作伙伴' },
|
||||
component: () => import('@/views/base/OtherCompanyPage.vue'),
|
||||
meta: { title: '合作伙伴', moduleId: 'v_b_othercompany' },
|
||||
},
|
||||
{
|
||||
path: '/base/contact',
|
||||
name: 'base-contact',
|
||||
component: PlaceholderPage,
|
||||
meta: { title: '联系人' },
|
||||
component: () => import('@/views/base/ContactPage.vue'),
|
||||
meta: { title: '联系人', moduleId: 'v_b_contact' },
|
||||
},
|
||||
{
|
||||
path: '/base/otherdata',
|
||||
name: 'base-otherdata',
|
||||
component: PlaceholderPage,
|
||||
meta: { title: '其他数据' },
|
||||
component: () => import('@/views/base/OtherDataPage.vue'),
|
||||
meta: { title: '其他数据', moduleId: 'v_b_otherdata' },
|
||||
},
|
||||
// System
|
||||
{
|
||||
path: '/system/module-management',
|
||||
name: 'system-module-management',
|
||||
component: PlaceholderPage,
|
||||
meta: { title: '模块管理' },
|
||||
component: () => import('@/views/system/ModuleManagementPage.vue'),
|
||||
meta: { title: '模块管理', moduleId: 'm_metadata' },
|
||||
},
|
||||
{
|
||||
path: '/system/i18n-type',
|
||||
name: 'system-i18n-type',
|
||||
component: PlaceholderPage,
|
||||
meta: { title: '多语言类型' },
|
||||
component: () => import('@/views/system/I18nTypePage.vue'),
|
||||
meta: { title: '多语言类型', moduleId: 'm_i18n' },
|
||||
},
|
||||
{
|
||||
path: '/system/login-log',
|
||||
name: 'system-login-log',
|
||||
component: PlaceholderPage,
|
||||
meta: { title: '登录日志' },
|
||||
component: () => import('@/views/system/LoginLogPage.vue'),
|
||||
meta: { title: '登录日志', moduleId: 'd_login_log' },
|
||||
},
|
||||
{
|
||||
path: '/system/user',
|
||||
name: 'system-user',
|
||||
component: PlaceholderPage,
|
||||
meta: { title: '用户管理' },
|
||||
component: () => import('@/views/system/UserPage.vue'),
|
||||
meta: { title: '用户管理', moduleId: 'b_user' },
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -107,8 +80,9 @@ const router = createRouter({
|
||||
],
|
||||
})
|
||||
|
||||
// Auth guard
|
||||
router.beforeEach((to) => {
|
||||
// Auth + permission guard
|
||||
router.beforeEach(async (to) => {
|
||||
NProgress.start()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
if (to.path === '/login') {
|
||||
@@ -120,7 +94,21 @@ router.beforeEach((to) => {
|
||||
if (!authStore.isAuthenticated) {
|
||||
return { path: '/login', query: { redirect: to.fullPath } }
|
||||
}
|
||||
|
||||
// Permission check
|
||||
const moduleId = (to.meta as { moduleId?: string }).moduleId
|
||||
if (moduleId) {
|
||||
const permissionStore = usePermissionStore()
|
||||
await permissionStore.load()
|
||||
if (!permissionStore.canAccess(moduleId)) {
|
||||
return '/dashboard'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
router.afterEach(() => {
|
||||
NProgress.done()
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in new issue
Block a user