【procomponents】根据表单查询表格数据的两种写法

第一种:表单QueryFilter+表格ProTable

typescript 复制代码
<QueryFilter
  formRef={formRef}
  initialValues={{
    mediaCategoryId: opts.mediaOpts?.[0]?.mediaCategoryId ?? '',
    dateRange: [moment(), moment()]
  }}
  optionRender={(_searchConfig, _formProps, dom) => [
    ...dom.reverse(),
    <Button 
      key="export" 
      loading={exportLoading}
    >
      导出
    </Button>,
  ]}
  // 点击查询调用getList
  onFinish={() => {
    actionRef.current?.reload();
  }}  
  // 点击重置将表单恢复为initialValues数据,调用getList
  onReset={() => {
    actionRef.current?.reloadAndRest();
  }}
>
  <ProFormSelect
    name="id"
    label="种类"
    rules={[
      { required: true, message: '请选择种类!' }
    ]}
    fieldProps={{
      options: opts.mediaOpts,
      fieldNames: { label: 'name', value: 'id' },
      allowClear: false,
    }}
  />
  <ProFormDateRangePicker 
    name="dateRange" 
    label="日期" 
    fieldProps={{
      allowClear: false,
    }}
  />
</QueryFilter>
<ProTable
   actionRef={actionRef}
   search={false}
   toolBarRender={false}
   scroll={{ 
     // x: 'max-content',
     y: 'calc(100% - 50px)'
   }}
   columns={columns}
   pagination={{
     pageSizeOptions: ['15', '20', '50', '100'],
     pageSize: pagination.pageSize,
     current: pagination.pageNum,
     showSizeChanger: true,
     showQuickJumper: true,
     showTotal: (total, range) => `共 ${total} 条`,
     hideOnSinglePage: false,
     onChange: (pageNum, pageSize) => {
       setPagination(prev => ({ ...prev, pageNum, pageSize }));
     }
   }}
   request={async(params) => {
     setLoading(true);
     if(firstRender.current) {
       await getOpts();
       firstRender.current = false;
     }
     const { id, dateRange } = formRef.current?.getFieldsValue();
     return getList({
       id,
       startTime: dateRange?.[0] ? moment(dateRange[0]).format('YYYY-MM-DD') : undefined,
       endTime: dateRange?.[1] ? moment(dateRange[1]).format('YYYY-MM-DD') : undefined,
       pageSize: params?.pageSize ?? 15,
       pageNum: params?.current ?? 1
     }).then((res: any) => {
       if(res.code === 200) {
         return { data: res?.rows || [], total: res?.total || 0, success: true };
       }else {
         return { data: [{}], total: 0, success: false };
       }
     }).catch(() => {
       return { data: [{}], total: 0, success: false };
     }).finally(() => {
       setLoading(false);
     }); 
   }}
 />

第二种:待更新

相关推荐
parade岁月26 分钟前
VTable Guild 3.0.0 发布,面向 Vue 3 的 ProTable 式业务表格
前端
xurileidian42 分钟前
第 17 篇 · 边玩边学Python · for 遍历 enumerate 与 zip
java·前端·python
掘金安东尼2 小时前
更多审查智能体,更少盲区:GitHub Copilot 代码审查是怎么做的
前端·github copilot
Hilaku4 小时前
2026 年了,jQuery 真的该死了吗?
前端·javascript·程序员
zach4 小时前
吃透 React setState 同步异步之谜:从批量更新、事件循环到版本演进的完整拆解
前端·react.js
不服老的小黑哥4 小时前
02-从 pnpm dev 到 Spring Boot 启动:后端服务到底怎么跑起来?
前端
htzyl2064 小时前
javaScript——this 的四种绑定:为什么箭头函数改不了它
前端·javascript
bai2734 小时前
*.js 匹配到了 B.JS:fs.globSync 在 Windows 上的五个默认值
javascript·后端
欧雷殿4 小时前
做自己的第一位客户:一人公司的数据治理公开实践
前端·ai编程·团队管理
时间的情敌5 小时前
Three.js 工业场景性能优化合集|大批量管线、InstancedMesh 实例化、合并 Geometry、显存释放
开发语言·javascript·性能优化·three.js