tableConfig.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { Statistic, Image, Space, Badge } from 'antd'
  2. import { ColumnsType } from 'antd/lib/table'
  3. import { SortOrder } from 'antd/lib/table/interface'
  4. import React from 'react'
  5. import style from './index.less'
  6. function columns(props?: { sortOrder?: { columnKey: string, order: SortOrder | undefined } }) {
  7. let newArr: ColumnsType<any> = [
  8. // {
  9. // title: '图片链接',
  10. // dataIndex: 'preview_url',
  11. // key: 'preview_url',
  12. // align: 'center',
  13. // width: 60,
  14. // fixed: 'left',
  15. // render: (url: string) => {
  16. // let urls = url?.split(',')
  17. // return <Space>
  18. // {
  19. // urls.map((a, b) => {
  20. // return <Image src={a} style={{ width: 100 }} preview key={b} />
  21. // })
  22. // }
  23. // </Space>
  24. // }
  25. // },
  26. {
  27. title: '图片链接',
  28. dataIndex: 'preview_url',
  29. key: 'preview_url',
  30. align: 'center',
  31. ellipsis: true,
  32. fixed: 'left',
  33. width:60,
  34. render: (url: string) => {
  35. let urls = url?.split(',')
  36. return <Space style={{display:'flex',flexFlow:'row wrap',justifyContent:'center',}} className={style.img}>
  37. <Image.PreviewGroup>
  38. {
  39. urls?.map((a, b) => {
  40. return <Badge count={urls?.length > 1 ? urls?.length : ''} style={b > 0 ?{ display:'none' }:{}} size='small'>
  41. <Image src={a} preview key={b} style={b > 0 ?{ display:'none'}:{width:20,zIndex:100}}/>
  42. </Badge>
  43. })
  44. }
  45. </Image.PreviewGroup>
  46. </Space>
  47. }
  48. },
  49. {
  50. title: '消耗',
  51. dataIndex: 'sum(cost)',
  52. key: 'sum(cost)',
  53. align: 'center',
  54. width: 60,
  55. sorter: true,
  56. sortOrder: (props?.sortOrder?.columnKey === 'sum(cost)' && props?.sortOrder?.order) || undefined,
  57. render: (a: any) => {
  58. return <Statistic value={a || 0} />
  59. }
  60. },
  61. {
  62. title: '点击率',
  63. dataIndex: 'ctr',
  64. key: 'ctr',
  65. align: 'center',
  66. width: 60,
  67. sorter: true,
  68. sortOrder: (props?.sortOrder?.columnKey === 'ctr' && props?.sortOrder?.order) || undefined,
  69. render: (a: number) => {
  70. a = a ? parseFloat((a * 100).toFixed(2)) : 0
  71. return <span style={a <= 8 ? { color: '#0f990f', fontWeight: 600 } : a >= 100 ? { color: 'red', fontWeight: 600 } : {}}> {a + '%'}</span >
  72. },
  73. },
  74. {
  75. title: '点击均价',
  76. dataIndex: 'cpc',
  77. key: 'cpc',
  78. align: 'center',
  79. width: 60,
  80. sorter: true,
  81. sortOrder: (props?.sortOrder?.columnKey === 'cpc' && props?.sortOrder?.order) || undefined,
  82. render: (a: any) => {
  83. return <Statistic value={a || 0} />
  84. }
  85. },
  86. ]
  87. return newArr
  88. }
  89. export { columns }