【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);
     }); 
   }}
 />

第二种:待更新

相关推荐
空中湖27 分钟前
Spring AI Agent 编排:ReAct 模式 + 多 Agent 协作实战
人工智能·spring·react.js
吃糖的小孩41 分钟前
从只读页面到可控真实探针:我如何给 Owner Console 加手动诊断
前端
谷无姜41 分钟前
为什么你的性能优化无效?可能是"木桶效应"在作祟
前端·性能优化
雾非雾1 小时前
《基于具身交互智能数字人技术:如何打造AI数字人宣讲平台"红厅智播”》
前端
Revolution611 小时前
一段 JavaScript 代码执行时,到底发生了什么
前端·javascript
智能起源1 小时前
关于元素层级过多,导致压祯的问题(使用winform或者WPF应用的webview组件嵌套网页时,动效卡顿问题)
前端
Old Uncle Tom2 小时前
银行用户画像 -- 金融目标与需求意图
前端·人工智能·金融
IT_陈寒2 小时前
Vue的响应式让我加班到凌晨3点,原来问题出在这
前端·人工智能·后端
东方小月2 小时前
从0开发一个 Coding Agent(一):前言
前端·人工智能·typescript