creativeTemplateContent.tsx 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { Button, Card, Form, Radio, Space } from "antd"
  2. import React, { useContext, useMemo } from "react"
  3. import { DispatchDynamic } from "./newDynamic";
  4. import New1Radio from "@/pages/launchSystemV3/components/New1Radio";
  5. import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
  6. import BrandImage from "@/pages/launchSystemV3/components/BrandImage";
  7. import { SelectProfiles } from "@/pages/launchSystemV3/tencenTasset/profiles";
  8. /**
  9. * 创意内容
  10. * @returns
  11. */
  12. const CreativeTemplateContent: React.FC<{ automaticSiteEnabled: boolean }> = ({ automaticSiteEnabled }) => {
  13. /******************************************/
  14. const { creativeComponents, form, adgroups: { siteSet } } = useContext(DispatchDynamic)!;
  15. const pageType = Form.useWatch(['jumpInfo', 'pageType'], form)
  16. const pageSpec = Form.useWatch('pageSpec', form)
  17. const deliveryMode = Form.useWatch('deliveryMode', form)
  18. const linkName = Form.useWatch(['textLink', 'value', 'linkName'], form)
  19. /******************************************/
  20. const content = useMemo(() => {
  21. let brand;
  22. let enumeration: PULLIN.DataType[] = []
  23. let pageTypeList: PULLIN.DataType[] = []
  24. let jumpInfoNumber = 1
  25. Object.keys(creativeComponents).forEach(key => {
  26. switch (key) {
  27. case 'brand':
  28. brand = creativeComponents[key]
  29. let page_type = brand.children.page_type
  30. let typeList = ["PAGE_TYPE_WECHAT_OFFICIAL_ACCOUNT_DETAIL", "PAGE_TYPE_H5_PROFILE", "PAGE_TYPE_NOT_USED"]
  31. enumeration = (page_type.enumProperty.enumeration as { value: string, description: string }[]).filter((item: { value: string; }) => typeList.includes(item.value)).map(item => ({ label: item.value === 'PAGE_TYPE_NOT_USED' ? '品牌形象' : item.description, value: item.value }))
  32. break
  33. case 'jump_info':
  34. let jump_info = creativeComponents[key]
  35. jumpInfoNumber = jump_info?.arrayProperty?.maxNumber || 1
  36. let jumpInfoPageType = jump_info.children.page_type
  37. pageTypeList = (jumpInfoPageType.enumProperty.enumeration as { value: string, description: string }[]).filter(item => !["PAGE_TYPE_WECHAT_CANVAS_MINI_PROGRAM", "PAGE_TYPE_H5", "PAGE_TYPE_WECHAT_SIMPLE_CANVAS", "PAGE_TYPE_APP_DEEP_LINK"].includes(item.value)).map(item => ({ label: item.description, value: item.value, disabled: "PAGE_TYPE_WECHAT_CANVAS" !== item.value }))
  38. break
  39. }
  40. })
  41. return <>
  42. {brand && <Form.Item style={{ marginBottom: 0 }}>
  43. <Form.Item name={['jumpInfo', 'pageType']} label={<strong>品牌形象跳转</strong>} rules={[{ required: true, message: '请选择品牌形象跳转!' }]} tooltip="品牌形象将在各流量版位下广告外层创意展示。此外,朋友圈广告在此基础上支持跳转,点击品牌形象可跳转到品牌简介页或搜一搜品牌主页">
  44. <New1Radio data={enumeration} />
  45. </Form.Item>
  46. {['PAGE_TYPE_H5_PROFILE'].includes(pageType) ? <div style={{ margin: '0 0 10px', backgroundColor: '#fafafb', padding: '8px 16px 8px', borderRadius: 8 }}>
  47. <Form.Item name='brand' style={{ marginBottom: 0 }} rules={[{ required: true, message: '请选择一个头像及昵称跳转页,与广告创意一起展示' }]}>
  48. <SelectProfiles />
  49. </Form.Item>
  50. </div> : ["PAGE_TYPE_NOT_USED"].includes(pageType) && <div style={{ margin: '0 0 10px', backgroundColor: '#fafafb', padding: '8px 16px 8px', borderRadius: 8 }}>
  51. <Form.Item name='brand' style={{ marginBottom: 0 }} rules={[{ required: true, message: '请选择一个品牌形象,与广告创意一起展示' }]}>
  52. <BrandImage />
  53. </Form.Item>
  54. </div>}
  55. </Form.Item>}
  56. <Form.Item style={{ marginBottom: 0 }} label={<strong>跳转类型({pageSpec?.length || 1}/{jumpInfoNumber})</strong>}>
  57. <Form.List name="pageSpec">
  58. {(fields, { add, remove }) => (
  59. <>
  60. {fields.map(({ key, name, ...restField }) => (
  61. <Space key={key} style={{ display: 'flex', marginBottom: 8, width: '100%' }} align="baseline">
  62. <Space direction="vertical" style={{ width: '100%' }}>
  63. <Form.Item
  64. {...restField}
  65. name={[name, 'pageType']}
  66. style={{ marginBottom: 0 }}
  67. rules={[{ required: true, message: '请选择跳转类型!' }]}
  68. >
  69. <New1Radio
  70. data={pageTypeList}
  71. onChange={(pageType) => {
  72. form.setFieldsValue({ pageSpec: pageSpec.map((item: any) => ({ ...item, pageType })) })
  73. if (Object.keys(creativeComponents).includes('text_link')) {
  74. let textLink = creativeComponents['text_link']
  75. let linkNameType = textLink?.children?.link_name_type
  76. let linkNameEnumeration = (linkNameType?.enumProperty?.enumeration as { value: string, description: string }[]).map(item => ({ label: item.description, value: item.value + '_' + item.description }))
  77. form.setFieldsValue({
  78. textLink: {
  79. value: {
  80. linkName: linkName || linkNameEnumeration?.[0]?.value,
  81. jump_info: {
  82. pageType: pageType
  83. }
  84. }
  85. }
  86. })
  87. }
  88. }}
  89. />
  90. </Form.Item>
  91. {((siteSet?.some((name: string) => name === 'SITE_SET_MOMENTS') || automaticSiteEnabled) && pageSpec?.[key]?.pageType === 'PAGE_TYPE_WECHAT_CANVAS') && <div style={{ margin: 0, backgroundColor: '#fafafb', padding: '8px 16px 8px', borderRadius: 8 }}>
  92. <Form.Item
  93. name={[name, 'overrideCanvasHeadOption']}
  94. style={{ marginBottom: 0 }}
  95. >
  96. <Radio.Group>
  97. {deliveryMode === 'DELIVERY_MODE_CUSTOMIZE' && <Radio value="OPTION_KEEP_DIFFERENT">不替换原生推广页顶部素材</Radio>}
  98. <Radio disabled={deliveryMode === 'DELIVERY_MODE_COMPONENT'} value="OPTION_CREATIVE_OVERRIDE_CANVAS">使用外层创意素材替换原生推广页顶部素材</Radio>
  99. </Radio.Group>
  100. </Form.Item>
  101. </div>}
  102. </Space>
  103. {pageSpec?.length > 1 && <MinusCircleOutlined onClick={() => remove(name)} />}
  104. </Space>
  105. ))}
  106. {pageSpec?.length < jumpInfoNumber && <Form.Item>
  107. <Button type="dashed" disabled onClick={() => add({ pageType: pageSpec?.[0]?.pageType || 'PAGE_TYPE_WECHAT_CANVAS', overrideCanvasHeadOption: 'OPTION_CANVAS_OVERRIDE_CREATIVE' })} block icon={<PlusOutlined />}>
  108. 还可以添加 {jumpInfoNumber - pageSpec?.length} 组
  109. </Button>
  110. </Form.Item>}
  111. </>
  112. )}
  113. </Form.List>
  114. </Form.Item>
  115. </>
  116. }, [creativeComponents, pageType, pageSpec, siteSet])
  117. return <Card
  118. title={<strong style={{ fontSize: 18 }}>创意内容</strong>}
  119. className="cardResetCss"
  120. >
  121. {content}
  122. </Card>
  123. }
  124. export default React.memo(CreativeTemplateContent)