@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,507 @@
1
+ <!-- 表单组件 -->
2
+ <!-- 支持常用表单组件、自定义组件、插槽、校验、隐藏表单项 -->
3
+ <!-- 写法同 ElementPlus 官方文档组件,把属性写在 props 里面就可以了 -->
4
+ <template>
5
+ <section class="px-4 pb-0 pt-4 md:px-4 md:pt-4">
6
+ <ElForm
7
+ ref="formRef"
8
+ :model="modelValue"
9
+ :label-position="labelPosition"
10
+ v-bind="{ ...$attrs }"
11
+ >
12
+ <ElRow class="flex flex-wrap" :gutter="gutter">
13
+ <ElCol
14
+ v-for="item in visibleFormItems"
15
+ :key="item.key"
16
+ :xs="getColSpan(item.span, 'xs')"
17
+ :sm="getColSpan(item.span, 'sm')"
18
+ :md="getColSpan(item.span, 'md')"
19
+ :lg="getColSpan(item.span, 'lg')"
20
+ :xl="getColSpan(item.span, 'xl')"
21
+ >
22
+ <ElFormItem
23
+ :prop="item.key"
24
+ :label-width="item.label ? item.labelWidth || labelWidth : undefined"
25
+ >
26
+ <template #label v-if="item.label">
27
+ <component v-if="typeof item.label !== 'string'" :is="item.label" />
28
+ <span v-else>{{ item.label }}</span>
29
+ </template>
30
+ <slot :name="item.key" :item="item" :modelValue="modelValue">
31
+ <component
32
+ :is="getComponent(item)"
33
+ :model-value="getFieldValue(item.key)"
34
+ @update:model-value="setFieldValue(item.key, $event)"
35
+ v-bind="getProps(item)"
36
+ >
37
+ <!-- 下拉选择 -->
38
+ <template v-if="item.type === 'select' && getProps(item)?.options">
39
+ <ElOption
40
+ v-for="option in getProps(item).options"
41
+ v-bind="option"
42
+ :key="option.value"
43
+ />
44
+ </template>
45
+
46
+ <!-- 复选框组 -->
47
+ <template v-if="item.type === 'checkboxgroup' && getProps(item)?.options">
48
+ <ElCheckbox
49
+ v-for="option in getProps(item).options"
50
+ v-bind="option"
51
+ :key="option.value"
52
+ />
53
+ </template>
54
+
55
+ <!-- 单选框组 -->
56
+ <template v-if="item.type === 'radiogroup' && getProps(item)?.options">
57
+ <ElRadio
58
+ v-for="option in getProps(item).options"
59
+ v-bind="option"
60
+ :key="option.value"
61
+ />
62
+ </template>
63
+
64
+ <!-- 动态插槽支持 -->
65
+ <template v-for="(slotFn, slotName) in getSlots(item)" :key="slotName" #[slotName]>
66
+ <component :is="slotFn" />
67
+ </template>
68
+ </component>
69
+ </slot>
70
+ </ElFormItem>
71
+ </ElCol>
72
+ <ElCol :xs="24" :sm="24" :md="span" :lg="span" :xl="span" class="max-w-full flex-1">
73
+ <div
74
+ class="mb-3 flex-c flex-wrap justify-end md:flex-row md:items-stretch md:gap-2"
75
+ :style="actionButtonsStyle"
76
+ >
77
+ <div class="flex gap-2 md:justify-center">
78
+ <ElButton v-if="showReset" class="reset-button" @click="handleReset" v-ripple>
79
+ {{ t('table.form.reset') }}
80
+ </ElButton>
81
+ <ElButton
82
+ v-if="showSubmit"
83
+ type="primary"
84
+ class="submit-button"
85
+ @click="handleSubmit"
86
+ v-ripple
87
+ :disabled="disabledSubmit"
88
+ >
89
+ {{ t('table.form.submit') }}
90
+ </ElButton>
91
+ </div>
92
+ </div>
93
+ </ElCol>
94
+ </ElRow>
95
+ </ElForm>
96
+ </section>
97
+ </template>
98
+
99
+ <script setup lang="ts">
100
+ import { useWindowSize } from '@vueuse/core'
101
+ import { useI18n } from 'vue-i18n'
102
+ import { toRaw, type Component } from 'vue'
103
+ import {
104
+ ElCascader,
105
+ ElCheckbox,
106
+ ElCheckboxGroup,
107
+ ElDatePicker,
108
+ ElInput,
109
+ ElInputTag,
110
+ ElInputNumber,
111
+ ElRadioGroup,
112
+ ElRate,
113
+ ElSelect,
114
+ ElSlider,
115
+ ElSwitch,
116
+ ElTimePicker,
117
+ ElTimeSelect,
118
+ ElTreeSelect,
119
+ type FormInstance
120
+ } from 'element-plus'
121
+ import { calculateResponsiveSpan, type ResponsiveBreakpoint } from '@kevairy/components'
122
+
123
+ defineOptions({ name: 'ArtForm' })
124
+
125
+ const componentMap = {
126
+ input: ElInput, // 输入框
127
+ inputtag: ElInputTag, // 标签输入框
128
+ number: ElInputNumber, // 数字输入框
129
+ select: ElSelect, // 选择器
130
+ switch: ElSwitch, // 开关
131
+ checkbox: ElCheckbox, // 复选框
132
+ checkboxgroup: ElCheckboxGroup, // 复选框组
133
+ radiogroup: ElRadioGroup, // 单选框组
134
+ date: ElDatePicker, // 日期选择器
135
+ daterange: ElDatePicker, // 日期范围选择器
136
+ datetime: ElDatePicker, // 日期时间选择器
137
+ datetimerange: ElDatePicker, // 日期时间范围选择器
138
+ rate: ElRate, // 评分
139
+ slider: ElSlider, // 滑块
140
+ cascader: ElCascader, // 级联选择器
141
+ timepicker: ElTimePicker, // 时间选择器
142
+ timeselect: ElTimeSelect, // 时间选择
143
+ treeselect: ElTreeSelect // 树选择器
144
+ }
145
+
146
+ const { width } = useWindowSize()
147
+ const { t } = useI18n()
148
+ const isMobile = computed(() => width.value < 500)
149
+
150
+ const formInstance = useTemplateRef<FormInstance>('formRef')
151
+
152
+ // 表单项配置
153
+ export interface FormItem {
154
+ /** 表单项的唯一标识 */
155
+ key: string
156
+ /** 表单项的标签文本或自定义渲染函数 */
157
+ label: string | (() => VNode) | Component
158
+ /** 表单项标签的宽度,会覆盖 Form 的 labelWidth */
159
+ labelWidth?: string | number
160
+ /** 表单项类型,支持预定义的组件类型 */
161
+ type?: keyof typeof componentMap | string
162
+ /** 自定义渲染函数或组件,用于渲染自定义组件(优先级高于 type) */
163
+ render?: (() => VNode) | Component
164
+ /** 是否隐藏该表单项 */
165
+ hidden?: boolean
166
+ /** 表单项占据的列宽,基于24格栅格系统 */
167
+ span?: number
168
+ /** 选项数据,用于 select、checkbox-group、radio-group 等 */
169
+ options?: Record<string, any>
170
+ /** 传递给表单项组件的属性 */
171
+ props?: Record<string, any>
172
+ /** 表单项的插槽配置 */
173
+ slots?: Record<string, (() => any) | undefined>
174
+ /** 表单项的占位符文本 */
175
+ placeholder?: string
176
+ /** 更多属性配置请参考 ElementPlus 官方文档 */
177
+ }
178
+
179
+ // 表单配置
180
+ interface FormProps {
181
+ /** 表单数据 */
182
+ items: FormItem[]
183
+ /** 每列的宽度(基于 24 格布局) */
184
+ span?: number
185
+ /** 表单控件间隙 */
186
+ gutter?: number
187
+ /** 表单域标签的位置 */
188
+ labelPosition?: 'left' | 'right' | 'top'
189
+ /** 文字宽度 */
190
+ labelWidth?: string | number
191
+ /** 按钮靠左对齐限制(表单项小于等于该值时) */
192
+ buttonLeftLimit?: number
193
+ /** 是否显示重置按钮 */
194
+ showReset?: boolean
195
+ /** 是否显示提交按钮 */
196
+ showSubmit?: boolean
197
+ /** 是否禁用提交按钮 */
198
+ disabledSubmit?: boolean
199
+ /** 提交时是否清洗空值 */
200
+ sanitizeOutput?: Partial<SanitizeOutputOptions>
201
+ }
202
+
203
+ interface SanitizeOutputOptions {
204
+ /** 移除空字符串 */
205
+ removeEmptyString: boolean
206
+ /** 移除空数组 */
207
+ removeEmptyArray: boolean
208
+ /** 移除清洗后为空的对象 */
209
+ removeEmptyObject: boolean
210
+ /** 移除空富文本占位内容,如 <p><br></p> */
211
+ removeEmptyRichText: boolean
212
+ /** 保留数字 0 这类有效值 */
213
+ keepZero: boolean
214
+ /** 保留 false 这类有效值 */
215
+ keepFalse: boolean
216
+ }
217
+
218
+ const props = withDefaults(defineProps<FormProps>(), {
219
+ items: () => [],
220
+ span: 6,
221
+ gutter: 12,
222
+ labelPosition: 'right',
223
+ labelWidth: '70px',
224
+ buttonLeftLimit: 2,
225
+ showReset: true,
226
+ showSubmit: true,
227
+ disabledSubmit: false,
228
+ sanitizeOutput: () => ({})
229
+ })
230
+
231
+ interface FormEmits {
232
+ reset: []
233
+ submit: [Record<string, any>]
234
+ }
235
+
236
+ const emit = defineEmits<FormEmits>()
237
+
238
+ const modelValue = defineModel<Record<string, any>>({ default: () => ({}) })
239
+ const initialModelValue = ref<Record<string, any>>({})
240
+
241
+ // 保存组件初始化时的表单快照,用于 reset 时恢复默认值。
242
+ const cloneModelValue = (value: Record<string, any> | undefined) => {
243
+ if (!value) return {}
244
+
245
+ const deepClone = (source: unknown): unknown => {
246
+ if (Array.isArray(source)) {
247
+ return source.map((item) => deepClone(item))
248
+ }
249
+
250
+ if (source && typeof source === 'object') {
251
+ const rawSource = toRaw(source)
252
+ return Object.keys(rawSource).reduce<Record<string, unknown>>((accumulator, key) => {
253
+ accumulator[key] = deepClone((rawSource as Record<string, unknown>)[key])
254
+ return accumulator
255
+ }, {})
256
+ }
257
+
258
+ return source
259
+ }
260
+
261
+ return deepClone(toRaw(value)) as Record<string, any>
262
+ }
263
+
264
+ initialModelValue.value = cloneModelValue(modelValue.value)
265
+
266
+ const rootProps = ['label', 'labelWidth', 'key', 'type', 'hidden', 'span', 'slots']
267
+ // 输出时的清洗策略默认偏“接口友好”,但允许按业务覆盖。
268
+ const sanitizeOutputOptions = computed<SanitizeOutputOptions>(() => ({
269
+ removeEmptyString: true,
270
+ removeEmptyArray: true,
271
+ removeEmptyObject: true,
272
+ removeEmptyRichText: true,
273
+ keepZero: true,
274
+ keepFalse: true,
275
+ ...props.sanitizeOutput
276
+ }))
277
+
278
+ const PATH_NUMBER_RE = /^\d+$/
279
+
280
+ // 兼容 a.b、a.0.b 这类路径写法,数字段会被当作数组索引处理。
281
+ const parsePath = (path: string) => {
282
+ return path
283
+ .split('.')
284
+ .filter(Boolean)
285
+ .map((segment) => (PATH_NUMBER_RE.test(segment) ? Number(segment) : segment))
286
+ }
287
+
288
+ const getFieldValue = (path: string) => {
289
+ return parsePath(path).reduce<any>((currentValue, segment) => {
290
+ if (currentValue == null) return undefined
291
+ return currentValue[segment]
292
+ }, modelValue.value)
293
+ }
294
+
295
+ // 清空字段时只删除路径的最后一段,避免误删同级数据。
296
+ const deleteFieldValue = (path: string) => {
297
+ const segments = parsePath(path)
298
+ if (!segments.length) return
299
+
300
+ const lastSegment = segments.pop()
301
+ const parent = segments.reduce<any>((currentValue, segment) => {
302
+ if (currentValue == null) return undefined
303
+ return currentValue[segment]
304
+ }, modelValue.value)
305
+
306
+ if (parent != null && lastSegment !== undefined) {
307
+ delete parent[lastSegment]
308
+ }
309
+ }
310
+
311
+ // 表单清空输入时不保留空字符串,同时按路径自动补齐中间对象或数组。
312
+ const setFieldValue = (path: string, value: unknown) => {
313
+ const normalizedValue = value === '' ? undefined : value
314
+ const segments = parsePath(path)
315
+
316
+ if (!segments.length) return
317
+
318
+ if (normalizedValue === undefined) {
319
+ deleteFieldValue(path)
320
+ return
321
+ }
322
+
323
+ let currentValue: any = modelValue.value
324
+
325
+ segments.forEach((segment, index) => {
326
+ const isLast = index === segments.length - 1
327
+
328
+ if (isLast) {
329
+ currentValue[segment] = normalizedValue
330
+ return
331
+ }
332
+
333
+ const nextSegment = segments[index + 1]
334
+ const nextContainer = typeof nextSegment === 'number' ? [] : {}
335
+
336
+ if (
337
+ currentValue[segment] === null ||
338
+ currentValue[segment] === undefined ||
339
+ typeof currentValue[segment] !== 'object'
340
+ ) {
341
+ currentValue[segment] = nextContainer
342
+ }
343
+
344
+ currentValue = currentValue[segment]
345
+ })
346
+ }
347
+
348
+ const isRichTextEmpty = (value: string) => {
349
+ if (/<(img|video|audio|iframe|embed|object)\b/i.test(value)) {
350
+ return false
351
+ }
352
+
353
+ // 去掉编辑器常见占位标签后再判断是否还有实际内容。
354
+ return (
355
+ value
356
+ .replace(/&nbsp;/gi, '')
357
+ .replace(/<br\s*\/?>/gi, '')
358
+ .replace(/<[^>]*>/g, '')
359
+ .trim() === ''
360
+ )
361
+ }
362
+
363
+ // 提交时按配置清洗空值,但保留 0 和 false 这类有效值。
364
+ const sanitizeOutputValue = (value: unknown): unknown => {
365
+ const options = sanitizeOutputOptions.value
366
+
367
+ if (Array.isArray(value)) {
368
+ const sanitizedArray = value
369
+ .map((item) => sanitizeOutputValue(item))
370
+ .filter((item) => item !== undefined)
371
+ return sanitizedArray.length === 0 && options.removeEmptyArray ? undefined : sanitizedArray
372
+ }
373
+
374
+ if (value && typeof value === 'object') {
375
+ const rawValue = toRaw(value)
376
+ const sanitizedObject = Object.entries(rawValue).reduce<Record<string, unknown>>(
377
+ (accumulator, [key, item]) => {
378
+ const sanitizedItem = sanitizeOutputValue(item)
379
+ if (sanitizedItem !== undefined) {
380
+ accumulator[key] = sanitizedItem
381
+ }
382
+ return accumulator
383
+ },
384
+ {}
385
+ )
386
+ return Object.keys(sanitizedObject).length === 0 && options.removeEmptyObject
387
+ ? undefined
388
+ : sanitizedObject
389
+ }
390
+
391
+ if (typeof value === 'string') {
392
+ if (options.removeEmptyString && value.trim() === '') {
393
+ return undefined
394
+ }
395
+ if (options.removeEmptyRichText && isRichTextEmpty(value)) {
396
+ return undefined
397
+ }
398
+ return value
399
+ }
400
+
401
+ if (value === 0) {
402
+ return options.keepZero ? value : undefined
403
+ }
404
+
405
+ if (value === false) {
406
+ return options.keepFalse ? value : undefined
407
+ }
408
+
409
+ return value ?? undefined
410
+ }
411
+
412
+ const getSanitizedOutput = () => {
413
+ return (sanitizeOutputValue(cloneModelValue(modelValue.value)) || {}) as Record<string, any>
414
+ }
415
+
416
+ const getProps = (item: FormItem) => {
417
+ if (item.props) return item.props
418
+ const props = { ...item }
419
+ rootProps.forEach((key) => delete (props as Record<string, any>)[key])
420
+ return props
421
+ }
422
+
423
+ // 获取插槽
424
+ const getSlots = (item: FormItem) => {
425
+ if (!item.slots) return {}
426
+ const validSlots: Record<string, () => any> = {}
427
+ Object.entries(item.slots).forEach(([key, slotFn]) => {
428
+ if (slotFn) {
429
+ validSlots[key] = slotFn
430
+ }
431
+ })
432
+ return validSlots
433
+ }
434
+
435
+ // 组件
436
+ const getComponent = (item: FormItem) => {
437
+ // 优先使用 render 函数或组件渲染自定义组件
438
+ if (item.render) {
439
+ return item.render
440
+ }
441
+ // 使用 type 获取预定义组件
442
+ const { type } = item
443
+ return componentMap[type as keyof typeof componentMap] || componentMap['input']
444
+ }
445
+
446
+ /**
447
+ * 获取列宽 span 值
448
+ * 根据屏幕尺寸智能降级,避免小屏幕上表单项被压缩过小
449
+ */
450
+ const getColSpan = (itemSpan: number | undefined, breakpoint: ResponsiveBreakpoint): number => {
451
+ return calculateResponsiveSpan(itemSpan, span.value, breakpoint)
452
+ }
453
+
454
+ /**
455
+ * 可见的表单项
456
+ */
457
+ const visibleFormItems = computed(() => {
458
+ return props.items.filter((item) => !item.hidden)
459
+ })
460
+
461
+ /**
462
+ * 操作按钮样式
463
+ */
464
+ const actionButtonsStyle = computed(() => ({
465
+ 'justify-content': isMobile.value
466
+ ? 'flex-end'
467
+ : props.items.filter((item) => !item.hidden).length <= props.buttonLeftLimit
468
+ ? 'flex-start'
469
+ : 'flex-end'
470
+ }))
471
+
472
+ /**
473
+ * 处理重置事件
474
+ */
475
+ const handleReset = () => {
476
+ // 重置表单字段(UI 层)
477
+ formInstance.value?.resetFields()
478
+
479
+ // 恢复初始表单值,保留默认值而不是简单清空。
480
+ Object.keys(modelValue.value).forEach((key) => {
481
+ delete modelValue.value[key]
482
+ })
483
+ Object.assign(modelValue.value, cloneModelValue(initialModelValue.value))
484
+
485
+ // 触发 reset 事件
486
+ emit('reset')
487
+ }
488
+
489
+ /**
490
+ * 处理提交事件
491
+ */
492
+ const handleSubmit = () => {
493
+ // 对外只抛出清洗后的结果,避免业务层重复过滤空值。
494
+ emit('submit', getSanitizedOutput())
495
+ }
496
+
497
+ defineExpose({
498
+ ref: formInstance,
499
+ validate: (...args: any[]) => formInstance.value?.validate(...args),
500
+ reset: handleReset,
501
+ // 允许外部在不触发提交事件时主动获取清洗后的输出。
502
+ getOutput: getSanitizedOutput
503
+ })
504
+
505
+ // 解构 props 以便在模板中直接使用
506
+ const { span, gutter, labelPosition, labelWidth } = toRefs(props)
507
+ </script>