@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,745 @@
1
+ /**
2
+ * useChart - ECharts 图表管理
3
+ *
4
+ * 提供完整的 ECharts 图表生命周期管理和配置能力,简化图表开发流程。
5
+ * 自动处理图表初始化、更新、销毁、主题切换、响应式调整等复杂逻辑。
6
+ *
7
+ * ## 核心功能
8
+ *
9
+ * 1. 图表生命周期管理 - 自动处理初始化、更新、销毁,支持延迟加载和可见性检测
10
+ * 2. 主题自动适配 - 响应系统主题变化,自动更新图表样式和配色
11
+ * 3. 响应式调整 - 监听窗口大小、菜单展开等变化,自动调整图表尺寸
12
+ * 4. 空状态处理 - 优雅的空数据展示,自动显示"暂无数据"提示
13
+ * 5. 样式配置统一 - 提供坐标轴、图例、提示框等统一的样式配置方法
14
+ * 6. 性能优化 - 防抖处理、样式缓存、requestAnimationFrame 优化
15
+ * 7. 高级组件抽象 - useChartComponent 提供更高层次的图表组件封装
16
+ *
17
+ * ## 使用示例
18
+ *
19
+ * ```typescript
20
+ * // 基础用法
21
+ * const {
22
+ * chartRef,
23
+ * initChart,
24
+ * updateChart,
25
+ * getAxisLineStyle,
26
+ * getTooltipStyle
27
+ * } = useChart()
28
+ *
29
+ * onMounted(() => {
30
+ * initChart({
31
+ * xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed'] },
32
+ * yAxis: { type: 'value' },
33
+ * series: [{ data: [120, 200, 150], type: 'bar' }]
34
+ * })
35
+ * })
36
+ *
37
+ * // 高级用法 - 组件抽象
38
+ * const chart = useChartComponent({
39
+ * props,
40
+ * generateOptions: () => ({
41
+ * // ECharts 配置
42
+ * }),
43
+ * checkEmpty: () => data.value.length === 0,
44
+ * watchSources: [() => props.data]
45
+ * })
46
+ * ```
47
+ *
48
+ * @module useChart
49
+ * @author Art Design Pro Team
50
+ */
51
+
52
+ import { echarts, type EChartsOption } from '@/plugins/echarts'
53
+ import { storeToRefs } from 'pinia'
54
+ import { useSettingStore } from '@/store/modules/setting'
55
+ import { getCssVar } from '@/utils/ui'
56
+ import type { BaseChartProps, ChartThemeConfig, UseChartOptions } from '@/types/component/chart'
57
+
58
+ // 图表主题配置
59
+ export const useChartOps = (): ChartThemeConfig => ({
60
+ /** */
61
+ chartHeight: '16rem',
62
+ /** 字体大小 */
63
+ fontSize: 13,
64
+ /** 字体颜色 */
65
+ fontColor: '#999',
66
+ /** 主题颜色 */
67
+ themeColor: getCssVar('--el-color-primary-light-1'),
68
+ /** 颜色组 */
69
+ colors: [
70
+ getCssVar('--el-color-primary-light-1'),
71
+ '#4ABEFF',
72
+ '#EDF2FF',
73
+ '#14DEBA',
74
+ '#FFAF20',
75
+ '#FA8A6C',
76
+ '#FFAF20'
77
+ ]
78
+ })
79
+
80
+ // 常量定义
81
+ const RESIZE_DELAYS = [50, 100, 200, 350] as const
82
+ const MENU_RESIZE_DELAYS = [50, 100, 200] as const
83
+ const RESIZE_DEBOUNCE_DELAY = 100
84
+
85
+ export function useChart(options: UseChartOptions = {}) {
86
+ const { initOptions, initDelay = 0, threshold = 0.1, autoTheme = true } = options
87
+
88
+ const settingStore = useSettingStore()
89
+ const { isDark, menuOpen, menuType } = storeToRefs(settingStore)
90
+
91
+ const chartRef = ref<HTMLElement>()
92
+ let chart: echarts.ECharts | null = null
93
+ let intersectionObserver: IntersectionObserver | null = null
94
+ let pendingOptions: EChartsOption | null = null
95
+ let resizeTimeoutId: number | null = null
96
+ let resizeFrameId: number | null = null
97
+ let isDestroyed = false
98
+ let emptyStateDiv: HTMLElement | null = null
99
+
100
+ // 清理定时器的统一方法
101
+ const clearTimers = () => {
102
+ if (resizeTimeoutId) {
103
+ clearTimeout(resizeTimeoutId)
104
+ resizeTimeoutId = null
105
+ }
106
+ if (resizeFrameId) {
107
+ cancelAnimationFrame(resizeFrameId)
108
+ resizeFrameId = null
109
+ }
110
+ }
111
+
112
+ // 使用 requestAnimationFrame 优化 resize 处理
113
+ const requestAnimationResize = () => {
114
+ if (resizeFrameId) {
115
+ cancelAnimationFrame(resizeFrameId)
116
+ }
117
+ resizeFrameId = requestAnimationFrame(() => {
118
+ handleResize()
119
+ resizeFrameId = null
120
+ })
121
+ }
122
+
123
+ // 防抖的resize处理(用于窗口resize事件)
124
+ const debouncedResize = () => {
125
+ if (resizeTimeoutId) {
126
+ clearTimeout(resizeTimeoutId)
127
+ }
128
+ resizeTimeoutId = window.setTimeout(() => {
129
+ requestAnimationResize()
130
+ resizeTimeoutId = null
131
+ }, RESIZE_DEBOUNCE_DELAY)
132
+ }
133
+
134
+ // 多延迟resize处理 - 统一方法
135
+ const multiDelayResize = (delays: readonly number[]) => {
136
+ // 立即调用一次,快速响应
137
+ nextTick(requestAnimationResize)
138
+
139
+ // 使用延迟时间,确保图表正确适应变化
140
+ delays.forEach((delay) => {
141
+ setTimeout(requestAnimationResize, delay)
142
+ })
143
+ }
144
+
145
+ // 收缩菜单时,重新计算图表大小(仅在图表存在时监听)
146
+ let menuOpenStopHandle: (() => void) | null = null
147
+ let menuTypeStopHandle: (() => void) | null = null
148
+
149
+ const setupMenuWatchers = () => {
150
+ menuOpenStopHandle = watch(menuOpen, () => multiDelayResize(RESIZE_DELAYS))
151
+ menuTypeStopHandle = watch(menuType, () => {
152
+ nextTick(requestAnimationResize)
153
+ setTimeout(() => multiDelayResize(MENU_RESIZE_DELAYS), 0)
154
+ })
155
+ }
156
+
157
+ const cleanupMenuWatchers = () => {
158
+ menuOpenStopHandle?.()
159
+ menuTypeStopHandle?.()
160
+ menuOpenStopHandle = null
161
+ menuTypeStopHandle = null
162
+ }
163
+
164
+ // 主题变化时重新设置图表选项
165
+ let themeStopHandle: (() => void) | null = null
166
+
167
+ const setupThemeWatcher = () => {
168
+ if (autoTheme) {
169
+ themeStopHandle = watch(isDark, () => {
170
+ // 更新空状态样式
171
+ emptyStateManager.updateStyle()
172
+
173
+ if (chart && !isDestroyed) {
174
+ // 使用 requestAnimationFrame 优化主题更新
175
+ requestAnimationFrame(() => {
176
+ if (chart && !isDestroyed) {
177
+ const currentOptions = chart.getOption()
178
+ if (currentOptions) {
179
+ updateChart(currentOptions as EChartsOption)
180
+ }
181
+ }
182
+ })
183
+ }
184
+ })
185
+ }
186
+ }
187
+
188
+ const cleanupThemeWatcher = () => {
189
+ themeStopHandle?.()
190
+ themeStopHandle = null
191
+ }
192
+
193
+ // 样式生成器 - 统一的样式配置
194
+ const createLineStyle = (color: string, width = 1, type?: 'solid' | 'dashed') => ({
195
+ color,
196
+ width,
197
+ ...(type && { type })
198
+ })
199
+
200
+ // 缓存样式配置以减少重复计算
201
+ const styleCache = {
202
+ axisLine: null as any,
203
+ splitLine: null as any,
204
+ axisLabel: null as any,
205
+ lastDarkValue: isDark.value
206
+ }
207
+
208
+ const clearStyleCache = () => {
209
+ styleCache.axisLine = null
210
+ styleCache.splitLine = null
211
+ styleCache.axisLabel = null
212
+ styleCache.lastDarkValue = isDark.value
213
+ }
214
+
215
+ // 坐标轴线样式
216
+ const getAxisLineStyle = (show: boolean = true) => {
217
+ if (styleCache.lastDarkValue !== isDark.value) {
218
+ clearStyleCache()
219
+ }
220
+ if (!styleCache.axisLine) {
221
+ styleCache.axisLine = {
222
+ show,
223
+ lineStyle: createLineStyle(isDark.value ? '#444' : '#EDEDED')
224
+ }
225
+ }
226
+ return styleCache.axisLine
227
+ }
228
+
229
+ // 分割线样式
230
+ const getSplitLineStyle = (show: boolean = true) => {
231
+ if (styleCache.lastDarkValue !== isDark.value) {
232
+ clearStyleCache()
233
+ }
234
+ if (!styleCache.splitLine) {
235
+ styleCache.splitLine = {
236
+ show,
237
+ lineStyle: createLineStyle(isDark.value ? '#444' : '#EDEDED', 1, 'dashed')
238
+ }
239
+ }
240
+ return styleCache.splitLine
241
+ }
242
+
243
+ // 坐标轴标签样式
244
+ const getAxisLabelStyle = (show: boolean = true) => {
245
+ if (styleCache.lastDarkValue !== isDark.value) {
246
+ clearStyleCache()
247
+ }
248
+ if (!styleCache.axisLabel) {
249
+ const { fontColor, fontSize } = useChartOps()
250
+ styleCache.axisLabel = {
251
+ show,
252
+ color: fontColor,
253
+ fontSize
254
+ }
255
+ }
256
+ return styleCache.axisLabel
257
+ }
258
+
259
+ // 坐标轴刻度样式(静态配置,无需缓存)
260
+ const getAxisTickStyle = () => ({
261
+ show: false
262
+ })
263
+
264
+ // 获取动画配置
265
+ const getAnimationConfig = (animationDelay: number = 50, animationDuration: number = 1500) => ({
266
+ animationDelay: (idx: number) => idx * animationDelay + 200,
267
+ animationDuration: (idx: number) => animationDuration - idx * 50,
268
+ animationEasing: 'quarticOut' as const
269
+ })
270
+
271
+ // 获取统一的 tooltip 配置
272
+ const getTooltipStyle = (trigger: 'item' | 'axis' = 'axis', customOptions: any = {}) => ({
273
+ trigger,
274
+ backgroundColor: isDark.value ? 'rgba(0, 0, 0, 0.8)' : 'rgba(255, 255, 255, 0.9)',
275
+ borderColor: isDark.value ? '#333' : '#ddd',
276
+ borderWidth: 1,
277
+ textStyle: {
278
+ color: isDark.value ? '#fff' : '#333'
279
+ },
280
+ ...customOptions
281
+ })
282
+
283
+ // 获取统一的图例配置
284
+ const getLegendStyle = (
285
+ position: 'bottom' | 'top' | 'left' | 'right' = 'bottom',
286
+ customOptions: any = {}
287
+ ) => {
288
+ const baseConfig = {
289
+ textStyle: {
290
+ color: isDark.value ? '#fff' : '#333'
291
+ },
292
+ itemWidth: 12,
293
+ itemHeight: 12,
294
+ itemGap: 20,
295
+ ...customOptions
296
+ }
297
+
298
+ // 根据位置设置不同的配置
299
+ switch (position) {
300
+ case 'bottom':
301
+ return {
302
+ ...baseConfig,
303
+ bottom: 0,
304
+ left: 'center',
305
+ orient: 'horizontal',
306
+ icon: 'roundRect'
307
+ }
308
+ case 'top':
309
+ return {
310
+ ...baseConfig,
311
+ top: 0,
312
+ left: 'center',
313
+ orient: 'horizontal',
314
+ icon: 'roundRect'
315
+ }
316
+ case 'left':
317
+ return {
318
+ ...baseConfig,
319
+ left: 0,
320
+ top: 'center',
321
+ orient: 'vertical',
322
+ icon: 'roundRect'
323
+ }
324
+ case 'right':
325
+ return {
326
+ ...baseConfig,
327
+ right: 0,
328
+ top: 'center',
329
+ orient: 'vertical',
330
+ icon: 'roundRect'
331
+ }
332
+ default:
333
+ return baseConfig
334
+ }
335
+ }
336
+
337
+ // 根据图例位置计算 grid 配置
338
+ const getGridWithLegend = (
339
+ showLegend: boolean,
340
+ legendPosition: 'bottom' | 'top' | 'left' | 'right' = 'bottom',
341
+ baseGrid: any = {}
342
+ ) => {
343
+ const defaultGrid = {
344
+ top: 15,
345
+ right: 15,
346
+ bottom: 8,
347
+ left: 0,
348
+ containLabel: true,
349
+ ...baseGrid
350
+ }
351
+
352
+ if (!showLegend) {
353
+ return defaultGrid
354
+ }
355
+
356
+ // 根据图例位置调整 grid
357
+ switch (legendPosition) {
358
+ case 'bottom':
359
+ return {
360
+ ...defaultGrid,
361
+ bottom: 40
362
+ }
363
+ case 'top':
364
+ return {
365
+ ...defaultGrid,
366
+ top: 40
367
+ }
368
+ case 'left':
369
+ return {
370
+ ...defaultGrid,
371
+ left: 120
372
+ }
373
+ case 'right':
374
+ return {
375
+ ...defaultGrid,
376
+ right: 120
377
+ }
378
+ default:
379
+ return defaultGrid
380
+ }
381
+ }
382
+
383
+ // 创建IntersectionObserver
384
+ const createIntersectionObserver = () => {
385
+ if (intersectionObserver || !chartRef.value) return
386
+
387
+ intersectionObserver = new IntersectionObserver(
388
+ (entries) => {
389
+ entries.forEach((entry) => {
390
+ if (entry.isIntersecting && pendingOptions && !isDestroyed) {
391
+ // 使用 requestAnimationFrame 确保在下一帧初始化图表
392
+ requestAnimationFrame(() => {
393
+ if (!isDestroyed && pendingOptions) {
394
+ try {
395
+ // 元素变为可见,初始化图表
396
+ if (!chart) {
397
+ chart = echarts.init(entry.target as HTMLElement)
398
+ }
399
+
400
+ // 触发自定义事件,让组件处理动画逻辑
401
+ const event = new CustomEvent('chartVisible', {
402
+ detail: { options: pendingOptions }
403
+ })
404
+ entry.target.dispatchEvent(event)
405
+
406
+ pendingOptions = null
407
+ cleanupIntersectionObserver()
408
+ } catch (error) {
409
+ console.error('图表初始化失败:', error)
410
+ }
411
+ }
412
+ })
413
+ }
414
+ })
415
+ },
416
+ { threshold }
417
+ )
418
+
419
+ intersectionObserver.observe(chartRef.value)
420
+ }
421
+
422
+ // 清理IntersectionObserver
423
+ const cleanupIntersectionObserver = () => {
424
+ if (intersectionObserver) {
425
+ intersectionObserver.disconnect()
426
+ intersectionObserver = null
427
+ }
428
+ }
429
+
430
+ // 检查容器是否可见
431
+ const isContainerVisible = (element: HTMLElement): boolean => {
432
+ const rect = element.getBoundingClientRect()
433
+ return rect.width > 0 && rect.height > 0 && rect.top < window.innerHeight && rect.bottom > 0
434
+ }
435
+
436
+ // 图表初始化核心逻辑
437
+ const performChartInit = (options: EChartsOption) => {
438
+ if (!chart && chartRef.value && !isDestroyed) {
439
+ chart = echarts.init(chartRef.value)
440
+ // 图表创建后立即设置监听器
441
+ setupMenuWatchers()
442
+ setupThemeWatcher()
443
+ }
444
+ if (chart && !isDestroyed) {
445
+ chart.setOption(options)
446
+ pendingOptions = null
447
+ }
448
+ }
449
+
450
+ // 空状态管理器
451
+ const emptyStateManager = {
452
+ create: () => {
453
+ if (!chartRef.value || emptyStateDiv) return
454
+
455
+ emptyStateDiv = document.createElement('div')
456
+ emptyStateDiv.style.cssText = `
457
+ position: absolute;
458
+ top: 0;
459
+ left: 0;
460
+ right: 0;
461
+ bottom: 0;
462
+ display: flex;
463
+ flex-direction: column;
464
+ align-items: center;
465
+ justify-content: center;
466
+ font-size: 12px;
467
+ color: ${isDark.value ? '#555555' : '#B3B2B2'};
468
+ background: transparent;
469
+ z-index: 10;
470
+ `
471
+ emptyStateDiv.innerHTML = `<span>暂无数据</span>`
472
+
473
+ // 确保父容器有相对定位
474
+ if (
475
+ chartRef.value.style.position !== 'relative' &&
476
+ chartRef.value.style.position !== 'absolute'
477
+ ) {
478
+ chartRef.value.style.position = 'relative'
479
+ }
480
+
481
+ chartRef.value.appendChild(emptyStateDiv)
482
+ },
483
+
484
+ remove: () => {
485
+ if (emptyStateDiv && chartRef.value) {
486
+ chartRef.value.removeChild(emptyStateDiv)
487
+ emptyStateDiv = null
488
+ }
489
+ },
490
+
491
+ updateStyle: () => {
492
+ if (emptyStateDiv) {
493
+ emptyStateDiv.style.color = isDark.value ? '#666' : '#999'
494
+ }
495
+ }
496
+ }
497
+
498
+ // 初始化图表
499
+ const initChart = (options: EChartsOption = {}, isEmpty: boolean = false) => {
500
+ if (!chartRef.value || isDestroyed) return
501
+
502
+ const mergedOptions = { ...initOptions, ...options }
503
+
504
+ try {
505
+ if (isEmpty) {
506
+ // 处理空数据情况 - 显示自定义空状态div
507
+ if (chart) {
508
+ chart.clear()
509
+ }
510
+ emptyStateManager.create()
511
+ return
512
+ } else {
513
+ // 有数据时移除空状态div
514
+ emptyStateManager.remove()
515
+ }
516
+
517
+ if (isContainerVisible(chartRef.value)) {
518
+ // 容器可见,正常初始化
519
+ if (initDelay > 0) {
520
+ setTimeout(() => performChartInit(mergedOptions), initDelay)
521
+ } else {
522
+ performChartInit(mergedOptions)
523
+ }
524
+ } else {
525
+ // 容器不可见,保存选项并设置监听器
526
+ pendingOptions = mergedOptions
527
+ createIntersectionObserver()
528
+ }
529
+ } catch (error) {
530
+ console.error('图表初始化失败:', error)
531
+ }
532
+ }
533
+
534
+ // 更新图表
535
+ const updateChart = (options: EChartsOption) => {
536
+ if (isDestroyed) return
537
+
538
+ try {
539
+ if (!chart) {
540
+ // 如果图表不存在,先初始化
541
+ initChart(options)
542
+ return
543
+ }
544
+ chart.setOption(options)
545
+ } catch (error) {
546
+ console.error('图表更新失败:', error)
547
+ }
548
+ }
549
+
550
+ // 处理窗口大小变化
551
+ const handleResize = () => {
552
+ if (chart && !isDestroyed) {
553
+ try {
554
+ chart.resize()
555
+ } catch (error) {
556
+ console.error('图表resize失败:', error)
557
+ }
558
+ }
559
+ }
560
+
561
+ // 销毁图表
562
+ const destroyChart = () => {
563
+ isDestroyed = true
564
+
565
+ if (chart) {
566
+ try {
567
+ chart.dispose()
568
+ } catch (error) {
569
+ console.error('图表销毁失败:', error)
570
+ } finally {
571
+ chart = null
572
+ }
573
+ }
574
+
575
+ // 清理所有监听器和资源
576
+ cleanupMenuWatchers()
577
+ cleanupThemeWatcher()
578
+ emptyStateManager.remove()
579
+ cleanupIntersectionObserver()
580
+ clearTimers()
581
+ clearStyleCache()
582
+ pendingOptions = null
583
+ }
584
+
585
+ // 获取图表实例
586
+ const getChartInstance = () => chart
587
+
588
+ // 获取图表是否已初始化
589
+ const isChartInitialized = () => chart !== null
590
+
591
+ onMounted(() => {
592
+ window.addEventListener('resize', debouncedResize)
593
+ })
594
+
595
+ onBeforeUnmount(() => {
596
+ window.removeEventListener('resize', debouncedResize)
597
+ })
598
+
599
+ onUnmounted(() => {
600
+ destroyChart()
601
+ })
602
+
603
+ return {
604
+ isDark,
605
+ chartRef,
606
+ initChart,
607
+ updateChart,
608
+ handleResize,
609
+ destroyChart,
610
+ getChartInstance,
611
+ isChartInitialized,
612
+ emptyStateManager,
613
+ getAxisLineStyle,
614
+ getSplitLineStyle,
615
+ getAxisLabelStyle,
616
+ getAxisTickStyle,
617
+ getAnimationConfig,
618
+ getTooltipStyle,
619
+ getLegendStyle,
620
+ useChartOps,
621
+ getGridWithLegend
622
+ }
623
+ }
624
+
625
+ // 高级图表组件抽象
626
+ interface UseChartComponentOptions<T extends BaseChartProps> {
627
+ /** Props响应式对象 */
628
+ props: T
629
+ /** 图表配置生成函数 */
630
+ generateOptions: () => EChartsOption
631
+ /** 空数据检查函数 */
632
+ checkEmpty?: () => boolean
633
+ /** 自定义监听的响应式数据 */
634
+ watchSources?: (() => any)[]
635
+ /** 自定义可视事件处理 */
636
+ onVisible?: () => void
637
+ /** useChart选项 */
638
+ chartOptions?: UseChartOptions
639
+ }
640
+
641
+ export function useChartComponent<T extends BaseChartProps>(options: UseChartComponentOptions<T>) {
642
+ const {
643
+ props,
644
+ generateOptions,
645
+ checkEmpty,
646
+ watchSources = [],
647
+ onVisible,
648
+ chartOptions = {}
649
+ } = options
650
+
651
+ const chart = useChart(chartOptions)
652
+ const { chartRef, initChart, isDark, emptyStateManager } = chart
653
+
654
+ // 检查是否为空数据
655
+ const isEmpty = computed(() => {
656
+ if (props.isEmpty) return true
657
+ if (checkEmpty) return checkEmpty()
658
+ return false
659
+ })
660
+
661
+ // 更新图表
662
+ const updateChart = () => {
663
+ nextTick(() => {
664
+ if (isEmpty.value) {
665
+ // 处理空数据情况 - 显示自定义空状态div
666
+ if (chart.getChartInstance()) {
667
+ chart.getChartInstance()?.clear()
668
+ }
669
+ emptyStateManager.create()
670
+ } else {
671
+ // 有数据时移除空状态div并初始化图表
672
+ emptyStateManager.remove()
673
+ initChart(generateOptions())
674
+ }
675
+ })
676
+ }
677
+
678
+ // 处理图表进入可视区域时的逻辑
679
+ const handleChartVisible = () => {
680
+ if (onVisible) {
681
+ onVisible()
682
+ } else {
683
+ updateChart()
684
+ }
685
+ }
686
+
687
+ // 存储监听器停止函数
688
+ const stopHandles: (() => void)[] = []
689
+
690
+ // 设置数据监听
691
+ const setupWatchers = () => {
692
+ // 监听自定义数据源
693
+ if (watchSources.length > 0) {
694
+ const stopHandle = watch(watchSources, updateChart, { deep: true })
695
+ stopHandles.push(stopHandle)
696
+ }
697
+
698
+ // 监听主题变化
699
+ const themeStopHandle = watch(isDark, () => {
700
+ emptyStateManager.updateStyle()
701
+ updateChart()
702
+ })
703
+ stopHandles.push(themeStopHandle)
704
+ }
705
+
706
+ // 清理所有监听器
707
+ const cleanupWatchers = () => {
708
+ stopHandles.forEach((stop) => stop())
709
+ stopHandles.length = 0
710
+ }
711
+
712
+ // 设置生命周期
713
+ const setupLifecycle = () => {
714
+ onMounted(() => {
715
+ updateChart()
716
+
717
+ // 监听图表可见事件
718
+ if (chartRef.value) {
719
+ chartRef.value.addEventListener('chartVisible', handleChartVisible)
720
+ }
721
+ })
722
+
723
+ onBeforeUnmount(() => {
724
+ // 清理事件监听器
725
+ if (chartRef.value) {
726
+ chartRef.value.removeEventListener('chartVisible', handleChartVisible)
727
+ }
728
+ // 清理所有监听器
729
+ cleanupWatchers()
730
+ // 清理空状态div
731
+ emptyStateManager.remove()
732
+ })
733
+ }
734
+
735
+ // 初始化
736
+ setupWatchers()
737
+ setupLifecycle()
738
+
739
+ return {
740
+ ...chart,
741
+ isEmpty,
742
+ updateChart,
743
+ handleChartVisible
744
+ }
745
+ }