index.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import React, { useContext, useEffect, useState } from "react"
  2. import style from '../index.less'
  3. import { DispatchAddelivery } from "..";
  4. import { Button, Empty, Typography } from "antd";
  5. import { FolderOpenOutlined, RedoOutlined } from "@ant-design/icons";
  6. import AddMaterial from "./addMaterial";
  7. import VideoNews from "@/pages/launchSystemNew/components/newsModal/videoNews";
  8. const { Title } = Typography;
  9. const Material: React.FC = () => {
  10. /***************************************/
  11. const { materialData, addelivery, setAddelivery, clearData } = useContext(DispatchAddelivery)!;
  12. const { dynamic, dynamicMaterialDTos } = addelivery
  13. const { creativeTemplateId, deliveryMode } = dynamic
  14. const [newVisible, setNewVisible] = useState<boolean>(false)
  15. const [mType, setMtype] = useState<string>()
  16. /***************************************/
  17. useEffect(() => {
  18. if (materialData && Object.keys(materialData).length > 0) {
  19. let type = Object.keys(materialData)[0];
  20. setMtype(type)
  21. }
  22. }, [materialData])
  23. return <div className={`${style.settingsBody_content_row} ${style.row4}`}>
  24. <div className={style.title}>
  25. <span>创意素材 <span className={style.selected}>已选 {dynamicMaterialDTos?.dynamicGroup?.length || 0}</span></span>
  26. {(dynamicMaterialDTos && Object.keys(dynamicMaterialDTos).length > 0) ? <Button type="link" size="small" style={{ fontSize: 11, padding: 0 }} onClick={() => setAddelivery({ ...addelivery, dynamicMaterialDTos: [], dynamicCreativesTextDTOS: {} })}><RedoOutlined />清空</Button> : null}
  27. </div>
  28. <div className={style.detail}>
  29. <div className={style.detail_body}>
  30. {(dynamicMaterialDTos && Object.keys(dynamicMaterialDTos).length > 0) ?
  31. <div className={style.detail_body_m}>
  32. {dynamicMaterialDTos.dynamicGroup.map((item: any, index: number) => {
  33. return <div key={index} style={{ width: deliveryMode === 'DELIVERY_MODE_CUSTOMIZE' ? [641, 642, 643].includes(creativeTemplateId) ? '100%' : [720, 721, 722, 1529, 618].includes(creativeTemplateId) ? '50%' : '25%' : '100%' }}>
  34. <Title level={5} style={{ fontSize: 12 }}>创意组{index + 1}</Title>
  35. {mType ? ['short_video', 'video'].includes(mType) ? <div className={style.video}>
  36. <VideoNews src={item?.video_id?.url || item?.short_video1?.url} />
  37. {item?.cover_id && <div className={style.cover_image}>
  38. <img src={item?.cover_id?.url} />
  39. </div>}
  40. </div> : ['image_list'].includes(mType) ? <div className={style.imageList}>
  41. {item?.image_list?.map((item: { url: string | undefined; }, index: undefined) => <div className={style.cover_image} key={index}>
  42. <img src={item?.url} />
  43. </div>)}
  44. </div> : ['element_story'].includes(mType) ? <div className={style.imageList}>
  45. {item?.element_story?.map((item: { url: string | undefined; }, index: undefined) => <div className={style.cover_image} key={index}>
  46. <img src={item?.url} />
  47. </div>)}
  48. </div> : ['image'].includes(mType) ? <div className={style.cover_image}>
  49. <img src={item?.image_id?.url} />
  50. </div> : null : null}
  51. </div>
  52. })}
  53. </div> :
  54. <div className={style.empty_block}>
  55. <Empty description="暂无素材" imageStyle={{ height: 50 }} />
  56. </div>}
  57. {((dynamic && Object.keys(dynamic).length > 0) && !(materialData && Object.keys(materialData).length > 0)) && <div className={style.ad_config}>
  58. <div className={style.ad_config_item}>无需设置创意素材</div>
  59. </div>}
  60. </div>
  61. <div className={style.detail_footer}>
  62. <Button disabled={!(dynamic && Object.keys(dynamic)?.length > 0)} type="link" icon={<FolderOpenOutlined />} style={{ padding: 0, fontSize: 12 }} onClick={() => setNewVisible(true)}>选择素材</Button>
  63. </div>
  64. </div>
  65. {newVisible && <AddMaterial
  66. creativeTemplateId={creativeTemplateId}
  67. value={dynamicMaterialDTos}
  68. materialData={materialData}
  69. deliveryMode={deliveryMode}
  70. visible={newVisible}
  71. onClose={() => {
  72. setNewVisible(false)
  73. }}
  74. onChange={(values) => {
  75. setAddelivery({ ...addelivery, dynamicMaterialDTos: values, dynamicCreativesTextDTOS: {} })
  76. setNewVisible(false)
  77. clearData()
  78. }}
  79. />}
  80. </div>
  81. }
  82. export default React.memo(Material)