perf: 合并用户平台框架修改
This commit is contained in:
@@ -5,6 +5,11 @@
|
||||
|
||||
import type { GeneratedRoute } from '@elegant-router/types';
|
||||
|
||||
/**
|
||||
* custom routes
|
||||
*
|
||||
* @link https://github.com/soybeanjs/elegant-router?tab=readme-ov-file#custom-route
|
||||
*/
|
||||
export const generatedRoutes: GeneratedRoute[] = [
|
||||
{
|
||||
name: '403',
|
||||
@@ -40,16 +45,42 @@ export const generatedRoutes: GeneratedRoute[] = [
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'about',
|
||||
path: '/about',
|
||||
component: 'layout.base$view.about',
|
||||
name: 'home',
|
||||
path: '/home',
|
||||
component: 'layout.base$view.home',
|
||||
meta: {
|
||||
title: 'about',
|
||||
i18nKey: 'route.about',
|
||||
icon: 'fluent:book-information-24-regular',
|
||||
order: 10
|
||||
title: 'home',
|
||||
i18nKey: 'route.home',
|
||||
icon: 'mdi:monitor-dashboard',
|
||||
order: 0,
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'login',
|
||||
path: '/login/:module(pwd-login|code-login|register|reset-pwd|bind-wechat)?',
|
||||
component: 'layout.blank$view._builtin_login',
|
||||
props: true,
|
||||
meta: {
|
||||
title: 'login',
|
||||
i18nKey: 'route.login',
|
||||
constant: true,
|
||||
hideInMenu: true
|
||||
}
|
||||
},
|
||||
// {
|
||||
// name: 'user-center',
|
||||
// path: '/user-center',
|
||||
// component: 'layout.base$view.user-center',
|
||||
// meta: {
|
||||
// title: 'user-center',
|
||||
// hideInMenu: true,
|
||||
// constant: true,
|
||||
// keepAlive: false,
|
||||
// i18nKey: 'route.user-center'
|
||||
// }
|
||||
// },
|
||||
|
||||
// 下面是指定角色才有
|
||||
{
|
||||
name: 'function',
|
||||
path: '/function',
|
||||
@@ -58,7 +89,8 @@ export const generatedRoutes: GeneratedRoute[] = [
|
||||
title: 'function',
|
||||
i18nKey: 'route.function',
|
||||
icon: 'icon-park-outline:all-application',
|
||||
order: 6
|
||||
order: 1002,
|
||||
roles: ['super']
|
||||
},
|
||||
children: [
|
||||
{
|
||||
@@ -141,7 +173,6 @@ export const generatedRoutes: GeneratedRoute[] = [
|
||||
i18nKey: 'route.function_super-page',
|
||||
icon: 'ic:round-supervisor-account',
|
||||
order: 5,
|
||||
roles: ['R_SUPER']
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -169,38 +200,89 @@ export const generatedRoutes: GeneratedRoute[] = [
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'home',
|
||||
path: '/home',
|
||||
component: 'layout.base$view.home',
|
||||
name: 'about',
|
||||
path: '/about',
|
||||
component: 'layout.base$view.about',
|
||||
meta: {
|
||||
title: 'home',
|
||||
i18nKey: 'route.home',
|
||||
icon: 'mdi:monitor-dashboard',
|
||||
order: 1
|
||||
title: 'about',
|
||||
i18nKey: 'route.about',
|
||||
icon: 'fluent:book-information-24-regular',
|
||||
order: 1003,
|
||||
roles: ['super']
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'login',
|
||||
path: '/login/:module(pwd-login|code-login|register|reset-pwd|bind-wechat)?',
|
||||
component: 'layout.blank$view._builtin_login',
|
||||
props: true,
|
||||
meta: {
|
||||
title: 'login',
|
||||
i18nKey: 'route.login',
|
||||
constant: true,
|
||||
hideInMenu: true
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'user-center',
|
||||
path: '/user-center',
|
||||
component: 'layout.base$view.user-center',
|
||||
meta: {
|
||||
title: 'user-center',
|
||||
hideInMenu: true,
|
||||
constant: true,
|
||||
keepAlive: false,
|
||||
i18nKey: 'route.user-center'
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
/**自定义静态菜单 */
|
||||
export const customRoutes: GeneratedRoute[] = [
|
||||
{
|
||||
name: 'endpoint',
|
||||
path: '/endpoint',
|
||||
component: 'layout.base',
|
||||
meta: {
|
||||
title: '终端设备',
|
||||
i18nKey: 'view.endpoint',
|
||||
icon: 'icon-park-outline:all-application',
|
||||
order: 11,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
name: 'endpoint_access',
|
||||
path: '/endpoint/access',
|
||||
component: 'view.endpoint_access',
|
||||
meta: {
|
||||
title: '当前',
|
||||
i18nKey: 'view.endpoint_access',
|
||||
icon: 'material-symbols:filter-list-off',
|
||||
order: 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'endpoint_records',
|
||||
path: '/endpoint/records',
|
||||
component: 'view.endpoint_records',
|
||||
meta: {
|
||||
title: '历史',
|
||||
i18nKey: 'view.endpoint_records',
|
||||
icon: 'ic:round-supervisor-account',
|
||||
order: 3,
|
||||
}
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'billing',
|
||||
path: '/billing',
|
||||
component: 'layout.base',
|
||||
meta: {
|
||||
title: '账单',
|
||||
i18nKey: 'view.billing',
|
||||
icon: 'icon-park-outline:all-application',
|
||||
order: 13,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
name: 'billing_histories',
|
||||
path: '/billing/histories',
|
||||
component: 'view.billing_histories',
|
||||
meta: {
|
||||
title: '历史查询',
|
||||
i18nKey: 'view.billing_histories',
|
||||
icon: 'material-symbols:filter-list-off',
|
||||
order: 2
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'set-meal',
|
||||
path: '/set-meal',
|
||||
component: 'layout.base$view.set-meal',
|
||||
meta: {
|
||||
title: '套餐',
|
||||
i18nKey: 'view.set-meal',
|
||||
icon: 'icon-park-outline:all-application',
|
||||
order: 15,
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// Generated by elegant-router
|
||||
// Read more: https://github.com/soybeanjs/elegant-router
|
||||
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
import type { ElegantConstRoute } from '@elegant-router/vue';
|
||||
import type { RouteKey, RouteMap, RoutePath } from '@elegant-router/types';
|
||||
import type {RouteRecordRaw} from 'vue-router';
|
||||
import type {ElegantConstRoute} from '@elegant-router/vue';
|
||||
import type {RouteKey, RouteMap} from '@elegant-router/types';
|
||||
import BaseLayout from '@/layouts/base-layout/index.vue';
|
||||
import BlankLayout from '@/layouts/blank-layout/index.vue';
|
||||
|
||||
@@ -84,14 +84,14 @@ function transformElegantRouteToVueRoute(
|
||||
route.props = true;
|
||||
}
|
||||
|
||||
const { name, path, component, children, ...rest } = route;
|
||||
const {name, path, component, children, ...rest} = route;
|
||||
|
||||
const vueRoute = { name, path, ...rest } as RouteRecordRaw;
|
||||
const vueRoute = {name, path, ...rest} as RouteRecordRaw;
|
||||
|
||||
try {
|
||||
if (component) {
|
||||
if (isSingleLevelRoute(route)) {
|
||||
const { layout, view } = getSingleLevelRouteComponent(component);
|
||||
const {layout, view} = getSingleLevelRouteComponent(component);
|
||||
|
||||
const singleLevelRoute: RouteRecordRaw = {
|
||||
path,
|
||||
@@ -208,18 +208,5 @@ const routeMap: RouteMap = {
|
||||
* @param name route name
|
||||
*/
|
||||
export function getRoutePath<T extends RouteKey>(name: T) {
|
||||
console.log(name);
|
||||
return routeMap[name];
|
||||
}
|
||||
|
||||
/**
|
||||
* get route name by route path
|
||||
* @param path route path
|
||||
*/
|
||||
export function getRouteName(path: RoutePath) {
|
||||
const routeEntries = Object.entries(routeMap) as [RouteKey, RoutePath][];
|
||||
|
||||
const routeName: RouteKey | null = routeEntries.find(([, routePath]) => routePath === path)?.[0] || null;
|
||||
|
||||
return routeName;
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ export function createRouteGuard(router: Router) {
|
||||
const needLogin = !to.meta.constant;
|
||||
const routeRoles = to.meta.roles || [];
|
||||
|
||||
// const hasRole = authStore.userInfo.roles?.some(role => routeRoles.includes(role));
|
||||
const hasAuth = authStore.isStaticSuper || !routeRoles.length;
|
||||
const hasRole = authStore.userInfo.roles?.some(role => routeRoles.includes(role));
|
||||
const hasAuth = !routeRoles.length || hasRole
|
||||
|
||||
const routeSwitches: CommonType.StrategicPattern[] = [
|
||||
// if it is login route when logged in, then switch to the root page
|
||||
|
||||
@@ -1,57 +1,6 @@
|
||||
import type { ElegantConstRoute } from '@elegant-router/types';
|
||||
import { generatedRoutes } from '../elegant/routes';
|
||||
import { transformElegantRoutesToVueRoutes } from '../elegant/transform';
|
||||
|
||||
/**
|
||||
* custom routes
|
||||
*
|
||||
* @link https://github.com/soybeanjs/elegant-router?tab=readme-ov-file#custom-route
|
||||
*/
|
||||
const customRoutes: any[] = [
|
||||
{
|
||||
name: 'exception',
|
||||
path: '/exception',
|
||||
component: 'layout.base',
|
||||
meta: {
|
||||
title: 'exception',
|
||||
i18nKey: 'route.exception',
|
||||
icon: 'ant-design:exception-outlined',
|
||||
order: 7
|
||||
},
|
||||
children: [
|
||||
{
|
||||
name: 'exception_403',
|
||||
path: '/exception/403',
|
||||
component: 'view._builtin_403',
|
||||
meta: {
|
||||
title: 'exception_403',
|
||||
i18nKey: 'route.exception_403',
|
||||
icon: 'ic:baseline-block'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'exception_404',
|
||||
path: '/exception/404',
|
||||
component: 'view._builtin_404',
|
||||
meta: {
|
||||
title: 'exception_404',
|
||||
i18nKey: 'route.exception_404',
|
||||
icon: 'ic:baseline-web-asset-off'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'exception_500',
|
||||
path: '/exception/500',
|
||||
component: 'view._builtin_500',
|
||||
meta: {
|
||||
title: 'exception_500',
|
||||
i18nKey: 'route.exception_500',
|
||||
icon: 'ic:baseline-wifi-off'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
import type {ElegantConstRoute} from '@elegant-router/types';
|
||||
import {customRoutes, generatedRoutes} from '../elegant/routes';
|
||||
import {transformElegantRoutesToVueRoutes} from '../elegant/transform';
|
||||
|
||||
/** create routes when the auth route mode is static */
|
||||
export function createStaticRoutes() {
|
||||
@@ -59,7 +8,7 @@ export function createStaticRoutes() {
|
||||
|
||||
const authRoutes: any[] = [];
|
||||
|
||||
[...customRoutes, ...generatedRoutes].forEach(item => {
|
||||
[...generatedRoutes, ...customRoutes].forEach(item => {
|
||||
if (item.meta?.constant) {
|
||||
constantRoutes.push(item);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user