"use client"; import React, { useState, useEffect } from "react"; import { DotLoading, Popup, Toast, TextArea, Switch } from "antd-mobile"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faAngleLeft } from "@fortawesome/free-solid-svg-icons"; import requireAPI from "@/utils/requireAPI"; import { useRouter } from "next/navigation"; import { multiUploadImage } from "@/utils/upload"; import UploadImgs from "@/components/UploadImgs"; export default function CreatePost() { const [isSubmitting, setIsSubmitting] = useState(false); const [oldPhotos, setOldPhotos] = useState([]); //价格 const [formData, setFormData] = useState({ content: "", imageAssets: [], videoAssets: [], }); const router = useRouter(); useEffect(() => { getPostCountData(); }, []); const getPostCountData = async () => { try { const _data = await requireAPI( "POST", "/api/zone_moment/list_statistics_by_creater_mid" ); if (_data.ret === -1) { Toast.show({ icon: "fail", content: _data.msg, position: "top", }); return; } } catch (error) { console.error(error); } }; //发布内容 const handleSubmit = async () => { if (formData.content == "") { Toast.show({ icon: "fail", content: "动态内容不能为空", position: "top", }); return; } if ( formData.imageAssets.length === 0 && formData.videoAssets.length === 0 ) { Toast.show({ icon: "fail", content: "请上传图片或视频", position: "top", }); return; } //提交数据 if (isSubmitting) return; setIsSubmitting(true); const { content, imageAssets, videoAssets } = formData; const newImageMedia = imageAssets.filter((it) => it.id == undefined); const type = formData.imageAssets.length > 0 ? 1 : 2; const media = await multiUploadImage( type == 1 ? newImageMedia : videoAssets, type ); // const media = await multiUploadImage(imageAssets); if (type == 1) { media.image_ids = [ ...imageAssets.filter((it) => it.id != undefined).map((it) => it.id), ...media.image_ids, ]; } try { const body = { text: content, media_component: media, status: 2, }; const data = await requireAPI( "POST", "/api/moment/create", { body, }, true, 100000 ); if (data.ret === -1) { Toast.show({ icon: "fail", content: data.msg, position: "top", }); return; } //提交成功后显示Toast并返回上一页 Toast.show({ icon: "success", content: "发布成功", position: "top", }); router.back(); } catch (error) { console.error(error); } finally { setIsSubmitting(false); } }; return (
广场动态
{isSubmitting ? (动态内容
图片 (添加图片后不可添加视频)
视频 (添加视频后不可添加图片)