118 lines
3.1 KiB
TypeScript
118 lines
3.1 KiB
TypeScript
import type { AppRouteRecordRaw, AppRouteModule } from '@jeesite/core/router/types';
|
|
|
|
import { PAGE_NOT_FOUND_ROUTE, REDIRECT_ROUTE } from '@jeesite/core/router/routes/basic';
|
|
import SCREEN_LAYOUT from '@jeesite/core/layouts/screen/index.vue';
|
|
|
|
import { mainOutRoutes } from './mainOut';
|
|
import { PageEnum } from '@jeesite/core/enums/pageEnum';
|
|
import { t } from '@jeesite/core/hooks/web/useI18n';
|
|
|
|
const modules = import.meta.glob('./modules/**/*.ts', { eager: true });
|
|
const bigScreenModules = import.meta.glob('../../layouts/screen/welcome/**/index.vue');
|
|
|
|
const routeModuleList: AppRouteModule[] = [];
|
|
|
|
Object.keys(modules).forEach((key) => {
|
|
const mod = (modules as Recordable)[key].default || {};
|
|
const modList = Array.isArray(mod) ? [...mod] : [mod];
|
|
routeModuleList.push(...modList);
|
|
});
|
|
|
|
export const asyncRoutes = [PAGE_NOT_FOUND_ROUTE, ...routeModuleList];
|
|
|
|
export const RootRoute: AppRouteRecordRaw = {
|
|
path: '/',
|
|
name: 'Root',
|
|
redirect: PageEnum.BASE_LOGIN,
|
|
meta: {
|
|
title: 'Root',
|
|
},
|
|
};
|
|
|
|
export const LoginRoute: AppRouteRecordRaw = {
|
|
path: '/login',
|
|
name: 'Login',
|
|
component: () => import('@jeesite/core/layouts/views/login/Login.vue'),
|
|
meta: {
|
|
title: t('routes.basic.login'),
|
|
},
|
|
};
|
|
|
|
const ModPwdRoute: AppRouteModule = {
|
|
path: '/modPwd',
|
|
name: 'ModPwd',
|
|
component: () => import('@jeesite/core/layouts/views/account/modPwd.vue'),
|
|
meta: {
|
|
icon: 'i-ant-design:key-outlined',
|
|
title: t('sys.account.modifyPwd'),
|
|
},
|
|
};
|
|
|
|
function toPascalCase(value: string) {
|
|
return value
|
|
.split(/[-_/]+/)
|
|
.filter(Boolean)
|
|
.map((item) => item.charAt(0).toUpperCase() + item.slice(1))
|
|
.join('');
|
|
}
|
|
|
|
function createBigScreenChildren(): AppRouteRecordRaw[] {
|
|
return Object.entries(bigScreenModules)
|
|
.map(([filePath, component]) => {
|
|
const matched = filePath.match(/screen\/welcome(?:\/([^/]+))?\/index\.vue$/);
|
|
if (!matched) return null;
|
|
|
|
const segment = matched[1]?.toLowerCase() || 'welcome';
|
|
|
|
return {
|
|
path: segment,
|
|
name: `Screen${toPascalCase(segment)}`,
|
|
component,
|
|
meta: {
|
|
title: t('routes.screen.bigScreen'),
|
|
},
|
|
} as AppRouteRecordRaw;
|
|
})
|
|
.filter((route): route is AppRouteRecordRaw => !!route)
|
|
.sort((a, b) => {
|
|
if (a.path === 'welcome') return -1;
|
|
if (b.path === 'welcome') return 1;
|
|
return a.path.localeCompare(b.path);
|
|
});
|
|
}
|
|
|
|
const bigScreenChildren = createBigScreenChildren();
|
|
|
|
const BigScreenRoute: AppRouteRecordRaw = {
|
|
path: '/bigScreen',
|
|
name: 'BigScreen',
|
|
component: SCREEN_LAYOUT,
|
|
redirect: `/bigScreen/${bigScreenChildren[0]?.path || 'welcome'}`,
|
|
meta: {
|
|
title: t('routes.screen.bigScreen'),
|
|
ignoreAuth: false,
|
|
},
|
|
children: [
|
|
...bigScreenChildren,
|
|
{
|
|
path: 'setting',
|
|
name: 'ScreenSetting',
|
|
component: () => import('@jeesite/core/layouts/screen/setting/index.vue'),
|
|
meta: {
|
|
title: t('routes.screen.bigSetting'),
|
|
},
|
|
},
|
|
],
|
|
};
|
|
|
|
// Basic routing without permission
|
|
export const basicRoutes = [
|
|
LoginRoute,
|
|
ModPwdRoute,
|
|
RootRoute,
|
|
BigScreenRoute,
|
|
...mainOutRoutes,
|
|
REDIRECT_ROUTE,
|
|
PAGE_NOT_FOUND_ROUTE,
|
|
];
|