adcreativeCol.tsx 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { PromotedObjectType, SiteSetEnum } from "@/services/launchAdq/enum"
  3. import { get_adcreative_template_list } from "@/services/launchAdq/global"
  4. import React, { useEffect, useState } from "react"
  5. import { outAdcreativeTemplateIdFun } from "../localAd/adenum"
  6. import { Image, Space, Spin } from "antd"
  7. /**
  8. * 创意详情
  9. */
  10. interface Props {
  11. data: any,
  12. onChange?: (value: string) => void
  13. }
  14. const AdcreativeCol: React.FC<Props> = (props) => {
  15. /***************************/
  16. const { data, onChange } = props
  17. const { adcreativeName, promotedObjectType, siteSet, adcreativeTemplateId, adcreativeElements } = data
  18. const [adcreative_template_list, set_adcreative_template_list] = useState<any[]>([])
  19. const getAdcreativeTemplateList = useAjax((params) => get_adcreative_template_list(params))
  20. /***************************/
  21. /** 获取创意形式 */
  22. useEffect(() => {
  23. if (siteSet?.length > 0 && promotedObjectType && !(adcreative_template_list.length > 0)) {
  24. getAdcreativeTemplateList.run({
  25. siteSet,
  26. promotedObjectType,
  27. campaignType: 'CAMPAIGN_TYPE_NORMAL',
  28. }).then(res => {
  29. let newArr: any = []
  30. // 过滤掉相同的和即将下线的
  31. Object.values(res)?.forEach((arr: any) => {
  32. Array.isArray(arr) && arr?.forEach((item: any) => {
  33. if (newArr.length > 0) {
  34. if (outAdcreativeTemplateIdFun(item.adcreativeTemplateId) && newArr.every((i: { adcreativeTemplateId: any }) => i.adcreativeTemplateId !== item.adcreativeTemplateId)) {
  35. newArr.push(item)
  36. } else {
  37. // 找出通用创意
  38. newArr = newArr?.map((arr: { adcreativeTemplateId: any }) => {
  39. if (arr.adcreativeTemplateId === item.adcreativeTemplateId) {
  40. return { ...arr, isGeneral: true }
  41. }
  42. return arr
  43. })
  44. }
  45. } else {
  46. if (outAdcreativeTemplateIdFun(item.adcreativeTemplateId)) {
  47. newArr.push(item)
  48. }
  49. }
  50. })
  51. })
  52. set_adcreative_template_list(newArr)
  53. })
  54. }
  55. }, [siteSet, promotedObjectType])
  56. useEffect(() => {
  57. if (adcreative_template_list?.length > 0 && adcreativeTemplateId) {
  58. onChange && onChange(adcreative_template_list?.find((item: any) => item?.adcreativeTemplateId === adcreativeTemplateId)?.adcreativeTemplateAppellation || '')
  59. }
  60. }, [adcreative_template_list, adcreativeTemplateId])
  61. return <Spin size="small" spinning={getAdcreativeTemplateList?.loading}>
  62. <div>创意名称: <span>{adcreativeName}</span></div>
  63. <div>推广目标: <span>{PromotedObjectType[promotedObjectType]}</span></div>
  64. <div>广告版位: <span>{siteSet?.map((item: string) => SiteSetEnum[item]).toString()}</span></div>
  65. <div>创意形式: <span>{adcreative_template_list?.find((item: any) => item?.adcreativeTemplateId === adcreativeTemplateId)?.adcreativeTemplateAppellation || ''}</span></div>
  66. {adcreativeElements?.description && <div>创意文案: <span>{adcreativeElements?.description}</span></div>}
  67. {adcreativeElements?.title && <div>文案: <span>{adcreativeElements?.title}</span></div>}
  68. {adcreativeElements?.imageUrl && <div style={{ display: 'flex', alignItems: 'flex-start' }}>创意素材: <Image width={80} src={adcreativeElements?.imageUrl} style={{ borderRadius: 8, overflow: 'hidden', marginLeft: 5 }} /></div>}
  69. {adcreativeElements?.imageUrlList && <div style={{ display: 'flex', alignItems: 'flex-start', flexWrap: 'wrap' }}><span style={{ marginRight: 4 }}>创意素材:</span> <Image.PreviewGroup>
  70. <Space wrap>
  71. {adcreativeElements?.imageUrlList?.map((url: string, index: number) => <Image width={50} src={url} style={{ borderRadius: 4 }} key={'TOP_SLIDER' + index} />)}
  72. </Space>
  73. </Image.PreviewGroup></div>}
  74. {adcreativeElements?.shortVideoStruct?.shortVideo1Url && <div style={{ display: 'flex', alignItems: 'flex-start' }}><span style={{ marginRight: 4 }}>创意素材:</span> <video src={adcreativeElements?.shortVideoStruct?.shortVideo1Url} width={130} controls></video></div>}
  75. {adcreativeElements?.videoUrl && <div style={{ display: 'flex', alignItems: 'flex-start' }}><span style={{ marginRight: 4 }}>创意素材:</span> <video src={adcreativeElements?.videoUrl} width={130} controls></video></div>}
  76. </Spin>
  77. }
  78. export default React.memo(AdcreativeCol)