boxOther.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { Popover, Space } from 'antd'
  2. import React, { useMemo } from 'react'
  3. interface Props {
  4. creativeComponents: {
  5. brand?: {
  6. value: {
  7. brandName: string
  8. }
  9. }[],
  10. description?: {
  11. value: {
  12. content: string
  13. }
  14. }[],
  15. video?: {
  16. value: {
  17. videoUrl: string
  18. }
  19. }[],
  20. image?: {
  21. value: {
  22. imageUrl: string
  23. }
  24. }[]
  25. }
  26. }
  27. /**
  28. * 预览
  29. */
  30. const BoxOther: React.FC<Props> = ({ creativeComponents }) => {
  31. let el = useMemo(() => {
  32. let video = creativeComponents?.video?.[0]?.value?.videoUrl
  33. let imageUrl = creativeComponents?.image
  34. let titles = creativeComponents?.brand
  35. let descriptions = creativeComponents?.description
  36. if (video) {
  37. return <div>
  38. <Popover
  39. placement='right'
  40. content={<div>
  41. {titles && titles?.length > 0 && <Space direction="vertical">
  42. {titles.map((item, index) => <div key={index} style={{ maxWidth: 300 }}><strong style={{ fontSize: 15 }}>标题:</strong>{item?.value?.brandName}</div>)}
  43. </Space>}
  44. {descriptions && descriptions?.length > 0 && <Space direction="vertical">
  45. {descriptions.map((item, index) => <small key={index} style={{ fontSize: 10, maxWidth: 300, display: 'inline-block' }}><strong style={{ fontSize: 13 }}>描述:</strong>{item?.value?.content}</small>)}
  46. </Space>}
  47. <Space style={{ maxWidth: 300, display: 'flex', flexFlow: 'row wrap', margin: '10px 0' }}>
  48. <video src={video} style={{ width: 250 }} controls />
  49. </Space>
  50. </div>}
  51. destroyTooltipOnHide
  52. mouseEnterDelay={0.5}
  53. >
  54. <Space style={{ width: '100%' }}>
  55. <video src={video} style={{ maxHeight: 18, maxWidth: 25 }} />
  56. <span>{titles?.[0]?.value?.brandName}</span>
  57. </Space>
  58. </Popover>
  59. </div>
  60. } else if (imageUrl && imageUrl?.length > 0) {
  61. return <Popover
  62. placement='right'
  63. content={<div
  64. style={{ maxHeight: 450, overflow: 'hidden', overflowY: 'auto' }}
  65. >
  66. <Space direction="vertical">
  67. {titles && titles?.length > 0 && <Space direction="vertical">
  68. {titles.map((item, index) => <div key={index} style={{ maxWidth: 300 }}><strong style={{ fontSize: 15 }}>标题:</strong>{item?.value?.brandName}</div>)}
  69. </Space>}
  70. {descriptions && descriptions?.length > 0 && <Space direction="vertical">
  71. {descriptions.map((item, index) => <small key={index} style={{ fontSize: 10, maxWidth: 300, display: 'inline-block' }}><strong style={{ fontSize: 13 }}>描述:</strong>{item?.value?.content}</small>)}
  72. </Space>}
  73. <Space wrap style={{ maxWidth: 500 }}>
  74. {imageUrl?.map((item, index) => <img key={index} src={item?.value?.imageUrl} height={100} />)}
  75. </Space>
  76. </Space>
  77. </div>}
  78. destroyTooltipOnHide
  79. mouseEnterDelay={0.5}
  80. >
  81. {imageUrl?.[0]?.value?.imageUrl ? <img src={imageUrl?.[0]?.value?.imageUrl} height={18} /> : <span>无图片地址</span>}
  82. </Popover>
  83. } else if (titles && titles?.length > 0) {
  84. return <span>{titles?.[0]?.value?.brandName}</span>
  85. } else if (descriptions && descriptions?.length > 0) {
  86. return <span>{descriptions?.[0]?.value?.content}</span>
  87. } else {
  88. return <span>--</span>
  89. }
  90. }, [creativeComponents])
  91. return <div style={{ overflow: 'hidden', overflowX: 'auto' }}>
  92. {el}
  93. </div>
  94. }
  95. export default React.memo(BoxOther)