瀏覽代碼

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

vben 8 月之前
父節點
當前提交
5e0b01c725
共有 34 個文件被更改,包括 161 次插入44 次删除
  1. 1 2
      apps/web-antd/src/forward/access.ts
  2. 2 2
      apps/web-antd/src/router/guard.ts
  3. 13 15
      apps/web-antd/src/router/routes/core.ts
  4. 4 7
      apps/web-antd/src/router/routes/index.ts
  5. 4 6
      apps/web-antd/src/router/routes/modules/demos.ts
  6. 3 3
      apps/web-antd/src/router/routes/modules/vben.ts
  7. 1 1
      apps/web-antd/src/views/_core/README.md
  8. 0 0
      apps/web-antd/src/views/_core/authentication/code-login.vue
  9. 0 0
      apps/web-antd/src/views/_core/authentication/forget-password.vue
  10. 0 0
      apps/web-antd/src/views/_core/authentication/login.vue
  11. 0 0
      apps/web-antd/src/views/_core/authentication/qrcode-login.vue
  12. 0 0
      apps/web-antd/src/views/_core/authentication/register.vue
  13. 0 0
      apps/web-antd/src/views/_core/fallback/coming-soon.vue
  14. 0 0
      apps/web-antd/src/views/_core/fallback/forbidden.vue
  15. 0 0
      apps/web-antd/src/views/_core/fallback/internal-error.vue
  16. 0 0
      apps/web-antd/src/views/_core/fallback/not-found.vue
  17. 0 0
      apps/web-antd/src/views/_core/fallback/offline.vue
  18. 0 0
      apps/web-antd/src/views/_core/vben/about/index.vue
  19. 1 1
      packages/@core/locales/src/langs/en-US.json
  20. 1 1
      packages/@core/locales/src/langs/zh-CN.json
  21. 7 0
      packages/@core/shared/constants/build.config.ts
  22. 38 0
      packages/@core/shared/constants/package.json
  23. 3 2
      packages/@core/shared/constants/src/index.ts
  24. 6 0
      packages/@core/shared/constants/tsconfig.json
  25. 1 1
      packages/@core/shared/typings/src/index.ts
  26. 3 0
      packages/constants/package.json
  27. 0 0
      packages/constants/src/core.ts
  28. 2 2
      packages/constants/src/index.ts
  29. 7 0
      packages/hooks/build.config.ts
  30. 40 0
      packages/hooks/package.json
  31. 1 0
      packages/hooks/src/index.ts
  32. 6 0
      packages/hooks/tsconfig.json
  33. 9 1
      pnpm-lock.yaml
  34. 8 0
      vben-admin.code-workspace

+ 1 - 2
apps/web-antd/src/forward/access.ts

@@ -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');

+ 2 - 2
apps/web-antd/src/router/guard.ts

@@ -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
       ) {

+ 13 - 15
apps/web-antd/src/router/routes/_essentials.ts → apps/web-antd/src/router/routes/core.ts

@@ -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 };

+ 4 - 7
apps/web-antd/src/router/routes/index.ts

@@ -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 };

+ 4 - 6
apps/web-antd/src/router/routes/modules/demos.ts

@@ -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'),

+ 3 - 3
apps/web-antd/src/router/routes/modules/vben.ts

@@ -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',

+ 1 - 1
apps/web-antd/src/views/_essential/README.md → apps/web-antd/src/views/_core/README.md

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

+ 0 - 0
apps/web-antd/src/views/_essential/authentication/code-login.vue → apps/web-antd/src/views/_core/authentication/code-login.vue


+ 0 - 0
apps/web-antd/src/views/_essential/authentication/forget-password.vue → apps/web-antd/src/views/_core/authentication/forget-password.vue


+ 0 - 0
apps/web-antd/src/views/_essential/authentication/login.vue → apps/web-antd/src/views/_core/authentication/login.vue


+ 0 - 0
apps/web-antd/src/views/_essential/authentication/qrcode-login.vue → apps/web-antd/src/views/_core/authentication/qrcode-login.vue


+ 0 - 0
apps/web-antd/src/views/_essential/authentication/register.vue → apps/web-antd/src/views/_core/authentication/register.vue


+ 0 - 0
apps/web-antd/src/views/_essential/fallback/coming-soon.vue → apps/web-antd/src/views/_core/fallback/coming-soon.vue


+ 0 - 0
apps/web-antd/src/views/_essential/fallback/forbidden.vue → apps/web-antd/src/views/_core/fallback/forbidden.vue


+ 0 - 0
apps/web-antd/src/views/_essential/fallback/internal-error.vue → apps/web-antd/src/views/_core/fallback/internal-error.vue


+ 0 - 0
apps/web-antd/src/views/_essential/fallback/not-found.vue → apps/web-antd/src/views/_core/fallback/not-found.vue


+ 0 - 0
apps/web-antd/src/views/_essential/fallback/offline.vue → apps/web-antd/src/views/_core/fallback/offline.vue


+ 0 - 0
apps/web-antd/src/views/_essential/vben/about/index.vue → apps/web-antd/src/views/_core/vben/about/index.vue


+ 1 - 1
packages/@core/locales/src/langs/en-US.json

@@ -1,6 +1,6 @@
 {
   "page": {
-    "essentials": {
+    "core": {
       "login": "Login",
       "register": "Register",
       "codeLogin": "Code Login",

+ 1 - 1
packages/@core/locales/src/langs/zh-CN.json

@@ -1,6 +1,6 @@
 {
   "page": {
-    "essentials": {
+    "core": {
       "login": "登陆",
       "register": "注册",
       "codeLogin": "验证码登陆",

+ 7 - 0
packages/@core/shared/constants/build.config.ts

@@ -0,0 +1,7 @@
+import { defineBuildConfig } from 'unbuild';
+
+export default defineBuildConfig({
+  clean: true,
+  declaration: true,
+  entries: ['src/index'],
+});

+ 38 - 0
packages/@core/shared/constants/package.json

@@ -0,0 +1,38 @@
+{
+  "name": "@vben-core/constants",
+  "version": "5.0.0",
+  "homepage": "https://github.com/vbenjs/vue-vben-admin",
+  "bugs": "https://github.com/vbenjs/vue-vben-admin/issues",
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/vbenjs/vue-vben-admin.git",
+    "directory": "packages/@vben-core/shared/constants"
+  },
+  "license": "MIT",
+  "type": "module",
+  "scripts": {
+    "build": "pnpm unbuild",
+    "stub": "pnpm unbuild --stub"
+  },
+  "files": [
+    "dist"
+  ],
+  "sideEffects": false,
+  "main": "./dist/index.mjs",
+  "module": "./dist/index.mjs",
+  "exports": {
+    ".": {
+      "types": "./src/index.ts",
+      "development": "./src/index.ts",
+      "default": "./dist/index.mjs"
+    }
+  },
+  "publishConfig": {
+    "exports": {
+      ".": {
+        "types": "./dist/index.d.ts",
+        "default": "./dist/index.mjs"
+      }
+    }
+  }
+}

+ 3 - 2
packages/constants/src/vben.ts → packages/@core/shared/constants/src/index.ts

@@ -6,6 +6,7 @@ const VBEN_GITHUB_URL = 'https://github.com/vbenjs/vue-vben-admin';
 /**
  * @zh_CN Vben Logo
  */
-const VBEN_LOGO =
+const VBEN_LOGO_URL =
   'https://cdn.jsdelivr.net/npm/@vbenjs/static-source@0.1.3/source/logo-v1.webp';
-export { VBEN_GITHUB_URL, VBEN_LOGO };
+
+export { VBEN_GITHUB_URL, VBEN_LOGO_URL };

+ 6 - 0
packages/@core/shared/constants/tsconfig.json

@@ -0,0 +1,6 @@
+{
+  "$schema": "https://json.schemastore.org/tsconfig",
+  "extends": "@vben/tsconfig/library.json",
+  "include": ["src"],
+  "exclude": ["node_modules"]
+}

+ 1 - 1
packages/@core/shared/typings/src/index.ts

@@ -1,5 +1,5 @@
 export type * from './app';
-export * from './basic';
+export type * from './basic';
 export type * from './helper';
 export type * from './menu-record';
 export type * from './tabs';

+ 3 - 0
packages/constants/package.json

@@ -36,5 +36,8 @@
         "default": "./dist/index.mjs"
       }
     }
+  },
+  "dependencies": {
+    "@vben-core/constants": "workspace:*"
   }
 }

+ 0 - 0
packages/constants/src/_essentials.ts → packages/constants/src/core.ts


+ 2 - 2
packages/constants/src/index.ts

@@ -1,2 +1,2 @@
-export * from './_essentials';
-export * from './vben';
+export * from './core';
+export * from '@vben-core/constants';

+ 7 - 0
packages/hooks/build.config.ts

@@ -0,0 +1,7 @@
+import { defineBuildConfig } from 'unbuild';
+
+export default defineBuildConfig({
+  clean: true,
+  declaration: true,
+  entries: ['src/index'],
+});

+ 40 - 0
packages/hooks/package.json

@@ -0,0 +1,40 @@
+{
+  "name": "@vben/hooks",
+  "version": "5.0.0",
+  "homepage": "https://github.com/vbenjs/vue-vben-admin",
+  "bugs": "https://github.com/vbenjs/vue-vben-admin/issues",
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/vbenjs/vue-vben-admin.git",
+    "directory": "packages/hooks"
+  },
+  "license": "MIT",
+  "type": "module",
+  "scripts": {
+    "build": "pnpm unbuild",
+    "stub": "pnpm unbuild --stub"
+  },
+  "files": [
+    "dist"
+  ],
+  "sideEffects": [
+    "**/*.css"
+  ],
+  "main": "./dist/index.mjs",
+  "module": "./dist/index.mjs",
+  "exports": {
+    ".": {
+      "types": "./src/index.ts",
+      "development": "./src/index.ts",
+      "default": "./dist/index.mjs"
+    }
+  },
+  "publishConfig": {
+    "exports": {
+      ".": {
+        "types": "./dist/index.d.ts",
+        "default": "./dist/index.mjs"
+      }
+    }
+  }
+}

+ 1 - 0
packages/hooks/src/index.ts

@@ -0,0 +1 @@
+export {};

+ 6 - 0
packages/hooks/tsconfig.json

@@ -0,0 +1,6 @@
+{
+  "$schema": "https://json.schemastore.org/tsconfig",
+  "extends": "@vben/tsconfig/library.json",
+  "include": ["src"],
+  "exclude": ["node_modules"]
+}

+ 9 - 1
pnpm-lock.yaml

@@ -639,6 +639,8 @@ importers:
         specifier: ^9.13.1
         version: 9.13.1(vue@3.4.31(typescript@5.5.3))
 
+  packages/@core/shared/constants: {}
+
   packages/@core/shared/design:
     dependencies:
       modern-normalize:
@@ -908,7 +910,13 @@ importers:
         specifier: ^1.5.5
         version: 1.5.5
 
-  packages/constants: {}
+  packages/constants:
+    dependencies:
+      '@vben-core/constants':
+        specifier: workspace:*
+        version: link:../@core/shared/constants
+
+  packages/hooks: {}
 
   packages/icons:
     dependencies:

+ 8 - 0
vben-admin.code-workspace

@@ -64,6 +64,10 @@
       "name": "@vben-core/locales",
       "path": "packages/@core/locales",
     },
+    {
+      "name": "@vben-core/constants",
+      "path": "packages/@core/shared/constants",
+    },
     {
       "name": "@vben-core/design",
       "path": "packages/@core/shared/design",
@@ -116,6 +120,10 @@
       "name": "@vben/constants",
       "path": "packages/constants",
     },
+    {
+      "name": "@vben/hooks",
+      "path": "packages/hooks",
+    },
     {
       "name": "@vben/icons",
       "path": "packages/icons",