feat: add @vben/hooks and @vben-core/constants

This commit is contained in:
vben
2024-07-13 16:52:08 +08:00
parent daa31f7156
commit 5e0b01c725
34 changed files with 161 additions and 44 deletions

View File

@@ -12,8 +12,7 @@ import { getAllMenus } from '#/apis';
import { BasicLayout, IFrameView } from '#/layouts';
import { $t } from '#/locales';
const forbiddenComponent = () =>
import('#/views/_essential/fallback/forbidden.vue');
const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue');
async function generateAccess(options: GenerateMenuAndRoutesOptions) {
const pageMap: ComponentRecordType = import.meta.glob('../views/**/*.vue');

View File

@@ -8,7 +8,7 @@ import { useTitle } from '@vueuse/core';
import { generateAccess } from '#/forward';
import { $t } from '#/locales';
import { dynamicRoutes, essentialsRouteNames } from '#/router/routes';
import { coreRouteNames, dynamicRoutes } from '#/router/routes';
import { useAccessStore } from '#/store';
/**
@@ -63,7 +63,7 @@ function setupAccessGuard(router: Router) {
if (!accessToken) {
if (
// 基本路由,这些路由不需要进入权限拦截
essentialsRouteNames.includes(to.name as string) ||
coreRouteNames.includes(to.name as string) ||
// 明确声明忽略权限访问权限,则可以访问
to.meta.ignoreAccess
) {

View File

@@ -4,11 +4,11 @@ import { DEFAULT_HOME_PATH } from '@vben/constants';
import { AuthPageLayout } from '#/layouts';
import { $t } from '#/locales';
import Login from '#/views/_essential/authentication/login.vue';
import Login from '#/views/_core/authentication/login.vue';
/** 全局404页面 */
const fallbackNotFoundRoute: RouteRecordRaw = {
component: () => import('#/views/_essential/fallback/not-found.vue'),
component: () => import('#/views/_core/fallback/not-found.vue'),
meta: {
hideInBreadcrumb: true,
hideInMenu: true,
@@ -20,7 +20,7 @@ const fallbackNotFoundRoute: RouteRecordRaw = {
};
/** 基本路由,这些路由是必须存在的 */
const essentialsRoutes: RouteRecordRaw[] = [
const coreRoutes: RouteRecordRaw[] = [
{
meta: {
title: 'Root',
@@ -42,47 +42,45 @@ const essentialsRoutes: RouteRecordRaw[] = [
path: 'login',
component: Login,
meta: {
title: $t('page.essentials.login'),
title: $t('page.core.login'),
},
},
{
name: 'CodeLogin',
path: 'code-login',
component: () =>
import('#/views/_essential/authentication/code-login.vue'),
component: () => import('#/views/_core/authentication/code-login.vue'),
meta: {
title: $t('page.essentials.codeLogin'),
title: $t('page.core.codeLogin'),
},
},
{
name: 'QrCodeLogin',
path: 'qrcode-login',
component: () =>
import('#/views/_essential/authentication/qrcode-login.vue'),
import('#/views/_core/authentication/qrcode-login.vue'),
meta: {
title: $t('page.essentials.qrcodeLogin'),
title: $t('page.core.qrcodeLogin'),
},
},
{
name: 'ForgetPassword',
path: 'forget-password',
component: () =>
import('#/views/_essential/authentication/forget-password.vue'),
import('#/views/_core/authentication/forget-password.vue'),
meta: {
title: $t('page.essentials.forgetPassword'),
title: $t('page.core.forgetPassword'),
},
},
{
name: 'Register',
path: 'register',
component: () =>
import('#/views/_essential/authentication/register.vue'),
component: () => import('#/views/_core/authentication/register.vue'),
meta: {
title: $t('page.essentials.register'),
title: $t('page.core.register'),
},
},
],
},
];
export { essentialsRoutes, fallbackNotFoundRoute };
export { coreRoutes, fallbackNotFoundRoute };

View File

@@ -3,7 +3,7 @@ import type { RouteRecordRaw } from 'vue-router';
import { traverseTreeValues } from '@vben/utils';
import { mergeRouteModules } from '@vben-core/helpers';
import { essentialsRoutes, fallbackNotFoundRoute } from './_essentials';
import { coreRoutes, fallbackNotFoundRoute } from './core';
const dynamicRouteFiles = import.meta.glob('./modules/**/*.ts', {
eager: true,
@@ -21,15 +21,12 @@ const staticRoutes: RouteRecordRaw[] = [];
/** 路由列表,由基本路由+静态路由组成 */
const routes: RouteRecordRaw[] = [
...essentialsRoutes,
...coreRoutes,
...staticRoutes,
fallbackNotFoundRoute,
];
/** 基本路由列表,这些路由不需要进入权限拦截 */
const essentialsRouteNames = traverseTreeValues(
essentialsRoutes,
(route) => route.name,
);
const coreRouteNames = traverseTreeValues(coreRoutes, (route) => route.name);
export { dynamicRoutes, essentialsRouteNames, routes };
export { coreRouteNames, dynamicRoutes, routes };

View File

@@ -141,8 +141,7 @@ const routes: RouteRecordRaw[] = [
{
name: 'Fallback403',
path: '403',
component: () =>
import('#/views/_essential/fallback/forbidden.vue'),
component: () => import('#/views/_core/fallback/forbidden.vue'),
meta: {
icon: 'mdi:do-not-disturb-alt',
title: '403',
@@ -151,8 +150,7 @@ const routes: RouteRecordRaw[] = [
{
name: 'Fallback404',
path: '404',
component: () =>
import('#/views/_essential/fallback/not-found.vue'),
component: () => import('#/views/_core/fallback/not-found.vue'),
meta: {
icon: 'mdi:table-off',
title: '404',
@@ -162,7 +160,7 @@ const routes: RouteRecordRaw[] = [
name: 'Fallback500',
path: '500',
component: () =>
import('#/views/_essential/fallback/internal-error.vue'),
import('#/views/_core/fallback/internal-error.vue'),
meta: {
icon: 'mdi:server-network-off',
title: '500',
@@ -171,7 +169,7 @@ const routes: RouteRecordRaw[] = [
{
name: 'FallbackOffline',
path: 'offline',
component: () => import('#/views/_essential/fallback/offline.vue'),
component: () => import('#/views/_core/fallback/offline.vue'),
meta: {
icon: 'mdi:offline',
title: $t('fallback.offline'),

View File

@@ -1,6 +1,6 @@
import type { RouteRecordRaw } from 'vue-router';
import { VBEN_GITHUB_URL, VBEN_LOGO } from '@vben/constants';
import { VBEN_GITHUB_URL, VBEN_LOGO_URL } from '@vben/constants';
import { BasicLayout, IFrameView } from '#/layouts';
import { $t } from '#/locales';
@@ -10,7 +10,7 @@ const routes: RouteRecordRaw[] = [
component: BasicLayout,
meta: {
badgeType: 'dot',
icon: VBEN_LOGO,
icon: VBEN_LOGO_URL,
order: 9999,
title: 'Vben Admin',
},
@@ -21,7 +21,7 @@ const routes: RouteRecordRaw[] = [
{
name: 'VbenAbout',
path: 'about',
component: () => import('#/views/_essential/vben/about/index.vue'),
component: () => import('#/views/_core/vben/about/index.vue'),
meta: {
badgeType: 'dot',
icon: 'mdi:creative-commons',

View File

@@ -1,3 +1,3 @@
# \_essential
# \_core
此目录包含应用程序正常运行所需的基本视图。这些视图是应用程序布局中使用的视图。