@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,568 @@
1
+ /**
2
+ * 工作标签页状态管理模块
3
+ *
4
+ * 提供多标签页功能的完整状态管理
5
+ *
6
+ * ## 主要功能
7
+ *
8
+ * - 标签页打开和关闭
9
+ * - 标签页固定和取消固定
10
+ * - 批量关闭(左侧、右侧、其他、全部)
11
+ * - 标签页缓存管理(KeepAlive)
12
+ * - 标签页标题自定义
13
+ * - 标签页路由验证
14
+ * - 动态路由参数处理
15
+ *
16
+ * ## 使用场景
17
+ *
18
+ * - 多标签页导航
19
+ * - 页面缓存控制
20
+ * - 标签页右键菜单
21
+ * - 固定常用页面
22
+ * - 批量关闭标签
23
+ *
24
+ * ## 核心特性
25
+ *
26
+ * - 智能标签页复用(同路由名称复用)
27
+ * - 固定标签页保护(不可关闭)
28
+ * - KeepAlive 缓存排除管理
29
+ * - 路由有效性验证
30
+ * - 首页自动保留
31
+ *
32
+ * ## 持久化
33
+ * - 使用 localStorage 存储
34
+ * - 存储键:sys-v{version}-worktab
35
+ * - 刷新页面保持标签状态
36
+ *
37
+ * @module store/modules/worktab
38
+ * @author Art Design Pro Team
39
+ */
40
+ import { defineStore } from 'pinia'
41
+ import { ref, computed } from 'vue'
42
+ import { router } from '@/router'
43
+ import { LocationQueryRaw, Router } from 'vue-router'
44
+ import { WorkTab } from '@/types'
45
+ import { useCommon } from '@/hooks/core/useCommon'
46
+
47
+ interface WorktabState {
48
+ current: Partial<WorkTab>
49
+ opened: WorkTab[]
50
+ keepAliveExclude: string[]
51
+ }
52
+
53
+ /**
54
+ * 工作台标签页管理 Store
55
+ */
56
+ export const useWorktabStore = defineStore(
57
+ 'worktabStore',
58
+ () => {
59
+ // 状态定义
60
+ const current = ref<Partial<WorkTab>>({})
61
+ const opened = ref<WorkTab[]>([])
62
+ const keepAliveExclude = ref<string[]>([])
63
+
64
+ // 计算属性
65
+ const hasOpenedTabs = computed(() => opened.value.length > 0)
66
+ const hasMultipleTabs = computed(() => opened.value.length > 1)
67
+ const currentTabIndex = computed(() =>
68
+ current.value.path ? opened.value.findIndex((tab) => tab.path === current.value.path) : -1
69
+ )
70
+
71
+ /**
72
+ * 查找标签页索引
73
+ */
74
+ const findTabIndex = (path: string): number => {
75
+ return opened.value.findIndex((tab) => tab.path === path)
76
+ }
77
+
78
+ /**
79
+ * 获取标签页
80
+ */
81
+ const getTab = (path: string): WorkTab | undefined => {
82
+ return opened.value.find((tab) => tab.path === path)
83
+ }
84
+
85
+ /**
86
+ * 检查标签页是否可关闭
87
+ */
88
+ const isTabClosable = (tab: WorkTab): boolean => {
89
+ return !tab.fixedTab
90
+ }
91
+
92
+ /**
93
+ * 安全的路由跳转
94
+ */
95
+ const safeRouterPush = (tab: Partial<WorkTab>): void => {
96
+ if (!tab.path) {
97
+ console.warn('尝试跳转到无效路径的标签页')
98
+ return
99
+ }
100
+
101
+ try {
102
+ router.push({
103
+ path: tab.path,
104
+ query: tab.query as LocationQueryRaw
105
+ })
106
+ } catch (error) {
107
+ console.error('路由跳转失败:', error)
108
+ }
109
+ }
110
+
111
+ /**
112
+ * 打开或激活一个选项卡
113
+ */
114
+ const openTab = (tab: WorkTab): void => {
115
+ if (!tab.path) {
116
+ console.warn('尝试打开无效的标签页')
117
+ return
118
+ }
119
+
120
+ // 从 keepAlive 排除列表中移除
121
+ if (tab.name) {
122
+ removeKeepAliveExclude(tab.name)
123
+ }
124
+
125
+ // 先根据路由名称查找(应对动态路由参数导致的多开问题),找不到再根据路径查找
126
+ let existingIndex = -1
127
+ if (tab.name) {
128
+ existingIndex = opened.value.findIndex((t) => t.name === tab.name)
129
+ }
130
+ if (existingIndex === -1) {
131
+ existingIndex = findTabIndex(tab.path)
132
+ }
133
+
134
+ if (existingIndex === -1) {
135
+ // 新增标签页
136
+ const insertIndex = tab.fixedTab ? findFixedTabInsertIndex() : opened.value.length
137
+ const newTab = { ...tab }
138
+
139
+ if (tab.fixedTab) {
140
+ opened.value.splice(insertIndex, 0, newTab)
141
+ } else {
142
+ opened.value.push(newTab)
143
+ }
144
+
145
+ current.value = newTab
146
+ } else {
147
+ // 更新现有标签页(当动态路由参数或查询变更时,复用同一标签)
148
+ const existingTab = opened.value[existingIndex]
149
+
150
+ opened.value[existingIndex] = {
151
+ ...existingTab,
152
+ path: tab.path,
153
+ params: tab.params,
154
+ query: tab.query,
155
+ title: tab.title || existingTab.title,
156
+ fixedTab: tab.fixedTab ?? existingTab.fixedTab,
157
+ keepAlive: tab.keepAlive ?? existingTab.keepAlive,
158
+ name: tab.name || existingTab.name,
159
+ icon: tab.icon || existingTab.icon
160
+ }
161
+
162
+ current.value = opened.value[existingIndex]
163
+ }
164
+ }
165
+
166
+ /**
167
+ * 查找固定标签页的插入位置
168
+ */
169
+ const findFixedTabInsertIndex = (): number => {
170
+ let insertIndex = 0
171
+ for (let i = 0; i < opened.value.length; i++) {
172
+ if (opened.value[i].fixedTab) {
173
+ insertIndex = i + 1
174
+ } else {
175
+ break
176
+ }
177
+ }
178
+ return insertIndex
179
+ }
180
+
181
+ /**
182
+ * 关闭指定的选项卡
183
+ */
184
+ const removeTab = (path: string): void => {
185
+ const targetTab = getTab(path)
186
+ const targetIndex = findTabIndex(path)
187
+
188
+ if (targetIndex === -1) {
189
+ console.warn(`尝试关闭不存在的标签页: ${path}`)
190
+ return
191
+ }
192
+
193
+ if (targetTab && !isTabClosable(targetTab)) {
194
+ console.warn(`尝试关闭固定标签页: ${path}`)
195
+ return
196
+ }
197
+
198
+ // 从标签页列表中移除
199
+ opened.value.splice(targetIndex, 1)
200
+
201
+ // 处理缓存排除
202
+ if (targetTab?.name) {
203
+ addKeepAliveExclude(targetTab)
204
+ }
205
+
206
+ const { homePath } = useCommon()
207
+
208
+ // 如果关闭后无标签页,跳转首页
209
+ if (!hasOpenedTabs.value) {
210
+ if (path !== homePath.value) {
211
+ current.value = {}
212
+ safeRouterPush({ path: homePath.value })
213
+ }
214
+ return
215
+ }
216
+
217
+ // 如果关闭的是当前激活标签,需要激活其他标签
218
+ if (current.value.path === path) {
219
+ const newIndex = targetIndex >= opened.value.length ? opened.value.length - 1 : targetIndex
220
+ current.value = opened.value[newIndex]
221
+ safeRouterPush(current.value)
222
+ }
223
+ }
224
+
225
+ /**
226
+ * 关闭左侧选项卡
227
+ */
228
+ const removeLeft = (path: string): void => {
229
+ const targetIndex = findTabIndex(path)
230
+
231
+ if (targetIndex === -1) {
232
+ console.warn(`尝试关闭左侧标签页,但目标标签页不存在: ${path}`)
233
+ return
234
+ }
235
+
236
+ // 获取左侧可关闭的标签页
237
+ const leftTabs = opened.value.slice(0, targetIndex)
238
+ const closableLeftTabs = leftTabs.filter(isTabClosable)
239
+
240
+ if (closableLeftTabs.length === 0) {
241
+ console.warn('左侧没有可关闭的标签页')
242
+ return
243
+ }
244
+
245
+ // 标记为缓存排除
246
+ markTabsToRemove(closableLeftTabs)
247
+
248
+ // 移除左侧可关闭的标签页
249
+ opened.value = opened.value.filter(
250
+ (tab, index) => index >= targetIndex || !isTabClosable(tab)
251
+ )
252
+
253
+ // 确保当前标签是激活状态
254
+ const targetTab = getTab(path)
255
+ if (targetTab) {
256
+ current.value = targetTab
257
+ }
258
+ }
259
+
260
+ /**
261
+ * 关闭右侧选项卡
262
+ */
263
+ const removeRight = (path: string): void => {
264
+ const targetIndex = findTabIndex(path)
265
+
266
+ if (targetIndex === -1) {
267
+ console.warn(`尝试关闭右侧标签页,但目标标签页不存在: ${path}`)
268
+ return
269
+ }
270
+
271
+ // 获取右侧可关闭的标签页
272
+ const rightTabs = opened.value.slice(targetIndex + 1)
273
+ const closableRightTabs = rightTabs.filter(isTabClosable)
274
+
275
+ if (closableRightTabs.length === 0) {
276
+ console.warn('右侧没有可关闭的标签页')
277
+ return
278
+ }
279
+
280
+ // 标记为缓存排除
281
+ markTabsToRemove(closableRightTabs)
282
+
283
+ // 移除右侧可关闭的标签页
284
+ opened.value = opened.value.filter(
285
+ (tab, index) => index <= targetIndex || !isTabClosable(tab)
286
+ )
287
+
288
+ // 确保当前标签是激活状态
289
+ const targetTab = getTab(path)
290
+ if (targetTab) {
291
+ current.value = targetTab
292
+ }
293
+ }
294
+
295
+ /**
296
+ * 关闭其他选项卡
297
+ */
298
+ const removeOthers = (path: string): void => {
299
+ const targetTab = getTab(path)
300
+
301
+ if (!targetTab) {
302
+ console.warn(`尝试关闭其他标签页,但目标标签页不存在: ${path}`)
303
+ return
304
+ }
305
+
306
+ // 获取其他可关闭的标签页
307
+ const otherTabs = opened.value.filter((tab) => tab.path !== path)
308
+ const closableTabs = otherTabs.filter(isTabClosable)
309
+
310
+ if (closableTabs.length === 0) {
311
+ console.warn('没有其他可关闭的标签页')
312
+ return
313
+ }
314
+
315
+ // 标记为缓存排除
316
+ markTabsToRemove(closableTabs)
317
+
318
+ // 只保留当前标签和固定标签
319
+ opened.value = opened.value.filter((tab) => tab.path === path || !isTabClosable(tab))
320
+
321
+ // 确保当前标签是激活状态
322
+ current.value = targetTab
323
+ }
324
+
325
+ /**
326
+ * 关闭所有可关闭的标签页
327
+ */
328
+ const removeAll = (): void => {
329
+ const { homePath } = useCommon()
330
+ const hasFixedTabs = opened.value.some((tab) => tab.fixedTab)
331
+
332
+ // 获取可关闭的标签页
333
+ const closableTabs = opened.value.filter((tab) => {
334
+ if (!isTabClosable(tab)) return false
335
+ // 如果有固定标签,则所有可关闭的都可以关闭;否则保留首页
336
+ return hasFixedTabs || tab.path !== homePath.value
337
+ })
338
+
339
+ if (closableTabs.length === 0) {
340
+ console.warn('没有可关闭的标签页')
341
+ return
342
+ }
343
+
344
+ // 标记为缓存排除
345
+ markTabsToRemove(closableTabs)
346
+
347
+ // 保留不可关闭的标签页和首页(当没有固定标签时)
348
+ opened.value = opened.value.filter((tab) => {
349
+ return !isTabClosable(tab) || (!hasFixedTabs && tab.path === homePath.value)
350
+ })
351
+
352
+ // 处理激活状态
353
+ if (!hasOpenedTabs.value) {
354
+ current.value = {}
355
+ safeRouterPush({ path: homePath.value })
356
+ return
357
+ }
358
+
359
+ // 选择激活的标签页:优先首页,其次第一个可用标签
360
+ const homeTab = opened.value.find((tab) => tab.path === homePath.value)
361
+ const targetTab = homeTab || opened.value[0]
362
+
363
+ current.value = targetTab
364
+ safeRouterPush(targetTab)
365
+ }
366
+
367
+ /**
368
+ * 将指定选项卡添加到 keepAlive 排除列表中
369
+ */
370
+ const addKeepAliveExclude = (tab: WorkTab): void => {
371
+ if (!tab.keepAlive || !tab.name) return
372
+
373
+ if (!keepAliveExclude.value.includes(tab.name)) {
374
+ keepAliveExclude.value.push(tab.name)
375
+ }
376
+ }
377
+
378
+ /**
379
+ * 从 keepAlive 排除列表中移除指定组件名称
380
+ */
381
+ const removeKeepAliveExclude = (name: string): void => {
382
+ if (!name) return
383
+
384
+ keepAliveExclude.value = keepAliveExclude.value.filter((item) => item !== name)
385
+ }
386
+
387
+ /**
388
+ * 将传入的一组选项卡的组件名称标记为排除缓存
389
+ */
390
+ const markTabsToRemove = (tabs: WorkTab[]): void => {
391
+ tabs.forEach((tab) => {
392
+ if (tab.name) {
393
+ addKeepAliveExclude(tab)
394
+ }
395
+ })
396
+ }
397
+
398
+ /**
399
+ * 切换指定标签页的固定状态
400
+ */
401
+ const toggleFixedTab = (path: string): void => {
402
+ const targetIndex = findTabIndex(path)
403
+
404
+ if (targetIndex === -1) {
405
+ console.warn(`尝试切换不存在标签页的固定状态: ${path}`)
406
+ return
407
+ }
408
+
409
+ const tab = { ...opened.value[targetIndex] }
410
+ tab.fixedTab = !tab.fixedTab
411
+
412
+ // 移除原位置
413
+ opened.value.splice(targetIndex, 1)
414
+
415
+ if (tab.fixedTab) {
416
+ // 固定标签插入到所有固定标签的末尾
417
+ const firstNonFixedIndex = opened.value.findIndex((t) => !t.fixedTab)
418
+ const insertIndex = firstNonFixedIndex === -1 ? opened.value.length : firstNonFixedIndex
419
+ opened.value.splice(insertIndex, 0, tab)
420
+ } else {
421
+ // 非固定标签插入到所有固定标签后
422
+ const fixedCount = opened.value.filter((t) => t.fixedTab).length
423
+ opened.value.splice(fixedCount, 0, tab)
424
+ }
425
+
426
+ // 更新当前标签引用
427
+ if (current.value.path === path) {
428
+ current.value = tab
429
+ }
430
+ }
431
+
432
+ /**
433
+ * 验证工作台标签页的路由有效性
434
+ */
435
+ const validateWorktabs = (routerInstance: Router): void => {
436
+ try {
437
+ // 动态路由校验:优先使用路由 name 判断有效性;否则用 resolve 匹配参数化路径
438
+ const isTabRouteValid = (tab: Partial<WorkTab>): boolean => {
439
+ try {
440
+ if (tab.name) {
441
+ const routes = routerInstance.getRoutes()
442
+ if (routes.some((r) => r.name === tab.name)) return true
443
+ }
444
+ if (tab.path) {
445
+ const resolved = routerInstance.resolve({
446
+ path: tab.path,
447
+ query: (tab.query as LocationQueryRaw) || undefined
448
+ })
449
+ return resolved.matched.length > 0
450
+ }
451
+ return false
452
+ } catch {
453
+ return false
454
+ }
455
+ }
456
+
457
+ // 过滤出有效的标签页
458
+ const validTabs = opened.value.filter((tab) => isTabRouteValid(tab))
459
+
460
+ if (validTabs.length !== opened.value.length) {
461
+ console.warn('发现无效的标签页路由,已自动清理')
462
+ opened.value = validTabs
463
+ }
464
+
465
+ // 验证当前激活标签的有效性
466
+ const isCurrentValid = current.value && isTabRouteValid(current.value)
467
+
468
+ if (!isCurrentValid && validTabs.length > 0) {
469
+ console.warn('当前激活标签无效,已自动切换')
470
+ current.value = validTabs[0]
471
+ } else if (!isCurrentValid) {
472
+ current.value = {}
473
+ }
474
+ } catch (error) {
475
+ console.error('验证工作台标签页失败:', error)
476
+ }
477
+ }
478
+
479
+ /**
480
+ * 清空所有状态(用于登出等场景)
481
+ */
482
+ const clearAll = (): void => {
483
+ current.value = {}
484
+ opened.value = []
485
+ keepAliveExclude.value = []
486
+ }
487
+
488
+ /**
489
+ * 获取状态快照(用于持久化存储)
490
+ */
491
+ const getStateSnapshot = (): WorktabState => {
492
+ return {
493
+ current: { ...current.value },
494
+ opened: [...opened.value],
495
+ keepAliveExclude: [...keepAliveExclude.value]
496
+ }
497
+ }
498
+
499
+ /**
500
+ * 获取标签页标题
501
+ */
502
+ const getTabTitle = (path: string): WorkTab | undefined => {
503
+ const tab = getTab(path)
504
+ return tab
505
+ }
506
+
507
+ /**
508
+ * 更新标签页标题
509
+ */
510
+ const updateTabTitle = (path: string, title: string): void => {
511
+ const tab = getTab(path)
512
+ if (tab) {
513
+ tab.customTitle = title
514
+ }
515
+ }
516
+
517
+ /**
518
+ * 重置标签页标题
519
+ */
520
+ const resetTabTitle = (path: string): void => {
521
+ const tab = getTab(path)
522
+ if (tab) {
523
+ tab.customTitle = ''
524
+ }
525
+ }
526
+
527
+ return {
528
+ // 状态
529
+ current,
530
+ opened,
531
+ keepAliveExclude,
532
+
533
+ // 计算属性
534
+ hasOpenedTabs,
535
+ hasMultipleTabs,
536
+ currentTabIndex,
537
+
538
+ // 方法
539
+ openTab,
540
+ removeTab,
541
+ removeLeft,
542
+ removeRight,
543
+ removeOthers,
544
+ removeAll,
545
+ toggleFixedTab,
546
+ validateWorktabs,
547
+ clearAll,
548
+ getStateSnapshot,
549
+
550
+ // 工具方法
551
+ findTabIndex,
552
+ getTab,
553
+ isTabClosable,
554
+ addKeepAliveExclude,
555
+ removeKeepAliveExclude,
556
+ markTabsToRemove,
557
+ getTabTitle,
558
+ updateTabTitle,
559
+ resetTabTitle
560
+ }
561
+ },
562
+ {
563
+ persist: {
564
+ key: 'worktab',
565
+ storage: localStorage
566
+ }
567
+ }
568
+ )
@@ -0,0 +1,86 @@
1
+ /**
2
+ * API 接口类型定义模块
3
+ *
4
+ * 提供所有后端接口的类型定义
5
+ *
6
+ * ## 主要功能
7
+ *
8
+ * - 通用类型(分页参数、响应结构等)
9
+ * - 认证类型(登录、用户信息等)
10
+ * - 全局命名空间声明
11
+ *
12
+ * ## 使用场景
13
+ *
14
+ * - API 请求参数类型约束
15
+ * - API 响应数据类型定义
16
+ * - 接口文档类型同步
17
+ *
18
+ * ## 注意事项
19
+ *
20
+ * - 在 .vue 文件使用需要在 eslint.config.mjs 中配置 globals: { Api: 'readonly' }
21
+ * - 使用全局命名空间,无需导入即可使用
22
+ *
23
+ * ## 使用方式
24
+ *
25
+ * ```typescript
26
+ * const params: Api.Auth.LoginParams = { userName: 'admin', password: '123456' }
27
+ * const response: Api.Auth.UserInfo = await fetchUserInfo()
28
+ * ```
29
+ *
30
+ * @module types/api/api
31
+ * @author Art Design Pro Team
32
+ */
33
+
34
+ declare namespace Api {
35
+ /** 通用类型 */
36
+ namespace Common {
37
+ /** 分页参数 */
38
+ interface PaginationParams {
39
+ /** 当前页码 */
40
+ current: number
41
+ /** 每页条数 */
42
+ size: number
43
+ /** 总条数 */
44
+ total: number
45
+ }
46
+
47
+ /** 通用搜索参数 */
48
+ type CommonSearchParams = Pick<PaginationParams, 'current' | 'size'>
49
+
50
+ /** 分页响应基础结构 */
51
+ interface PaginatedResponse<T = any> {
52
+ records: T[]
53
+ current: number
54
+ size: number
55
+ total: number
56
+ }
57
+
58
+ /** 启用状态 */
59
+ type EnableStatus = '1' | '2'
60
+ }
61
+
62
+ /** 认证类型 */
63
+ namespace Auth {
64
+ /** 登录参数 */
65
+ interface LoginParams {
66
+ username: string
67
+ password: string
68
+ }
69
+
70
+ /** 登录响应 */
71
+ interface LoginResponse {
72
+ accessToken: string
73
+ refreshToken?: string
74
+ }
75
+
76
+ /** 用户信息 */
77
+ interface UserInfo {
78
+ buttons: string[]
79
+ roles: string[]
80
+ userId: number | string
81
+ userName: string
82
+ email: string
83
+ avatar?: string
84
+ }
85
+ }
86
+ }