index.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import { DevicePriceEnum, EducationEnum, ExcludedDimensionEnum, MaritalStatusEnum, NetworkEnum, OptimizationGoalEnum, UserOsEnum, WechatAdBehaviorEnum } from "@/services/launchAdq/enum"
  2. import React, { useEffect, useState } from "react"
  3. import './index.less'
  4. const targetingData = [
  5. { key: 'geoLocation', name: '地域' },
  6. { key: 'age', name: '年龄' },
  7. { key: 'gender', name: '性别' },
  8. { key: 'education', name: '学历' },
  9. { key: 'maritalStatus', name: '婚恋' },
  10. // { key: 'customAudience', name: '定向人群' },
  11. { key: 'deviceBrandModel', name: '品牌型号' },
  12. { key: 'wechatAdBehavior', name: '微信再营销' },
  13. { key: 'networkType', name: '联网方式' },
  14. { key: 'devicePrice', name: '设备价格' },
  15. { key: 'userOs', name: '手机系统' },
  16. { key: 'excludedConvertedAudience', name: '排除已转化用户' }
  17. ]
  18. interface Props {
  19. data: any,
  20. geoLocationList: any // 所有地域
  21. modelList: any // 所有品牌手机
  22. }
  23. interface ContentProps {
  24. unlimited?: string, // 不限
  25. geoLocation?: any[], // 地域
  26. age?: string, // 年龄
  27. gender?: string, // 性别
  28. education?: string[] // 学历
  29. maritalStatus?: string[], // 婚恋
  30. deviceBrandModel?: {
  31. excludedList?: string[], // 品牌型号
  32. includedList?: string[] // 排除品牌型号
  33. },
  34. wechatAdBehavior?: {
  35. actions?: string[], // 再营销
  36. excludedActions?: string[]// 排除营销
  37. },
  38. networkType?: string[] // 联网方式
  39. devicePrice?: string[] // 手机价格
  40. userOs?: string[] // 手机系统
  41. excludedConvertedAudience?: {
  42. conversionBehaviorList: string[],
  43. excludedDimension: string
  44. }
  45. }
  46. /**
  47. * 定向处理展示
  48. * @returns
  49. */
  50. const TargetingTooltip: React.FC<Props> = (props) => {
  51. /**********************/
  52. const { data, geoLocationList, modelList } = props
  53. const [content, setContent] = useState<ContentProps>({})
  54. /**********************/
  55. useEffect(() => {
  56. if (data && geoLocationList) {
  57. targetingData.forEach(item => {
  58. if (Object.keys(data?.targeting)?.includes(item.key)) {
  59. }
  60. })
  61. let newConten: ContentProps = {}
  62. newConten.unlimited = targetingData.filter((item: any) => !Object.keys(data?.targeting).includes(item.key))?.map((item: any) => item?.name)?.toString()
  63. Object.keys(data?.targeting)?.forEach((item: any) => {
  64. switch (item) {
  65. case 'geoLocation': // 地域
  66. if (data?.targeting[item]?.regions && data?.targeting[item]?.regions?.length > 0) {
  67. newConten.geoLocation = data?.targeting[item]?.regions?.map((item: any) => geoLocationList[item]?.name)
  68. }
  69. break
  70. case 'age':
  71. let newAge = data?.targeting[item][0]
  72. newConten.age = `${newAge.min}至${newAge.max > 65 ? '66岁及以上' : newAge.max + '岁'}`
  73. break
  74. case 'gender':
  75. newConten.gender = data?.targeting[item][0]
  76. break
  77. case 'education':
  78. newConten.education = data?.targeting[item]
  79. break
  80. case 'maritalStatus':
  81. newConten.maritalStatus = data?.targeting[item]
  82. break
  83. case 'deviceBrandModel': // 品牌型号
  84. let newData = data?.targeting[item]
  85. let deviceBrandModel: { excludedList?: string[], includedList?: string[] } = {}
  86. if (newData?.excludedList) {
  87. deviceBrandModel.excludedList = newData?.excludedList?.map((key: any) => modelList[key]?.name)
  88. }
  89. if (newData?.includedList) { // 排除
  90. deviceBrandModel.includedList = newData?.includedList?.map((key: any) => modelList[key]?.name)
  91. }
  92. newConten.deviceBrandModel = deviceBrandModel
  93. break
  94. case 'wechatAdBehavior': // 微信再营销
  95. let wechatAdBehaviorData = data?.targeting[item]
  96. let wechatAdBehavior: {
  97. actions?: string[], // 再营销
  98. excludedActions?: string[]// 排除营销
  99. } = {}
  100. if (wechatAdBehaviorData?.actions) {
  101. wechatAdBehavior.actions = wechatAdBehaviorData?.actions
  102. }
  103. if (wechatAdBehaviorData?.excludedActions) { // 排除
  104. wechatAdBehavior.excludedActions = wechatAdBehaviorData?.excludedActions
  105. }
  106. newConten.wechatAdBehavior = wechatAdBehavior
  107. break
  108. case 'networkType':
  109. newConten.networkType = data?.targeting[item]
  110. break
  111. case 'devicePrice':
  112. newConten.devicePrice = data?.targeting[item]
  113. break
  114. case 'userOs':
  115. newConten.userOs = data?.targeting[item]
  116. break
  117. case 'excludedConvertedAudience':
  118. newConten.excludedConvertedAudience = data?.targeting[item]
  119. break
  120. }
  121. setContent(newConten)
  122. })
  123. }
  124. }, [data, geoLocationList])
  125. return <div className='targetingTooltip'>
  126. {content?.geoLocation && <div>
  127. 地域:<span>{content?.geoLocation?.toString()}</span>
  128. </div>}
  129. {content?.age && <div>
  130. 年龄:<span>{content?.age}</span>
  131. </div>}
  132. {content?.gender && <div>
  133. 性别:<span>{content?.gender === 'MALE' ? '男' : '女'}</span>
  134. </div>}
  135. {(content?.education && content?.education?.length > 0) && <div>
  136. 学历:<span>{content?.education?.map((key: string) => EducationEnum[key]).toString()}</span>
  137. </div>}
  138. {(content?.networkType && content?.networkType?.length > 0) && <div>
  139. 联网方式:<span>{content?.networkType?.map((key: string) => NetworkEnum[key]).toString()}</span>
  140. </div>}
  141. {(content?.devicePrice && content?.devicePrice?.length > 0) && <div>
  142. 手机价格:<span>{content?.devicePrice?.map((key: string) => DevicePriceEnum[key]).toString()}</span>
  143. </div>}
  144. {(content?.userOs && content?.userOs?.length > 0) && <div>
  145. 手机系统:<span>{content?.userOs?.map((key: string) => UserOsEnum[key]).toString()}</span>
  146. </div>}
  147. {(content?.maritalStatus && content?.maritalStatus?.length > 0) && <div>
  148. 婚恋:<span>{content?.maritalStatus?.map((key: string) => MaritalStatusEnum[key]).toString()}</span>
  149. </div>}
  150. {content?.deviceBrandModel && <>
  151. {(content?.deviceBrandModel?.includedList && content?.deviceBrandModel?.includedList?.length > 0) && <div>
  152. 排除品牌型号:<span>{content?.deviceBrandModel?.includedList?.toString()}</span>
  153. </div>}
  154. {(content?.deviceBrandModel?.excludedList && content?.deviceBrandModel?.excludedList?.length > 0) && <div>
  155. 品牌型号:<span>{content?.deviceBrandModel?.excludedList?.toString()}</span>
  156. </div>}
  157. </>}
  158. {content?.wechatAdBehavior && <>
  159. {(content?.wechatAdBehavior?.actions && content?.wechatAdBehavior?.actions?.length > 0) && <div>
  160. 再营销:<span>{content?.wechatAdBehavior?.actions?.map((key: string) => WechatAdBehaviorEnum[key]).toString()}</span>
  161. </div>}
  162. {(content?.wechatAdBehavior?.excludedActions && content?.wechatAdBehavior?.excludedActions?.length > 0) && <div>
  163. 排除营销:<span>{content?.wechatAdBehavior?.excludedActions?.map((key: string) => WechatAdBehaviorEnum[key]).toString()}</span>
  164. </div>}
  165. </>}
  166. {content?.excludedConvertedAudience && <div>
  167. 排除已转化用户:<span>{ExcludedDimensionEnum[content?.excludedConvertedAudience?.excludedDimension]}{`(自定义转化行为:${OptimizationGoalEnum[content?.excludedConvertedAudience?.conversionBehaviorList[0]]})`}</span>
  168. </div>}
  169. {content?.unlimited && <div>
  170. 不限:<span>{!content?.geoLocation && '地域,'}{content?.unlimited}</span>
  171. </div>}
  172. </div>
  173. }
  174. export default React.memo(TargetingTooltip)