index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import React, { useEffect, useState } from "react"
  2. import './index.less'
  3. import { DEVICE_PRICE_ENUM, EDUCATION_ENUM, EXCLUDED_DIMENSION_ENUM, GAME_CONSUMPTION_LEVEL_ENUM, LOCATION_TYPES_ENUM, MARITAL_STATUS_ENUM, NETWORK_ENUM, OPTIMIZATIONGOAL_ENUM, USER_OS_ENUM, WECHAT_AD_NEHAVIOR_ENUM, WECHAT_AD_NEHAVIOR_GAME_ENUM } from "../../tencentAdPutIn/const"
  4. let 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: 'excludedOs', name: '排除操作系统' },
  17. { key: 'excludedConvertedAudience', name: '排除已转化用户' }
  18. ]
  19. interface Props {
  20. data: any,
  21. geoLocationList: any // 所有地域
  22. modelList: any // 所有品牌手机
  23. targetingName?: string
  24. taskType?: 'NOVEL' | 'GAME'
  25. }
  26. interface ContentProps {
  27. unlimited?: string, // 不限
  28. location?: string[], // 地点类型
  29. geoLocation?: any[], // 地域
  30. age?: string, // 年龄
  31. gender?: string, // 性别
  32. education?: string[] // 学历
  33. maritalStatus?: string[], // 婚恋
  34. deviceBrandModel?: {
  35. excludedList?: string[], // 品牌型号
  36. includedList?: string[] // 排除品牌型号
  37. },
  38. wechatAdBehavior?: {
  39. actions?: string[], // 再营销
  40. excludedActions?: string[]// 排除营销
  41. },
  42. networkType?: string[] // 联网方式
  43. devicePrice?: string[] // 手机价格
  44. userOs?: string[] // 手机系统
  45. excludedOs?: string[] // 手机系统
  46. gameConsumptionLevel?: string[] // 游戏消费能力
  47. excludedConvertedAudience?: {
  48. conversionBehaviorList: string[],
  49. excludedDimension: string
  50. }
  51. }
  52. /**
  53. * 定向处理展示
  54. * @returns
  55. */
  56. const TargetingTooltip: React.FC<Props> = (props) => {
  57. /**********************/
  58. const { data, geoLocationList, modelList, targetingName, taskType } = props
  59. const [content, setContent] = useState<ContentProps>({})
  60. /**********************/
  61. if (taskType == 'GAME') {
  62. targetingData = [...targetingData, { key: 'gameConsumptionLevel', name: '游戏消费能力' }]
  63. }
  64. useEffect(() => {
  65. if (data && geoLocationList) {
  66. let newConten: ContentProps = {}
  67. newConten.unlimited = targetingData.filter((item: any) => !Object.keys(data).includes(item.key))?.map((item: any) => item?.name)?.toString()
  68. Object.keys(data)?.forEach((item: any) => {
  69. switch (item) {
  70. case 'geoLocation': // 地域
  71. newConten.location = data[item]?.locationTypes || []
  72. if (data[item]?.regions && data[item]?.regions?.length > 0) {
  73. newConten.geoLocation = data[item]?.regions?.map((item: any) => geoLocationList[item]?.name)
  74. }
  75. break
  76. case 'age':
  77. let newAge = data[item][0]
  78. newConten.age = `${newAge.min}至${newAge.max > 65 ? '66岁及以上' : newAge.max + '岁'}`
  79. break
  80. case 'gender':
  81. newConten.gender = data[item][0]
  82. break
  83. case 'education':
  84. newConten.education = data[item]
  85. break
  86. case 'maritalStatus':
  87. newConten.maritalStatus = data[item]
  88. break
  89. case 'deviceBrandModel': // 品牌型号
  90. let newData = data[item]
  91. let deviceBrandModel: { excludedList?: string[], includedList?: string[] } = {}
  92. if (newData?.excludedList) {
  93. deviceBrandModel.excludedList = newData?.excludedList?.map((key: any) => modelList[key]?.name)
  94. }
  95. if (newData?.includedList) { // 排除
  96. deviceBrandModel.includedList = newData?.includedList?.map((key: any) => modelList[key]?.name)
  97. }
  98. newConten.deviceBrandModel = deviceBrandModel
  99. break
  100. case 'wechatAdBehavior': // 微信再营销
  101. let wechatAdBehaviorData = data[item]
  102. let wechatAdBehavior: {
  103. actions?: string[], // 再营销
  104. excludedActions?: string[]// 排除营销
  105. } = {}
  106. if (wechatAdBehaviorData?.actions) {
  107. wechatAdBehavior.actions = wechatAdBehaviorData?.actions
  108. }
  109. if (wechatAdBehaviorData?.excludedActions) { // 排除
  110. wechatAdBehavior.excludedActions = wechatAdBehaviorData?.excludedActions
  111. }
  112. newConten.wechatAdBehavior = wechatAdBehavior
  113. break
  114. case 'networkType':
  115. newConten.networkType = data[item]
  116. break
  117. case 'devicePrice':
  118. newConten.devicePrice = data[item]
  119. break
  120. case 'gameConsumptionLevel':
  121. newConten.gameConsumptionLevel = data[item]
  122. break
  123. case 'userOs':
  124. newConten.userOs = data[item]
  125. break
  126. case 'excludedOs':
  127. newConten.excludedOs = data[item]
  128. break
  129. case 'excludedConvertedAudience':
  130. newConten.excludedConvertedAudience = data[item]
  131. break
  132. }
  133. })
  134. setContent(newConten)
  135. } else {
  136. setContent({ unlimited: targetingData?.map((item: any) => item?.name)?.toString() })
  137. }
  138. }, [data, geoLocationList])
  139. return <div className='targetingTooltip'>
  140. {targetingName && <div style={{ fontWeight: 'bold', marginBottom: 4 }}>{targetingName}</div>}
  141. {content?.geoLocation && <div>
  142. <strong>地域:</strong><span>{(content?.location && content?.location?.length > 0) && `(${content?.location?.map((key: string) => LOCATION_TYPES_ENUM[key as keyof typeof LOCATION_TYPES_ENUM]).toString()})`}{content?.geoLocation?.toString()}</span>
  143. </div>}
  144. {content?.age && <div>
  145. <strong>年龄:</strong><span>{content?.age}</span>
  146. </div>}
  147. {content?.gender && <div>
  148. <strong> 性别:</strong><span>{content?.gender === 'MALE' ? '男' : '女'}</span>
  149. </div>}
  150. {(content?.education && content?.education?.length > 0) && <div>
  151. <strong>学历:</strong><span>{content?.education?.map((key: string) => EDUCATION_ENUM[key as keyof typeof EDUCATION_ENUM]).toString()}</span>
  152. </div>}
  153. {(content?.networkType && content?.networkType?.length > 0) && <div>
  154. <strong>联网方式:</strong><span>{content?.networkType?.map((key: string) => NETWORK_ENUM[key as keyof typeof NETWORK_ENUM]).toString()}</span>
  155. </div>}
  156. {(content?.devicePrice && content?.devicePrice?.length > 0) && <div>
  157. <strong>手机价格:</strong><span>{content?.devicePrice?.map((key: string) => DEVICE_PRICE_ENUM[key as keyof typeof DEVICE_PRICE_ENUM]).toString()}</span>
  158. </div>}
  159. {(content?.gameConsumptionLevel && content?.gameConsumptionLevel?.length > 0) && <div>
  160. <strong>游戏消费能力:</strong><span>{content?.gameConsumptionLevel?.map((key: string) => GAME_CONSUMPTION_LEVEL_ENUM[key as keyof typeof GAME_CONSUMPTION_LEVEL_ENUM]).toString()}</span>
  161. </div>}
  162. {(content?.userOs && content?.userOs?.length > 0) && <div>
  163. <strong>操作系统:</strong><span>{content?.userOs?.map((key: string) => USER_OS_ENUM[key as keyof typeof USER_OS_ENUM]).toString()}</span>
  164. </div>}
  165. {(content?.excludedOs && content?.excludedOs?.length > 0) && <div>
  166. <strong>排除操作系统:</strong><span>{content?.excludedOs?.map((key: string) => USER_OS_ENUM[key as keyof typeof USER_OS_ENUM]).toString()}</span>
  167. </div>}
  168. {(content?.maritalStatus && content?.maritalStatus?.length > 0) && <div>
  169. <strong>婚恋:</strong><span>{content?.maritalStatus?.map((key: string) => MARITAL_STATUS_ENUM[key as keyof typeof MARITAL_STATUS_ENUM]).toString()}</span>
  170. </div>}
  171. {content?.deviceBrandModel && <>
  172. {(content?.deviceBrandModel?.includedList && content?.deviceBrandModel?.includedList?.length > 0) && <div>
  173. <strong>品牌型号:</strong><span>{content?.deviceBrandModel?.includedList?.toString()}</span>
  174. </div>}
  175. {(content?.deviceBrandModel?.excludedList && content?.deviceBrandModel?.excludedList?.length > 0) && <div>
  176. <strong>排除品牌型号:</strong><span>{content?.deviceBrandModel?.excludedList?.toString()}</span>
  177. </div>}
  178. </>}
  179. {content?.wechatAdBehavior && taskType === 'GAME' ? <>
  180. {(content?.wechatAdBehavior?.actions && content?.wechatAdBehavior?.actions?.length > 0) && <div>
  181. <strong>再营销:</strong><span>{content?.wechatAdBehavior?.actions?.map((key: string) => WECHAT_AD_NEHAVIOR_GAME_ENUM[key as keyof typeof WECHAT_AD_NEHAVIOR_GAME_ENUM]).toString()}</span>
  182. </div>}
  183. {(content?.wechatAdBehavior?.excludedActions && content?.wechatAdBehavior?.excludedActions?.length > 0) && <div>
  184. <strong>排除营销:</strong><span>{content?.wechatAdBehavior?.excludedActions?.map((key: string) => WECHAT_AD_NEHAVIOR_GAME_ENUM[key as keyof typeof WECHAT_AD_NEHAVIOR_GAME_ENUM]).toString()}</span>
  185. </div>}
  186. </> : <>
  187. {(content?.wechatAdBehavior?.actions && content?.wechatAdBehavior?.actions?.length > 0) && <div>
  188. <strong>再营销:</strong><span>{content?.wechatAdBehavior?.actions?.map((key: string) => WECHAT_AD_NEHAVIOR_ENUM[key as keyof typeof WECHAT_AD_NEHAVIOR_ENUM]).toString()}</span>
  189. </div>}
  190. {(content?.wechatAdBehavior?.excludedActions && content?.wechatAdBehavior?.excludedActions?.length > 0) && <div>
  191. <strong>排除营销:</strong><span>{content?.wechatAdBehavior?.excludedActions?.map((key: string) => WECHAT_AD_NEHAVIOR_ENUM[key as keyof typeof WECHAT_AD_NEHAVIOR_ENUM]).toString()}</span>
  192. </div>}
  193. </>}
  194. {content?.excludedConvertedAudience && <div>
  195. <strong>排除已转化用户:</strong><span>{EXCLUDED_DIMENSION_ENUM[content?.excludedConvertedAudience?.excludedDimension as keyof typeof EXCLUDED_DIMENSION_ENUM]}{`(自定义转化行为:${content?.excludedConvertedAudience?.conversionBehaviorList?.map(item => OPTIMIZATIONGOAL_ENUM[item as keyof typeof OPTIMIZATIONGOAL_ENUM])?.toString()})`}</span>
  196. </div>}
  197. {content?.unlimited && <div>
  198. <strong>不限:</strong><span>{!content?.geoLocation && '地域,'}{content?.unlimited}</span>
  199. </div>}
  200. </div>
  201. }
  202. export default React.memo(TargetingTooltip)