perf: crud

pull/2/head
xingyu4j 2022-11-22 15:47:26 +08:00
parent 519b08f251
commit e6acf9e8dc
2 changed files with 37 additions and 16 deletions

View File

@ -156,20 +156,22 @@ const filterSearchSchema = (crudSchema: VxeCrudSchema): VxeFormItemProps[] => {
searchSchema.push(searchSchemaItem) searchSchema.push(searchSchemaItem)
} }
}) })
// 添加搜索按钮 if (searchSchema.length > 0) {
const buttons: VxeFormItemProps = { // 添加搜索按钮
span: 24, const buttons: VxeFormItemProps = {
align: 'center', span: 24,
collapseNode: searchSchema.length > 3, align: 'center',
itemRender: { collapseNode: searchSchema.length > 3,
name: '$buttons', itemRender: {
children: [ name: '$buttons',
{ props: { type: 'submit', content: t('common.query'), status: 'primary' } }, children: [
{ props: { type: 'reset', content: t('common.reset') } } { props: { type: 'submit', content: t('common.query'), status: 'primary' } },
] { props: { type: 'reset', content: t('common.reset') } }
]
}
} }
searchSchema.push(buttons)
} }
searchSchema.push(buttons)
return searchSchema return searchSchema
} }

View File

@ -12,10 +12,11 @@ const message = useMessage() // 消息弹窗
interface UseVxeGridConfig<T = any> { interface UseVxeGridConfig<T = any> {
allSchemas: VxeAllSchemas allSchemas: VxeAllSchemas
topActionSlots?: boolean // 是否开启表格内顶部操作栏插槽 topActionSlots?: boolean // 是否开启表格内顶部操作栏插槽
treeConfig?: VxeTablePropTypes.TreeConfig treeConfig?: VxeTablePropTypes.TreeConfig // 树形表单配置
getListApi: (option: any) => Promise<T> isList?: boolean // 是否不带分页的list
deleteApi?: (option: any) => Promise<T> getListApi: (option: any) => Promise<T> // 获取列表接口
exportListApi?: (option: any) => Promise<T> deleteApi?: (option: any) => Promise<T> // 删除接口
exportListApi?: (option: any) => Promise<T> // 导出接口
exportName?: string // 导出文件夹名称 exportName?: string // 导出文件夹名称
queryParams?: any // 其他查询参数 queryParams?: any // 其他查询参数
} }
@ -110,6 +111,24 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => {
if (config?.treeConfig) { if (config?.treeConfig) {
gridOptions.treeConfig = 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 { } else {
gridOptions.pagerConfig = { gridOptions.pagerConfig = {
border: false, // 带边框 border: false, // 带边框