From e6acf9e8dca81b0e2ca2293fb9fb3783d9a68e4c Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Tue, 22 Nov 2022 15:47:26 +0800 Subject: [PATCH] perf: crud --- .../src/hooks/web/useVxeCrudSchemas.ts | 26 +++++++++--------- .../src/hooks/web/useVxeGrid.ts | 27 ++++++++++++++++--- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts b/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts index 8b5a01158..5a5fe4997 100644 --- a/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts +++ b/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts @@ -156,20 +156,22 @@ const filterSearchSchema = (crudSchema: VxeCrudSchema): VxeFormItemProps[] => { searchSchema.push(searchSchemaItem) } }) - // 添加搜索按钮 - const buttons: VxeFormItemProps = { - span: 24, - align: 'center', - collapseNode: searchSchema.length > 3, - itemRender: { - name: '$buttons', - children: [ - { props: { type: 'submit', content: t('common.query'), status: 'primary' } }, - { props: { type: 'reset', content: t('common.reset') } } - ] + if (searchSchema.length > 0) { + // 添加搜索按钮 + const buttons: VxeFormItemProps = { + span: 24, + align: 'center', + collapseNode: searchSchema.length > 3, + itemRender: { + name: '$buttons', + children: [ + { props: { type: 'submit', content: t('common.query'), status: 'primary' } }, + { props: { type: 'reset', content: t('common.reset') } } + ] + } } + searchSchema.push(buttons) } - searchSchema.push(buttons) return searchSchema } diff --git a/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts b/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts index de1337894..14e69966e 100644 --- a/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts +++ b/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts @@ -12,10 +12,11 @@ const message = useMessage() // 消息弹窗 interface UseVxeGridConfig { allSchemas: VxeAllSchemas topActionSlots?: boolean // 是否开启表格内顶部操作栏插槽 - treeConfig?: VxeTablePropTypes.TreeConfig - getListApi: (option: any) => Promise - deleteApi?: (option: any) => Promise - exportListApi?: (option: any) => Promise + treeConfig?: VxeTablePropTypes.TreeConfig // 树形表单配置 + isList?: boolean // 是否不带分页的list + getListApi: (option: any) => Promise // 获取列表接口 + deleteApi?: (option: any) => Promise // 删除接口 + exportListApi?: (option: any) => Promise // 导出接口 exportName?: string // 导出文件夹名称 queryParams?: any // 其他查询参数 } @@ -110,6 +111,24 @@ export const useVxeGrid = (config?: UseVxeGridConfig) => { if (config?.treeConfig) { gridOptions.treeConfig = config.treeConfig + } else if (config?.isList) { + gridOptions.proxyConfig = { + seq: true, // 启用动态序号代理(分页之后索引自动计算为当前页的起始序号) + form: true, // 启用表单代理,当点击表单提交按钮时会自动触发 reload 行为 + props: { result: 'data' }, + ajax: { + query: ({ form }) => { + let queryParams: any = Object.assign({}, JSON.parse(JSON.stringify(form))) + if (config?.queryParams) { + queryParams = Object.assign(queryParams, config.queryParams) + } + gridOptions.loading = false + return new Promise(async (resolve) => { + resolve(await config?.getListApi(queryParams)) + }) + } + } + } } else { gridOptions.pagerConfig = { border: false, // 带边框