@kevairy/template 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (293) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +14 -0
  3. package/package.json +37 -0
  4. package/template/.env +22 -0
  5. package/template/.env.development +13 -0
  6. package/template/.env.production +10 -0
  7. package/template/.prettierignore +3 -0
  8. package/template/.prettierrc +20 -0
  9. package/template/.stylelintignore +9 -0
  10. package/template/.stylelintrc.cjs +84 -0
  11. package/template/LICENSE +21 -0
  12. package/template/README.md +22 -0
  13. package/template/_gitignore +19 -0
  14. package/template/eslint-auto-import.json +324 -0
  15. package/template/eslint.config.mjs +83 -0
  16. package/template/index.html +25 -0
  17. package/template/package.json +79 -0
  18. package/template/playwright.config.ts +25 -0
  19. package/template/public/favicon.ico +0 -0
  20. package/template/src/App.vue +39 -0
  21. package/template/src/adapters/auth/index.ts +9 -0
  22. package/template/src/adapters/auth/mock.ts +10 -0
  23. package/template/src/adapters/auth/types.ts +11 -0
  24. package/template/src/adapters/navigation/index.ts +13 -0
  25. package/template/src/adapters/navigation/types.ts +6 -0
  26. package/template/src/api/auth.ts +23 -0
  27. package/template/src/assets/images/avatar/avatar.webp +0 -0
  28. package/template/src/assets/images/avatar/avatar1.webp +0 -0
  29. package/template/src/assets/images/avatar/avatar10.webp +0 -0
  30. package/template/src/assets/images/avatar/avatar2.webp +0 -0
  31. package/template/src/assets/images/avatar/avatar3.webp +0 -0
  32. package/template/src/assets/images/avatar/avatar4.webp +0 -0
  33. package/template/src/assets/images/avatar/avatar5.webp +0 -0
  34. package/template/src/assets/images/avatar/avatar6.webp +0 -0
  35. package/template/src/assets/images/avatar/avatar7.webp +0 -0
  36. package/template/src/assets/images/avatar/avatar8.webp +0 -0
  37. package/template/src/assets/images/avatar/avatar9.webp +0 -0
  38. package/template/src/assets/images/ceremony/hb.png +0 -0
  39. package/template/src/assets/images/ceremony/sd.png +0 -0
  40. package/template/src/assets/images/ceremony/xc.png +0 -0
  41. package/template/src/assets/images/ceremony/yd.png +0 -0
  42. package/template/src/assets/images/common/logo.webp +0 -0
  43. package/template/src/assets/images/draw/draw1.png +0 -0
  44. package/template/src/assets/images/favicon.ico +0 -0
  45. package/template/src/assets/images/lock/bg_dark.webp +0 -0
  46. package/template/src/assets/images/lock/bg_light.webp +0 -0
  47. package/template/src/assets/images/login/kylin-hero-source.png +0 -0
  48. package/template/src/assets/images/login/lf_icon2.webp +0 -0
  49. package/template/src/assets/images/settings/menu_layouts/dual_column.png +0 -0
  50. package/template/src/assets/images/settings/menu_layouts/horizontal.png +0 -0
  51. package/template/src/assets/images/settings/menu_layouts/mixed.png +0 -0
  52. package/template/src/assets/images/settings/menu_layouts/vertical.png +0 -0
  53. package/template/src/assets/images/settings/menu_styles/dark.png +0 -0
  54. package/template/src/assets/images/settings/menu_styles/design.png +0 -0
  55. package/template/src/assets/images/settings/menu_styles/light.png +0 -0
  56. package/template/src/assets/images/settings/theme_styles/dark.png +0 -0
  57. package/template/src/assets/images/settings/theme_styles/light.png +0 -0
  58. package/template/src/assets/images/settings/theme_styles/system.png +0 -0
  59. package/template/src/assets/images/svg/403.svg +1 -0
  60. package/template/src/assets/images/svg/404.svg +1 -0
  61. package/template/src/assets/images/svg/500.svg +5 -0
  62. package/template/src/assets/images/svg/login_icon.svg +1 -0
  63. package/template/src/assets/images/user/avatar.webp +0 -0
  64. package/template/src/assets/images/user/bg.webp +0 -0
  65. package/template/src/assets/styles/core/app.scss +227 -0
  66. package/template/src/assets/styles/core/dark.scss +93 -0
  67. package/template/src/assets/styles/core/el-dark.scss +2 -0
  68. package/template/src/assets/styles/core/el-light.scss +34 -0
  69. package/template/src/assets/styles/core/el-ui.scss +519 -0
  70. package/template/src/assets/styles/core/md.scss +1036 -0
  71. package/template/src/assets/styles/core/mixin.scss +157 -0
  72. package/template/src/assets/styles/core/reset.scss +41 -0
  73. package/template/src/assets/styles/core/router-transition.scss +104 -0
  74. package/template/src/assets/styles/core/tailwind.css +219 -0
  75. package/template/src/assets/styles/core/theme-animation.scss +63 -0
  76. package/template/src/assets/styles/core/theme-change.scss +11 -0
  77. package/template/src/assets/styles/custom/one-dark-pro.scss +98 -0
  78. package/template/src/assets/styles/index.scss +23 -0
  79. package/template/src/assets/svg/loading.ts +32 -0
  80. package/template/src/bootstrap/initializeApp.ts +30 -0
  81. package/template/src/components/core/banners/art-basic-banner/index.vue +343 -0
  82. package/template/src/components/core/banners/art-card-banner/index.vue +114 -0
  83. package/template/src/components/core/base/art-back-to-top/index.vue +40 -0
  84. package/template/src/components/core/base/art-logo/index.vue +34 -0
  85. package/template/src/components/core/base/art-svg-icon/index.vue +24 -0
  86. package/template/src/components/core/cards/art-bar-chart-card/index.vue +103 -0
  87. package/template/src/components/core/cards/art-data-list-card/index.vue +74 -0
  88. package/template/src/components/core/cards/art-donut-chart-card/index.vue +124 -0
  89. package/template/src/components/core/cards/art-image-card/index.vue +89 -0
  90. package/template/src/components/core/cards/art-line-chart-card/index.vue +126 -0
  91. package/template/src/components/core/cards/art-progress-card/index.vue +86 -0
  92. package/template/src/components/core/cards/art-stats-card/index.vue +67 -0
  93. package/template/src/components/core/cards/art-timeline-list-card/index.vue +69 -0
  94. package/template/src/components/core/charts/art-bar-chart/index.vue +203 -0
  95. package/template/src/components/core/charts/art-dual-bar-compare-chart/index.vue +195 -0
  96. package/template/src/components/core/charts/art-h-bar-chart/index.vue +208 -0
  97. package/template/src/components/core/charts/art-k-line-chart/index.vue +152 -0
  98. package/template/src/components/core/charts/art-line-chart/index.vue +371 -0
  99. package/template/src/components/core/charts/art-radar-chart/index.vue +105 -0
  100. package/template/src/components/core/charts/art-ring-chart/index.vue +133 -0
  101. package/template/src/components/core/charts/art-scatter-chart/index.vue +115 -0
  102. package/template/src/components/core/feedback/art-page-loading/index.vue +281 -0
  103. package/template/src/components/core/forms/art-button-more/index.vue +71 -0
  104. package/template/src/components/core/forms/art-button-table/index.vue +59 -0
  105. package/template/src/components/core/forms/art-drag-verify/index.vue +430 -0
  106. package/template/src/components/core/forms/art-excel-export/index.vue +390 -0
  107. package/template/src/components/core/forms/art-excel-import/index.vue +62 -0
  108. package/template/src/components/core/forms/art-form/index.vue +507 -0
  109. package/template/src/components/core/forms/art-wang-editor/index.vue +261 -0
  110. package/template/src/components/core/forms/art-wang-editor/style.scss +273 -0
  111. package/template/src/components/core/layouts/art-breadcrumb/index.vue +142 -0
  112. package/template/src/components/core/layouts/art-chat-window/index.vue +262 -0
  113. package/template/src/components/core/layouts/art-fast-enter/index.vue +113 -0
  114. package/template/src/components/core/layouts/art-fireworks-effect/index.vue +633 -0
  115. package/template/src/components/core/layouts/art-global-component/index.vue +14 -0
  116. package/template/src/components/core/layouts/art-global-search/index.vue +431 -0
  117. package/template/src/components/core/layouts/art-header-bar/index.vue +485 -0
  118. package/template/src/components/core/layouts/art-header-bar/widget/ArtUserMenu.vue +118 -0
  119. package/template/src/components/core/layouts/art-menus/art-horizontal-menu/index.vue +110 -0
  120. package/template/src/components/core/layouts/art-menus/art-horizontal-menu/widget/HorizontalSubmenu.vue +106 -0
  121. package/template/src/components/core/layouts/art-menus/art-mixed-menu/index.vue +279 -0
  122. package/template/src/components/core/layouts/art-menus/art-sidebar-menu/index.vue +354 -0
  123. package/template/src/components/core/layouts/art-menus/art-sidebar-menu/style.scss +251 -0
  124. package/template/src/components/core/layouts/art-menus/art-sidebar-menu/theme.scss +258 -0
  125. package/template/src/components/core/layouts/art-menus/art-sidebar-menu/widget/SidebarSubmenu.vue +190 -0
  126. package/template/src/components/core/layouts/art-notification/index.vue +456 -0
  127. package/template/src/components/core/layouts/art-page-content/index.vue +137 -0
  128. package/template/src/components/core/layouts/art-settings-panel/composables/useSettingsConfig.ts +248 -0
  129. package/template/src/components/core/layouts/art-settings-panel/composables/useSettingsHandlers.ts +167 -0
  130. package/template/src/components/core/layouts/art-settings-panel/composables/useSettingsPanel.ts +233 -0
  131. package/template/src/components/core/layouts/art-settings-panel/composables/useSettingsState.ts +37 -0
  132. package/template/src/components/core/layouts/art-settings-panel/index.vue +72 -0
  133. package/template/src/components/core/layouts/art-settings-panel/style.scss +92 -0
  134. package/template/src/components/core/layouts/art-settings-panel/widget/BasicSettings.vue +77 -0
  135. package/template/src/components/core/layouts/art-settings-panel/widget/BoxStyleSettings.vue +38 -0
  136. package/template/src/components/core/layouts/art-settings-panel/widget/ColorSettings.vue +35 -0
  137. package/template/src/components/core/layouts/art-settings-panel/widget/ContainerSettings.vue +33 -0
  138. package/template/src/components/core/layouts/art-settings-panel/widget/MenuLayoutSettings.vue +31 -0
  139. package/template/src/components/core/layouts/art-settings-panel/widget/MenuStyleSettings.vue +44 -0
  140. package/template/src/components/core/layouts/art-settings-panel/widget/SectionTitle.vue +17 -0
  141. package/template/src/components/core/layouts/art-settings-panel/widget/SettingActions.vue +236 -0
  142. package/template/src/components/core/layouts/art-settings-panel/widget/SettingDrawer.vue +51 -0
  143. package/template/src/components/core/layouts/art-settings-panel/widget/SettingHeader.vue +18 -0
  144. package/template/src/components/core/layouts/art-settings-panel/widget/SettingItem.vue +101 -0
  145. package/template/src/components/core/layouts/art-settings-panel/widget/ThemeSettings.vue +28 -0
  146. package/template/src/components/core/layouts/art-work-tab/index.vue +584 -0
  147. package/template/src/components/core/media/art-cutter-img/index.vue +350 -0
  148. package/template/src/components/core/media/art-video-player/index.vue +111 -0
  149. package/template/src/components/core/others/art-menu-right/index.vue +415 -0
  150. package/template/src/components/core/others/art-watermark/index.vue +64 -0
  151. package/template/src/components/core/text-effect/art-count-to/index.vue +310 -0
  152. package/template/src/components/core/text-effect/art-festival-text-scroll/index.vue +32 -0
  153. package/template/src/components/core/text-effect/art-text-scroll/index.vue +285 -0
  154. package/template/src/components/core/theme/theme-svg/index.vue +100 -0
  155. package/template/src/components/core/views/exception/ArtException.vue +55 -0
  156. package/template/src/components/core/views/login/AuthTopBar.vue +149 -0
  157. package/template/src/components/core/views/login/LoginLeftView.vue +602 -0
  158. package/template/src/components/core/views/result/ArtResultPage.vue +43 -0
  159. package/template/src/components/core/widget/art-icon-button/index.vue +23 -0
  160. package/template/src/config/assets/images.ts +61 -0
  161. package/template/src/config/index.ts +170 -0
  162. package/template/src/config/modules/component.ts +98 -0
  163. package/template/src/config/modules/fastEnter.ts +16 -0
  164. package/template/src/config/modules/festival.ts +51 -0
  165. package/template/src/config/modules/headerBar.ts +64 -0
  166. package/template/src/config/setting.ts +109 -0
  167. package/template/src/directives/core/auth.ts +66 -0
  168. package/template/src/directives/core/highlight-loader.ts +37 -0
  169. package/template/src/directives/core/highlight.ts +253 -0
  170. package/template/src/directives/core/ripple.ts +116 -0
  171. package/template/src/directives/core/roles.ts +87 -0
  172. package/template/src/directives/index.ts +14 -0
  173. package/template/src/enums/appEnum.ts +81 -0
  174. package/template/src/enums/formEnum.ts +17 -0
  175. package/template/src/env.d.ts +32 -0
  176. package/template/src/hooks/core/useAppMode.ts +45 -0
  177. package/template/src/hooks/core/useAuth.ts +74 -0
  178. package/template/src/hooks/core/useCeremony.ts +184 -0
  179. package/template/src/hooks/core/useChart.ts +745 -0
  180. package/template/src/hooks/core/useCommon.ts +87 -0
  181. package/template/src/hooks/core/useFastEnter.ts +55 -0
  182. package/template/src/hooks/core/useHeaderBar.ts +201 -0
  183. package/template/src/hooks/core/useLayoutHeight.ts +148 -0
  184. package/template/src/hooks/core/useTableColumns.ts +313 -0
  185. package/template/src/hooks/core/useTheme.ts +174 -0
  186. package/template/src/hooks/index.ts +29 -0
  187. package/template/src/locales/index.ts +123 -0
  188. package/template/src/locales/langs/en.json +283 -0
  189. package/template/src/locales/langs/zh.json +283 -0
  190. package/template/src/main.ts +29 -0
  191. package/template/src/mock/auth.ts +46 -0
  192. package/template/src/plugins/echarts.ts +76 -0
  193. package/template/src/plugins/index.ts +6 -0
  194. package/template/src/router/core/ComponentLoader.ts +82 -0
  195. package/template/src/router/core/IframeRouteManager.ts +78 -0
  196. package/template/src/router/core/MenuProcessor.ts +280 -0
  197. package/template/src/router/core/RoutePermissionValidator.ts +161 -0
  198. package/template/src/router/core/RouteRegistry.ts +90 -0
  199. package/template/src/router/core/RouteTransformer.ts +132 -0
  200. package/template/src/router/core/RouteValidator.ts +187 -0
  201. package/template/src/router/core/index.ts +14 -0
  202. package/template/src/router/guards/afterEach.ts +34 -0
  203. package/template/src/router/guards/beforeEach.ts +442 -0
  204. package/template/src/router/index.ts +24 -0
  205. package/template/src/router/modules/dashboard.ts +23 -0
  206. package/template/src/router/modules/examples.ts +109 -0
  207. package/template/src/router/modules/exception.ts +46 -0
  208. package/template/src/router/modules/index.ts +12 -0
  209. package/template/src/router/modules/result.ts +32 -0
  210. package/template/src/router/routes/asyncRoutes.ts +9 -0
  211. package/template/src/router/routes/staticRoutes.ts +60 -0
  212. package/template/src/router/routesAlias.ts +8 -0
  213. package/template/src/services/auth.ts +15 -0
  214. package/template/src/store/index.ts +52 -0
  215. package/template/src/store/modules/menu.ts +109 -0
  216. package/template/src/store/modules/setting.ts +450 -0
  217. package/template/src/store/modules/user.ts +218 -0
  218. package/template/src/store/modules/worktab.ts +568 -0
  219. package/template/src/types/api/api.d.ts +86 -0
  220. package/template/src/types/common/index.ts +95 -0
  221. package/template/src/types/common/response.ts +32 -0
  222. package/template/src/types/component/chart.ts +324 -0
  223. package/template/src/types/component/index.ts +86 -0
  224. package/template/src/types/config/index.ts +253 -0
  225. package/template/src/types/directive/directive.d.ts +15 -0
  226. package/template/src/types/import/auto-imports.d.ts +319 -0
  227. package/template/src/types/import/components.d.ts +126 -0
  228. package/template/src/types/index.ts +22 -0
  229. package/template/src/types/router/index.ts +80 -0
  230. package/template/src/types/store/index.ts +157 -0
  231. package/template/src/utils/form/index.ts +9 -0
  232. package/template/src/utils/form/validator.ts +316 -0
  233. package/template/src/utils/http/contract.ts +39 -0
  234. package/template/src/utils/http/error.ts +182 -0
  235. package/template/src/utils/http/index.ts +226 -0
  236. package/template/src/utils/http/status.ts +18 -0
  237. package/template/src/utils/index.ts +31 -0
  238. package/template/src/utils/navigation/index.ts +10 -0
  239. package/template/src/utils/navigation/jump.ts +68 -0
  240. package/template/src/utils/navigation/route.ts +85 -0
  241. package/template/src/utils/navigation/worktab.ts +67 -0
  242. package/template/src/utils/router.ts +63 -0
  243. package/template/src/utils/socket/index.ts +423 -0
  244. package/template/src/utils/storage/index.ts +7 -0
  245. package/template/src/utils/storage/storage-config.ts +127 -0
  246. package/template/src/utils/storage/storage-key-manager.ts +97 -0
  247. package/template/src/utils/storage/storage.ts +250 -0
  248. package/template/src/utils/sys/console.ts +9 -0
  249. package/template/src/utils/sys/error-handle.ts +143 -0
  250. package/template/src/utils/sys/index.ts +2 -0
  251. package/template/src/utils/sys/mittBus.ts +61 -0
  252. package/template/src/utils/ui/animation.ts +80 -0
  253. package/template/src/utils/ui/colors.ts +273 -0
  254. package/template/src/utils/ui/emojo.ts +24 -0
  255. package/template/src/utils/ui/iconify-loader.ts +31 -0
  256. package/template/src/utils/ui/index.ts +11 -0
  257. package/template/src/utils/ui/loading.ts +158 -0
  258. package/template/src/utils/ui/tabs.ts +60 -0
  259. package/template/src/views/auth/forget-password/index.vue +62 -0
  260. package/template/src/views/auth/login/index.vue +166 -0
  261. package/template/src/views/auth/login/style.css +38 -0
  262. package/template/src/views/auth/register/index.vue +240 -0
  263. package/template/src/views/dashboard/console/index.vue +173 -0
  264. package/template/src/views/examples/analytics/index.vue +389 -0
  265. package/template/src/views/examples/complex-form/index.vue +395 -0
  266. package/template/src/views/examples/crud-workspace/index.vue +412 -0
  267. package/template/src/views/examples/navigation/detail/index.vue +151 -0
  268. package/template/src/views/examples/navigation/state/index.vue +226 -0
  269. package/template/src/views/examples/overview/index.vue +309 -0
  270. package/template/src/views/examples/permissions/index.vue +303 -0
  271. package/template/src/views/examples/search-table/index.vue +182 -0
  272. package/template/src/views/examples/search-table/search.config.ts +81 -0
  273. package/template/src/views/examples/search-table/service.ts +116 -0
  274. package/template/src/views/examples/search-table/table.config.ts +37 -0
  275. package/template/src/views/exception/403/index.vue +16 -0
  276. package/template/src/views/exception/404/index.vue +16 -0
  277. package/template/src/views/exception/500/index.vue +16 -0
  278. package/template/src/views/index/index.vue +29 -0
  279. package/template/src/views/index/style.scss +93 -0
  280. package/template/src/views/outside/Iframe.vue +42 -0
  281. package/template/src/views/result/fail/index.vue +28 -0
  282. package/template/src/views/result/success/index.vue +21 -0
  283. package/template/tests/e2e/auth.spec.ts +14 -0
  284. package/template/tests/e2e/search-table.spec.ts +154 -0
  285. package/template/tests/unit/adapters/auth.spec.ts +38 -0
  286. package/template/tests/unit/config/app-config.spec.ts +17 -0
  287. package/template/tests/unit/directives/highlight.spec.ts +20 -0
  288. package/template/tests/unit/http/contract.spec.ts +47 -0
  289. package/template/tests/unit/mock/search-table.spec.ts +62 -0
  290. package/template/tests/unit/router/examples.spec.ts +52 -0
  291. package/template/tsconfig.json +28 -0
  292. package/template/vite.config.ts +181 -0
  293. package/template/vitest.config.ts +27 -0
@@ -0,0 +1,442 @@
1
+ /**
2
+ * 路由全局前置守卫模块
3
+ *
4
+ * 提供完整的路由导航守卫功能
5
+ *
6
+ * ## 主要功能
7
+ *
8
+ * - 登录状态验证和重定向
9
+ * - 动态路由注册和权限控制
10
+ * - 菜单数据获取和处理(前端/后端模式)
11
+ * - 用户信息获取和缓存
12
+ * - 页面标题设置
13
+ * - 工作标签页管理
14
+ * - 进度条和加载动画控制
15
+ * - 静态路由识别和处理
16
+ * - 错误处理和异常跳转
17
+ *
18
+ * ## 使用场景
19
+ *
20
+ * - 路由跳转前的权限验证
21
+ * - 动态菜单加载和路由注册
22
+ * - 用户登录状态管理
23
+ * - 页面访问控制
24
+ * - 路由级别的加载状态管理
25
+ *
26
+ * ## 工作流程
27
+ *
28
+ * 1. 检查登录状态,未登录跳转到登录页
29
+ * 2. 首次访问时获取用户信息和菜单数据
30
+ * 3. 根据权限动态注册路由
31
+ * 4. 设置页面标题和工作标签页
32
+ * 5. 处理根路径重定向到首页
33
+ * 6. 未匹配路由跳转到 404 页面
34
+ *
35
+ * @module router/guards/beforeEach
36
+ * @author Art Design Pro Team
37
+ */
38
+ import type { Router, RouteLocationNormalized, NavigationGuardNext } from 'vue-router'
39
+ import { nextTick } from 'vue'
40
+ import NProgress from 'nprogress'
41
+ import { useSettingStore } from '@/store/modules/setting'
42
+ import { useUserStore } from '@/store/modules/user'
43
+ import { useMenuStore } from '@/store/modules/menu'
44
+ import { setWorktab } from '@/utils/navigation'
45
+ import { setPageTitle } from '@/utils/router'
46
+ import { RoutesAlias } from '../routesAlias'
47
+ import { staticRoutes } from '../routes/staticRoutes'
48
+ import { loadingService } from '@/utils/ui'
49
+ import { useCommon } from '@/hooks/core/useCommon'
50
+ import { useWorktabStore } from '@/store/modules/worktab'
51
+ import { fetchGetUserInfo } from '@/api/auth'
52
+ import { ApiStatus } from '@/utils/http/status'
53
+ import { isHttpError } from '@/utils/http/error'
54
+ import { RouteRegistry, MenuProcessor, IframeRouteManager, RoutePermissionValidator } from '../core'
55
+
56
+ // 路由注册器实例
57
+ let routeRegistry: RouteRegistry | null = null
58
+
59
+ // 菜单处理器实例
60
+ const menuProcessor = new MenuProcessor()
61
+
62
+ // 跟踪是否需要关闭 loading
63
+ let pendingLoading = false
64
+
65
+ // 路由初始化失败标记,防止死循环
66
+ // 一旦设置为 true,只有刷新页面或重新登录才能重置
67
+ let routeInitFailed = false
68
+
69
+ // 路由初始化进行中标记,防止并发请求
70
+ let routeInitInProgress = false
71
+
72
+ /**
73
+ * 获取 pendingLoading 状态
74
+ */
75
+ export function getPendingLoading(): boolean {
76
+ return pendingLoading
77
+ }
78
+
79
+ /**
80
+ * 重置 pendingLoading 状态
81
+ */
82
+ export function resetPendingLoading(): void {
83
+ pendingLoading = false
84
+ }
85
+
86
+ /**
87
+ * 获取路由初始化失败状态
88
+ */
89
+ export function getRouteInitFailed(): boolean {
90
+ return routeInitFailed
91
+ }
92
+
93
+ /**
94
+ * 重置路由初始化状态(用于重新登录场景)
95
+ */
96
+ export function resetRouteInitState(): void {
97
+ routeInitFailed = false
98
+ routeInitInProgress = false
99
+ }
100
+
101
+ /**
102
+ * 设置路由全局前置守卫
103
+ */
104
+ export function setupBeforeEachGuard(router: Router): void {
105
+ // 初始化路由注册器
106
+ routeRegistry = new RouteRegistry(router)
107
+
108
+ router.beforeEach(
109
+ async (
110
+ to: RouteLocationNormalized,
111
+ from: RouteLocationNormalized,
112
+ next: NavigationGuardNext
113
+ ) => {
114
+ try {
115
+ await handleRouteGuard(to, from, next, router)
116
+ } catch (error) {
117
+ console.error('[RouteGuard] 路由守卫处理失败:', error)
118
+ closeLoading()
119
+ next({ name: 'Exception500' })
120
+ }
121
+ }
122
+ )
123
+ }
124
+
125
+ /**
126
+ * 关闭 loading 效果
127
+ */
128
+ function closeLoading(): void {
129
+ if (pendingLoading) {
130
+ nextTick(() => {
131
+ loadingService.hideLoading()
132
+ pendingLoading = false
133
+ })
134
+ }
135
+ }
136
+
137
+ /**
138
+ * 处理路由守卫逻辑
139
+ */
140
+ async function handleRouteGuard(
141
+ to: RouteLocationNormalized,
142
+ from: RouteLocationNormalized,
143
+ next: NavigationGuardNext,
144
+ router: Router
145
+ ): Promise<void> {
146
+ const settingStore = useSettingStore()
147
+ const userStore = useUserStore()
148
+
149
+ // 启动进度条
150
+ if (settingStore.showNprogress) {
151
+ NProgress.start()
152
+ }
153
+
154
+ // 1. 检查登录状态
155
+ if (!handleLoginStatus(to, userStore, next)) {
156
+ return
157
+ }
158
+
159
+ // 2. 检查路由初始化是否已失败(防止死循环)
160
+ if (routeInitFailed) {
161
+ // 已经失败过,直接放行到错误页面,不再重试
162
+ if (to.matched.length > 0) {
163
+ next()
164
+ } else {
165
+ // 未匹配到路由,跳转到 500 页面
166
+ next({ name: 'Exception500', replace: true })
167
+ }
168
+ return
169
+ }
170
+
171
+ // 3. 处理动态路由注册
172
+ if (!routeRegistry?.isRegistered() && userStore.isLogin) {
173
+ // 防止并发请求(快速连续导航场景)
174
+ if (routeInitInProgress) {
175
+ // 正在初始化中,等待完成后重新导航
176
+ next(false)
177
+ return
178
+ }
179
+ await handleDynamicRoutes(to, next, router)
180
+ return
181
+ }
182
+
183
+ // 4. 处理根路径重定向
184
+ if (handleRootPathRedirect(to, next)) {
185
+ return
186
+ }
187
+
188
+ // 5. 处理已匹配的路由
189
+ if (to.matched.length > 0) {
190
+ setWorktab(to)
191
+ setPageTitle(to)
192
+ next()
193
+ return
194
+ }
195
+
196
+ // 6. 未匹配到路由,跳转到 404
197
+ next({ name: 'Exception404' })
198
+ }
199
+
200
+ /**
201
+ * 处理登录状态
202
+ * @returns true 表示可以继续,false 表示已处理跳转
203
+ */
204
+ function handleLoginStatus(
205
+ to: RouteLocationNormalized,
206
+ userStore: ReturnType<typeof useUserStore>,
207
+ next: NavigationGuardNext
208
+ ): boolean {
209
+ const hasActiveSession = userStore.isLogin && Boolean(userStore.accessToken)
210
+
211
+ if (to.path === RoutesAlias.Login && hasActiveSession) {
212
+ next({ path: '/', replace: true })
213
+ return false
214
+ }
215
+
216
+ // 已登录或访问登录页或静态路由,直接放行
217
+ if (hasActiveSession || to.path === RoutesAlias.Login || isStaticRoute(to.path)) {
218
+ return true
219
+ }
220
+
221
+ // 未登录且访问需要权限的页面,跳转到登录页并携带 redirect 参数
222
+ userStore.clearAuthState(false)
223
+ next({
224
+ name: 'Login',
225
+ query: { redirect: to.fullPath }
226
+ })
227
+ return false
228
+ }
229
+
230
+ /**
231
+ * 检查路由是否为静态路由
232
+ */
233
+ function isStaticRoute(path: string): boolean {
234
+ const checkRoute = (routes: any[], targetPath: string): boolean => {
235
+ return routes.some((route) => {
236
+ // 404 catch-all 路由不应视为可匿名访问的静态页,
237
+ // 否则未登录时手动输入任意地址会直接落到 404,无法跳转登录页。
238
+ if (route.name === 'Exception404') {
239
+ return false
240
+ }
241
+
242
+ // 处理动态路由参数匹配
243
+ const routePath = route.path
244
+ const pattern = routePath.replace(/:[^/]+/g, '[^/]+').replace(/\*/g, '.*')
245
+ const regex = new RegExp(`^${pattern}$`)
246
+
247
+ if (regex.test(targetPath)) {
248
+ return true
249
+ }
250
+ if (route.children && route.children.length > 0) {
251
+ return checkRoute(route.children, targetPath)
252
+ }
253
+ return false
254
+ })
255
+ }
256
+
257
+ return checkRoute(staticRoutes, path)
258
+ }
259
+
260
+ /**
261
+ * 处理动态路由注册
262
+ */
263
+ async function handleDynamicRoutes(
264
+ to: RouteLocationNormalized,
265
+ next: NavigationGuardNext,
266
+ router: Router
267
+ ): Promise<void> {
268
+ // 标记初始化进行中
269
+ routeInitInProgress = true
270
+
271
+ // 显示 loading
272
+ pendingLoading = true
273
+ loadingService.showLoading()
274
+
275
+ try {
276
+ // 1. 获取用户信息
277
+ await fetchUserInfo()
278
+
279
+ // 2. 获取菜单数据
280
+ const menuList = await menuProcessor.getMenuList()
281
+
282
+ // 3. 验证菜单数据
283
+ if (!menuProcessor.validateMenuList(menuList)) {
284
+ throw new Error('获取菜单列表失败,请重新登录')
285
+ }
286
+
287
+ // 4. 注册动态路由
288
+ routeRegistry?.register(menuList)
289
+
290
+ // 5. 保存菜单数据到 store
291
+ const menuStore = useMenuStore()
292
+ menuStore.setMenuList(menuList)
293
+ menuStore.addRemoveRouteFns(routeRegistry?.getRemoveRouteFns() || [])
294
+
295
+ // 6. 保存 iframe 路由
296
+ IframeRouteManager.getInstance().save()
297
+
298
+ // 7. 验证工作标签页
299
+ useWorktabStore().validateWorktabs(router)
300
+
301
+ // 8. 静态路由不依赖菜单权限,初始化后直接恢复目标地址。
302
+ if (isStaticRoute(to.path)) {
303
+ routeInitInProgress = false
304
+ next({
305
+ path: to.path,
306
+ query: to.query,
307
+ hash: to.hash,
308
+ replace: true
309
+ })
310
+ return
311
+ }
312
+
313
+ // 8. 验证目标路径权限
314
+ const { homePath } = useCommon()
315
+ const { path: validatedPath, hasPermission } = RoutePermissionValidator.validatePath(
316
+ to.path,
317
+ menuList,
318
+ homePath.value || '/'
319
+ )
320
+
321
+ // 初始化成功,重置进行中标记
322
+ routeInitInProgress = false
323
+
324
+ // 9. 重新导航到目标路由
325
+ if (!hasPermission) {
326
+ // 无权限访问,跳转到首页
327
+ closeLoading()
328
+
329
+ // 输出警告信息
330
+ console.warn(`[RouteGuard] 用户无权限访问路径: ${to.path},已跳转到首页`)
331
+
332
+ // 直接跳转到首页
333
+ next({
334
+ path: validatedPath,
335
+ replace: true
336
+ })
337
+ } else {
338
+ // 有权限,正常导航
339
+ next({
340
+ path: to.path,
341
+ query: to.query,
342
+ hash: to.hash,
343
+ replace: true
344
+ })
345
+ }
346
+ } catch (error) {
347
+ console.error('[RouteGuard] 动态路由注册失败:', error)
348
+
349
+ // 关闭 loading
350
+ closeLoading()
351
+
352
+ // 401 错误:axios 拦截器已处理退出登录,取消当前导航
353
+ if (isUnauthorizedError(error)) {
354
+ // 重置状态,允许重新登录后再次初始化
355
+ routeInitInProgress = false
356
+ next(false)
357
+ return
358
+ }
359
+
360
+ if (isForbiddenError(error)) {
361
+ routeInitFailed = true
362
+ routeInitInProgress = false
363
+ next({ name: 'Exception403', replace: true })
364
+ return
365
+ }
366
+
367
+ // 标记初始化失败,防止死循环
368
+ routeInitFailed = true
369
+ routeInitInProgress = false
370
+
371
+ // 输出详细错误信息,便于排查
372
+ if (isHttpError(error)) {
373
+ console.error(`[RouteGuard] 错误码: ${error.code}, 消息: ${error.message}`)
374
+ }
375
+
376
+ // 跳转到 500 页面,使用 replace 避免产生历史记录
377
+ next({ name: 'Exception500', replace: true })
378
+ }
379
+ }
380
+
381
+ /**
382
+ * 获取用户信息
383
+ */
384
+ async function fetchUserInfo(): Promise<void> {
385
+ const userStore = useUserStore()
386
+ const data = await fetchGetUserInfo()
387
+ userStore.setUserInfo(data)
388
+ // 检查并清理工作台标签页(如果是不同用户登录)
389
+ userStore.checkAndClearWorktabs()
390
+ }
391
+
392
+ /**
393
+ * 重置路由相关状态
394
+ */
395
+ export function resetRouterState(delay: number): void {
396
+ const reset = () => {
397
+ routeRegistry?.unregister()
398
+ IframeRouteManager.getInstance().clear()
399
+
400
+ const menuStore = useMenuStore()
401
+ menuStore.removeAllDynamicRoutes()
402
+ menuStore.setMenuList([])
403
+
404
+ // 重置路由初始化状态,允许重新登录后再次初始化
405
+ resetRouteInitState()
406
+ }
407
+
408
+ if (delay > 0) {
409
+ setTimeout(reset, delay)
410
+ } else {
411
+ reset()
412
+ }
413
+ }
414
+
415
+ /**
416
+ * 处理根路径重定向到首页
417
+ * @returns true 表示已处理跳转,false 表示无需跳转
418
+ */
419
+ function handleRootPathRedirect(to: RouteLocationNormalized, next: NavigationGuardNext): boolean {
420
+ if (to.path !== '/') {
421
+ return false
422
+ }
423
+
424
+ const { homePath } = useCommon()
425
+ if (homePath.value && homePath.value !== '/') {
426
+ next({ path: homePath.value, replace: true })
427
+ return true
428
+ }
429
+
430
+ return false
431
+ }
432
+
433
+ /**
434
+ * 判断是否为未授权错误(401)
435
+ */
436
+ function isUnauthorizedError(error: unknown): boolean {
437
+ return isHttpError(error) && error.code === ApiStatus.unauthorized
438
+ }
439
+
440
+ function isForbiddenError(error: unknown): boolean {
441
+ return isHttpError(error) && error.code === ApiStatus.forbidden
442
+ }
@@ -0,0 +1,24 @@
1
+ import type { App } from 'vue'
2
+ import { createRouter, createWebHashHistory } from 'vue-router'
3
+ import { staticRoutes } from './routes/staticRoutes'
4
+ import { configureNProgress } from '@/utils/router'
5
+ import { setupBeforeEachGuard } from './guards/beforeEach'
6
+ import { setupAfterEachGuard } from './guards/afterEach'
7
+ import AppConfig from '@/config'
8
+
9
+ // 创建路由实例
10
+ export const router = createRouter({
11
+ history: createWebHashHistory(),
12
+ routes: staticRoutes // 静态路由
13
+ })
14
+
15
+ // 初始化路由
16
+ export function initRouter(app: App<Element>): void {
17
+ configureNProgress() // 顶部进度条
18
+ setupBeforeEachGuard(router) // 路由前置守卫
19
+ setupAfterEachGuard(router) // 路由后置守卫
20
+ app.use(router)
21
+ }
22
+
23
+ // 主页路径,默认使用菜单第一个有效路径,配置后使用此路径
24
+ export const HOME_PAGE_PATH = AppConfig.navigation.homePath
@@ -0,0 +1,23 @@
1
+ import { AppRouteRecord } from '@/types/router'
2
+
3
+ export const dashboardRoutes: AppRouteRecord = {
4
+ name: 'Dashboard',
5
+ path: '/dashboard',
6
+ component: '/index/index',
7
+ meta: {
8
+ title: 'menus.dashboard.title',
9
+ icon: 'ri:dashboard-3-line'
10
+ },
11
+ children: [
12
+ {
13
+ path: 'console',
14
+ name: 'Console',
15
+ component: '/dashboard/console',
16
+ meta: {
17
+ title: 'menus.dashboard.console',
18
+ keepAlive: true,
19
+ fixedTab: true
20
+ }
21
+ }
22
+ ]
23
+ }
@@ -0,0 +1,109 @@
1
+ import { AppRouteRecord } from '@/types/router'
2
+ import { resultExampleRoutes } from './result'
3
+
4
+ export const examplesRoutes: AppRouteRecord = {
5
+ name: 'Examples',
6
+ path: '/examples',
7
+ component: '/index/index',
8
+ meta: {
9
+ title: 'menus.examples.title',
10
+ icon: 'ri:apps-2-line'
11
+ },
12
+ children: [
13
+ {
14
+ path: 'overview',
15
+ name: 'ExampleOverview',
16
+ component: '/examples/overview',
17
+ meta: {
18
+ title: 'menus.examples.overview',
19
+ icon: 'ri:route-line',
20
+ keepAlive: true
21
+ }
22
+ },
23
+ {
24
+ path: 'search-table',
25
+ name: 'SearchTableExample',
26
+ component: '/examples/search-table',
27
+ meta: {
28
+ title: 'menus.examples.searchTable',
29
+ icon: 'ri:table-view',
30
+ keepAlive: true
31
+ }
32
+ },
33
+ {
34
+ path: 'crud-workspace',
35
+ name: 'CrudWorkspaceExample',
36
+ component: '/examples/crud-workspace',
37
+ meta: {
38
+ title: 'menus.examples.crudWorkspace',
39
+ icon: 'ri:edit-box-line',
40
+ keepAlive: true
41
+ }
42
+ },
43
+ {
44
+ path: 'analytics',
45
+ name: 'AnalyticsDashboardExample',
46
+ component: '/examples/analytics',
47
+ meta: {
48
+ title: 'menus.examples.analytics',
49
+ icon: 'ri:line-chart-line',
50
+ keepAlive: true
51
+ }
52
+ },
53
+ {
54
+ path: 'complex-form',
55
+ name: 'ComplexFormExample',
56
+ component: '/examples/complex-form',
57
+ meta: {
58
+ title: 'menus.examples.complexForm',
59
+ icon: 'ri:list-check-3',
60
+ keepAlive: true
61
+ }
62
+ },
63
+ {
64
+ path: 'permissions',
65
+ name: 'PermissionPlaygroundExample',
66
+ component: '/examples/permissions',
67
+ meta: {
68
+ title: 'menus.examples.permissions',
69
+ icon: 'ri:shield-keyhole-line',
70
+ authList: [
71
+ { title: '新增', authMark: 'create' },
72
+ { title: '编辑', authMark: 'edit' },
73
+ { title: '导出', authMark: 'export' }
74
+ ],
75
+ keepAlive: true
76
+ }
77
+ },
78
+ {
79
+ path: 'navigation',
80
+ name: 'NavigationExamples',
81
+ meta: {
82
+ title: 'menus.examples.navigation.title',
83
+ icon: 'ri:stack-line'
84
+ },
85
+ children: [
86
+ {
87
+ path: 'state',
88
+ name: 'NavigationState',
89
+ component: '/examples/navigation/state',
90
+ meta: {
91
+ title: 'menus.examples.navigation.state',
92
+ keepAlive: true
93
+ }
94
+ },
95
+ {
96
+ path: 'detail/:id',
97
+ name: 'NavigationDetail',
98
+ component: '/examples/navigation/detail',
99
+ meta: {
100
+ title: 'menus.examples.navigation.detail',
101
+ isHide: true,
102
+ activePath: '/examples/navigation/state'
103
+ }
104
+ }
105
+ ]
106
+ },
107
+ resultExampleRoutes
108
+ ]
109
+ }
@@ -0,0 +1,46 @@
1
+ import { AppRouteRecord } from '@/types/router'
2
+
3
+ export const exceptionRoutes: AppRouteRecord = {
4
+ path: '/exception',
5
+ name: 'Exception',
6
+ component: '/index/index',
7
+ meta: {
8
+ title: 'menus.exception.title',
9
+ icon: 'ri:error-warning-line'
10
+ },
11
+ children: [
12
+ {
13
+ path: '403',
14
+ name: 'Exception403',
15
+ component: '/exception/403',
16
+ meta: {
17
+ title: 'menus.exception.forbidden',
18
+ keepAlive: true,
19
+ isHideTab: true,
20
+ isFullPage: true
21
+ }
22
+ },
23
+ {
24
+ path: '404',
25
+ name: 'Exception404',
26
+ component: '/exception/404',
27
+ meta: {
28
+ title: 'menus.exception.notFound',
29
+ keepAlive: true,
30
+ isHideTab: true,
31
+ isFullPage: true
32
+ }
33
+ },
34
+ {
35
+ path: '500',
36
+ name: 'Exception500',
37
+ component: '/exception/500',
38
+ meta: {
39
+ title: 'menus.exception.serverError',
40
+ keepAlive: true,
41
+ isHideTab: true,
42
+ isFullPage: true
43
+ }
44
+ }
45
+ ]
46
+ }
@@ -0,0 +1,12 @@
1
+ import { AppRouteRecord } from '@/types/router'
2
+ import { dashboardRoutes } from './dashboard'
3
+ import { examplesRoutes } from './examples'
4
+ import AppConfig from '@/config'
5
+
6
+ /**
7
+ * 导出所有模块化路由
8
+ */
9
+ export const routeModules: AppRouteRecord[] = [
10
+ dashboardRoutes,
11
+ ...(AppConfig.features.examples ? [examplesRoutes] : [])
12
+ ]
@@ -0,0 +1,32 @@
1
+ import { AppRouteRecord } from '@/types/router'
2
+
3
+ export const resultExampleRoutes: AppRouteRecord = {
4
+ path: 'result',
5
+ name: 'ExampleResult',
6
+ meta: {
7
+ title: 'menus.examples.result.title',
8
+ icon: 'ri:checkbox-circle-line'
9
+ },
10
+ children: [
11
+ {
12
+ path: 'success',
13
+ name: 'ResultSuccess',
14
+ component: '/result/success',
15
+ meta: {
16
+ title: 'menus.examples.result.success',
17
+ icon: 'ri:checkbox-circle-line',
18
+ keepAlive: true
19
+ }
20
+ },
21
+ {
22
+ path: 'fail',
23
+ name: 'ResultFail',
24
+ component: '/result/fail',
25
+ meta: {
26
+ title: 'menus.examples.result.fail',
27
+ icon: 'ri:close-circle-line',
28
+ keepAlive: true
29
+ }
30
+ }
31
+ ]
32
+ }
@@ -0,0 +1,9 @@
1
+ // 权限文档:https://www.artd.pro/docs/zh/guide/in-depth/permission.html
2
+ import { AppRouteRecord } from '@/types/router'
3
+ import { routeModules } from '../modules'
4
+
5
+ /**
6
+ * 动态路由(需要权限才能访问的路由)
7
+ * 用于渲染菜单以及根据菜单权限动态加载路由,如果没有权限无法访问
8
+ */
9
+ export const asyncRoutes: AppRouteRecord[] = routeModules