centerTop.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import React, { useContext } from "react"
  2. import { DispatchMiniPageCreate } from "./drawerMini";
  3. import { useDrop } from "ahooks";
  4. import './global.less'
  5. import { topImageContent, topShortVideoContent, topVideoContent } from "./const";
  6. import { DeleteOutlined } from '@ant-design/icons';
  7. import { Swiper, SwiperSlide } from 'swiper/react'
  8. import 'swiper/css'
  9. import { ReactComponent as TopNullBack } from '../../../../public/svg/topNullBack.svg'
  10. import { ReactComponent as TopImgSvg } from '../../../../public/svg/topimg.svg'
  11. import { ReactComponent as EditSvg } from '../../../../public/svg/edit.svg'
  12. import { ReactComponent as TopVideoSvg } from '../../../../public/svg/topvideo.svg'
  13. import VideoNews from "../../components/newsModal/videoNews";
  14. import { Button } from "antd";
  15. import UploadLoad from "../../components/materialMould/uploadLoad";
  16. const CenterTop: React.FC = () => {
  17. /**************************************/
  18. const { dragging, pageSpecs, setDragging, setPageSpecs, installActive, setTopUrl, setTopShortVideoUrl } = useContext(DispatchMiniPageCreate)!;
  19. const { pageElementsSpecList, globalElementsSpecList, pageType } = pageSpecs
  20. const topSpec = pageElementsSpecList?.[0]
  21. /**************************************/
  22. // 头部内容拖到接收区
  23. const [dropProps] = useDrop({
  24. onDom: (key: string) => { // 头部
  25. const newPageElementsSpecList = pageElementsSpecList?.map(item => ({ ...item, comptActive: false }))
  26. const newGlobalElementsSpecList = globalElementsSpecList?.map(item => ({ ...item, comptActive: false }))
  27. if (key === 'TOP_IMAGE') {
  28. newPageElementsSpecList[0] = { ...topImageContent, comptActive: true }
  29. } else if (key === 'TOP_VIDEO') {
  30. newPageElementsSpecList[0] = { ...topVideoContent, comptActive: true }
  31. } else if (key === 'TOP_SHORT_VIDEO') {
  32. newPageElementsSpecList[0] = { ...topShortVideoContent, comptActive: true }
  33. } else {
  34. return
  35. }
  36. setPageSpecs({ ...pageSpecs, pageElementsSpecList: newPageElementsSpecList, globalElementsSpecList: newGlobalElementsSpecList })
  37. }
  38. });
  39. const delTopSpec = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
  40. e.stopPropagation();
  41. setDragging(null);
  42. const newPageSpecs = JSON.parse(JSON.stringify(pageSpecs))
  43. newPageSpecs.pageElementsSpecList[0] = { elementType: 'empty' }
  44. setPageSpecs(newPageSpecs)
  45. }
  46. if (topSpec?.elementType) {
  47. switch (topSpec.elementType) {
  48. case "TOP_IMAGE":
  49. return <div className={`compt componentType41 ${topSpec?.comptActive && 'comptActive'}`} onClick={(e) => { installActive(e, 0) }}>
  50. <div className={'componentWrap'}>
  51. <div className={'componentContent'}>
  52. {topSpec?.url ? <img src={topSpec?.url} style={{ display: 'block', width: '100%', margin: 0 }} /> : <div className={'default'} style={{ width: 375, height: 300, margin: 0 }}>
  53. <div className={'defaultIcon'} style={{ marginTop: 80 }}>
  54. <TopImgSvg />
  55. </div>
  56. </div>}
  57. </div>
  58. </div>
  59. {!topSpec?.url && <div className={'comptUpload'} style={{ margin: 0 }}><UploadLoad
  60. type='image'
  61. uploadButton={<button style={{ marginTop: 150 }} className={'comptEditButton'} onClick={() => { }}>上传图片</button>}
  62. onChange={(value) => {
  63. setTopUrl(value)
  64. }}
  65. /></div>}
  66. <section className={'comptEditBtns'}>
  67. <div className={'comptEditBtnsInner'}>
  68. {topSpec?.url && <UploadLoad
  69. type='image'
  70. uploadButton={<Button icon={<EditSvg />}></Button>}
  71. onChange={(value) => {
  72. setTopUrl(value)
  73. }}
  74. />}
  75. <Button onClick={delTopSpec} icon={<DeleteOutlined />} style={{ fontSize: 14 }} />
  76. </div>
  77. </section>
  78. </div>
  79. case "TOP_VIDEO":
  80. return <div className={`compt componentType61 ${topSpec?.comptActive && 'comptActive'}`} onClick={(e) => { installActive(e, 0) }}>
  81. <div className={'componentWrap'}>
  82. <div className={'componentContent'} style={{ lineHeight: 'normal' }}>
  83. {topSpec?.url ? <div className="videoPlay">
  84. <VideoNews src={topSpec.url} style={{ display: 'block', width: '100%', margin: 0, height: '100%' }} maskImgStyle={{ position: 'absolute', top: '50%', left: '50%', width: 40, height: 40, transform: 'translate(-50%, -50%)', zIndex: 10 }} />
  85. </div> : <div className={'default'} style={{ width: 375, height: 300, margin: 0 }}>
  86. <div className={'defaultIcon'} style={{ marginTop: 80 }}>
  87. <TopVideoSvg />
  88. </div>
  89. </div>}
  90. </div>
  91. </div>
  92. {!topSpec?.url && <div className={'comptUpload'} style={{ margin: 0 }}><UploadLoad
  93. type='video'
  94. uploadButton={<button style={{ marginTop: 150 }} className={'comptEditButton'} onClick={() => { }}>上传视频</button>}
  95. onChange={(value) => {
  96. setTopUrl(value)
  97. }}
  98. /></div>}
  99. <section className={'comptEditBtns'}>
  100. <div className={'comptEditBtnsInner'}>
  101. {topSpec?.url && <UploadLoad
  102. type='video'
  103. uploadButton={<Button icon={<EditSvg />}></Button>}
  104. onChange={(value) => {
  105. setTopUrl(value)
  106. }}
  107. />}
  108. <Button onClick={delTopSpec} icon={<DeleteOutlined />} style={{ fontSize: 14 }} />
  109. </div>
  110. </section>
  111. </div>
  112. case "TOP_SHORT_VIDEO":
  113. return <div className={`compt componentType62 ${topSpec?.comptActive && 'comptActive'}`} onClick={(e) => { installActive(e, 0) }}>
  114. <Swiper
  115. direction="vertical"
  116. slidesPerView={1}
  117. spaceBetween={0}
  118. style={{ height: '750px' }}
  119. >
  120. {topSpec?.data?.map((item, index) => <SwiperSlide key={index}>
  121. <div className={'componentWrap'}>
  122. <div className={'componentContent'} style={{ lineHeight: 'normal' }}>
  123. {item?.url ? <div className="videoPlay">
  124. <VideoNews src={item.url} style={{ display: 'block', width: '100%', margin: 0, height: 750 }} maskImgStyle={{ position: 'absolute', top: '50%', left: '50%', width: 40, height: 40, transform: 'translate(-50%, -50%)', zIndex: 10 }} />
  125. </div> : <div className={'default'} style={{ width: 375, height: 750, margin: 0 }}>
  126. <div className={'defaultIcon'} style={{ marginTop: 280 }}>
  127. <TopVideoSvg />
  128. </div>
  129. </div>}
  130. </div>
  131. </div>
  132. {!item?.url && <div className={'comptUpload'} style={{ margin: 0 }}><UploadLoad
  133. type='video'
  134. uploadButton={<button style={{ marginTop: 360 }} className={'comptEditButton'}>上传视频</button>}
  135. onChange={(value, videoInfo) => {
  136. setTopShortVideoUrl(value, videoInfo, index)
  137. }}
  138. /></div>}
  139. </SwiperSlide>)}
  140. </Swiper>
  141. </div>
  142. default:
  143. return pageType === 'LANDING_PAGE' ? <div className={`compt topComptArea ${dragging ? 'dragging' : ''}`} {...dropProps}>
  144. <TopNullBack />
  145. {dragging ? <div className="topAreaTitle" style={{ marginTop: 30 }}>
  146. 拖至此处
  147. </div> : <>
  148. <p className={'topAreaTitle'}>顶部组件区</p>
  149. <div className={'desc'}>在左上方,选择顶部组件添加到此处</div>
  150. </>}
  151. </div> : <div style={{ minHeight: 648 }} className={`compt topComptArea topShortVideo ${dragging ? 'dragging' : ''}`} {...dropProps}>
  152. <TopNullBack />
  153. {dragging ? <div className="topAreaTitle" style={{ marginTop: 30 }}>
  154. 拖至此处
  155. </div> : <>
  156. <p className={'topAreaTitle'}>短视频组件区</p>
  157. <div className={'desc'}>在左上方,选择顶部组件添加到此处</div>
  158. </>}
  159. </div>
  160. }
  161. }
  162. return <span>页面BUG,刷新页面后尝试</span>
  163. }
  164. export default React.memo(CenterTop)