import React, { useState } from "react" import { Button, Popover, Space, Tag } from "antd" import { PlusOutlined, EditOutlined, DeleteOutlined, DownOutlined, UpOutlined, VerticalAlignTopOutlined, VerticalAlignBottomOutlined } from '@ant-design/icons'; import { MediaContentProps, MediaTypeProps } from "../../API/weMaterial/weMaterial"; import TextNews from "../newsMould/textNews"; import style from './index.less' import useNewToken from "@/Hook/useNewToken"; import ImgNews from "../newsMould/imgNews"; import UploadButton, { MediaSize } from "./uploadButton"; import FileNews from "../newsMould/fileNews"; import VideoNews from "../newsMould/videoNews"; import { RcFile } from "antd/es/upload"; import AudioNews from "../newsMould/audioNews"; import LinkNews from "../newsMould/linkNews"; import MiniprogramNews from "../newsMould/miniprogramNews"; interface Props { data: MediaContentProps[] onChange?: (item: MediaContentProps | string, index: number, type: 'add' | 'edit' | 'del' | 'up' | 'down' | 'upV' | 'downV', mediaType?: MediaTypeProps | 'sck', file?: RcFile, name?: string) => void, noShowType?: Array<'text' | 'video' | 'file' | 'link' | 'voice' | 'miniprogram' | 'sck' | 'image'>, textCount?: number, // 可选文案数量 dataLength: number mediaSize?: MediaSize disabledAdd?: boolean } // /** * 素材库使用内容模板 * @returns */ const ContentBox: React.FC = ({ data, onChange, noShowType, dataLength, mediaSize, textCount, disabledAdd }) => { /****************************/ const { token } = useNewToken() const [hover, setHover] = useState(-1) /****************************/ // 鼠标移入 const hoverIn = (index: number) => { setHover(index) } // 鼠标移出 const hoverOut = () => { setHover(-1) } // 点击按钮 const clickHandle = (item: MediaContentProps | string, index: number, type: 'add' | 'edit' | 'del' | 'up' | 'down' | 'upV' | 'downV', mediaType?: MediaTypeProps | 'sck', file?: RcFile, name?: string) => { onChange?.(item, index, type, mediaType, file, name) } return <> {data?.filter(item => textCount ? item.mediaType !== 'text' : true)?.map(((item, index) => { return
{ hoverIn(index) }} onMouseLeave={hoverOut} style={{ background: hover === index ? token.colorPrimaryBgHover : token.colorBgContainerDisabled, borderRadius: token.borderRadius }} >
{index + 1} {item?.mediaType === 'text' ?
: item?.mediaType === 'image' ?
: item?.mediaType === 'video' ?
: item?.mediaType === 'voice' ?
: item?.mediaType === 'miniprogram' ?
: item?.mediaType === 'link' ?
: item?.mediaType === 'file' ?
: null}
{(data.length < dataLength && !disabledAdd) && {!(noShowType?.some(i => i === 'text')) && !textCount && } {!(noShowType?.some(i => i === 'image')) && { clickHandle(url, index, 'add', 'image', file, name) }} />} {!(noShowType?.some(i => i === 'video')) && { clickHandle(url, index, 'add', 'video', file, name) }} />} {!(noShowType?.some(i => i === 'file')) && { clickHandle(url, index, 'add', 'file', file, name) }} />} {!(noShowType?.some(i => i === 'link')) && } {/* {!(noShowType?.some(i => i === 'voice')) && { clickHandle(url, index, 'add', 'voice', file, name) }} />} */} {!(noShowType?.some(i => i === 'miniprogram')) && } {!(noShowType?.some(i => i === 'sck')) && } } color={token.colorBgBase} > } {['image', 'video', 'file', 'voice'].includes(item?.mediaType as any) ? } mediaSize={mediaSize} type={item?.mediaType} size="small" onChange={(url, file) => { clickHandle(url, index, 'edit', item?.mediaType, file) }} /> : } {!disabledAdd && } {data.length > 1 && <> {data.length !== index + 1 && <> } {index !== 0 && <> } }
}))} } export default React.memo(ContentBox)