@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,633 @@
1
+ <!-- 烟花效果 | 礼花效果 -->
2
+ <template>
3
+ <canvas
4
+ ref="canvasRef"
5
+ class="fixed top-0 left-0 z-[9999] w-full h-full pointer-events-none"
6
+ ></canvas>
7
+ </template>
8
+
9
+ <script setup lang="ts">
10
+ import { useEventListener } from '@vueuse/core'
11
+ import { mittBus } from '@/utils/sys'
12
+ import type { Handler } from 'mitt'
13
+ import bp from '@/assets/images/ceremony/hb.png'
14
+ import sd from '@/assets/images/ceremony/sd.png'
15
+ import yd from '@/assets/images/ceremony/yd.png'
16
+
17
+ defineOptions({ name: 'ArtFireworksEffect' })
18
+
19
+ /**
20
+ * 烟花系统配置接口
21
+ * 定义了烟花效果的所有可配置参数
22
+ */
23
+ interface FireworkConfig {
24
+ /** 对象池大小 - 预先创建的粒子对象数量 */
25
+ readonly POOL_SIZE: number
26
+ /** 每次爆炸产生的粒子数量 */
27
+ readonly PARTICLES_PER_BURST: number
28
+ /** 各种形状的尺寸配置 */
29
+ readonly SIZES: {
30
+ /** 矩形粒子的宽高 */
31
+ readonly RECTANGLE: { readonly WIDTH: number; readonly HEIGHT: number }
32
+ /** 正方形粒子的边长 */
33
+ readonly SQUARE: { readonly SIZE: number }
34
+ /** 圆形粒子的直径 */
35
+ readonly CIRCLE: { readonly SIZE: number }
36
+ /** 三角形粒子的边长 */
37
+ readonly TRIANGLE: { readonly SIZE: number }
38
+ /** 椭圆粒子的宽高 */
39
+ readonly OVAL: { readonly WIDTH: number; readonly HEIGHT: number }
40
+ /** 图片粒子的宽高 */
41
+ readonly IMAGE: { readonly WIDTH: number; readonly HEIGHT: number }
42
+ }
43
+ /** 旋转相关参数 */
44
+ readonly ROTATION: {
45
+ /** 基础旋转速度 */
46
+ readonly BASE_SPEED: number
47
+ /** 随机旋转速度增量 */
48
+ readonly RANDOM_SPEED: number
49
+ /** 旋转衰减系数 - 控制旋转速度递减 */
50
+ readonly DECAY: number
51
+ }
52
+ /** 物理效果参数 */
53
+ readonly PHYSICS: {
54
+ /** 重力加速度 */
55
+ readonly GRAVITY: number
56
+ /** 下落速度阈值 - 超过此值开始淡出 */
57
+ readonly VELOCITY_THRESHOLD: number
58
+ /** 透明度衰减速度 */
59
+ readonly OPACITY_DECAY: number
60
+ }
61
+ /** 烟花粒子颜色配置(带透明度) */
62
+ readonly COLORS: readonly string[]
63
+ /** 烟花粒子形状配置(矩形出现概率更高) */
64
+ readonly SHAPES: readonly string[]
65
+ }
66
+
67
+ /**
68
+ * 单个烟花粒子对象
69
+ * 包含粒子的位置、速度、外观等所有属性
70
+ */
71
+ interface Firework {
72
+ /** X坐标位置 */
73
+ x: number
74
+ /** Y坐标位置 */
75
+ y: number
76
+ /** X方向速度 */
77
+ vx: number
78
+ /** Y方向速度 */
79
+ vy: number
80
+ /** 粒子颜色 (RGBA格式) */
81
+ color: string
82
+ /** 当前旋转角度 */
83
+ rotation: number
84
+ /** 旋转速度 */
85
+ rotationSpeed: number
86
+ /** 缩放比例 */
87
+ scale: number
88
+ /** 粒子形状类型 */
89
+ shape: string
90
+ /** 透明度 (0-1) */
91
+ opacity: number
92
+ /** 是否处于活动状态 */
93
+ active: boolean
94
+ /** 图片URL (当shape为image时使用) */
95
+ imageUrl?: string
96
+ }
97
+
98
+ /**
99
+ * 图片缓存接口
100
+ * 用于缓存预加载的图片资源
101
+ */
102
+ interface ImageCache {
103
+ [url: string]: HTMLImageElement
104
+ }
105
+
106
+ /**
107
+ * 烟花效果的全局配置
108
+ * 使用 as const 确保配置的不可变性
109
+ */
110
+ const CONFIG: FireworkConfig = {
111
+ // 性能相关配置
112
+ POOL_SIZE: 600, // 对象池大小,影响同时存在的最大粒子数
113
+ PARTICLES_PER_BURST: 200, // 每次爆炸的粒子数量,影响视觉效果密度
114
+
115
+ // 粒子尺寸配置
116
+ SIZES: {
117
+ RECTANGLE: { WIDTH: 24, HEIGHT: 12 }, // 矩形粒子尺寸
118
+ SQUARE: { SIZE: 12 }, // 正方形粒子尺寸
119
+ CIRCLE: { SIZE: 12 }, // 圆形粒子尺寸
120
+ TRIANGLE: { SIZE: 10 }, // 三角形粒子尺寸
121
+ OVAL: { WIDTH: 24, HEIGHT: 12 }, // 椭圆粒子尺寸
122
+ IMAGE: { WIDTH: 30, HEIGHT: 30 } // 图片粒子尺寸
123
+ },
124
+
125
+ // 旋转动画配置
126
+ ROTATION: {
127
+ BASE_SPEED: 2, // 基础旋转速度
128
+ RANDOM_SPEED: 3, // 额外随机旋转速度范围
129
+ DECAY: 0.98 // 旋转速度衰减系数 (越小衰减越快)
130
+ },
131
+
132
+ // 物理效果配置
133
+ PHYSICS: {
134
+ GRAVITY: 0.525, // 重力加速度,影响粒子下落速度
135
+ VELOCITY_THRESHOLD: 10, // 速度阈值,超过时开始透明度衰减
136
+ OPACITY_DECAY: 0.02 // 透明度衰减速度,影响粒子消失快慢
137
+ },
138
+
139
+ // 粒子颜色配置 - 使用RGBA格式支持透明度
140
+ COLORS: [
141
+ 'rgba(255, 68, 68, 1)', // 红色系
142
+ 'rgba(255, 68, 68, 0.9)',
143
+ 'rgba(255, 68, 68, 0.8)',
144
+ 'rgba(255, 116, 188, 1)', // 粉色系
145
+ 'rgba(255, 116, 188, 0.9)',
146
+ 'rgba(255, 116, 188, 0.8)',
147
+ 'rgba(68, 68, 255, 0.8)', // 蓝色系
148
+ 'rgba(92, 202, 56, 0.7)', // 绿色系
149
+ 'rgba(255, 68, 255, 0.8)', // 紫色系
150
+ 'rgba(68, 255, 255, 0.7)', // 青色系
151
+ 'rgba(255, 136, 68, 0.7)', // 橙色系
152
+ 'rgba(68, 136, 255, 1)', // 蓝色系
153
+ 'rgba(250, 198, 122, 0.8)' // 金色系
154
+ ],
155
+
156
+ // 粒子形状配置 - 矩形出现概率更高,营造更丰富的视觉效果
157
+ SHAPES: [
158
+ 'rectangle',
159
+ 'rectangle',
160
+ 'rectangle',
161
+ 'rectangle',
162
+ 'rectangle',
163
+ 'rectangle',
164
+ 'rectangle',
165
+ 'circle',
166
+ 'triangle',
167
+ 'oval'
168
+ ]
169
+ } as const
170
+
171
+ /** Canvas DOM 元素引用 */
172
+ const canvasRef = ref<HTMLCanvasElement>()
173
+ /** Canvas 2D 绘制上下文 */
174
+ const ctx = ref<CanvasRenderingContext2D | null>(null)
175
+
176
+ /**
177
+ * 烟花系统核心类
178
+ * 负责管理粒子生命周期、渲染和动画
179
+ */
180
+ class FireworkSystem {
181
+ /** 粒子对象池 - 预先创建的粒子对象数组 */
182
+ private particlePool: Firework[] = []
183
+ /** 当前活动的粒子数组 */
184
+ private activeParticles: Firework[] = []
185
+ /** 对象池索引指针 - 用于循环分配粒子 */
186
+ private poolIndex = 0
187
+ /** 图片资源缓存 */
188
+ private imageCache: ImageCache = {}
189
+ /** 动画帧ID - 用于取消动画 */
190
+ private animationId = 0
191
+ /** 画布宽度缓存 */
192
+ private canvasWidth = 0
193
+ /** 画布高度缓存 */
194
+ private canvasHeight = 0
195
+
196
+ constructor() {
197
+ this.initializePool()
198
+ }
199
+
200
+ /**
201
+ * 初始化对象池
202
+ * 预先创建指定数量的粒子对象,避免运行时频繁创建
203
+ */
204
+ private initializePool(): void {
205
+ for (let i = 0; i < CONFIG.POOL_SIZE; i++) {
206
+ this.particlePool.push(this.createParticle())
207
+ }
208
+ }
209
+
210
+ /**
211
+ * 创建一个新的粒子对象
212
+ * 返回初始化状态的粒子
213
+ */
214
+ private createParticle(): Firework {
215
+ return {
216
+ x: 0,
217
+ y: 0,
218
+ vx: 0,
219
+ vy: 0,
220
+ color: '',
221
+ rotation: 0,
222
+ rotationSpeed: 0,
223
+ scale: 1,
224
+ shape: 'circle',
225
+ opacity: 1,
226
+ active: false
227
+ }
228
+ }
229
+
230
+ /**
231
+ * 从对象池获取可用粒子 (性能优化版本)
232
+ * 使用循环索引而非Array.find(),时间复杂度从O(n)降至O(1)
233
+ * @returns 可用的粒子对象或null
234
+ */
235
+ private getAvailableParticle(): Firework | null {
236
+ for (let i = 0; i < CONFIG.POOL_SIZE; i++) {
237
+ const index = (this.poolIndex + i) % CONFIG.POOL_SIZE
238
+ const particle = this.particlePool[index]
239
+
240
+ if (!particle.active) {
241
+ this.poolIndex = (index + 1) % CONFIG.POOL_SIZE
242
+ particle.active = true
243
+ return particle
244
+ }
245
+ }
246
+ return null
247
+ }
248
+
249
+ /**
250
+ * 预加载单个图片资源
251
+ * @param url 图片URL
252
+ * @returns Promise<HTMLImageElement>
253
+ */
254
+ async preloadImage(url: string): Promise<HTMLImageElement> {
255
+ // 如果已缓存,直接返回
256
+ if (this.imageCache[url]) {
257
+ return this.imageCache[url]
258
+ }
259
+
260
+ return new Promise((resolve, reject) => {
261
+ const img = new Image()
262
+ img.crossOrigin = 'anonymous' // 处理跨域问题
263
+ img.onload = () => {
264
+ this.imageCache[url] = img
265
+ resolve(img)
266
+ }
267
+ img.onerror = reject
268
+ img.src = url
269
+ })
270
+ }
271
+
272
+ /**
273
+ * 预加载所有需要的图片资源
274
+ * 在组件初始化时调用,确保图片ready
275
+ */
276
+ async preloadAllImages(): Promise<void> {
277
+ const imageUrls = [bp, sd, yd]
278
+ try {
279
+ await Promise.all(imageUrls.map((url) => this.preloadImage(url)))
280
+ } catch (error) {
281
+ console.error('Image preloading failed:', error)
282
+ }
283
+ }
284
+
285
+ /**
286
+ * 创建烟花爆炸效果
287
+ * @param imageUrl 可选的图片URL,如果提供则使用图片粒子
288
+ */
289
+ createFirework(imageUrl?: string): void {
290
+ // 随机确定爆炸起始位置
291
+ const startX = Math.random() * this.canvasWidth
292
+ const startY = this.canvasHeight
293
+
294
+ // 根据是否有图片确定可用形状
295
+ const availableShapes = imageUrl && this.imageCache[imageUrl] ? ['image'] : CONFIG.SHAPES
296
+
297
+ // 批量创建粒子数组,减少频繁的数组操作
298
+ const particles: Firework[] = []
299
+
300
+ for (let i = 0; i < CONFIG.PARTICLES_PER_BURST; i++) {
301
+ const particle = this.getAvailableParticle()
302
+ if (!particle) continue
303
+
304
+ // 计算粒子发射角度和速度 (恢复原始算法)
305
+ const angle = (Math.PI * i) / (CONFIG.PARTICLES_PER_BURST / 2) // 扇形分布
306
+ const speed = (12 + Math.random() * 6) * 1.5 // 随机速度
307
+ const spread = Math.random() * Math.PI * 2 // 360度随机扩散
308
+
309
+ // 直接属性赋值,避免Object.assign的性能开销
310
+ particle.x = startX
311
+ particle.y = startY
312
+ // 复杂的速度计算,模拟真实烟花爆炸轨迹
313
+ particle.vx = Math.cos(angle) * Math.cos(spread) * speed * (Math.random() * 0.5 + 0.5)
314
+ particle.vy = Math.sin(angle) * speed - 15 // 向上初始速度
315
+ particle.color = CONFIG.COLORS[Math.floor(Math.random() * CONFIG.COLORS.length)]
316
+ particle.rotation = Math.random() * 360
317
+ particle.rotationSpeed =
318
+ (Math.random() * CONFIG.ROTATION.RANDOM_SPEED + CONFIG.ROTATION.BASE_SPEED) *
319
+ (Math.random() > 0.5 ? 1 : -1) // 随机旋转方向
320
+ particle.scale = 0.8 + Math.random() * 0.4 // 随机缩放
321
+ particle.shape = availableShapes[Math.floor(Math.random() * availableShapes.length)]
322
+ particle.opacity = 1
323
+ particle.imageUrl = imageUrl && this.imageCache[imageUrl] ? imageUrl : undefined
324
+
325
+ particles.push(particle)
326
+ }
327
+
328
+ // 批量添加到活动粒子数组,减少多次数组操作
329
+ this.activeParticles.push(...particles)
330
+ }
331
+
332
+ /**
333
+ * 更新所有粒子的物理状态 (性能优化版本)
334
+ * 包括位置、速度、旋转、透明度等
335
+ */
336
+ private updateParticles(): void {
337
+ const { GRAVITY, VELOCITY_THRESHOLD, OPACITY_DECAY } = CONFIG.PHYSICS
338
+ const { DECAY } = CONFIG.ROTATION
339
+
340
+ // 使用倒序遍历,避免删除元素时的索引混乱问题
341
+ for (let i = this.activeParticles.length - 1; i >= 0; i--) {
342
+ const particle = this.activeParticles[i]
343
+
344
+ // 更新粒子位置 (匀加速运动)
345
+ particle.x += particle.vx
346
+ particle.y += particle.vy
347
+ particle.vy += GRAVITY // 重力影响
348
+
349
+ // 更新旋转状态
350
+ particle.rotation += particle.rotationSpeed
351
+ particle.rotationSpeed *= DECAY // 旋转速度衰减
352
+
353
+ // 透明度衰减逻辑 - 当粒子下落速度超过阈值时开始淡出
354
+ if (particle.vy > VELOCITY_THRESHOLD) {
355
+ particle.opacity -= OPACITY_DECAY
356
+ if (particle.opacity <= 0) {
357
+ this.recycleParticle(i)
358
+ continue
359
+ }
360
+ }
361
+
362
+ // 边界检查 - 移除超出屏幕范围的粒子
363
+ if (this.isOutOfBounds(particle)) {
364
+ this.recycleParticle(i)
365
+ }
366
+ }
367
+ }
368
+
369
+ /**
370
+ * 回收粒子到对象池
371
+ * @param index 要回收的粒子在活动数组中的索引
372
+ */
373
+ private recycleParticle(index: number): void {
374
+ const particle = this.activeParticles[index]
375
+ particle.active = false // 标记为非活动状态
376
+ this.activeParticles.splice(index, 1) // 从活动数组中移除
377
+ }
378
+
379
+ /**
380
+ * 检查粒子是否超出屏幕边界
381
+ * @param particle 要检查的粒子
382
+ * @returns 是否超出边界
383
+ */
384
+ private isOutOfBounds(particle: Firework): boolean {
385
+ const margin = 100 // 边界缓冲区
386
+ return (
387
+ particle.x < -margin ||
388
+ particle.x > this.canvasWidth + margin ||
389
+ particle.y < -margin ||
390
+ particle.y > this.canvasHeight + margin
391
+ )
392
+ }
393
+
394
+ /**
395
+ * 绘制单个粒子
396
+ * @param particle 要绘制的粒子对象
397
+ */
398
+ private drawParticle(particle: Firework): void {
399
+ if (!ctx.value) return
400
+
401
+ // 保存当前画布状态
402
+ ctx.value.save()
403
+ ctx.value.globalAlpha = particle.opacity // 设置透明度
404
+ ctx.value.translate(particle.x, particle.y) // 移动到粒子位置
405
+ ctx.value.rotate((particle.rotation * Math.PI) / 180) // 应用旋转
406
+ ctx.value.scale(particle.scale, particle.scale) // 应用缩放
407
+
408
+ // 渲染粒子形状
409
+ this.renderShape(particle)
410
+
411
+ // 恢复画布状态
412
+ ctx.value.restore()
413
+ }
414
+
415
+ /**
416
+ * 根据粒子类型渲染对应的形状
417
+ * @param particle 要渲染的粒子
418
+ */
419
+ private renderShape(particle: Firework): void {
420
+ if (!ctx.value) return
421
+
422
+ const { SIZES } = CONFIG
423
+ ctx.value.fillStyle = particle.color
424
+
425
+ switch (particle.shape) {
426
+ case 'rectangle':
427
+ // 绘制矩形
428
+ ctx.value.fillRect(
429
+ -SIZES.RECTANGLE.WIDTH / 2,
430
+ -SIZES.RECTANGLE.HEIGHT / 2,
431
+ SIZES.RECTANGLE.WIDTH,
432
+ SIZES.RECTANGLE.HEIGHT
433
+ )
434
+ break
435
+
436
+ case 'square':
437
+ // 绘制正方形
438
+ ctx.value.fillRect(
439
+ -SIZES.SQUARE.SIZE / 2,
440
+ -SIZES.SQUARE.SIZE / 2,
441
+ SIZES.SQUARE.SIZE,
442
+ SIZES.SQUARE.SIZE
443
+ )
444
+ break
445
+
446
+ case 'circle':
447
+ // 绘制圆形
448
+ ctx.value.beginPath()
449
+ ctx.value.arc(0, 0, SIZES.CIRCLE.SIZE / 2, 0, Math.PI * 2)
450
+ ctx.value.fill()
451
+ break
452
+
453
+ case 'triangle':
454
+ // 绘制三角形
455
+ ctx.value.beginPath()
456
+ ctx.value.moveTo(0, -SIZES.TRIANGLE.SIZE)
457
+ ctx.value.lineTo(SIZES.TRIANGLE.SIZE, SIZES.TRIANGLE.SIZE)
458
+ ctx.value.lineTo(-SIZES.TRIANGLE.SIZE, SIZES.TRIANGLE.SIZE)
459
+ ctx.value.closePath()
460
+ ctx.value.fill()
461
+ break
462
+
463
+ case 'oval':
464
+ // 绘制椭圆
465
+ ctx.value.beginPath()
466
+ ctx.value.ellipse(0, 0, SIZES.OVAL.WIDTH / 2, SIZES.OVAL.HEIGHT / 2, 0, 0, Math.PI * 2)
467
+ ctx.value.fill()
468
+ break
469
+
470
+ case 'image':
471
+ // 绘制图片
472
+ this.renderImage(particle)
473
+ break
474
+ }
475
+ }
476
+
477
+ /**
478
+ * 渲染图片类型的粒子
479
+ * @param particle 包含图片URL的粒子对象
480
+ */
481
+ private renderImage(particle: Firework): void {
482
+ if (!ctx.value || !particle.imageUrl) return
483
+
484
+ const img = this.imageCache[particle.imageUrl]
485
+ if (img?.complete) {
486
+ const { WIDTH, HEIGHT } = CONFIG.SIZES.IMAGE
487
+ ctx.value.drawImage(img, -WIDTH / 2, -HEIGHT / 2, WIDTH, HEIGHT)
488
+ }
489
+ }
490
+
491
+ /**
492
+ * 渲染所有活动粒子到画布
493
+ * 清除画布并重新绘制所有粒子
494
+ */
495
+ private render(): void {
496
+ if (!ctx.value || !canvasRef.value) return
497
+
498
+ // 清除整个画布
499
+ ctx.value.clearRect(0, 0, this.canvasWidth, this.canvasHeight)
500
+ // 设置混合模式为"变亮",增强视觉效果
501
+ ctx.value.globalCompositeOperation = 'lighter'
502
+
503
+ // 渲染所有活动粒子
504
+ for (const particle of this.activeParticles) {
505
+ this.drawParticle(particle)
506
+ }
507
+ }
508
+
509
+ /**
510
+ * 动画主循环
511
+ * 使用箭头函数保持this绑定
512
+ */
513
+ private animate = (): void => {
514
+ this.updateParticles() // 更新粒子状态
515
+ this.render() // 渲染粒子
516
+ this.animationId = requestAnimationFrame(this.animate) // 请求下一帧
517
+ }
518
+
519
+ /**
520
+ * 更新画布尺寸缓存
521
+ * 在窗口大小改变时调用
522
+ * @param width 新的画布宽度
523
+ * @param height 新的画布高度
524
+ */
525
+ updateCanvasSize(width: number, height: number): void {
526
+ this.canvasWidth = width
527
+ this.canvasHeight = height
528
+ }
529
+
530
+ /**
531
+ * 启动动画循环
532
+ */
533
+ start(): void {
534
+ this.animate()
535
+ }
536
+
537
+ /**
538
+ * 停止动画循环
539
+ * 在组件卸载时调用,避免内存泄漏
540
+ */
541
+ stop(): void {
542
+ if (this.animationId) {
543
+ cancelAnimationFrame(this.animationId)
544
+ this.animationId = 0
545
+ }
546
+ }
547
+
548
+ /**
549
+ * 获取当前活动粒子数量
550
+ * 用于调试和性能监控
551
+ * @returns 活动粒子数量
552
+ */
553
+ getActiveParticleCount(): number {
554
+ return this.activeParticles.length
555
+ }
556
+ }
557
+
558
+ /** 烟花系统实例 */
559
+ const fireworkSystem = new FireworkSystem()
560
+
561
+ /**
562
+ * 处理键盘快捷键
563
+ * 监听 Ctrl+Shift+P 或 Cmd+Shift+P 组合键触发烟花
564
+ * @param event 键盘事件对象
565
+ */
566
+ const handleKeyPress = (event: KeyboardEvent): void => {
567
+ const isFireworkShortcut =
568
+ (event.ctrlKey && event.shiftKey && event.key.toLowerCase() === 'p') ||
569
+ (event.metaKey && event.shiftKey && event.key.toLowerCase() === 'p')
570
+
571
+ if (isFireworkShortcut) {
572
+ event.preventDefault()
573
+ fireworkSystem.createFirework()
574
+ }
575
+ }
576
+
577
+ /**
578
+ * 调整Canvas画布大小
579
+ * 响应窗口大小变化,确保画布始终覆盖整个视口
580
+ */
581
+ const resizeCanvas = (): void => {
582
+ if (!canvasRef.value) return
583
+
584
+ const { innerWidth, innerHeight } = window
585
+ canvasRef.value.width = innerWidth
586
+ canvasRef.value.height = innerHeight
587
+ fireworkSystem.updateCanvasSize(innerWidth, innerHeight)
588
+ }
589
+
590
+ /**
591
+ * 处理外部触发的烟花事件
592
+ * 通过 mittBus 事件总线接收触发指令
593
+ * @param event 事件数据,可能包含图片URL
594
+ */
595
+ const handleFireworkTrigger: Handler<unknown> = (event: unknown) => {
596
+ const imageUrl = event as string | undefined
597
+ fireworkSystem.createFirework(imageUrl)
598
+ }
599
+
600
+ /**
601
+ * 组件挂载时的初始化逻辑
602
+ */
603
+ onMounted(async () => {
604
+ if (!canvasRef.value) return
605
+
606
+ // 获取Canvas 2D绘制上下文
607
+ ctx.value = canvasRef.value.getContext('2d')
608
+ if (!ctx.value) return
609
+
610
+ // 设置初始画布大小
611
+ resizeCanvas()
612
+
613
+ // 预加载所有图片资源
614
+ await fireworkSystem.preloadAllImages()
615
+
616
+ // 启动动画循环
617
+ fireworkSystem.start()
618
+
619
+ // 注册事件监听器
620
+ useEventListener(window, 'keydown', handleKeyPress) // 键盘快捷键
621
+ useEventListener(window, 'resize', resizeCanvas) // 窗口大小变化
622
+ mittBus.on('triggerFireworks', handleFireworkTrigger) // 外部触发事件
623
+ })
624
+
625
+ /**
626
+ * 组件卸载时的清理逻辑
627
+ * 停止动画循环并移除事件监听器,防止内存泄漏
628
+ */
629
+ onUnmounted(() => {
630
+ fireworkSystem.stop()
631
+ mittBus.off('triggerFireworks', handleFireworkTrigger)
632
+ })
633
+ </script>
@@ -0,0 +1,14 @@
1
+ <!-- 全局组件 -->
2
+ <template>
3
+ <component
4
+ v-for="componentConfig in enabledComponents"
5
+ :key="componentConfig.key"
6
+ :is="componentConfig.component"
7
+ />
8
+ </template>
9
+
10
+ <script setup lang="ts">
11
+ import { getEnabledGlobalComponents } from '@/config/modules/component'
12
+ defineOptions({ name: 'ArtGlobalComponent' })
13
+ const enabledComponents = computed(() => getEnabledGlobalComponents())
14
+ </script>