# useCrudSchemas 统一生成 `Search` 、 `Form` 、 `Descriptions` 、 `Table` 组件所需要的数据结构。 由于以上四个组件都需要 `Sechema` 或者 `columns` 的字段,如果每个组件都写一遍的话,会造成大量重复代码,所以提供 `useCrudSchemas` 来进行统一的数据生成。 useCrudSchemas 位于 [src/hooks/web/useCrudSchemas.ts](https://github.com/kailong321200875/vue-element-plus-admin/tree/master/src/hooks/web/useCrudSchemas.ts) ## 用法 ::: tip 如果不需要某个字段,如 `formSchema` 不需要 `field` 为 `index` 的字段,可以使用 `form: { hidden: true }` 进行过滤,其他组件同理。 ::: `Search` 是基于 `Form` 进行二次封装的,所以 `Search` 支持的参数 `Form` 也都支持。 `search` 与 `form` 字段,可以传入 `dictName` 来获取全局的字典数据,也可以传入 `api` 来获取接口数据,如果使用 `api` ,需要主动 `return` 数据。 如果想看更复杂点的例子,请[在线预览](https://element-plus-admin.cn/#/hooks/useCrudSchemas) ```vue ``` ### 参数介绍 ```ts const { allSchemas } = useCrudSchemas(crudSchemas) ``` **allSchemas** `allSchemas` 存放着四个组件所需要的数据结果 ***allSchemas.fromSchema*** `Form` 组件的 `Sechema` ***allSchemas.searchSchema*** `Search` 组件的 `Sechema` ***allSchemas.detailSchema*** `Descriptions` 组件的 `Sechema` ***allSchemas.tableColumns*** `Table` 组件的 `columns` ## CrudSchema | 属性 | 说明 | 类型 | 可选值 | 默认值 | | ---- | ---- | ---- | ---- | ---- | | search | 用于设置 `searchSchema` | `CrudSearchParams` | - | - | | table | 用于设置 `tableColumns` | `CrudTableParams` | - | - | | form | 用于设置 `fromSchema` | `CrudFormParams` | - | - | | detail | 用于设置 `DescriptionsSchema` | `CrudDescriptionsParams` | - | - | | children | 如果是 `Table` 组件,则可能会有多表头的情况存在 | `CrudSchema[]` | - | - |