usage-example.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // 使用示例:如何替换你的 ChannelTableWidget 组件
  2. // 1. 替换导入语句
  3. // 原来:
  4. // import { ActionType, ProTable } from "@ant-design/pro-components";
  5. // 现在:
  6. import ProTable, { ActionType } from "./ProTable";
  7. // 2. 其他代码保持不变,ProTable 组件会自动适配你的用法
  8. // 主要实现的功能:
  9. // ✅ actionRef - 通过 ref.current?.reload() 刷新表格
  10. // ✅ columns 配置 - 支持所有你使用的列配置
  11. // ✅ request 异步请求 - 支持分页、排序、过滤参数
  12. // ✅ rowKey - 行唯一标识
  13. // ✅ bordered - 边框样式
  14. // ✅ pagination - 分页配置(showQuickJumper, showSizeChanger)
  15. // ✅ search - 搜索功能(options.search)
  16. // ✅ toolBarRender - 工具栏渲染
  17. // ✅ toolbar.menu - 标签页切换(my/collaboration/community)
  18. // ✅ valueEnum - 枚举值过滤
  19. // ✅ valueType - 日期格式化
  20. // ✅ sorter - 排序支持
  21. // ✅ filters/onFilter - 过滤支持
  22. // ✅ ellipsis - 文本溢出省略
  23. // ✅ hideInTable - 隐藏列
  24. // 完整替换示例:
  25. /*
  26. import ProTable, { ActionType } from './ProTable';
  27. import { FormattedMessage, useIntl } from "react-intl";
  28. // ... 其他导入保持不变
  29. const ChannelTableWidget = ({ ... }) => {
  30. const ref = useRef<ActionType>();
  31. return (
  32. <ProTable<IChannelItem>
  33. actionRef={ref}
  34. columns={[ ... ]} // 你的列配置保持不变
  35. request={async (params, sorter, filter) => {
  36. // 你的请求逻辑保持不变
  37. // ...
  38. return {
  39. total: res.data.count,
  40. success: true,
  41. data: items,
  42. };
  43. }}
  44. rowKey="id"
  45. bordered
  46. pagination={{
  47. showQuickJumper: true,
  48. showSizeChanger: true,
  49. }}
  50. search={false}
  51. options={{
  52. search: true,
  53. }}
  54. toolBarRender={() => [ ... ]} // 保持不变
  55. toolbar={{
  56. menu: {
  57. activeKey,
  58. items: [ ... ],
  59. onChange(key) { ... }
  60. }
  61. }}
  62. />
  63. );
  64. };
  65. */