diff --git a/.changeset/config.json b/.changeset/config.json index 7f769543..f954fb4b 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -11,7 +11,7 @@ }, "privatePackages": { "version": true, "tag": true }, "linked": [], - "access": "restricted", + "access": "public", "baseBranch": "main", "updateInternalDependencies": "patch", "ignore": [] diff --git a/.github/workflows/action-build.yml b/.github/workflows/action-build.yml index 55fcadf7..b1820591 100644 --- a/.github/workflows/action-build.yml +++ b/.github/workflows/action-build.yml @@ -45,5 +45,5 @@ jobs: - name: Test and Build run: | - pnpm run test + pnpm run test:unit pnpm run build diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da7758a5..e308ec57 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,7 +68,7 @@ jobs: # run: git config --global user.email "you@example.com" && git config --global user.name "Your Name" - name: Vitest tests - run: pnpm run test + run: pnpm run test:unit # - name: Upload coverage # uses: codecov/codecov-action@v4 diff --git a/.ls-lint.yml b/.ls-lint.yml index 63d6b761..7f8b7ce6 100644 --- a/.ls-lint.yml +++ b/.ls-lint.yml @@ -7,7 +7,7 @@ ls: .css: kebab-case | pointcase .d.ts: kebab-case | pointcase # shadcn 自动生成文件为 PascalCase 格式 - packages/@vben-core/ui-kit/shadcn-ui/src/components/ui: + packages/@core/ui-kit/shadcn-ui/src/components/ui: .vue: PascalCase ignore: @@ -25,3 +25,4 @@ ignore: - .vscode - .idea - node_modules + - .cache diff --git a/.vscode/settings.json b/.vscode/settings.json index ffba678d..9b97c9e2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -71,7 +71,8 @@ "**/CVS": true, "**/.stylelintcache": true, "**/.DS_Store": true, - "**/vite.config.mts.*": true + "**/vite.config.mts.*": true, + "**/tea.yaml": true }, "files.watcherExclude": { "**/.git/objects/**": true, @@ -190,7 +191,7 @@ "eslint.config.mjs": ".eslintignore,.prettierignore,.stylelintignore,.commitlintrc.*,.prettierrc.*,stylelint.config.*,.lintstagedrc.mjs,.ls-lint*,cspell.json", "tailwind.config.mjs": "postcss.*" }, - "commentTranslate.hover.enabled": true, + "commentTranslate.hover.enabled": false, "i18n-ally.keystyle": "nested", "commentTranslate.multiLineMerge": true } diff --git a/LICENSE b/LICENSE index a4a2fe5c..cec5b427 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024-present, Vben Admin +Copyright (c) 2024-present, Vben Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index f2119b6a..a33ae3e2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![license](https://img.shields.io/github/license/anncwb/vue-vben-admin.svg)](LICENSE) -

Vue vben admin

+

Vue Vben Admin

**English** | [中文](./README.zh-CN.md) diff --git a/apps/backend-mock/middleware/1.api.ts b/apps/backend-mock/middleware/1.api.ts new file mode 100644 index 00000000..315d7e0c --- /dev/null +++ b/apps/backend-mock/middleware/1.api.ts @@ -0,0 +1,14 @@ +export default defineEventHandler((event) => { + // setResponseHeaders(event, { + // 'Access-Control-Allow-Credentials': 'true', + // 'Access-Control-Allow-Headers': '*', + // 'Access-Control-Allow-Methods': 'GET,HEAD,PUT,PATCH,POST,DELETE', + // 'Access-Control-Allow-Origin': '*', + // 'Access-Control-Expose-Headers': '*', + // }); + if (event.method === 'OPTIONS') { + event.node.res.statusCode = 204; + event.node.res.statusMessage = 'No Content.'; + return 'OK'; + } +}); diff --git a/apps/backend-mock/nitro.config.ts b/apps/backend-mock/nitro.config.ts index 76b12dc1..b3013298 100644 --- a/apps/backend-mock/nitro.config.ts +++ b/apps/backend-mock/nitro.config.ts @@ -3,4 +3,16 @@ import errorHandler from './error'; export default defineNitroConfig({ devErrorHandler: errorHandler, errorHandler: '~/error', + routeRules: { + '/api/**': { + cors: true, + headers: { + 'Access-Control-Allow-Credentials': 'true', + 'Access-Control-Allow-Headers': '*', + 'Access-Control-Allow-Methods': 'GET,HEAD,PUT,PATCH,POST,DELETE', + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Expose-Headers': '*', + }, + }, + }, }); diff --git a/apps/backend-mock/utils/mock-data.ts b/apps/backend-mock/utils/mock-data.ts index 10076ac9..46c0e5a2 100644 --- a/apps/backend-mock/utils/mock-data.ts +++ b/apps/backend-mock/utils/mock-data.ts @@ -80,8 +80,8 @@ const createDemosMenus = (role: 'admin' | 'super' | 'user') => { icon: 'mdi:button-cursor', title: 'page.demos.access.adminVisible', }, - name: 'AccessAdminVisible', - path: 'admin-visible', + name: 'AccessAdminVisibleDemo', + path: '/demos/access/admin-visible', }, super: { component: '/demos/access/super-visible', @@ -89,8 +89,8 @@ const createDemosMenus = (role: 'admin' | 'super' | 'user') => { icon: 'mdi:button-cursor', title: 'page.demos.access.superVisible', }, - name: 'AccessSuperVisible', - path: 'super-visible', + name: 'AccessSuperVisibleDemo', + path: '/demos/access/super-visible', }, user: { component: '/demos/access/user-visible', @@ -98,8 +98,8 @@ const createDemosMenus = (role: 'admin' | 'super' | 'user') => { icon: 'mdi:button-cursor', title: 'page.demos.access.userVisible', }, - name: 'AccessUserVisible', - path: 'user-visible', + name: 'AccessUserVisibleDemo', + path: '/demos/access/user-visible', }, }; @@ -117,8 +117,8 @@ const createDemosMenus = (role: 'admin' | 'super' | 'user') => { redirect: '/demos/access', children: [ { - name: 'Access', - path: 'access', + name: 'AccessDemos', + path: '/demosaccess', meta: { icon: 'mdi:cloud-key-outline', title: 'page.demos.access.backendPermissions', @@ -126,8 +126,8 @@ const createDemosMenus = (role: 'admin' | 'super' | 'user') => { redirect: '/demos/access/page-control', children: [ { - name: 'AccessPageControl', - path: 'page-control', + name: 'AccessPageControlDemo', + path: '/demos/access/page-control', component: '/demos/access/index', meta: { icon: 'mdi:page-previous-outline', @@ -135,8 +135,8 @@ const createDemosMenus = (role: 'admin' | 'super' | 'user') => { }, }, { - name: 'AccessButtonControl', - path: 'button-control', + name: 'AccessButtonControlDemo', + path: '/demos/access/button-control', component: '/demos/access/button-control', meta: { icon: 'mdi:button-cursor', @@ -144,8 +144,8 @@ const createDemosMenus = (role: 'admin' | 'super' | 'user') => { }, }, { - name: 'AccessMenuVisible403', - path: 'menu-visible-403', + name: 'AccessMenuVisible403Demo', + path: '/demos/access/menu-visible-403', component: '/demos/access/menu-visible-403', meta: { authority: ['no-body'], diff --git a/apps/web-antd/.env b/apps/web-antd/.env index 5a7032d4..57000a52 100644 --- a/apps/web-antd/.env +++ b/apps/web-antd/.env @@ -1,6 +1,5 @@ -VITE_PORT = 5555 +# 应用标题 +VITE_GLOB_APP_TITLE=Vben Admin -# spa-title -VITE_GLOB_APP_TITLE = Vben Admin - -VITE_APP_NAMESPACE = web-antd +# 应用命名空间,用于缓存、store等功能的前缀,确保隔离 +VITE_APP_NAMESPACE=vben-web-antd diff --git a/apps/web-antd/.env.analyze b/apps/web-antd/.env.analyze index f367addb..ffafa8dd 100644 --- a/apps/web-antd/.env.analyze +++ b/apps/web-antd/.env.analyze @@ -1,8 +1,7 @@ - # public path -VITE_PUBLIC_PATH = / +VITE_BASE=/ # Basic interface address SPA VITE_GLOB_API_URL=/api -VITE_VISUALIZER = true +VITE_VISUALIZER=true diff --git a/apps/web-antd/.env.development b/apps/web-antd/.env.development index 447b41c4..dcf361e7 100644 --- a/apps/web-antd/.env.development +++ b/apps/web-antd/.env.development @@ -1,5 +1,16 @@ -VITE_PUBLIC_PATH = / +# 端口号 +VITE_PORT=5555 +VITE_BASE=/ + +# 接口地址 VITE_GLOB_API_URL=/api -VITE_NITRO_MOCK = true +# 是否开启 Nitro Mock服务,true 为开启,false 为关闭 +VITE_NITRO_MOCK=true + +# 是否打开 devtools,true 为打开,false 为关闭 +VITE_DEVTOOLS=false + +# 是否注入全局loading +VITE_INJECT_APP_LOADING=true diff --git a/apps/web-antd/.env.production b/apps/web-antd/.env.production index 209bd7a0..ce8f5503 100644 --- a/apps/web-antd/.env.production +++ b/apps/web-antd/.env.production @@ -1,9 +1,16 @@ -# public path -VITE_PUBLIC_PATH = / +VITE_BASE=/ -# Basic interface address SPA -VITE_GLOB_API_URL = https://mock-napi.vben.pro/api +# 接口地址 +VITE_GLOB_API_URL=https://mock-napi.vben.pro/api -VITE_COMPRESS = gzip +# 是否开启压缩,可以设置为 none, brotli, gzip +VITE_COMPRESS=gzip -VITE_PWA = false +# 是否开启 PWA +VITE_PWA=false + +# vue-router 的模式 +VITE_ROUTER_HISTORY=hash + +# 是否注入全局loading +VITE_INJECT_APP_LOADING=true diff --git a/apps/web-antd/index.html b/apps/web-antd/index.html index 64c4ff88..01d77c1e 100644 --- a/apps/web-antd/index.html +++ b/apps/web-antd/index.html @@ -14,6 +14,19 @@ <%= VITE_GLOB_APP_TITLE %> +
diff --git a/apps/web-antd/package.json b/apps/web-antd/package.json index b970d8ca..38a7cd8f 100644 --- a/apps/web-antd/package.json +++ b/apps/web-antd/package.json @@ -44,7 +44,7 @@ "ant-design-vue": "^4.2.3", "dayjs": "^1.11.12", "pinia": "2.1.7", - "vue": "^3.4.33", + "vue": "^3.4.34", "vue-router": "^4.4.0" } } diff --git a/apps/web-antd/src/api/core/auth.ts b/apps/web-antd/src/api/core/auth.ts new file mode 100644 index 00000000..6950e3bf --- /dev/null +++ b/apps/web-antd/src/api/core/auth.ts @@ -0,0 +1,33 @@ +import { requestClient } from '#/api/request'; + +export namespace AuthApi { + /** 登录接口参数 */ + export interface LoginParams { + password: string; + username: string; + } + + /** 登录接口返回值 */ + export interface LoginResult { + accessToken: string; + desc: string; + realName: string; + refreshToken: string; + userId: string; + username: string; + } +} + +/** + * 登录 + */ +export async function login(data: AuthApi.LoginParams) { + return requestClient.post('/auth/login', data); +} + +/** + * 获取用户权限码 + */ +export async function getAccessCodes() { + return requestClient.get('/auth/codes'); +} diff --git a/apps/web-antd/src/apis/core/index.ts b/apps/web-antd/src/api/core/index.ts similarity index 100% rename from apps/web-antd/src/apis/core/index.ts rename to apps/web-antd/src/api/core/index.ts diff --git a/apps/web-antd/src/apis/core/menu.ts b/apps/web-antd/src/api/core/menu.ts similarity index 81% rename from apps/web-antd/src/apis/core/menu.ts rename to apps/web-antd/src/api/core/menu.ts index 57088aca..62c40f17 100644 --- a/apps/web-antd/src/apis/core/menu.ts +++ b/apps/web-antd/src/api/core/menu.ts @@ -1,6 +1,6 @@ import type { RouteRecordStringComponent } from '@vben/types'; -import { requestClient } from '#/apis/request'; +import { requestClient } from '#/api/request'; /** * 获取用户所有菜单 diff --git a/apps/web-antd/src/apis/core/user.ts b/apps/web-antd/src/api/core/user.ts similarity index 77% rename from apps/web-antd/src/apis/core/user.ts rename to apps/web-antd/src/api/core/user.ts index 5eecf0bd..34c14ea9 100644 --- a/apps/web-antd/src/apis/core/user.ts +++ b/apps/web-antd/src/api/core/user.ts @@ -1,6 +1,6 @@ import type { UserInfo } from '@vben/types'; -import { requestClient } from '#/apis/request'; +import { requestClient } from '#/api/request'; /** * 获取用户信息 diff --git a/apps/web-antd/src/apis/demos/index.ts b/apps/web-antd/src/api/demos/index.ts similarity index 100% rename from apps/web-antd/src/apis/demos/index.ts rename to apps/web-antd/src/api/demos/index.ts diff --git a/apps/web-antd/src/apis/demos/status.ts b/apps/web-antd/src/api/demos/status.ts similarity index 78% rename from apps/web-antd/src/apis/demos/status.ts rename to apps/web-antd/src/api/demos/status.ts index 7da2d49c..daa3d638 100644 --- a/apps/web-antd/src/apis/demos/status.ts +++ b/apps/web-antd/src/api/demos/status.ts @@ -1,4 +1,4 @@ -import { requestClient } from '#/apis/request'; +import { requestClient } from '#/api/request'; /** * 模拟任意状态码 diff --git a/apps/web-antd/src/apis/index.ts b/apps/web-antd/src/api/index.ts similarity index 62% rename from apps/web-antd/src/apis/index.ts rename to apps/web-antd/src/api/index.ts index 911672b7..2b42e898 100644 --- a/apps/web-antd/src/apis/index.ts +++ b/apps/web-antd/src/api/index.ts @@ -1,3 +1,2 @@ export * from './core'; export * from './demos'; -export type * from './types'; diff --git a/apps/web-antd/src/apis/request.ts b/apps/web-antd/src/api/request.ts similarity index 78% rename from apps/web-antd/src/apis/request.ts rename to apps/web-antd/src/api/request.ts index f56ba744..817d0d6d 100644 --- a/apps/web-antd/src/apis/request.ts +++ b/apps/web-antd/src/api/request.ts @@ -3,6 +3,7 @@ */ import type { HttpResponse } from '@vben/request'; +import { useAppConfig } from '@vben/hooks'; import { preferences } from '@vben/preferences'; import { RequestClient } from '@vben/request'; @@ -10,13 +11,11 @@ import { message } from 'ant-design-vue'; import { useAccessStore } from '#/store'; -/** - * 创建请求实例 - * Create a request instance - */ -function createRequestClient() { +const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD); + +function createRequestClient(baseURL: string) { const client = new RequestClient({ - baseURL: import.meta.env.VITE_GLOB_API_URL, + baseURL, // 为每个请求携带 Authorization makeAuthorization: () => { return { @@ -43,6 +42,13 @@ function createRequestClient() { }; }, makeErrorMessage: (msg) => message.error(msg), + + makeRequestHeaders: () => { + return { + // 为每个请求携带 Accept-Language + 'Accept-Language': preferences.app.locale, + }; + }, }); client.addResponseInterceptor((response) => { const { data: responseData, status } = response; @@ -56,9 +62,4 @@ function createRequestClient() { return client; } -const requestClient = createRequestClient(); - -// 其他配置的请求方法 -// const { request: xxxRequest } = createRequest(); - -export { requestClient }; +export const requestClient = createRequestClient(apiURL); diff --git a/apps/web-antd/src/apis/core/auth.ts b/apps/web-antd/src/apis/core/auth.ts deleted file mode 100644 index 227d0f2a..00000000 --- a/apps/web-antd/src/apis/core/auth.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { UserApi } from '../types'; - -import { requestClient } from '#/apis/request'; - -/** - * 登录 - */ -export async function login(data: UserApi.LoginParams) { - return requestClient.post('/auth/login', data); -} - -/** - * 获取用户权限码 - */ -export async function getAccessCodes() { - return requestClient.get('/auth/codes'); -} diff --git a/apps/web-antd/src/apis/types/index.ts b/apps/web-antd/src/apis/types/index.ts deleted file mode 100644 index d20c6861..00000000 --- a/apps/web-antd/src/apis/types/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type * from './user'; diff --git a/apps/web-antd/src/apis/types/user.ts b/apps/web-antd/src/apis/types/user.ts deleted file mode 100644 index 6c49df91..00000000 --- a/apps/web-antd/src/apis/types/user.ts +++ /dev/null @@ -1,19 +0,0 @@ -namespace UserApi { - /** 登录接口参数 */ - export interface LoginParams { - password: string; - username: string; - } - - /** 登录接口返回值 */ - export interface LoginResult { - accessToken: string; - desc: string; - realName: string; - refreshToken: string; - userId: string; - username: string; - } -} - -export type { UserApi }; diff --git a/apps/web-antd/src/bootstrap.ts b/apps/web-antd/src/bootstrap.ts index 607f7fa7..8141e95f 100644 --- a/apps/web-antd/src/bootstrap.ts +++ b/apps/web-antd/src/bootstrap.ts @@ -1,10 +1,9 @@ import { createApp } from 'vue'; -import { preferences } from '@vben/preferences'; import '@vben/styles'; import '@vben/styles/antd'; -import { loadMessages, setupI18n } from '#/locales'; +import { setupI18n } from '#/locales'; import { setupStore } from '#/store'; import App from './app.vue'; @@ -14,11 +13,7 @@ async function bootstrap(namespace: string) { const app = createApp(App); // 国际化 i18n 配置 - await setupI18n(app, { - defaultLocale: preferences.app.locale, - loadMessages, - missingWarn: !import.meta.env.PROD, - }); + await setupI18n(app); // 配置 pinia-store await setupStore(app, { namespace }); diff --git a/apps/web-antd/src/locales/index.ts b/apps/web-antd/src/locales/index.ts index 11438544..a3e23661 100644 --- a/apps/web-antd/src/locales/index.ts +++ b/apps/web-antd/src/locales/index.ts @@ -1,9 +1,11 @@ -import type { SupportedLanguagesType } from '@vben/types'; +import type { LocaleSetupOptions, SupportedLanguagesType } from '@vben/locales'; import type { Locale } from 'ant-design-vue/es/locale'; +import type { App } from 'vue'; import { ref } from 'vue'; -import { $t, loadLocalesMap, setupI18n } from '@vben/locales'; +import { $t, setupI18n as coreSetup, loadLocalesMap } from '@vben/locales'; +import { preferences } from '@vben/preferences'; import antdEnLocale from 'ant-design-vue/es/locale/en_US'; import antdDefaultLocale from 'ant-design-vue/es/locale/zh_CN'; @@ -76,4 +78,13 @@ async function loadAntdLocale(lang: SupportedLanguagesType) { } } +async function setupI18n(app: App, options: LocaleSetupOptions = {}) { + await coreSetup(app, { + defaultLocale: preferences.app.locale, + loadMessages, + missingWarn: !import.meta.env.PROD, + ...options, + }); +} + export { $t, antdLocale, loadMessages, setupI18n }; diff --git a/apps/web-antd/src/locales/langs/en-US.json b/apps/web-antd/src/locales/langs/en-US.json index 014aabaa..6b1d636e 100644 --- a/apps/web-antd/src/locales/langs/en-US.json +++ b/apps/web-antd/src/locales/langs/en-US.json @@ -33,11 +33,17 @@ "text": "Text Badge", "color": "Badge Color" }, + "activeIcon": { + "title": "Active Menu Icon", + "children": "Children Active Icon" + }, "fallback": { "title": "Fallback Page" }, "features": { "title": "Features", "hideChildrenInMenu": "Hide Menu Children", "loginExpired": "Login Expired", + "icons": "Icons", + "watermark": "Watermark", "tabs": "Tabs", "tabDetail": "Tab Detail Page" }, diff --git a/apps/web-antd/src/locales/langs/zh-CN.json b/apps/web-antd/src/locales/langs/zh-CN.json index 08b3fa1f..0ce11b74 100644 --- a/apps/web-antd/src/locales/langs/zh-CN.json +++ b/apps/web-antd/src/locales/langs/zh-CN.json @@ -33,6 +33,10 @@ "text": "文本徽标", "color": "徽标颜色" }, + "activeIcon": { + "title": "菜单激活图标", + "children": "子级激活图标" + }, "fallback": { "title": "缺省页" }, @@ -40,6 +44,8 @@ "title": "功能", "hideChildrenInMenu": "隐藏子菜单", "loginExpired": "登录过期", + "icons": "图标", + "watermark": "水印", "tabs": "标签页", "tabDetail": "标签详情页" }, diff --git a/apps/web-antd/src/main.ts b/apps/web-antd/src/main.ts index 89d7b2cd..dedabbcb 100644 --- a/apps/web-antd/src/main.ts +++ b/apps/web-antd/src/main.ts @@ -1,3 +1,4 @@ +import { unmountGlobalLoading } from '@vben/hooks'; import { initPreferences } from '@vben/preferences'; import { overridesPreferences } from './preferences'; @@ -9,7 +10,8 @@ async function initApplication() { // name用于指定项目唯一标识 // 用于区分不同项目的偏好设置以及存储数据的key前缀以及其他一些需要隔离的数据 const env = import.meta.env.PROD ? 'prod' : 'dev'; - const namespace = `${import.meta.env.VITE_APP_NAMESPACE}-${env}`; + const appVersion = import.meta.env.VITE_APP_VERSION; + const namespace = `${import.meta.env.VITE_APP_NAMESPACE}-${appVersion}-${env}`; // app偏好设置初始化 await initPreferences({ @@ -23,38 +25,7 @@ async function initApplication() { await bootstrap(namespace); // 移除并销毁loading - destroyAppLoading(); -} - -/** - * 移除并销毁loading - * 放在这里是而不是放在 index.html 的app标签内,是因为这样比较不会生硬,渲染过快可能会有闪烁 - * 通过先添加css动画隐藏,在动画结束后在移除loading节点来改善体验 - * 不好的地方是会增加一些代码量 - */ -function destroyAppLoading() { - // 查找全局 loading 元素 - const loadingElement = document.querySelector('#__app-loading__'); - - if (loadingElement) { - // 添加隐藏类,触发过渡动画 - loadingElement.classList.add('hidden'); - - // 查找所有需要移除的注入 loading 元素 - const injectLoadingElements = document.querySelectorAll( - '[data-app-loading^="inject"]', - ); - - // 当过渡动画结束时,移除 loading 元素和所有注入的 loading 元素 - loadingElement.addEventListener( - 'transitionend', - () => { - loadingElement.remove(); // 移除 loading 元素 - injectLoadingElements.forEach((el) => el.remove()); // 移除所有注入的 loading 元素 - }, - { once: true }, - ); // 确保事件只触发一次 - } + unmountGlobalLoading(); } initApplication(); diff --git a/apps/web-antd/src/preferences.ts b/apps/web-antd/src/preferences.ts index 9683596a..e8607fbd 100644 --- a/apps/web-antd/src/preferences.ts +++ b/apps/web-antd/src/preferences.ts @@ -1,9 +1,15 @@ +import { useAppConfig } from '@vben/hooks'; import { defineOverridesPreferences } from '@vben/preferences'; +const { appTitle } = useAppConfig(import.meta.env, import.meta.env.PROD); + /** * @description 项目配置文件 * 只需要覆盖项目中的一部分配置,不需要的配置不用覆盖,会自动使用默认配置 */ export const overridesPreferences = defineOverridesPreferences({ // overrides + app: { + name: appTitle, + }, }); diff --git a/apps/web-antd/src/router/access.ts b/apps/web-antd/src/router/access.ts index b2a0a4f8..251db72f 100644 --- a/apps/web-antd/src/router/access.ts +++ b/apps/web-antd/src/router/access.ts @@ -8,7 +8,7 @@ import { preferences } from '@vben/preferences'; import { message } from 'ant-design-vue'; -import { getAllMenus } from '#/apis'; +import { getAllMenus } from '#/api'; import { BasicLayout, IFrameView } from '#/layouts'; import { $t } from '#/locales'; diff --git a/apps/web-antd/src/router/index.ts b/apps/web-antd/src/router/index.ts index bddd05c3..0c9d2c4a 100644 --- a/apps/web-antd/src/router/index.ts +++ b/apps/web-antd/src/router/index.ts @@ -1,6 +1,10 @@ import type { RouteRecordName, RouteRecordRaw } from 'vue-router'; -import { createRouter, createWebHashHistory } from 'vue-router'; +import { + createRouter, + createWebHashHistory, + createWebHistory, +} from 'vue-router'; import { traverseTreeValues } from '@vben/utils'; @@ -11,11 +15,14 @@ import { routes } from './routes'; * @zh_CN 创建vue-router实例 */ const router = createRouter({ - history: createWebHashHistory(import.meta.env.VITE_PUBLIC_PATH), + history: + import.meta.env.VITE_ROUTER_HISTORY === 'hash' + ? createWebHashHistory(import.meta.env.VITE_BASE) + : createWebHistory(import.meta.env.VITE_BASE), // 应该添加到路由的初始路由列表。 routes, scrollBehavior: () => ({ left: 0, top: 0 }), - // 是否应该禁止尾部斜杠。默认为假 + // 是否应该禁止尾部斜杠。 // strict: true, }); diff --git a/apps/web-antd/src/router/routes/modules/dashboard.ts b/apps/web-antd/src/router/routes/modules/dashboard.ts index 123bdbeb..a8cdb05d 100644 --- a/apps/web-antd/src/router/routes/modules/dashboard.ts +++ b/apps/web-antd/src/router/routes/modules/dashboard.ts @@ -13,11 +13,10 @@ const routes: RouteRecordRaw[] = [ }, name: 'Dashboard', path: '/', - redirect: '/analytics', children: [ { name: 'Analytics', - path: 'analytics', + path: '/analytics', component: () => import('#/views/dashboard/analytics/index.vue'), meta: { affixTab: true, @@ -27,7 +26,7 @@ const routes: RouteRecordRaw[] = [ }, { name: 'Workspace', - path: 'workspace', + path: '/workspace', component: () => import('#/views/dashboard/workspace/index.vue'), meta: { title: $t('page.dashboard.workspace'), diff --git a/apps/web-antd/src/router/routes/modules/demos.ts b/apps/web-antd/src/router/routes/modules/demos.ts index c0e369a4..1c766832 100644 --- a/apps/web-antd/src/router/routes/modules/demos.ts +++ b/apps/web-antd/src/router/routes/modules/demos.ts @@ -14,7 +14,6 @@ const routes: RouteRecordRaw[] = [ }, name: 'Demos', path: '/demos', - redirect: '/demos/access', children: [ // 权限控制 { @@ -22,13 +21,12 @@ const routes: RouteRecordRaw[] = [ icon: 'mdi:shield-key-outline', title: $t('page.demos.access.frontendPermissions'), }, - name: 'Access', - path: 'access', - redirect: '/demos/access/page-control', + name: 'AccessDemos', + path: '/demos/access', children: [ { - name: 'AccessPageControl', - path: 'page-control', + name: 'AccessPageControlDemo', + path: '/demos/access/page-control', component: () => import('#/views/demos/access/index.vue'), meta: { icon: 'mdi:page-previous-outline', @@ -36,8 +34,8 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'AccessButtonControl', - path: 'button-control', + name: 'AccessButtonControlDemo', + path: '/demos/access/button-control', component: () => import('#/views/demos/access/button-control.vue'), meta: { icon: 'mdi:button-cursor', @@ -45,8 +43,8 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'AccessMenuVisible403', - path: 'menu-visible-403', + name: 'AccessMenuVisible403Demo', + path: '/demos/access/menu-visible-403', component: () => import('#/views/demos/access/menu-visible-403.vue'), meta: { @@ -57,8 +55,8 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'AccessSuperVisible', - path: 'super-visible', + name: 'AccessSuperVisibleDemo', + path: '/demos/access/super-visible', component: () => import('#/views/demos/access/super-visible.vue'), meta: { authority: ['super'], @@ -67,8 +65,8 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'AccessAdminVisible', - path: 'admin-visible', + name: 'AccessAdminVisibleDemo', + path: '/demos/access/admin-visible', component: () => import('#/views/demos/access/admin-visible.vue'), meta: { authority: ['admin'], @@ -77,8 +75,8 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'AccessUserVisible', - path: 'user-visible', + name: 'AccessUserVisibleDemo', + path: '/demos/access/user-visible', component: () => import('#/views/demos/access/user-visible.vue'), meta: { authority: ['user'], @@ -94,13 +92,39 @@ const routes: RouteRecordRaw[] = [ icon: 'mdi:feature-highlight', title: $t('page.demos.features.title'), }, - name: 'Features', - path: 'features', - redirect: '/demos/features/tabs', + name: 'FeaturesDemos', + path: '/demos/features', children: [ + { + name: 'LoginExpiredDemo', + path: '/demos/features/login-expired', + component: () => + import('#/views/demos/features/login-expired/index.vue'), + meta: { + icon: 'mdi:encryption-expiration', + title: $t('page.demos.features.loginExpired'), + }, + }, + { + name: 'IconsDemo', + path: '/demos/features/icons', + component: () => import('#/views/demos/features/icons/index.vue'), + meta: { + title: $t('page.demos.features.icons'), + }, + }, + { + name: 'WatermarkDemo', + path: '/demos/features/watermark', + component: () => + import('#/views/demos/features/watermark/index.vue'), + meta: { + title: $t('page.demos.features.watermark'), + }, + }, { name: 'FeatureTabsDemo', - path: 'tabs', + path: '/demos/features/tabs', component: () => import('#/views/demos/features/tabs/index.vue'), meta: { icon: 'lucide:app-window', @@ -109,7 +133,7 @@ const routes: RouteRecordRaw[] = [ }, { name: 'FeatureTabDetailDemo', - path: 'tabs/detail/:id', + path: '/demos/features/tabs/detail/:id', component: () => import('#/views/demos/features/tabs/tab-detail.vue'), meta: { @@ -120,19 +144,19 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'HideChildrenInMenuParent', - path: 'hide-menu-children', + name: 'HideChildrenInMenuParentDemo', + path: '/demos/features/hide-menu-children', component: () => import('#/views/demos/features/hide-menu-children/parent.vue'), meta: { hideChildrenInMenu: true, icon: 'ic:round-menu', - title: 'page.demos.features.hideChildrenInMenu', + title: $t('page.demos.features.hideChildrenInMenu'), }, children: [ { - name: 'HideChildrenInMenuChildren', - path: 'hide-children-in-menu', + name: 'HideChildrenInMenuChildrenDemo', + path: '/demos/features/hide-menu-children/children', component: () => import( '#/views/demos/features/hide-menu-children/children.vue' @@ -140,31 +164,20 @@ const routes: RouteRecordRaw[] = [ }, ], }, - { - name: 'LoginExpired', - path: 'login-expired', - component: () => - import('#/views/demos/features/login-expired/index.vue'), - meta: { - icon: 'mdi:encryption-expiration', - title: $t('page.demos.features.loginExpired'), - }, - }, ], }, // 面包屑导航 { name: 'BreadcrumbDemos', - path: 'breadcrumb', + path: '/demos/breadcrumb', meta: { icon: 'lucide:navigation', title: $t('page.demos.breadcrumb.navigation'), }, - redirect: '/demos/breadcrumb/lateral', children: [ { - name: 'BreadcrumbLateral', - path: 'lateral', + name: 'BreadcrumbLateralDemo', + path: '/demos/breadcrumb/lateral', component: () => import('#/views/demos/breadcrumb/lateral.vue'), meta: { icon: 'lucide:navigation', @@ -172,8 +185,8 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'BreadcrumbLateralDetail', - path: 'lateral-detail', + name: 'BreadcrumbLateralDetailDemo', + path: '/demos/breadcrumb/lateral-detail', component: () => import('#/views/demos/breadcrumb/lateral-detail.vue'), meta: { @@ -183,17 +196,16 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'BreadcrumbLevel', - path: 'level', + name: 'BreadcrumbLevelDemo', + path: '/demos/breadcrumb/level', meta: { icon: 'lucide:navigation', title: $t('page.demos.breadcrumb.level'), }, - redirect: '/demos/breadcrumb/level/detail', children: [ { - name: 'BreadcrumbLevelDetail', - path: 'detail', + name: 'BreadcrumbLevelDetailDemo', + path: '/demos/breadcrumb/level/detail', component: () => import('#/views/demos/breadcrumb/level-detail.vue'), meta: { @@ -210,13 +222,12 @@ const routes: RouteRecordRaw[] = [ icon: 'mdi:lightbulb-error-outline', title: $t('page.demos.fallback.title'), }, - name: 'Fallback', - path: 'fallback', - redirect: '/demos/fallback/403', + name: 'FallbackDemos', + path: '/demos/fallback', children: [ { - name: 'Fallback403', - path: '403', + name: 'Fallback403Demo', + path: '/demos/fallback/403', component: () => import('#/views/_core/fallback/forbidden.vue'), meta: { icon: 'mdi:do-not-disturb-alt', @@ -224,8 +235,8 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'Fallback404', - path: '404', + name: 'Fallback404Demo', + path: '/demos/fallback/404', component: () => import('#/views/_core/fallback/not-found.vue'), meta: { icon: 'mdi:table-off', @@ -233,8 +244,8 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'Fallback500', - path: '500', + name: 'Fallback500Demo', + path: '/demos/fallback/500', component: () => import('#/views/_core/fallback/internal-error.vue'), meta: { @@ -243,8 +254,8 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'FallbackOffline', - path: 'offline', + name: 'FallbackOfflineDemo', + path: '/demos/fallback/offline', component: () => import('#/views/_core/fallback/offline.vue'), meta: { icon: 'mdi:offline', @@ -261,14 +272,13 @@ const routes: RouteRecordRaw[] = [ icon: 'lucide:circle-dot', title: $t('page.demos.badge.title'), }, - name: 'BadgeDemo', - path: 'badge', - redirect: '/demos/badge/dot', + name: 'BadgeDemos', + path: '/demos/badge', children: [ { name: 'BadgeDotDemo', component: () => import('#/views/demos/badge/index.vue'), - path: 'dot', + path: '/demos/badge/dot', meta: { badgeType: 'dot', icon: 'lucide:square-dot', @@ -278,7 +288,7 @@ const routes: RouteRecordRaw[] = [ { name: 'BadgeTextDemo', component: () => import('#/views/demos/badge/index.vue'), - path: 'text', + path: '/demos/badge/text', meta: { badge: '10', icon: 'lucide:square-dot', @@ -288,7 +298,7 @@ const routes: RouteRecordRaw[] = [ { name: 'BadgeColorDemo', component: () => import('#/views/demos/badge/index.vue'), - path: 'color', + path: '/demos/badge/color', meta: { badge: 'Hot', badgeVariants: 'destructive', @@ -298,28 +308,48 @@ const routes: RouteRecordRaw[] = [ }, ], }, + // 菜单激活图标 + { + meta: { + activeIcon: 'fluent-emoji:radioactive', + icon: 'bi:radioactive', + title: $t('page.demos.activeIcon.title'), + }, + name: 'ActiveIconDemos', + path: '/demos/active-icon', + children: [ + { + name: 'ActiveIconDemo', + component: () => import('#/views/demos/active-icon/index.vue'), + path: '/demos/active-icon/children', + meta: { + activeIcon: 'fluent-emoji:radioactive', + icon: 'bi:radioactive', + title: $t('page.demos.activeIcon.children'), + }, + }, + ], + }, // 外部链接 { meta: { icon: 'ic:round-settings-input-composite', title: $t('page.demos.outside.title'), }, - name: 'Outside', - path: 'outside', - redirect: '/demos/outside/iframe', + name: 'OutsideDemos', + path: '/demos/outside', children: [ { - name: 'iframe', - path: 'iframe', + name: 'IframeDemos', + path: '/demos/outside/iframe', meta: { icon: 'mdi:newspaper-variant-outline', title: $t('page.demos.outside.embedded'), }, - redirect: '/demos/outside/iframe/vue-document', children: [ { - name: 'VueDocument', - path: 'vue-document', + name: 'VueDocumentDemo', + path: '/demos/outside/iframe/vue-document', component: IFrameView, meta: { icon: 'logos:vue', @@ -329,8 +359,8 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'Tailwindcss', - path: 'tailwindcss', + name: 'TailwindcssDemo', + path: '/demos/outside/iframe/tailwindcss', component: IFrameView, meta: { icon: 'devicon:tailwindcss', @@ -342,17 +372,16 @@ const routes: RouteRecordRaw[] = [ ], }, { - name: 'ExternalLink', - path: 'external-link', + name: 'ExternalLinkDemos', + path: '/demos/outside/external-link', meta: { icon: 'mdi:newspaper-variant-multiple-outline', title: $t('page.demos.outside.externalLink'), }, - redirect: '/demos/outside/external-link/vite', children: [ { - name: 'Vite', - path: 'vite', + name: 'ViteDemo', + path: '/demos/outside/external-link/vite', component: IFrameView, meta: { icon: 'logos:vitejs', @@ -361,8 +390,8 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'VueUse', - path: 'vue-use', + name: 'VueUseDemo', + path: '/demos/outside/external-link/vue-use', component: IFrameView, meta: { icon: 'logos:vueuse', @@ -380,13 +409,12 @@ const routes: RouteRecordRaw[] = [ icon: 'ic:round-menu', title: $t('page.demos.nested.title'), }, - name: 'Nested', - path: 'nested', - redirect: '/demos/nested/menu1', + name: 'NestedDemos', + path: '/demos/nested', children: [ { - name: 'Menu1', - path: 'menu1', + name: 'Menu1Demo', + path: '/demos/nested/menu1', component: () => import('#/views/demos/nested/menu-1.vue'), meta: { icon: 'ic:round-menu', @@ -395,18 +423,17 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'Menu2', - path: 'menu2', + name: 'Menu2Demo', + path: '/demos/nested/menu2', meta: { icon: 'ic:round-menu', keepAlive: true, title: $t('page.demos.nested.menu2'), }, - redirect: '/demos/nested/menu2/menu2-1', children: [ { - name: 'Menu21', - path: 'menu2-1', + name: 'Menu21Demo', + path: '/demos/nested/menu2/menu2-1', component: () => import('#/views/demos/nested/menu-2-1.vue'), meta: { icon: 'ic:round-menu', @@ -417,16 +444,15 @@ const routes: RouteRecordRaw[] = [ ], }, { - name: 'Menu3', - path: 'menu3', + name: 'Menu3Demo', + path: '/demos/nested/menu3', meta: { icon: 'ic:round-menu', title: $t('page.demos.nested.menu3'), }, - redirect: '/demos/nested/menu3/menu3-1', children: [ { - name: 'Menu31', + name: 'Menu31Demo', path: 'menu3-1', component: () => import('#/views/demos/nested/menu-3-1.vue'), meta: { @@ -436,17 +462,16 @@ const routes: RouteRecordRaw[] = [ }, }, { - name: 'Menu32', + name: 'Menu32Demo', path: 'menu3-2', meta: { icon: 'ic:round-menu', title: $t('page.demos.nested.menu3_2'), }, - redirect: '/demos/nested/menu3/menu3-2/menu3-2-1', children: [ { - name: 'Menu321', - path: 'menu3-2-1', + name: 'Menu321Demo', + path: '/demos/nested/menu3/menu3-2/menu3-2-1', component: () => import('#/views/demos/nested/menu-3-2-1.vue'), meta: { diff --git a/apps/web-antd/src/router/routes/modules/vben.ts b/apps/web-antd/src/router/routes/modules/vben.ts index 4df1475e..2d1fdf24 100644 --- a/apps/web-antd/src/router/routes/modules/vben.ts +++ b/apps/web-antd/src/router/routes/modules/vben.ts @@ -17,11 +17,10 @@ const routes: RouteRecordRaw[] = [ }, name: 'VbenProject', path: '/vben-admin', - redirect: '/vben-admin/about', children: [ { name: 'VbenAbout', - path: 'about', + path: '/vben-admin/about', component: () => import('#/views/_core/vben/about/index.vue'), meta: { badgeType: 'dot', @@ -32,7 +31,7 @@ const routes: RouteRecordRaw[] = [ }, { name: 'VbenDocument', - path: 'document', + path: '/vben-admin/document', component: IFrameView, meta: { icon: 'lucide:book-open-text', @@ -43,7 +42,7 @@ const routes: RouteRecordRaw[] = [ }, { name: 'VbenGithub', - path: 'github', + path: '/vben-admin/github', component: IFrameView, meta: { icon: 'mdi:github', diff --git a/apps/web-antd/src/store/modules/access.ts b/apps/web-antd/src/store/modules/access.ts index c459931d..b4afb546 100644 --- a/apps/web-antd/src/store/modules/access.ts +++ b/apps/web-antd/src/store/modules/access.ts @@ -11,7 +11,7 @@ import { resetAllStores, useCoreAccessStore } from '@vben/stores'; import { notification } from 'ant-design-vue'; import { defineStore } from 'pinia'; -import { getAccessCodes, getUserInfo, login } from '#/apis'; +import { getAccessCodes, getUserInfo, login } from '#/api'; import { $t } from '#/locales'; export const useAccessStore = defineStore('access', () => { diff --git a/apps/web-antd/src/views/_core/fallback/forbidden.vue b/apps/web-antd/src/views/_core/fallback/forbidden.vue index e6c47bae..8ea65fed 100644 --- a/apps/web-antd/src/views/_core/fallback/forbidden.vue +++ b/apps/web-antd/src/views/_core/fallback/forbidden.vue @@ -1,5 +1,7 @@