import { Button, Col, Drawer, Form, Input, InputNumber, message, Modal, Radio, Row, Select, Slider, Space, Spin, Switch, Tooltip } from 'antd' import React, { useCallback, useEffect, useMemo, useState } from "react" import modal from "antd/lib/modal" import style from './index.less' import './index1.less' import { ReactComponent as Topimg } from '@/assets/topimg.svg' import { ReactComponent as Topslider } from '@/assets/topslider.svg' import { ReactComponent as Topvideo } from '@/assets/topvideo.svg' import { ReactComponent as Img } from '@/assets/img.svg' import { ReactComponent as MyText } from '@/assets/text.svg' import { ReactComponent as TopNullBack } from '@/assets/topNullBack.svg' import { ReactComponent as FollowAcc } from '@/assets/followAcc.svg' import { ReactComponent as EditSvg } from '@/assets/edit.svg' import { ReactComponent as SliderImgSvg } from '@/assets/sliderImgSvg.svg' import { ReactComponent as JumpLink } from '@/assets/jumpLink.svg' import { ReactComponent as ImgText } from '@/assets/imgText.svg' import { ReactComponent as FloatbuttonSvg } from '@/assets/floatbuttonSvg.svg' import { ReactComponent as WxAutoSvg } from '@/assets/wxAutoSvg.svg' import { AlignCenterOutlined, AlignLeftOutlined, AlignRightOutlined, DeleteOutlined, PlusOutlined, QuestionCircleOutlined, RetweetOutlined, SwapLeftOutlined, SwapRightOutlined } from '@ant-design/icons' import { useDrop, useDrag } from 'ahooks' import arrayMove from "array-move"; import ColorPicker from '@/components/ColorPicker1' import TextArea from 'antd/lib/input/TextArea' import moment from 'moment' import { TopImg, TopVideo, Text, Img as ImgProps, GhButton, TopSlider, Floatbutton, ImageTextItem, ITItemGhSpec } from '../../req' import { imgContent, txtContent, ghContent, topvideoNewContent, topsliderContent, topimgContent, wxAutoContent, floatbuttonContent, floatbuttonBtTypeWxAuto, floatbuttonBtTypeGh, imageTextGh, ghITItemContent, wxAutoITItemContent, imageTextItem } from './content' import { landingPageReducer, Content, Props } from './landingPageReducer' import { SortableList, SortableItemText, SortableItemImg, SortableItemFollowAcc, SortableItemImgText, SortableUlList, SortableItemNoLi, SortableItemLi, SortableItemJumpLink, SortableItemWxAuto, SortableItemFloatbutton } from './sortable' import { useModel } from 'umi' import SelectCloud from '../selectCloud' import { getTypeKey, replaceSpecialTxt, txtLength } from '@/utils/utils' const { Option } = Select; function AddLandingPage(props: Props) { let { visible, hideModal, ajax, id } = props const { state, stateGlobal, dispatch, dispatchGlobal } = landingPageReducer() const { content, pageBackColor } = state const { componentItem } = stateGlobal const { currentUser }: any = useModel('@@initialState', model => ({ currentUser: model.initialState?.currentUser })) const { init, add, get } = useModel('useLaunchAdq.useBdMediaPup') const { state: { parentId, belongUser } } = useModel('useLaunchAdq.useBdMedia') /** 变量开始 */ const [selectImgVisible, setSelectImgVisible] = useState(false) // 选择图片弹窗 const [lastVisible, setLastVisible] = useState(false) // 最后保存设置 const [shareTittle, setShareTittle] = useState('') // 分享标题 const [shareDesc, setShareDesc] = useState('') // 分享描述 const [pageName, setPageName] = useState('') // 落地页名称 const [sort, setSort] = useState(0) // 排序 const [scType, setCcType] = useState<1 | 2 | 3 | 4 | 5>(1) // 视频 单图片 多图片处理 const [sliderImgContent, setSliderImgContent] = useState<{ url: string, width?: number, height?: number }[]>([]) // 保存回填数据 const [imgTextButtonShow, setImgTextButtonShow] = useState(false) const [goodsCount, setGoodsCount] = useState(0) /** 变量结束 */ console.log('content---->', content) // 回填 useEffect(() => { if (id) { get.run({ sysMediaId: id, mediaType: 'PAGE' }).then(res => { if (res) { const { pageSpecsList, shareContentSpec, globalSpec } = res dispatch({ type: 'setPageBackColor', params: { pageBackColor: pageSpecsList[0]?.bgColor } }) let pageElementsSpecList = pageSpecsList[0]?.pageElementsSpecList dispatch({ type: 'setCon', params: { content: pageElementsSpecList?.map((item: any) => { let typeKey = getTypeKey(item?.elementType) if (typeKey) { let data = item[typeKey] || {} if (item?.elementType === "IMAGE_TEXT" && data?.imageTextItem) { data.imageTextItem = data.imageTextItem?.map((item: any) => { if (item?.subElemType === 'GH') { let { ghSpec, ...GHData } = item return { ...GHData, content: { ...ghSpec } } } else { let { enterpriseWxSpec, ...EnterpriseWxData } = item return { ...EnterpriseWxData, content: { ...enterpriseWxSpec } } } }) } return { elementType: item?.elementType, ...data } } return item }) } }) setShareDesc(() => shareContentSpec?.shareTitle || '') setShareTittle(() => shareContentSpec?.shareDescription || '') if (globalSpec && Object.keys(globalSpec).length > 0) { let globalElementsSpecList = globalSpec.globalElementsSpecList let newComponentItem = globalElementsSpecList?.map((item: { elementType: string }) => { let typeKey = getTypeKey(item.elementType) let { elementType, ...data } = item[typeKey] let typeKey1 = getTypeKey(elementType) let componentItem: any = data[typeKey1] if (componentItem) { componentItem['elementType'] = elementType } data.componentItem = componentItem data.elementType = item.elementType delete data[typeKey1] return data }) dispatchGlobal({ type: "setConItem", params: { componentItem: newComponentItem || [] } }) } } }) } else { // dispatch({ type: 'init', params: { elementType: 'empty' } }) } }, [id]) const config = { title: '警告!', cancelText: '取消', okText: '确定', onOk: () => { hideModal() }, content: ( <>
不会保存您所做的更改,确定关闭?
), }; /** 获取选中内容对应图片视频尺寸大小 */ useEffect(() => { let selectData = content?.find((item: Content) => item.comptActive) if (!selectData) { selectData = componentItem?.find((item: { comptActive: boolean }) => item.comptActive) } if (selectData?.elementType === "TOP_IMAGE") { if (selectData?.adLocation === 'sns') { // 朋友圈信息流 if (selectData?.outerStyle === 0) { // 常规广告 init({ mediaType: 'IMG', cloudSize: [[{ relation: '=', width: 800, height: 800 }]], maxSize: 300 * 1024 }) } else { // 卡片广告 init({ mediaType: 'IMG', cloudSize: [[{ relation: '=', width: 800, height: 450 }]], maxSize: 300 * 1024 }) } } else { // 公众号及其他 init({ mediaType: 'IMG', cloudSize: [[{ relation: '=', width: 800, height: 800 }], [{ relation: '=', width: 800, height: 450 }], [{ relation: '=', width: 800, height: 640 }], [{ relation: '=', width: 640, height: 800 }]], maxSize: 300 * 1024 }) } } else if (selectData?.elementType === 'IMAGE') { // 内容图片 init({ mediaType: 'IMG', cloudSize: [[{ relation: '=', width: 750, height: null }, { relation: '<=', width: null, height: 1536 }]], maxSize: 300 * 1024 }) } else if (selectData?.elementType === 'TOP_SLIDER') { // 轮播图 init({ mediaType: 'IMG', num: selectData?.imageUrlList?.length || 3, cloudSize: [[{ relation: '=', width: 800, height: 800 }]], maxSize: 300 * 1024 }) } else if (selectData?.elementType === 'TOP_VIDEO') { // 视频 if (selectData?.adLocation === 'sns') { // 朋友圈信息流 if (selectData?.outerStyle === 0) { // 常规广告 init({ mediaType: 'VIDEO', cloudSize: [[{ relation: '=', width: 640, height: 480 }], [{ relation: '=', width: 640, height: 360 }], [{ relation: '=', width: 750, height: 1334 }], [{ relation: '=', width: 720, height: 1280 }]], maxSize: 20 * 1024 * 1024 }) } else { // 卡片广告 init({ mediaType: 'VIDEO', cloudSize: [[{ relation: '=', width: 750, height: null }, { relation: '<=', width: null, height: 1536 }]], maxSize: 20 * 1024 * 1024 }) } } else { // 公众号及其它 init({ mediaType: 'VIDEO', cloudSize: [[{ relation: '=', width: 750, height: null }, { relation: '<=', width: null, height: 1536 }]], maxSize: 20 * 1024 * 1024 }) } } else if (selectData?.elementType === 'IMAGE_TEXT') { // 图文复合组件 1个 if (selectData?.imageTextItem?.length === 1) { init({ mediaType: 'IMG', cloudSize: [[{ relation: '=', width: 360, height: 360 }]], maxSize: 300 * 1024 }) } else if (selectData?.imageTextItem?.length === 2) { init({ mediaType: 'IMG', cloudSize: [[{ relation: '=', width: 480, height: 480 }]], maxSize: 300 * 1024 }) } } else if (selectData?.elementType === 'FLOAT_BUTTON') { init({ mediaType: 'IMG', cloudSize: [[{ relation: '=', width: 96, height: 96 }]], maxSize: 300 * 1024 }) } }, [content]) const [dragging, setDragging] = useState(null); const getDragProps = useDrag({ onDragStart: (data) => { setDragging(data); }, onDragEnd: () => { setDragging(null); }, }); // 头部内容拖到接收区 const [dropProps] = useDrop({ onDom: (con: string, e) => { // 头部 let newCon = content?.map((item: TopImg | TopVideo | TopSlider) => { return { ...item, comptActive: false } }) let topCon = newCon[0] topCon.type = con topCon.comptActive = true let conContent: TopImg | TopVideo | TopSlider if (con === 'TOP_SLIDER') { conContent = { ...topsliderContent, comptActive: true } as TopSlider } else if (con === 'TOP_IMAGE') { conContent = { ...topimgContent, comptActive: true } as TopImg } else if (con === 'TOP_VIDEO') { conContent = { ...topvideoNewContent, comptActive: true } as TopVideo } else { return } topCon = { ...conContent } newCon[0] = topCon dispatch({ type: 'setCon', params: { content: newCon } }) }, }); const [draggingCon, setDraggingCon] = useState(null); const getDragPropsCon = useDrag({ onDragStart: (data) => { setDraggingCon(data); }, onDragEnd: () => { setDraggingCon(null); }, }); // 内容拖到接收区 const [dropConProps, { isHovering: isHoveringCon }] = useDrop({ onDom: (con: string, e) => { // 内容 let newCon: Content[] = content?.map((item: Text | ImgProps | GhButton) => { // | LinkButton | WxAutoButton return { ...item, comptActive: false } }) let newConItem = componentItem?.map((item: Floatbutton) => { return { ...item, comptActive: false } }) if (con === 'TEXT') { newCon.push({ ...txtContent, comptActive: true } as any) } else if (con === 'IMAGE') { newCon.push({ ...imgContent, comptActive: true } as any) } else if (con === 'GH') { newCon.push({ ...ghContent, comptActive: true } as any) // } else if (con === 'JumpLink') { // newCon.push({ ...linkContent, comptActive: true } as any) } else if (con === 'IMAGE_TEXT') { newCon.push({ ...imageTextGh, comptActive: true } as any) } else if (con === 'ENTERPRISE_WX') { newCon.push({ ...wxAutoContent, comptActive: true } as any) } else if (con === 'FLOAT_BUTTON') { newConItem.push({ ...floatbuttonContent, comptActive: true }) setDraggingCon(null); } else { return } dispatch({ type: 'setCon', params: { content: newCon } }) dispatchGlobal({ type: "setConItem", params: { componentItem: newConItem } }) }, }); /** 选中设置 */ const installActive = useCallback((e, index: number) => { e.stopPropagation(); e.preventDefault(); let newCon = content?.map((item: any) => { return { ...item, comptActive: false } }) let newConItem = componentItem?.map((item: { elementType: string }) => { return { ...item, comptActive: false } }) setImgTextButtonShow(false) if (index === 99999) { newConItem = newConItem?.map((item: { elementType: string }) => { if (item.elementType === 'FLOAT_BUTTON') { return { ...item, comptActive: true } } return item }) } else { newCon[index].comptActive = true } dispatch({ type: 'setCon', params: { content: newCon } }) dispatchGlobal({ type: "setConItem", params: { componentItem: newConItem } }) }, [content, imgTextButtonShow, componentItem]) /** 清除选中 */ const installActiveNull = useCallback((e) => { e.stopPropagation(); e.preventDefault(); let newCon = content?.map((item: any) => { return { ...item, comptActive: false } }) setImgTextButtonShow(false) dispatch({ type: 'setCon', params: { content: newCon } }) let newConItem = componentItem?.map((item: { widgetTypeV2: string }) => { return { ...item, comptActive: false } }) dispatchGlobal({ type: "setConItem", params: { componentItem: newConItem } }) }, [content]) /** 内容功能按钮区 */ const handleBtn = useCallback((type: string, index: number) => { let newContent = JSON.parse(JSON.stringify(content)) switch (type) { case 'lower': // 下移动 dispatch({ type: 'setCon', params: { content: arrayMove(content, index, index + 1) } }) break; case 'upper': // 上移动 dispatch({ type: 'setCon', params: { content: arrayMove(content, index, index - 1) } }) break; case 'IMAGE': // 图片 newContent.splice(index, 0, { ...imgContent }); dispatch({ type: 'setCon', params: { content: newContent } }) break; case 'TEXT': // 文本 newContent.splice(index, 0, { ...txtContent }); dispatch({ type: 'setCon', params: { content: newContent } }) break; case 'GH': // 关注公众号按钮 newContent.splice(index, 0, { ...ghContent }); dispatch({ type: 'setCon', params: { content: newContent } }) break; // case 'link': // 跳转链接按钮 // newContent.splice(index, 0, { ...linkContent }); // dispatch({ type: 'setCon', params: { content: newContent } }) // break; case 'IMAGE_TEXT': // 图文复合组件 newContent.splice(index, 0, JSON.parse(JSON.stringify(imageTextGh))); dispatch({ type: 'setCon', params: { content: newContent } }) break; case 'ENTERPRISE_WX': // 图文复合组件 newContent.splice(index, 0, { ...wxAutoContent }); dispatch({ type: 'setCon', params: { content: newContent } }) break; } }, [content]) /** 头部删除 */ const topDelType = useCallback(() => { setDragging(null); content[0] = { elementType: 'empty', comptActive: false } dispatch({ type: 'setCon', params: { content } }) }, [content, dragging]) /** 内容删除 */ const delType = useCallback((e, index: number) => { e.stopPropagation(); e.preventDefault(); setImgTextButtonShow(false) if (index === 99999) { // 删除悬浮组件 let newContentItem = JSON.parse(JSON.stringify(componentItem)) newContentItem = newContentItem?.filter((item: { elementType: string }) => item.elementType !== 'FLOAT_BUTTON') dispatchGlobal({ type: 'setConItem', params: { componentItem: JSON.parse(JSON.stringify(newContentItem)) } }) } else { let newContent = JSON.parse(JSON.stringify(content)) newContent?.splice(index, 1) dispatch({ type: 'setCon', params: { content: JSON.parse(JSON.stringify(newContent)) } }) } }, [content, componentItem, imgTextButtonShow]) const onSortEnd = ({ oldIndex, newIndex }: { oldIndex: number, newIndex: number }) => { dispatch({ type: 'setCon', params: { content: arrayMove(content, oldIndex, newIndex) } }) } // 基础内容 const comptCon = () => { if (content?.length === 0) { return null } else { return item.elementType === 'FLOAT_BUTTON')}> {content.map((value: Text | ImgProps | GhButton, index: number) => { if (value?.elementType === 'IMAGE') { return { installActive(e, index) }} del={(e: any) => { delType(e, index) }} upload={(num: number) => { clickUpdateImg(num) }} handleBtn={handleBtn} /> } else if (value?.elementType === 'TEXT') { return { installActive(e, index) }} del={(e: any) => { delType(e, index) }} pageBackColor={pageBackColor} handleBtn={handleBtn} /> } else if (value?.elementType === 'GH') { return { installActive(e, index) }} del={(e: any) => { delType(e, index) }} handleBtn={handleBtn} /> } else if (value?.elementType === 'ENTERPRISE_WX') { return { installActive(e, index) }} del={(e: any) => { delType(e, index) }} handleBtn={handleBtn} /> // } else if (value?.elementType === 'link') { // return { installActive(e, index) }} del={(e: any) => { delType(e, index) }} handleBtn={handleBtn} /> } else if (value?.elementType === 'IMAGE_TEXT') { return { installActive(e, index) }} del={(e: any) => { delType(e, index) }} handleBtn={handleBtn} /> } else { return null } })}
{(isHoveringCon || draggingCon) && '请拖至此处'}
{componentItem?.some((item: { elementType: string }) => item.elementType === 'FLOAT_BUTTON') && item.elementType === 'FLOAT_BUTTON')} click={(e: any) => { installActive(e, 99999) }} del={(e: any) => { delType(e, 99999) }} />}
} } /** 设置start */ const setCon = useCallback((key: string, value: any) => { let newContent = JSON.parse(JSON.stringify(content)) let selectIndex = newContent?.findIndex((item: Content) => item.comptActive) let oldContent = newContent if (selectIndex !== -1) { let selectCon = oldContent[selectIndex] selectCon[key] = value if (selectCon?.elementType === 'TOP_VIDEO' && (key === 'adLocation' || key === 'outerStyle')) { selectCon['videoUrl'] = '' } let newSelectCon = { ...selectCon } oldContent[selectIndex] = newSelectCon dispatch({ type: 'setCon', params: { content: [...oldContent] } }) } }, [content, goodsCount]) /** 设置end */ // 顶部组件 const topCon = useMemo(() => { let { imageUrl, elementType, activeIndex, imageUrlList, videoUrl } = content[0] return <> { elementType === 'TOP_IMAGE' ? <>
{ installActive(e, 0) }}>
{imageUrl ? :
}
{!imageUrl &&
}
{imageUrl && }
: elementType === 'TOP_SLIDER' ? <>
{ installActive(e, 0) }}>
{imageUrlList?.length > 0 ?
{imageUrlList?.map((imgUrl: any, index: number) => { if (imgUrl) { return } else { return
} })}
{imageUrlList.map((item: any, index: number) => )}
:
{imageUrlList.fill('').map((item: any, index: number) => )}
}
: elementType === 'TOP_VIDEO' ? <>
{ installActive(e, 0) }}>
{ videoUrl ?
:
}
{!videoUrl &&
}
{videoUrl && }
:
{dragging ?
拖至此处
: <>

顶部组件区

在左上方,选择顶部组件添加到此处
}
} }, [content, state, dragging]) /** 图标开启与关闭 */ const iconHandle = (e: boolean) => { let newContent = JSON.parse(JSON.stringify(content)) let selectIndex = newContent?.findIndex((item: Content) => item.comptActive) let oldContent = newContent if (selectIndex !== -1) { let selectCon = oldContent[selectIndex] selectCon['useIcon'] = e ? 1 : 0 oldContent[selectIndex] = selectCon dispatch({ type: 'setCon', params: { content: [...oldContent] } }) } } /** 视频切换广告位 */ const changeAdLocation = (value: 'sns' | 'gh') => { let newContent = JSON.parse(JSON.stringify(content)) let selectIndex = newContent?.findIndex((item: Content) => item.comptActive) let oldContent = newContent if (selectIndex !== -1) { let selectCon = oldContent[selectIndex] selectCon['adLocation'] = value if (value === 'gh') { selectCon['styleType'] = 1 } else { selectCon['styleType'] = 0 } selectCon['videoUrl'] = '' oldContent[selectIndex] = selectCon dispatch({ type: 'setCon', params: { content: [...oldContent] } }) } } /** 视频切换外层样式 */ const changeOuterLayout = (value: string) => { let newContent = JSON.parse(JSON.stringify(content)) let selectIndex = newContent?.findIndex((item: Content) => item.comptActive) let oldContent = newContent if (selectIndex !== -1) { let selectCon = oldContent[selectIndex] selectCon['viewType'] = value let newSelectCon: any if (value === '0') { let { outerUseTopMaterial, streamDisplayWidth, streamDisplayHeight, streamVideoThumb, streamVideoUrl, streamDisplayType, streamThumbMd5, streamVideoMd5, displayType, ...clearSelectCon } = selectCon newSelectCon = { ...clearSelectCon } } else { newSelectCon = { ...selectCon, outerUseTopMaterial: '0', styleType: '0' } } oldContent[selectIndex] = newSelectCon dispatch({ type: 'setCon', params: { content: [...oldContent] } }) } } /** 轮播图选择点击切换图片 多张图片 */ const sliderSelect = (index: number, count: number) => { let newContent = JSON.parse(JSON.stringify(content)) let selectIndex = newContent?.findIndex((item: Content) => item.comptActive) if (selectIndex !== -1) { let selectCon = newContent[selectIndex] let imgList: any[] = [] selectCon?.imageUrlList?.forEach((item: string) => { if (item) { imgList.push({ url: item }) } }) setSliderImgContent(imgList) } setCon('activeIndex', index) setCcType(3) setSelectImgVisible(true) } /** 轮播图图片数量设置 */ const sliderImgNum = useCallback((num: string) => { let newContent = JSON.parse(JSON.stringify(content)) let selectIndex = newContent?.findIndex((item: Content) => item.comptActive) let oldContent = newContent if (selectIndex !== -1) { let selectCon = oldContent[selectIndex] let { imageUrlList } = selectCon if (imageUrlList?.length > Number(num)) { // 减少 selectCon['imageUrlList'] = [...imageUrlList?.splice(0, Number(num))] } else { // 增加 let newGroup = Array(Number(num) - imageUrlList?.length).fill('').map(() => "") imageUrlList = [...imageUrlList, ...newGroup] selectCon['imageUrlList'] = imageUrlList } oldContent[selectIndex] = { ...selectCon } dispatch({ type: 'setCon', params: { content: [...oldContent] } }) } }, [content]) /** 轮播图位置拖动切换顺序 */ const onSortEndSlider = useCallback(({ oldIndex, newIndex }: { oldIndex: number, newIndex: number }) => { let newContent = JSON.parse(JSON.stringify(content)) let selectIndex = newContent?.findIndex((item: Content) => item.comptActive) let oldContent = newContent if (selectIndex !== -1) { let selectCon = oldContent[selectIndex] let { imageUrlList } = selectCon imageUrlList = arrayMove(imageUrlList, oldIndex, newIndex) selectCon['imageUrlList'] = imageUrlList oldContent[selectIndex] = { ...selectCon } dispatch({ type: 'setCon', params: { content: [...oldContent] } }) } }, [content]) /** 图文单个设置 */ const onShelfnewTxtCon = useCallback((value: string, parameter: string) => { let newContent = JSON.parse(JSON.stringify(content)) let selectIndex = newContent?.findIndex((item: Content) => item.comptActive) let oldContent = newContent if (selectIndex !== -1) { let selectCon = oldContent[selectIndex] let length = selectCon?.imageTextItem?.length || 0; if (length === 2) { let imageTextItem = selectCon?.imageTextItem[goodsCount] imageTextItem[parameter] = value } else if (length === 1) { let imageTextItem = selectCon?.imageTextItem[0] imageTextItem[parameter] = value } oldContent[selectIndex] = { ...selectCon } dispatch({ type: 'setCon', params: { content: [...oldContent] } }) } }, [content, goodsCount]) // 设置图文跳转链接按钮 const onSetShelfnewButton = useCallback((value: string) => { let newContent = JSON.parse(JSON.stringify(content)) let selectIndex = newContent?.findIndex((item: Content) => item.comptActive) let oldContent = newContent if (selectIndex !== -1) { let selectCon = oldContent[selectIndex] let length = selectCon?.imageTextItem?.length || 0; if (length === 2) { let imageTextItem = selectCon?.imageTextItem[goodsCount] imageTextItem.subElemType = value switch(value) { case 'GH': imageTextItem.content = JSON.parse(JSON.stringify(ghITItemContent)) break; case 'ENTERPRISE_WX': imageTextItem.content = JSON.parse(JSON.stringify(wxAutoITItemContent)) break } } else if (length === 1) { let imageTextItem = selectCon?.imageTextItem[0] imageTextItem.subElemType = value switch(value) { case 'GH': imageTextItem.content = JSON.parse(JSON.stringify(ghITItemContent)) break; case 'ENTERPRISE_WX': imageTextItem.content = JSON.parse(JSON.stringify(wxAutoITItemContent)) break } } oldContent[selectIndex] = { ...selectCon } dispatch({ type: 'setCon', params: { content: [...oldContent] } }) } }, [content, goodsCount]) // 配置图文跳转链接按钮字段 const onSetShelfnewButtonField = useCallback((field: string, value: string | number) => { let newContent = JSON.parse(JSON.stringify(content)) let selectIndex = newContent?.findIndex((item: Content) => item.comptActive) let oldContent = newContent if (selectIndex !== -1) { let selectCon = oldContent[selectIndex] let length = selectCon.imageTextItem.length if (length === 2) { let content = selectCon.imageTextItem[goodsCount].content content[field] = value } else if (length === 1) { let content = selectCon.imageTextItem[0].content content[field] = value } oldContent[selectIndex] = { ...selectCon } dispatch({ type: 'setCon', params: { content: [...oldContent] } }) } }, [content, goodsCount]) // 设置图文复合组件类型 const setShelfnewType = useCallback((value: string) => { let newContent = JSON.parse(JSON.stringify(content)) let selectIndex = newContent?.findIndex((item: Content) => item.comptActive) if (selectIndex !== -1) { if (value === '2') { newContent[selectIndex].imageTextItem = [ JSON.parse(JSON.stringify({ ...imageTextItem, content: { ...ghITItemContent } })), JSON.parse(JSON.stringify({ ...imageTextItem, content: { ...ghITItemContent } })) ] } else if (value === '1') { newContent[selectIndex].alignMode = 0 let imageTextItem = newContent[selectIndex].imageTextItem let newImageTextItem = imageTextItem.splice(0, 1) newContent[selectIndex].imageTextItem = newImageTextItem } dispatch({ type: 'setCon', params: { content: [...newContent] } }) } }, [content]) // 设置悬浮弹窗 const setGlobalComponentItem = (key: string, value: any, isDel = false) => { let newConItem = JSON.parse(JSON.stringify(componentItem)) let selectIndex = newConItem?.findIndex((item: Content) => item.comptActive) let oldContent = newConItem if (selectIndex !== -1) { let selectCon = oldContent[selectIndex] // 设置悬浮窗 转化按钮 if (key === 'componentItem' && (value === 'GH' || value === 'ENTERPRISE_WX')) { if (value === 'GH') { selectCon[key] = floatbuttonBtTypeGh } else if (value === 'ENTERPRISE_WX') { selectCon[key] = floatbuttonBtTypeWxAuto } } else { if (!isDel) { selectCon[key] = value if (key === 'styleType') { if (value === 0) { selectCon['imageUrl'] = "" selectCon['desc'] = selectCon?.desc || "" } else if (value === 1) { delete selectCon['imageUrl'] selectCon['desc'] = selectCon?.desc || "" } else if (value === 2) { delete selectCon['imageUrl'] delete selectCon['desc'] } selectCon[key] = value } } else { delete selectCon[key] } } dispatchGlobal({ type: 'setConItem', params: { componentItem: JSON.parse(JSON.stringify(oldContent)) } }) } } // 选中设置 const rightCon = () => { let selectCon = content?.find((item: Content) => item.comptActive) if (!selectCon) { selectCon = componentItem?.find((item: { comptActive: boolean }) => item.comptActive) } if (selectCon) { let { elementType, adLocation, outerStyle, imageUrlList, imageUrl, text, fontColor, fontSize, fontStyle, textAlignment, paddingTop, paddingBottom, fastFollow, btnTitle, btnFontType, btnBorderColorTheme, btnBgColorTheme, useIcon, styleType, imageTextItem, initHeight, alignMode, activeIndex, title, desc, titleColor, descColor, componentItem, appearType, disappearType } = selectCon let imgTextData: ImageTextItem = { borderColor: '#e5e5e5', titleColor: '#353535', descColor: '#b2b2b2', bgColor: '#ffffff', jumpMode: 'btn_jump', imageUrl: '', title: '', desc: '', subElemType: 'GH', content: { btnTitle: '关注公众号', fontColor: '#FFFFFF', btnBgColorTheme: '#07C160', btnBorderColorTheme: '#FFFFFF', btnFontType: 0, useIcon: 0, fastFollow: 1, paddingTop: 28, paddingBottom: 28, } } let imageTextItemIndex = 1; let custorGroup = [] if (elementType === 'enterprise_wx_auto') { custorGroup = selectCon?.custorData || [] } else if (elementType === 'IMAGE_TEXT') { imageTextItemIndex = imageTextItem?.length || 1 if (imageTextItemIndex === 1) { // 图文复合组件 单个 imgTextData = imageTextItem[0] } else if (imageTextItemIndex === 2) { imgTextData = imageTextItem[goodsCount] } } return <> { elementType === 'TOP_IMAGE' ?
顶部组件:图片
广告位与样式
广告位
{ setCon('adLocation', e.target.value) }} value={adLocation} size='small'> 朋友圈信息流 公众号及其他
{adLocation === 'sns' &&
外层样式
}
素材设置
图片素材
{imageUrl ?
{ clickUpdateImg(1) }}>
:
{ clickUpdateImg(1) }}>
}
: elementType === 'TOP_SLIDER' ?
顶部组件:轮播图
素材设置
图片数量
{ sliderImgNum(e.target.value) }} value={imageUrlList?.length || 3} size='small'> 3张 4张 6张
上传素材
{imageUrlList?.map((item: any, index: number) => { if (item) { return { sliderSelect(index, imageUrlList.length) }} setActiveIndex={() => { setCon('activeIndex', index) }}> } else { return { sliderSelect(index, imageUrlList.length) }}> } })}
: elementType === 'TOP_VIDEO' ?
顶部组件:视频
广告位与样式
广告位
{ changeAdLocation(e.target.value) }} value={adLocation} size='small'> 朋友圈信息流 公众号及其他
{adLocation === 'sns' &&
外层样式
} {/* { adLocation === 'sns' && outerStyle === 0 &&
视频类型
{ viewTypeChange(e.target.value, 1) }} value={styleType} size='small'> 横板视频 竖版视频
} { adLocation === 'sns' && outerStyle === 1 &&
外层素材
{ outerUseTopMaterialHandle(e.target.checked) }} checked={outerUseTopMaterial === '0' ? false : true}>顶部素材不用于广告外层
} */} {/* { outerUseTopMaterial === '1' &&
视频类型
{ viewTypeChange(e.target.value, 2) }} value={type} size='small'> 短视频 长视频
} */} {/* { adLocation === 'gh' &&
视频类型
{ viewTypeChange(e.target.value, 2) }} value={type} size='small'> 短视频 长视频
} */} {adLocation === 'sns' && styleType === '1' &&
视频尺寸
{ setCon('initHeight', e.target.value) }}> 750像素 x 1536像素 750像素 x 1334像素 720像素 x 1280像素
}
: elementType === 'TEXT' ?
文本
推广文案