From 16b3e910e4d2d7c9cae013780f64bf6532d3c508 Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Sat, 12 Nov 2022 17:08:23 +0800 Subject: [PATCH] perf: vxe --- .../src/hooks/web/useVxeCrudSchemas.ts | 50 +++++-------------- .../views/system/errorCode/errorCode.data.ts | 18 ++----- .../src/views/system/post/post.data.ts | 20 ++------ 3 files changed, 23 insertions(+), 65 deletions(-) diff --git a/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts b/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts index 59c68903f..e58034977 100644 --- a/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts +++ b/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts @@ -26,33 +26,18 @@ type VxeCrudColumns = Omit & { field: string title?: string formatter?: VxeColumnPropTypes.Formatter - search?: CrudSearchParams - table?: CrudTableParams - form?: CrudFormParams - detail?: CrudDescriptionsParams + isSearch?: boolean + search?: VxeFormItemProps + isTable?: boolean + table?: VxeTableDefines.ColumnOptions + isForm?: boolean + form?: FormSchema + isDetail?: boolean + detail?: DescriptionsSchema print?: CrudPrintParams children?: VxeCrudColumns[] dictType?: string } -type CrudSearchParams = { - // 是否显示在查询项 - show?: boolean -} & Omit - -type CrudTableParams = { - // 是否显示表头 - show?: boolean -} & Omit - -type CrudFormParams = { - // 是否显示表单项 - show?: boolean -} & Omit - -type CrudDescriptionsParams = { - // 是否显示表单项 - show?: boolean -} & Omit type CrudPrintParams = { // 是否显示表单项 @@ -108,7 +93,7 @@ const filterSearchSchema = (crudSchema: VxeCrudSchema): VxeFormItemProps[] => { const searchSchema: VxeFormItemProps[] = [] eachTree(crudSchema.columns, (schemaItem: VxeCrudColumns) => { // 判断是否显示 - if (schemaItem?.search?.show) { + if (schemaItem?.isSearch) { let itemRenderName = schemaItem?.search?.itemRender?.name || '$input' const options: any[] = [] let itemRender: FormItemRenderOptions = { @@ -122,7 +107,7 @@ const filterSearchSchema = (crudSchema: VxeCrudSchema): VxeFormItemProps[] => { options.push(dict) }) itemRender.options = options - if (!schemaItem.search.itemRender?.name) itemRenderName = '$select' + if (!schemaItem?.search?.itemRender?.name) itemRenderName = '$select' itemRender = { name: itemRenderName, options: options, @@ -174,7 +159,7 @@ const filterTableSchema = (crudSchema: VxeCrudSchema): VxeGridPropTypes.Columns } eachTree(crudSchema.columns, (schemaItem: VxeCrudColumns) => { // 判断是否显示 - if (schemaItem?.table?.show !== false) { + if (schemaItem?.isTable !== false) { const tableSchemaItem = { ...schemaItem.table, field: schemaItem.field, @@ -190,9 +175,6 @@ const filterTableSchema = (crudSchema: VxeCrudSchema): VxeGridPropTypes.Columns } } - // 删除不必要的字段 - delete tableSchemaItem.show - tableSchema.push(tableSchemaItem) } }) @@ -217,7 +199,7 @@ const filterFormSchema = (crudSchema: VxeCrudSchema): FormSchema[] => { eachTree(crudSchema.columns, (schemaItem: VxeCrudColumns) => { // 判断是否显示 - if (schemaItem?.form?.show !== false) { + if (schemaItem?.isForm !== false) { let component = schemaItem?.form?.component || 'Input' const options: ComponentOptions[] = [] let comonentProps = {} @@ -239,9 +221,6 @@ const filterFormSchema = (crudSchema: VxeCrudSchema): FormSchema[] => { label: schemaItem.form?.label || schemaItem.title } - // 删除不必要的字段 - delete formSchemaItem.show - formSchema.push(formSchemaItem) } }) @@ -255,16 +234,13 @@ const filterDescriptionsSchema = (crudSchema: VxeCrudSchema): DescriptionsSchema eachTree(crudSchema.columns, (schemaItem: VxeCrudColumns) => { // 判断是否显示 - if (schemaItem?.detail?.show !== false) { + if (schemaItem?.isDetail !== false) { const descriptionsSchemaItem = { ...schemaItem.detail, field: schemaItem.field, label: schemaItem.detail?.label || schemaItem.title } - // 删除不必要的字段 - delete descriptionsSchemaItem.show - descriptionsSchema.push(descriptionsSchemaItem) } }) diff --git a/yudao-ui-admin-vue3/src/views/system/errorCode/errorCode.data.ts b/yudao-ui-admin-vue3/src/views/system/errorCode/errorCode.data.ts index 59b2345b1..92bcbebbd 100644 --- a/yudao-ui-admin-vue3/src/views/system/errorCode/errorCode.data.ts +++ b/yudao-ui-admin-vue3/src/views/system/errorCode/errorCode.data.ts @@ -20,23 +20,17 @@ const crudSchemas = reactive({ title: '错误码类型', field: 'type', dictType: DICT_TYPE.SYSTEM_ERROR_CODE_TYPE, - search: { - show: true - } + isSearch: true }, { title: '应用名', field: 'applicationName', - search: { - show: true - } + isSearch: true }, { title: '错误码编码', field: 'code', - search: { - show: true - } + isSearch: true }, { title: '错误码错误提示', @@ -46,11 +40,9 @@ const crudSchemas = reactive({ title: t('common.createTime'), field: 'createTime', formatter: 'formatDate', - form: { - show: false - }, + isForm: false, + isSearch: true, search: { - show: true, itemRender: { name: 'XDataTimePicker' } diff --git a/yudao-ui-admin-vue3/src/views/system/post/post.data.ts b/yudao-ui-admin-vue3/src/views/system/post/post.data.ts index d9592d2fc..c22828be2 100644 --- a/yudao-ui-admin-vue3/src/views/system/post/post.data.ts +++ b/yudao-ui-admin-vue3/src/views/system/post/post.data.ts @@ -21,16 +21,12 @@ const crudSchemas = reactive({ { title: '岗位名称', field: 'name', - search: { - show: true - } + isSearch: true }, { title: '岗位编码', field: 'code', - search: { - show: true - } + isSearch: true }, { title: '岗位顺序', @@ -40,24 +36,18 @@ const crudSchemas = reactive({ title: t('common.status'), field: 'status', dictType: DICT_TYPE.COMMON_STATUS, - search: { - show: true - } + isSearch: true }, { title: '备注', field: 'remark', - table: { - show: false - } + isTable: false }, { title: t('common.createTime'), field: 'createTime', formatter: 'formatDate', - form: { - show: false - } + isForm: false } ] })