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

第二种:待更新

相关推荐
酷炫码神几秒前
Day 9|Vue Router:把单页后台拆成能跳转的多页面
前端·javascript·vue.js
Sapphire~11 分钟前
odoo-095 视图的重写规则(全部重写还是部分改写)
开发语言·javascript·ecmascript
肖永威19 分钟前
python版微电网仿真工具的前端托管选型:从http.server到FastAPI StaticFiles
前端·python·http·fastapi
风骏时光牛马20 分钟前
AI插件开发与效能提效工具箱
前端
IT_陈寒22 分钟前
为什么你应该学习Java?
前端·人工智能·后端
weixin_4173968343 分钟前
监控画面卡顿与录像缺失:码率、NVR与存储容量的排查顺序
前端·网络·技术·酒店·综合布线·弱电
曹牧1 小时前
Eclipse 工作空间(Workspace)的默认 JDK 配置
前端
其实防守也摸鱼2 小时前
Cylab在线靶场——挑战图书馆初学者指南
服务器·前端·数据库·chrome·安全·网络安全·靶场
拆房老料4 小时前
【第四部分:Agentic 智能体设计模式】16. 一个 Prompt 搞不定复杂任务?试试 Prompt Chaining
java·前端·人工智能·设计模式·prompt
曹牧9 小时前
C#:空合并运算符
java·前端·数据库