|
@@ -26,6 +26,8 @@ const Material: React.FC<Props> = (props) => {
|
|
|
const [visible, setVisible] = useState<boolean>(false)
|
|
|
const [selectVideoVisible, set_selectVideoVisible] = useState(false)
|
|
|
const [videoImgsVisbile, set_videoImgsVisbile] = useState(false)
|
|
|
+ const [videoUploads, setVideoUploads] = useState<any>()
|
|
|
+ const [imgUploads, setImgUploads] = useState<any>()
|
|
|
const { init } = useModel('useLaunchAdq.useBdMediaPup')
|
|
|
const [materialConfig, setMaterialConfig] = useState<{
|
|
|
adcreativeTemplateId?: number,
|
|
@@ -95,6 +97,18 @@ const Material: React.FC<Props> = (props) => {
|
|
|
}
|
|
|
}, [value, visible])
|
|
|
|
|
|
+ // 处理判断有哪些素材 展示按钮
|
|
|
+ useEffect(() => {
|
|
|
+ console.log('material----->', material);
|
|
|
+ if (material?.length > 0) {
|
|
|
+ setVideoUploads(material?.find((item: { name: string }) => item.name === 'short_video1' || item.name === 'video'))
|
|
|
+ setImgUploads(material?.find((item: { name: string }) => item.name === 'image' || item.name === 'image_list'))
|
|
|
+ } else {
|
|
|
+ setVideoUploads({})
|
|
|
+ setImgUploads({})
|
|
|
+ }
|
|
|
+ }, [material])
|
|
|
+
|
|
|
// 确定
|
|
|
const handleOk = () => {
|
|
|
form.validateFields().then(values => {
|
|
@@ -125,7 +139,42 @@ const Material: React.FC<Props> = (props) => {
|
|
|
|
|
|
return <>
|
|
|
<span onClick={() => { setVisible(true) }}>{value && value?.length > 0 ? '编辑' : '添加'}</span>
|
|
|
- {visible && <Modal visible={visible} onCancel={() => setVisible(false)} title="创意素材" width={930} onOk={handleOk}>
|
|
|
+ {visible && <Modal
|
|
|
+ visible={visible}
|
|
|
+ onCancel={() => setVisible(false)}
|
|
|
+ title={<>
|
|
|
+ <span>创意素材</span>
|
|
|
+ {videoUploads && Object.keys(videoUploads)?.length > 0 && <Button type="link" onClick={() => {
|
|
|
+ console.log('videoUploads---->', videoUploads);
|
|
|
+ init({ mediaType: 'VIDEO', num: 100, cloudSize: adcreativeTemplateId === 1708 ? [[{ relation: '=', width: 1280, height: 720 }]] : [[{ relation: '=', width: videoUploads.restriction.videoRestriction.minWidth, height: videoUploads.restriction.videoRestriction.minHeight }]], maxSize: videoUploads.restriction.videoRestriction.fileSize * 1024 })
|
|
|
+ setMaterialConfig({
|
|
|
+ ...materialConfig,
|
|
|
+ type: videoUploads.name,
|
|
|
+ max: 1,
|
|
|
+ index: 99999,
|
|
|
+ adcreativeTemplateId
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ set_selectVideoVisible(true)
|
|
|
+ }, 100)
|
|
|
+ }}>批量添加视频素材</Button>}
|
|
|
+ {imgUploads && Object.keys(imgUploads)?.length > 0 && <Button type="link" onClick={() => {
|
|
|
+ init({ mediaType: 'IMG', num: 100, cloudSize: [[{ relation: '=', width: imgUploads.restriction.imageRestriction.width, height: imgUploads.restriction.imageRestriction.height }]], maxSize: imgUploads.restriction.imageRestriction.fileSize * 1024 })
|
|
|
+ setMaterialConfig({
|
|
|
+ ...materialConfig,
|
|
|
+ type: imgUploads.name,
|
|
|
+ max: imgUploads.name === 'image_list' ? imgUploads.arrayProperty.maxNumber : 1,
|
|
|
+ index: 99999,
|
|
|
+ adcreativeTemplateId
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ set_selectVideoVisible(true)
|
|
|
+ }, 100)
|
|
|
+ }}>批量添加图片素材</Button>}
|
|
|
+ </>}
|
|
|
+ width={930}
|
|
|
+ onOk={handleOk}
|
|
|
+ >
|
|
|
<Form name="dynamic_form_item" form={form} labelAlign='left' >
|
|
|
<Form.List name="materials">
|
|
|
{(fields, { add, remove }) => (<>
|
|
@@ -181,7 +230,6 @@ const Material: React.FC<Props> = (props) => {
|
|
|
})
|
|
|
setTimeout(() => {
|
|
|
set_selectVideoVisible(true)
|
|
|
-
|
|
|
}, 100)
|
|
|
}}>
|
|
|
<p>
|
|
@@ -208,8 +256,7 @@ const Material: React.FC<Props> = (props) => {
|
|
|
type: item.name,
|
|
|
max: item.arrayProperty.maxNumber,
|
|
|
index: num,
|
|
|
- adcreativeTemplateId,
|
|
|
- sliderImgContent: (materials?.length > 0 && materials[num] && Object.keys(materials[num])?.includes(item.name)) ? materials[num][item.name]?.map((item: string) => ({ url: item })) : undefined
|
|
|
+ adcreativeTemplateId
|
|
|
})
|
|
|
setTimeout(() => {
|
|
|
set_selectVideoVisible(true)
|
|
@@ -246,33 +293,107 @@ const Material: React.FC<Props> = (props) => {
|
|
|
{selectVideoVisible && <SelectCloud
|
|
|
visible={selectVideoVisible}
|
|
|
onClose={() => set_selectVideoVisible(false)}
|
|
|
- sliderImgContent={materialConfig.type === 'image_list'
|
|
|
- ? (materials[materialConfig.index] && Object.keys(materials[materialConfig.index])?.includes(materialConfig.type)) ? materials[materialConfig.index][materialConfig.type]?.map((item: string) => ({ url: item })) : undefined
|
|
|
+ sliderImgContent={materialConfig.index === 99999 ? undefined : materialConfig.type === 'image_list'
|
|
|
+ ? (materials[materialConfig.index] && Object.keys(materials[materialConfig.index])?.includes('image_list')) ? materials[materialConfig.index]['image_list']?.map((item: string) => ({ url: item })) : undefined
|
|
|
: (materials[materialConfig.index] && Object.keys(materials[materialConfig.index])?.includes(materialConfig.type)) ? [{ url: materials[materialConfig.index][materialConfig.type] }] : undefined
|
|
|
}
|
|
|
onChange={(content: any) => {
|
|
|
if (content.length > 0) {
|
|
|
- materials = materials?.map((item: any, index: number) => {
|
|
|
- if (materialConfig.index === index) {
|
|
|
- if (materialConfig.type === 'image_list') {
|
|
|
- if (item) {
|
|
|
- item[materialConfig.type] = content?.map((item: any) => item?.url)
|
|
|
- return { ...item }
|
|
|
+ if (materialConfig.index === 99999) {
|
|
|
+ if (materialConfig.type === 'image_list') {
|
|
|
+ let urls = content?.map((item: any) => item?.url)
|
|
|
+ let max = materialConfig.max
|
|
|
+ let materialsNew = materials.map((item: any) => {
|
|
|
+ let newItem = item || {}
|
|
|
+ // 判断是否有字段,是否设置了值
|
|
|
+ if (Object.keys(newItem).includes(materialConfig.type) && newItem[materialConfig.type]) {
|
|
|
+ if (max > newItem[materialConfig.type].length && urls.length > 0) {
|
|
|
+ let difference = max - newItem[materialConfig.type].length
|
|
|
+ let material: any[] = []
|
|
|
+ if (urls.length >= difference) {
|
|
|
+ material = urls.splice(0, difference)
|
|
|
+ } else {
|
|
|
+ material = urls.splice(0, urls.length)
|
|
|
+ }
|
|
|
+ newItem[materialConfig.type] = [...newItem[materialConfig.type], ...material]
|
|
|
+ return newItem
|
|
|
+ } else {
|
|
|
+ return newItem
|
|
|
+ }
|
|
|
} else {
|
|
|
- return { [materialConfig.type]: content?.map((item: any) => item?.url) }
|
|
|
+ if (urls.length >= max) {
|
|
|
+ let material = urls.splice(0, max)
|
|
|
+ return { ...newItem, [materialConfig.type]: material }
|
|
|
+ } else if (urls.length > 0) {
|
|
|
+ let material = urls.splice(0, urls.length)
|
|
|
+ return { ...newItem, [materialConfig.type]: material }
|
|
|
+ } else {
|
|
|
+ return newItem
|
|
|
+ }
|
|
|
}
|
|
|
- } else {
|
|
|
- if (item) {
|
|
|
- item[materialConfig.type] = content[0]?.url
|
|
|
- return { ...item }
|
|
|
- } else {
|
|
|
- return { [materialConfig.type]: content[0]?.url }
|
|
|
+ })
|
|
|
+ if (urls.length > 0) {
|
|
|
+ let data = Array(Math.ceil(urls.length / max)).fill(undefined).map(item => {
|
|
|
+ if (urls.length >= max) {
|
|
|
+ let material = urls.splice(0, max)
|
|
|
+ return { [materialConfig.type]: material }
|
|
|
+ } else {
|
|
|
+ let material = urls.splice(0, urls.length)
|
|
|
+ return { [materialConfig.type]: material }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ materialsNew = [...materialsNew, ...data]
|
|
|
+ }
|
|
|
+ form.setFieldsValue({ materials: materialsNew })
|
|
|
+ } else {
|
|
|
+ let newMaterials = content?.map((item: any) => ({ [materialConfig.type]: item?.url }))
|
|
|
+ if (newMaterials.length > 0) {
|
|
|
+ if (materials?.every((item: any) => !item)) { // 没设置过
|
|
|
+ form.setFieldsValue({ materials: newMaterials })
|
|
|
+ } else { // 设置过
|
|
|
+ let materialsNew = materials.map((item: any) => {
|
|
|
+ let newItem = item || {}
|
|
|
+ if (Object.keys(newItem).includes(materialConfig.type) && newItem[materialConfig.type]) {
|
|
|
+ return item
|
|
|
+ } else {
|
|
|
+ if (newMaterials.length > 0) {
|
|
|
+ let material = newMaterials.splice(0, 1)
|
|
|
+ return { ...newItem, ...material[0] }
|
|
|
+ } else {
|
|
|
+ return item
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (newMaterials.length > 0) {
|
|
|
+ materialsNew = [...materialsNew, ...newMaterials]
|
|
|
+ }
|
|
|
+ form.setFieldsValue({ materials: materialsNew })
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return item
|
|
|
- })
|
|
|
- form.setFieldsValue({ materials })
|
|
|
+ } else {
|
|
|
+ materials = materials?.map((item: any, index: number) => {
|
|
|
+ if (materialConfig.index === index) {
|
|
|
+ if (materialConfig.type === 'image_list') {
|
|
|
+ if (item) {
|
|
|
+ item[materialConfig.type] = content?.map((item: any) => item?.url)
|
|
|
+ return { ...item }
|
|
|
+ } else {
|
|
|
+ return { [materialConfig.type]: content?.map((item: any) => item?.url) }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (item) {
|
|
|
+ item[materialConfig.type] = content[0]?.url
|
|
|
+ return { ...item }
|
|
|
+ } else {
|
|
|
+ return { [materialConfig.type]: content[0]?.url }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return item
|
|
|
+ })
|
|
|
+ form.setFieldsValue({ materials })
|
|
|
+ }
|
|
|
}
|
|
|
set_selectVideoVisible(false)
|
|
|
}}
|