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