From 23bcf4f61b8d4c0fe243b477d068eea7d89141c9 Mon Sep 17 00:00:00 2001 From: chenminjie <943130926@qq.com> Date: Tue, 26 Nov 2024 06:07:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E7=BB=84=E4=BB=B6=E5=B9=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E8=A1=A8=E5=8D=95=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除未使用的 Verify 验证码组件及其相关文件 - 在组件适配器中添加自定义表单组件的注册支持 - 扩展 ComponentType 类型以支持自定义组件类型 --- apps/web-antd/src/adapter/component/index.ts | 10 +- .../src/components/Verification/index.ts | 1 - .../components/Verification/src/Verify.vue | 162 ------------------ .../components/description/description.vue | 77 +++++++++ .../src/components/description/index.ts | 2 + .../src/components/description/types.d.ts | 54 ++++++ .../src/components/form/component-map.ts | 37 ++++ .../form/components/api-checkbox-group.vue | 137 +++++++++++++++ .../components/form/components/api-dict.vue | 53 ++++++ .../form/components/api-radio-group.vue | 143 ++++++++++++++++ .../components/form/components/api-select.vue | 150 ++++++++++++++++ .../form/components/api-tree-select.vue | 140 +++++++++++++++ apps/web-antd/src/components/form/index.ts | 5 + .../src/components/form/types/index.d.ts | 6 + .../src/components/view/component-map.ts | 27 +++ .../view/components/api-checkbox-group.vue | 6 + .../components/view/components/api-dict.vue | 64 +++++++ .../view/components/api-radio-group.vue | 6 + .../components/view/components/api-select.vue | 154 +++++++++++++++++ .../view/components/api-tree-select.vue | 95 ++++++++++ 20 files changed, 1165 insertions(+), 164 deletions(-) delete mode 100644 apps/web-antd/src/components/Verification/index.ts delete mode 100644 apps/web-antd/src/components/Verification/src/Verify.vue create mode 100644 apps/web-antd/src/components/description/description.vue create mode 100644 apps/web-antd/src/components/description/index.ts create mode 100644 apps/web-antd/src/components/description/types.d.ts create mode 100644 apps/web-antd/src/components/form/component-map.ts create mode 100644 apps/web-antd/src/components/form/components/api-checkbox-group.vue create mode 100644 apps/web-antd/src/components/form/components/api-dict.vue create mode 100644 apps/web-antd/src/components/form/components/api-radio-group.vue create mode 100644 apps/web-antd/src/components/form/components/api-select.vue create mode 100644 apps/web-antd/src/components/form/components/api-tree-select.vue create mode 100644 apps/web-antd/src/components/form/index.ts create mode 100644 apps/web-antd/src/components/form/types/index.d.ts create mode 100644 apps/web-antd/src/components/view/component-map.ts create mode 100644 apps/web-antd/src/components/view/components/api-checkbox-group.vue create mode 100644 apps/web-antd/src/components/view/components/api-dict.vue create mode 100644 apps/web-antd/src/components/view/components/api-radio-group.vue create mode 100644 apps/web-antd/src/components/view/components/api-select.vue create mode 100644 apps/web-antd/src/components/view/components/api-tree-select.vue diff --git a/apps/web-antd/src/adapter/component/index.ts b/apps/web-antd/src/adapter/component/index.ts index 1afa6217..9e102896 100644 --- a/apps/web-antd/src/adapter/component/index.ts +++ b/apps/web-antd/src/adapter/component/index.ts @@ -5,6 +5,8 @@ import type { BaseFormComponentType } from '@vben/common-ui'; +import type { CustomComponentType } from '#/components/form/types'; + import type { Component, SetupContext } from 'vue'; import { h } from 'vue'; @@ -36,6 +38,8 @@ import { Upload, } from 'ant-design-vue'; +import { registerComponent as registerCustomFormComponent } from '#/components/form/component-map'; + const withDefaultPlaceholder = ( component: T, type: 'input' | 'select', @@ -70,7 +74,8 @@ export type ComponentType = | 'TimePicker' | 'TreeSelect' | 'Upload' - | BaseFormComponentType; + | BaseFormComponentType + | CustomComponentType; async function initComponentAdapter() { const components: Partial> = { @@ -108,6 +113,9 @@ async function initComponentAdapter() { Upload, }; + // 注册自定义组件 + registerCustomFormComponent(components); + // 将组件注册到全局共享状态中 globalShareState.setComponents(components); diff --git a/apps/web-antd/src/components/Verification/index.ts b/apps/web-antd/src/components/Verification/index.ts deleted file mode 100644 index 0d53aa67..00000000 --- a/apps/web-antd/src/components/Verification/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as Verify } from './src/Verify.vue'; diff --git a/apps/web-antd/src/components/Verification/src/Verify.vue b/apps/web-antd/src/components/Verification/src/Verify.vue deleted file mode 100644 index 53199c6e..00000000 --- a/apps/web-antd/src/components/Verification/src/Verify.vue +++ /dev/null @@ -1,162 +0,0 @@ - - - diff --git a/apps/web-antd/src/components/description/description.vue b/apps/web-antd/src/components/description/description.vue new file mode 100644 index 00000000..ec5e220e --- /dev/null +++ b/apps/web-antd/src/components/description/description.vue @@ -0,0 +1,77 @@ + + diff --git a/apps/web-antd/src/components/description/index.ts b/apps/web-antd/src/components/description/index.ts new file mode 100644 index 00000000..745e7550 --- /dev/null +++ b/apps/web-antd/src/components/description/index.ts @@ -0,0 +1,2 @@ +export { default as Description } from './description.vue'; +export type * from './types'; diff --git a/apps/web-antd/src/components/description/types.d.ts b/apps/web-antd/src/components/description/types.d.ts new file mode 100644 index 00000000..c5120b8e --- /dev/null +++ b/apps/web-antd/src/components/description/types.d.ts @@ -0,0 +1,54 @@ +import type { CollapseContainerOptions } from '@/components/Container'; +import type { DescriptionsProps } from 'ant-design-vue/es/descriptions'; + +import type { CSSProperties, VNode } from 'vue'; + +export interface DescItem { + labelMinWidth?: number; + contentMinWidth?: number; + labelStyle?: CSSProperties; + field: string; + label: JSX.Element | string | VNode; + // Merge column + span?: number; + show?: (...arg: any) => boolean; + // render + render?: ( + val: any, + data: Recordable, + ) => Element | JSX.Element | number | string | undefined | VNode; + component: string; + componentProps?: any; + children?: DescItem[]; +} + +export interface DescriptionProps extends DescriptionsProps { + // Whether to include the collapse component + useCollapse?: boolean; + /** + * item configuration + * @type DescItem + */ + schema: DescItem[]; + /** + * 数据 + * @type object + */ + data: Recordable; + /** + * Built-in CollapseContainer component configuration + * @type CollapseContainerOptions + */ + collapseOptions?: CollapseContainerOptions; +} + +export interface DescInstance { + setDescProps(descProps: Partial): void; +} + +export type Register = (descInstance: DescInstance) => void; + +/** + * @description: + */ +export type UseDescReturnType = [Register, DescInstance]; diff --git a/apps/web-antd/src/components/form/component-map.ts b/apps/web-antd/src/components/form/component-map.ts new file mode 100644 index 00000000..e4f66445 --- /dev/null +++ b/apps/web-antd/src/components/form/component-map.ts @@ -0,0 +1,37 @@ +import type { CustomComponentType } from './types'; + +import type { Component } from 'vue'; + +import { kebabToCamelCase } from '@vben/utils'; + +const componentMap = new Map(); +// import.meta.glob() 直接引入所有的模块 Vite 独有的功能 +const modules = import.meta.glob('./components/**/*.vue', { eager: true }); +// 加入到路由集合中 +Object.keys(modules).forEach((key) => { + if (!key.includes('-ignore')) { + const mod = (modules as any)[key].default || {}; + // ./components/ApiDict.vue + // 获取ApiDict + const compName = key.replace('./components/', '').replace('.vue', ''); + componentMap.set(kebabToCamelCase(compName), mod); + } +}); + +export function add(compName: string, component: Component) { + componentMap.set(compName, component); +} + +export function del(compName: string) { + componentMap.delete(compName); +} +/** + * 注册组件 + * @param components + */ +export const registerComponent = (components: any) => { + componentMap.forEach((value, key) => { + components[key] = value as Component; + }); +}; +export { componentMap }; diff --git a/apps/web-antd/src/components/form/components/api-checkbox-group.vue b/apps/web-antd/src/components/form/components/api-checkbox-group.vue new file mode 100644 index 00000000..1ef81da2 --- /dev/null +++ b/apps/web-antd/src/components/form/components/api-checkbox-group.vue @@ -0,0 +1,137 @@ + + + diff --git a/apps/web-antd/src/components/form/components/api-dict.vue b/apps/web-antd/src/components/form/components/api-dict.vue new file mode 100644 index 00000000..6b9f80db --- /dev/null +++ b/apps/web-antd/src/components/form/components/api-dict.vue @@ -0,0 +1,53 @@ + + diff --git a/apps/web-antd/src/components/form/components/api-radio-group.vue b/apps/web-antd/src/components/form/components/api-radio-group.vue new file mode 100644 index 00000000..d87e7445 --- /dev/null +++ b/apps/web-antd/src/components/form/components/api-radio-group.vue @@ -0,0 +1,143 @@ + + + diff --git a/apps/web-antd/src/components/form/components/api-select.vue b/apps/web-antd/src/components/form/components/api-select.vue new file mode 100644 index 00000000..4e6f1772 --- /dev/null +++ b/apps/web-antd/src/components/form/components/api-select.vue @@ -0,0 +1,150 @@ + + + diff --git a/apps/web-antd/src/components/form/components/api-tree-select.vue b/apps/web-antd/src/components/form/components/api-tree-select.vue new file mode 100644 index 00000000..776ce772 --- /dev/null +++ b/apps/web-antd/src/components/form/components/api-tree-select.vue @@ -0,0 +1,140 @@ + + + diff --git a/apps/web-antd/src/components/form/index.ts b/apps/web-antd/src/components/form/index.ts new file mode 100644 index 00000000..750820af --- /dev/null +++ b/apps/web-antd/src/components/form/index.ts @@ -0,0 +1,5 @@ +export { default as ApiCheckboxGroup } from './components/api-checkbox-group.vue'; +export { default as ApiDict } from './components/api-dict.vue'; +export { default as ApiRadioGroup } from './components/api-radio-group.vue'; +export { default as ApiSelect } from './components/api-select.vue'; +export { default as ApiTreeSelect } from './components/api-tree-select.vue'; diff --git a/apps/web-antd/src/components/form/types/index.d.ts b/apps/web-antd/src/components/form/types/index.d.ts new file mode 100644 index 00000000..e60e17e0 --- /dev/null +++ b/apps/web-antd/src/components/form/types/index.d.ts @@ -0,0 +1,6 @@ +export type CustomComponentType = + | 'ApiCheckboxGroup' + | 'ApiDict' + | 'ApiRadioGroup' + | 'ApiSelect' + | 'ApiTreeSelect'; diff --git a/apps/web-antd/src/components/view/component-map.ts b/apps/web-antd/src/components/view/component-map.ts new file mode 100644 index 00000000..f0a1b2a8 --- /dev/null +++ b/apps/web-antd/src/components/view/component-map.ts @@ -0,0 +1,27 @@ +import type { Component } from 'vue'; + +import { toPascalCase } from '#/util/tool'; + +const componentMap = new Map(); +// import.meta.glob() 直接引入所有的模块 Vite 独有的功能 +const modules = import.meta.glob('./components/**/*.vue', { eager: true }); +// 加入到路由集合中 +Object.keys(modules).forEach((key) => { + if (!key.includes('-ignore')) { + const mod = (modules as any)[key].default || {}; + // ./components/ApiDict.vue + // 获取ApiDict + const compName = key.replace('./components/', '').replace('.vue', ''); + componentMap.set(toPascalCase(compName), mod); + } +}); + +export function add(compName: string, component: Component) { + componentMap.set(compName, component); +} + +export function del(compName: string) { + componentMap.delete(compName); +} + +export { componentMap }; diff --git a/apps/web-antd/src/components/view/components/api-checkbox-group.vue b/apps/web-antd/src/components/view/components/api-checkbox-group.vue new file mode 100644 index 00000000..dbca93f9 --- /dev/null +++ b/apps/web-antd/src/components/view/components/api-checkbox-group.vue @@ -0,0 +1,6 @@ + + diff --git a/apps/web-antd/src/components/view/components/api-dict.vue b/apps/web-antd/src/components/view/components/api-dict.vue new file mode 100644 index 00000000..d4ec0df6 --- /dev/null +++ b/apps/web-antd/src/components/view/components/api-dict.vue @@ -0,0 +1,64 @@ + + + diff --git a/apps/web-antd/src/components/view/components/api-radio-group.vue b/apps/web-antd/src/components/view/components/api-radio-group.vue new file mode 100644 index 00000000..dbca93f9 --- /dev/null +++ b/apps/web-antd/src/components/view/components/api-radio-group.vue @@ -0,0 +1,6 @@ + + diff --git a/apps/web-antd/src/components/view/components/api-select.vue b/apps/web-antd/src/components/view/components/api-select.vue new file mode 100644 index 00000000..de417747 --- /dev/null +++ b/apps/web-antd/src/components/view/components/api-select.vue @@ -0,0 +1,154 @@ + + + diff --git a/apps/web-antd/src/components/view/components/api-tree-select.vue b/apps/web-antd/src/components/view/components/api-tree-select.vue new file mode 100644 index 00000000..c581a06e --- /dev/null +++ b/apps/web-antd/src/components/view/components/api-tree-select.vue @@ -0,0 +1,95 @@ + + +