Commit 0b23ce416e1f58d725faaf96a65d6ee2dffd5bc6

Authored by xingyu4j
1 parent 7225150e

perf: crud

yudao-ui-admin-vue3/src/hooks/web/useCrudSchemas.ts
... ... @@ -7,10 +7,14 @@ import { DescriptionsSchema } from '@/types/descriptions'
7 7 import { ComponentOptions } from '@/types/components'
8 8  
9 9 export type CrudSchema = Omit<TableColumn, 'children'> & {
10   - search?: CrudSearchParams
11   - table?: CrudTableParams
12   - form?: CrudFormParams
13   - detail?: CrudDescriptionsParams
  10 + isSearch?: boolean // 是否在查询显示
  11 + search?: CrudSearchParams // 查询的详细配置
  12 + isTable?: boolean // 是否在列表显示
  13 + table?: CrudTableParams // 列表的详细配置
  14 + isForm?: boolean // 是否在表单显示
  15 + form?: CrudFormParams // 表单的详细配置
  16 + isDetail?: boolean // 是否在详情显示
  17 + detail?: CrudDescriptionsParams // 详情的详细配置
14 18 children?: CrudSchema[]
15 19 dictType?: string // 字典类型
16 20 dictData?: 'string' | 'number' | 'boolean' // 字典数据类型 string | number | boolean
... ... @@ -80,7 +84,7 @@ const filterSearchSchema = (crudSchema: CrudSchema[]): FormSchema[] =&gt; {
80 84  
81 85 eachTree(crudSchema, (schemaItem: CrudSchema) => {
82 86 // 判断是否显示
83   - if (schemaItem?.search?.show) {
  87 + if (schemaItem?.isSearch || schemaItem.search?.show) {
84 88 let component = schemaItem?.search?.component || 'Input'
85 89 const options: ComponentOptions[] = []
86 90 let comonentProps = {}
... ... @@ -93,7 +97,7 @@ const filterSearchSchema = (crudSchema: CrudSchema[]): FormSchema[] =&gt; {
93 97 comonentProps = {
94 98 options: options
95 99 }
96   - if (!schemaItem.search.component) component = 'Select'
  100 + if (!schemaItem.search?.component) component = 'Select'
97 101 }
98 102 const searchSchemaItem = {
99 103 // 默认为 input
... ... @@ -116,7 +120,7 @@ const filterSearchSchema = (crudSchema: CrudSchema[]): FormSchema[] =&gt; {
116 120 const filterTableSchema = (crudSchema: CrudSchema[]): TableColumn[] => {
117 121 const tableColumns = treeMap<CrudSchema>(crudSchema, {
118 122 conversion: (schema: CrudSchema) => {
119   - if (schema?.table?.show !== false) {
  123 + if (schema?.isTable !== false || schema?.table?.show !== false) {
120 124 return {
121 125 ...schema.table,
122 126 ...schema
... ... @@ -140,7 +144,7 @@ const filterFormSchema = (crudSchema: CrudSchema[]): FormSchema[] =&gt; {
140 144  
141 145 eachTree(crudSchema, (schemaItem: CrudSchema) => {
142 146 // 判断是否显示
143   - if (schemaItem?.form?.show !== false) {
  147 + if (schemaItem?.isForm !== false || schemaItem?.form?.show == true) {
144 148 let component = schemaItem?.form?.component || 'Input'
145 149 let defaultValue: any = ''
146 150 if (schemaItem.form?.value) {
... ... @@ -197,7 +201,7 @@ const filterDescriptionsSchema = (crudSchema: CrudSchema[]): DescriptionsSchema[
197 201  
198 202 eachTree(crudSchema, (schemaItem: CrudSchema) => {
199 203 // 判断是否显示
200   - if (schemaItem?.detail?.show !== false) {
  204 + if (schemaItem?.isDetail !== false || schemaItem.detail?.show !== false) {
201 205 const descriptionsSchemaItem = {
202 206 ...schemaItem.detail,
203 207 field: schemaItem.field,
... ...
yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts
... ... @@ -181,7 +181,7 @@ const filterTableSchema = (crudSchema: VxeCrudSchema): VxeGridPropTypes.Columns
181 181 }
182 182 eachTree(crudSchema.columns, (schemaItem: VxeCrudColumns) => {
183 183 // 判断是否显示
184   - if (schemaItem?.isTable !== false) {
  184 + if (schemaItem?.isTable !== false && schemaItem?.table?.show !== false) {
185 185 const tableSchemaItem = {
186 186 ...schemaItem.table,
187 187 field: schemaItem.field,
... ... @@ -278,7 +278,7 @@ const filterDescriptionsSchema = (crudSchema: VxeCrudSchema): DescriptionsSchema
278 278  
279 279 eachTree(crudSchema.columns, (schemaItem: VxeCrudColumns) => {
280 280 // 判断是否显示
281   - if (schemaItem?.isDetail !== false) {
  281 + if (schemaItem?.isDetail !== false || schemaItem.detail?.show !== false) {
282 282 const descriptionsSchemaItem = {
283 283 ...schemaItem.detail,
284 284 field: schemaItem.field,
... ...
yudao-ui-admin-vue3/src/views/infra/codegen/codegen.data.ts
... ... @@ -17,40 +17,28 @@ const crudSchemas = reactive&lt;CrudSchema[]&gt;([
17 17 label: t('common.index'),
18 18 field: 'id',
19 19 type: 'index',
20   - form: {
21   - show: false
22   - },
23   - detail: {
24   - show: false
25   - }
  20 + isForm: false,
  21 + isDetail: false
26 22 },
27 23 {
28 24 label: '表名称',
29 25 field: 'tableName',
30   - search: {
31   - show: true
32   - }
  26 + isSearch: true
33 27 },
34 28 {
35 29 label: '表描述',
36 30 field: 'tableComment',
37   - search: {
38   - show: true
39   - }
  31 + isSearch: true
40 32 },
41 33 {
42 34 label: '实体',
43 35 field: 'className',
44   - search: {
45   - show: true
46   - }
  36 + isSearch: true
47 37 },
48 38 {
49 39 label: t('common.createTime'),
50 40 field: 'createTime',
51   - form: {
52   - show: false
53   - },
  41 + isForm: false,
54 42 search: {
55 43 show: true,
56 44 component: 'DatePicker',
... ... @@ -64,20 +52,14 @@ const crudSchemas = reactive&lt;CrudSchema[]&gt;([
64 52 {
65 53 label: t('common.updateTime'),
66 54 field: 'updateTime',
67   - form: {
68   - show: false
69   - }
  55 + isForm: false
70 56 },
71 57 {
72 58 label: t('table.action'),
73 59 field: 'action',
74   - width: '500px',
75   - form: {
76   - show: false
77   - },
78   - detail: {
79   - show: false
80   - }
  60 + width: '350px',
  61 + isForm: false,
  62 + isDetail: false
81 63 }
82 64 ])
83 65 export const { allSchemas } = useCrudSchemas(crudSchemas)
... ...