index.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. import { Carousel, Drawer, Spin } from "antd";
  2. import React, { useEffect, useMemo, useState } from "react"
  3. import { ReactComponent as Topimg } from '@/assets/topimg.svg'
  4. import { ReactComponent as Img } from '@/assets/img.svg'
  5. import style from './index.less'
  6. import '../addLandingPage/index1.less'
  7. import { UserAddOutlined } from "@ant-design/icons";
  8. import { useModel } from "umi";
  9. import { getTypeKey } from "@/utils/utils";
  10. type Props = {
  11. visible?: boolean,
  12. onClose?: () => void,
  13. id: number
  14. }
  15. /**
  16. * 查看落地页
  17. * @param props
  18. * @returns
  19. */
  20. function LookLanding(props: Props) {
  21. let { visible, onClose, id } = props
  22. const [pageBackColor, setPageBackColor] = useState<string>('#FFFFFF') // 背景颜色
  23. const [content, setContent] = useState<any[]>([]) // 内容
  24. const [globalData, setGlobalData] = useState<any>([]) // 浮窗
  25. const { get } = useModel('useLaunchAdq.useBdMediaPup')
  26. useEffect(() => {
  27. if (id) {
  28. get.run({ sysMediaId: id, mediaType: 'PAGE' }).then(res => {
  29. if (res) {
  30. const { pageSpecsList, globalSpec } = res
  31. setPageBackColor(pageSpecsList[0]?.bgColor)
  32. let pageElementsSpecList = pageSpecsList[0]?.pageElementsSpecList
  33. setContent(pageElementsSpecList?.map((item: any) => {
  34. let typeKey = getTypeKey(item?.elementType)
  35. if (typeKey) {
  36. let data = item[typeKey] || {}
  37. return {
  38. elementType: item?.elementType,
  39. ...data
  40. }
  41. }
  42. return item
  43. }))
  44. if (globalSpec && Object.keys(globalSpec).length > 0) {
  45. let globalElementsSpecList = globalSpec.globalElementsSpecList
  46. let newComponentItem = globalElementsSpecList?.map((item: { elementType: string }) => {
  47. let typeKey = getTypeKey(item.elementType)
  48. let { elementType, ...data } = item[typeKey]
  49. let typeKey1 = getTypeKey(elementType)
  50. let componentItem: any = data[typeKey1]
  51. if (componentItem) {
  52. componentItem['elementType'] = elementType
  53. }
  54. data.componentItem = componentItem
  55. data.elementType = item.elementType
  56. delete data[typeKey1]
  57. return data
  58. })
  59. setGlobalData(newComponentItem)
  60. }
  61. }
  62. })
  63. }
  64. }, [id])
  65. console.log('content---->', content)
  66. // 顶部组件
  67. const topCon = useMemo(() => {
  68. if (content?.length > 0) {
  69. let { imageUrl, elementType, imageUrlList, videoUrl } = content[0]
  70. return <>
  71. {
  72. elementType === 'TOP_IMAGE' ? <>
  73. <div className={`compt componentType41 ${content[0]?.comptActive && 'comptActive'}`}>
  74. <div className={'componentWrap'}>
  75. <div className={'componentContent'}>
  76. {
  77. imageUrl ? <img src={imageUrl} style={{ display: 'block', width: '100%', margin: 0 }} /> : <div className={'default'} style={{ width: 375, height: 300, margin: 0 }}>
  78. <div className={'defaultIcon'} style={{ marginTop: 80 }}>
  79. <Topimg />
  80. </div>
  81. </div>
  82. }
  83. </div>
  84. </div>
  85. </div>
  86. </> :
  87. elementType === 'TOP_SLIDER' ? <>
  88. <div className={`compt componentType101 ${content[0]?.comptActive && 'comptActive'}`}>
  89. <div className={'componentWrap'}>
  90. <div className={'componentContent'}>
  91. <Carousel autoplay style={{ width: 375, height: 375 }}>
  92. {imageUrlList?.map((item: any, index: number) => {
  93. return <div style={{ width: 375, height: 375 }} key={index}><img style={{ width: 375, height: 375 }} src={item} /></div>
  94. })}
  95. </Carousel>
  96. </div>
  97. </div>
  98. </div>
  99. </> :
  100. elementType === 'TOP_VIDEO' ? <>
  101. <div className={`compt componentType61 ${content[0]?.comptActive && 'comptActive'}`}>
  102. <div className={'componentWrap'}>
  103. <div className={'componentContent'}>
  104. {
  105. videoUrl && <div className="videoPlay">
  106. <video src={videoUrl} style={{ display: 'block', width: '100%', margin: 0 }} />
  107. <span></span>
  108. </div>
  109. }
  110. </div>
  111. </div>
  112. </div>
  113. </> : null
  114. }
  115. </>
  116. } else {
  117. return null
  118. }
  119. }, [content])
  120. const comptCon = () => {
  121. if (content?.length === 0) {
  122. return null
  123. } else {
  124. return <div className="page-0" style={globalData?.some((item: any) => item?.elementType === 'FLOAT_BUTTON') ? { paddingBottom: 90, minHeight: 510 } : {}}>
  125. {content.map((value: any, index: number) => {
  126. if (value.elementType === 'IMAGE') {
  127. let { imageUrl, paddingTop, paddingBottom } = value
  128. return <div className={`compt componentType41`} key={index}>
  129. <div className={'componentWrap'}>
  130. <div className={'componentContent'}>
  131. {
  132. imageUrl ? <img src={imageUrl} style={{ display: 'block', width: '100%', margin: 0, marginTop: paddingTop / 2 + 'px', marginBottom: paddingBottom / 2 + 'px' }} /> : <div className={'default'} style={{ width: 375, height: 222, margin: 0, marginTop: paddingTop / 2 + 'px', marginBottom: paddingBottom / 2 + 'px' }}>
  133. <div className={'defaultIcon'} style={{ marginTop: 44 }}>
  134. <Img />
  135. </div>
  136. </div>
  137. }
  138. </div>
  139. </div>
  140. </div>
  141. } else if (value.elementType === 'TEXT') {
  142. let { fontSize, fontColor, textAlignment, text, fontStyle, paddingTop, paddingBottom } = value
  143. return <div className={`compt componentType1`} key={index}>
  144. <div className={'componentWrap'}>
  145. <div className={'componentContent'} style={{ backgroundColor: pageBackColor }}>
  146. <div className={'text'} style={{ lineHeight: fontSize * 1.5 + 'px', fontSize: Number(fontSize), color: fontColor, textAlign: textAlignment === 0 ? 'left' : textAlignment === 1 ? 'center' : 'right', fontWeight: fontStyle === 0 ? 'normal' : 'bold', maxWidth: '100%', display: 'block', marginLeft: 24, marginRight: 24, marginTop: paddingTop / 2 + 'px', marginBottom: paddingBottom / 2 + 'px' }}>
  147. <div>{text ?
  148. text?.split(/[\r\n]/g)?.map((item: any, index: number) => {
  149. if (item) {
  150. return <div key={`item${index}`}>
  151. {item?.split(' ')?.map((item1: any, ind: number) => {
  152. if (item1) {
  153. return <span key={`item1${ind}`}>{item1}</span>
  154. } else {
  155. return <span key={`item1${ind}`}>&nbsp;</span>
  156. }
  157. })}
  158. </div>
  159. } else {
  160. return <div key={`item${index}`}>&nbsp;</div>
  161. }
  162. })
  163. : '请输入文本内容'}</div>
  164. </div>
  165. <div className={'textAreaDiv'} style={{ lineHeight: fontSize * 1.5 + 'px', fontSize: Number(fontSize), margin: '11px 24px', marginLeft: 24, marginRight: 24, marginTop: paddingTop / 2 + 'px', marginBottom: paddingBottom / 2 + 'px' }}>
  166. <textarea readOnly value={text} className={'textarea'} style={{ color: fontColor, fontWeight: fontStyle === 0 ? 'normal' : 'bold', textAlign: textAlignment === 0 ? 'left' : textAlignment === 1 ? 'center' : 'right', backgroundColor: pageBackColor }}></textarea>
  167. </div>
  168. </div>
  169. </div>
  170. </div>
  171. } else if (value.elementType === 'GH' || value.elementType === 'ENTERPRISE_WX') {
  172. let { paddingTop, paddingBottom, btnTitle, fontColor, btnBgColorTheme, btnBorderColorTheme, btnFontType, useIcon } = value
  173. return <div className={`compt componentType21`} key={index}>
  174. <div className={'componentWrap'}>
  175. <div className={'componentContent'}>
  176. <div style={{ marginTop: paddingTop / 2 + 'px', marginBottom: paddingBottom / 2 + 'px' }}>
  177. <div style={{ textAlign: 'center', lineHeight: 0, maxWidth: '100%', margin: '0 92.5px' }}>
  178. <a style={{
  179. textDecoration: 'none', color: fontColor || 'rgb(255,255,255)', backgroundColor: btnBgColorTheme || 'rgb(7, 193, 96)',
  180. border: ['#FFFFFF', '#ffffff', 'rgb(255, 255, 255)'].indexOf(btnBorderColorTheme) !== -1 ? '0px solid rgb(255, 255, 255)' : `2px solid ${btnBorderColorTheme}`, borderRadius: 4, display: 'flex', alignItems: 'center',
  181. overflow: 'hidden', justifyContent: 'center', whiteSpace: 'pre', fontWeight: btnFontType === 0 ? 'normal' : 'bold',
  182. height: 40, lineHeight: 40, width: '100%', fontSize: 15
  183. }}>{useIcon === '1' && <UserAddOutlined style={{ marginRight: 6 }} />}{btnTitle || ''}</a>
  184. </div>
  185. </div>
  186. </div>
  187. </div>
  188. </div>
  189. } else if (value?.elementType === 'shelfnew') {
  190. let { paddingTop, paddingBottom, layoutItems, borderColor, bgColor, type, wxad_align, id } = value
  191. if (type === '104') {
  192. let componentItem = layoutItems?.componentItem[0]?.layoutItems?.componentItem
  193. let otherData = componentItem[1]?.layoutItems?.componentItem
  194. return <div className={`compt componentType104`} key={id}>
  195. <div className={'componentWrap'}>
  196. <div className={'componentContent'}>
  197. <div className={'shelf listType'} style={{ marginTop: paddingTop / 2 + 'px', marginBottom: paddingBottom / 2 + 'px', marginLeft: 20, marginRight: 20 }}>
  198. <div className={'shelfItem'} style={{ border: `1px solid ${borderColor || "#e5e5e5"}`, backgroundColor: bgColor || "#ffffff" }}>
  199. <div className={'shelfItemImg'} style={{ marginLeft: 11.5, marginTop: 11.5 }}>
  200. {componentItem[0]?.pureImageUrl ? <img src={componentItem[0]?.pureImageUrl} style={{ display: 'flex', width: '100%', height: '100%' }} /> : <div className={'default'} style={{ width: '100%', height: '100%' }}>
  201. <div className={'defaultIcon'} style={{ marginTop: 27, width: 36, height: 36 }}>
  202. <Img />
  203. </div>
  204. </div>}
  205. </div>
  206. <div className={'shelfItemContent'} style={{ margin: '12px 20px 0 12px' }}>
  207. <p className={'title'} style={{ color: otherData[0]?.fontColor || "#353535", fontSize: 16 }}>{otherData[0]?.content || otherData[0]?.name}</p>
  208. <p className={'desc'} style={{ color: otherData[1]?.fontColor || "#B2B2B2" }}>{otherData[1]?.content || otherData[1]?.name}</p>
  209. <div
  210. className={'btn'}
  211. style={{
  212. color: otherData[2]?.fontColor || 'rgb(255, 255, 255)',
  213. textDecoration: 'none',
  214. fontWeight: otherData[2]?.btnFontType === '0' ? 'normal' : 'bold',
  215. backgroundColor: otherData[2]?.btnBgColorTheme || "#07C160",
  216. border: ['#FFFFFF', '#ffffff', 'rgb(255, 255, 255)'].indexOf(otherData[2]?.btnBorderColorTheme) !== -1 ? '0px solid rgb(255, 255, 255)' : `2px solid ${otherData[2]?.btnBorderColorTheme}`,
  217. borderRadius: 4
  218. }}
  219. >{otherData[2]?.btnTitle}</div>
  220. </div>
  221. </div>
  222. </div>
  223. </div>
  224. </div>
  225. </div>
  226. } else if (type === '103') {
  227. let componentItem = layoutItems?.componentItem
  228. return <div className={`compt componentType103`} key={id}>
  229. <div className={'componentWrap'}>
  230. <div className={'componentContent'}>
  231. <div className='shelf gridType' style={{ marginTop: paddingTop / 2 + 'px', marginBottom: paddingBottom / 2 + 'px', marginLeft: 20 }}>
  232. {
  233. componentItem?.map((item: any, index: number) => {
  234. let shelfnewItem = item?.layoutItems?.componentItem[0]?.layoutItems?.componentItem
  235. return <div className='shelfItem-3q' key={index} style={{ borderWidth: 1, borderStyle: 'solid', borderColor: item?.borderColor, backgroundColor: item?.bgColor || 'rgb(255,255,255)', marginLeft: index === 1 ? 11 : 0 }}>
  236. <div className='shelfItemImg' style={{ marginLeft: 5.5, marginTop: 5.5 }}>
  237. {shelfnewItem[0]?.pureImageUrl ? <img src={shelfnewItem[0]?.pureImageUrl} style={{ display: 'flex', width: '100%', height: '100%' }} /> : <div className="default" style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
  238. <div className={'defaultIcon'} style={{ width: 36, height: 36 }}>
  239. <Img />
  240. </div>
  241. </div>}
  242. </div>
  243. <div className='shelfItemContent' style={{ marginLeft: 12, textAlign: wxad_align === 0 ? 'left' : 'center' }}>
  244. <p className='title' style={{ color: shelfnewItem[1]?.fontColor || 'rgb(53, 53, 53)', fontSize: 16, marginBottom: 4 }}>{shelfnewItem[1]?.content || shelfnewItem[1]?.name}</p>
  245. <p className='desc' style={{ color: shelfnewItem[2]?.fontColor || 'rgb(178, 178, 178)', marginBottom: 14 }}>{shelfnewItem[2]?.content || shelfnewItem[2]?.name}</p>
  246. <p className='btn' style={{
  247. textDecoration: 'none',
  248. fontWeight: shelfnewItem[3]?.btnFontType === '0' ? 400 : 'bold',
  249. color: shelfnewItem[3]?.fontColor || 'rgb(255, 255, 255)',
  250. backgroundColor: shelfnewItem[3]?.btnBgColorTheme || 'rgb(7,193,96)',
  251. borderWidth: shelfnewItem[3]?.borderSize ? Number(shelfnewItem[3]?.borderSize) : 0,
  252. borderStyle: 'solid',
  253. borderColor: shelfnewItem[3]?.btnBorderColorTheme,
  254. borderRadius: 4
  255. }}>{shelfnewItem[3]?.btnTitle}</p>
  256. </div>
  257. </div>
  258. })
  259. }
  260. </div>
  261. </div>
  262. </div>
  263. </div>
  264. } else {
  265. return null
  266. }
  267. } else {
  268. return null
  269. }
  270. })}
  271. {globalData.map((value: any, index: number) => {
  272. if (value?.elementType === 'FLOAT_BUTTON') {
  273. let { titleColor, descColor, componentItem, imageUrl, title, desc, styleType } = value
  274. return <div className={`compt componentType134 comptFixedBottom`} key={'floatbutton' + index}>
  275. <div className={'componentWrap'}>
  276. <div className="componentContent">
  277. <div className="floatButtonWrapper">
  278. <div className="floatButton">
  279. {styleType === 0 && (imageUrl ? <img src={imageUrl} className="floatButtonAvatar" /> : <div className="floatButtonAvatarPlaceholder"></div>)}
  280. <div className="floatButtonTexts">
  281. <div className="floatButtonTitle" style={{ color: titleColor || 'rgb(23, 23, 23)' }}>{title || '标题'}</div>
  282. {(styleType === 1 || styleType === 0) && <div className="floatButtonDesc" style={{ color: descColor || 'rgb(76, 76, 76)' }}>{desc || '描述'}</div>}
  283. </div>
  284. <div className="floatButtonLink" style={{
  285. color: componentItem?.fontColor || 'rgb(255,255,255)',
  286. fontWeight: componentItem?.btnFontType === '0' ? 'normal' : 'bold',
  287. backgroundColor: componentItem?.btnBgColorTheme || 'rgb(7, 193, 96)',
  288. width: ((componentItem?.layoutWidth || 160) / 2) + 'px',
  289. textAlign: 'center',
  290. overflow: 'hidden',
  291. whiteSpace: 'pre'
  292. }}>{componentItem?.btnTitle}</div>
  293. </div>
  294. </div>
  295. </div>
  296. </div>
  297. </div>
  298. }
  299. return null
  300. })}
  301. </div>
  302. }
  303. }
  304. return <Drawer
  305. title="查看"
  306. placement="right"
  307. closable={false}
  308. onClose={() => { onClose && onClose() }}
  309. visible={visible}
  310. width={420}
  311. >
  312. <Spin spinning={get.loading}>
  313. <div className={style.page} style={{ backgroundColor: pageBackColor || '#FFFFFF' }}>
  314. {/* 头部 */}
  315. {topCon}
  316. {/* 内容*/}
  317. <div className={`comptPlaceholder lastChild`} id="comptCon">
  318. {comptCon()}
  319. </div>
  320. </div>
  321. </Spin>
  322. </Drawer>
  323. }
  324. export default React.memo(LookLanding)