routes.ts 3.2 KB
import { setupLayouts } from 'virtual:meta-layouts'
import generatedRoutes from 'virtual:generated-pages'
import type { RouteRecordRaw } from 'vue-router'
import DataAssess from './modules/dataAsset';

import type { Route } from '#/global'
import useSettingsStore from '@/store/modules/settings'

/** 路由配置的meta信息接口注释。 */
interface metaInfoRaw {
  // 是否使用keepAlive缓存,大部分页面都要用。
  cache: boolean;
  /** 若是菜单第一级节点需要配置false,下级节点,不需要配置,默认为true. */
  sidebar: boolean;
  /** 是否是编辑页面,若是编辑页面,则叉掉,会提示当前修改尚未保存,是否确认关闭。 */
  editPage: boolean;
  /** 有些页面,需要根据不同的参数即fullPath来判断是否缓存,如详情页面,查看日志信息等,需要配置为true。 */
  reuse: boolean;
}

// 固定路由(默认路由)
const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/login-zgsjzc',
    name: 'login',
    component: () => import('@/views/login.vue'),
    meta: {
      title: '登录',
    },
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('@/views/register.vue'),
    meta: {
      title: '注册',
    },
  },
  {
    path: '/:all(.*)*',
    name: 'notFound',
    component: () => import('@/views/[...all].vue'),
    meta: {
      title: '数据资产管理',
    },
  },
]

// 系统路由
const systemRoutes: RouteRecordRaw[] = [
  {
    path: '/',
    component: () => import('@/layouts/index.vue'),
    meta: {
      title: () => useSettingsStore().settings.home.title,
      breadcrumb: false,
    },
    children: [
      // {
      //   path: 'login',
      //   name: 'login',
      //   component: () => import('@/views/login.vue'),
      //   meta: {
      //     title: () => useSettingsStore().settings.home.title,
      //     breadcrumb: false,
      //   },
      // },
      {
        path: 'reload',
        name: 'reload',
        component: () => import('@/views/reload.vue'),
        meta: {
          title: '重新加载',
          breadcrumb: false,
        },
      },
      {
        path: 'setting',
        name: 'personalSetting',
        component: () => import('@/views/personal/setting.vue'),
        meta: {
          title: '个人设置',
          cache: 'personalEditPassword',
        },
      },
      {
        path: 'edit/password',
        name: 'personalEditPassword',
        component: () => import('@/views/personal/edit.password.vue'),
        meta: {
          title: '修改密码',
        },
      },
    ],
  },
]

// 动态路由(异步路由、导航栏路由)
const asyncRoutes: Route.recordMainRaw[] = [
  {
    meta: {
      title: '数据资产管理',
    },
    children: [
      ...DataAssess,
    ],
  },
]

const constantRoutesByFilesystem = generatedRoutes.filter((item) => {
  return item.meta?.enabled !== false && item.meta?.constant === true
})

const asyncRoutesByFilesystem = setupLayouts(generatedRoutes.filter((item) => {
  return item.meta?.enabled !== false && item.meta?.constant !== true && item.meta?.layout !== false
}))

export {
  constantRoutes,
  systemRoutes,
  asyncRoutes,
  constantRoutesByFilesystem,
  asyncRoutesByFilesystem,
}