"use client"; import React, { useState, useEffect } from "react"; import { DotLoading, Popup, Toast, TextArea, Switch, Modal } 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"; import OwnInput from "@/components/OwnInput"; import DefaultMask from "@/components/DefaultMask"; export default function CreateVideoPost() { const [isSubmitting, setIsSubmitting] = useState(false); const [priceEdit, setPriceEdit] = useState(false); // const [isFreeForIronfan, setIsFreeForIronfan] = useState(false); const [postCount, setPostCount] = useState(null); const [isBlockModalVisible, setIsBlockModalVisible] = useState(false); //价格 const [formData, setFormData] = useState({ price: 0, content: "", paidText: "", imageAssets: [], blurCover: true, isCreatingPaidText: true, isFreeForIronfan: false, }); const [priceEditData, setPriceEditData] = useState({ price: 0, blurCover: true, isCreatingPaidText: false, isFreeForIronfan: false, }); 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; } setPostCount(_data.data); if (_data.data.rejected_count >= 5) setIsBlockModalVisible(true); } catch (error) { console.error(error); } }; //发布内容 const handleSubmit = async () => { if (formData.content == "") { Toast.show({ icon: "fail", content: "动态内容不能为空", position: "top", }); return; } if (formData.imageAssets.length === 0) { Toast.show({ icon: "fail", content: "请上传至少一张图片", position: "top", }); return; } if ( formData.isCreatingPaidText && formData.price > 0 && formData.paidText == "" ) { Toast.show({ icon: "fail", content: "请填写付费文案", position: "top", }); return; } //提交数据 if (isSubmitting) return; setIsSubmitting(true); const { price, isFreeForIronfan, content, imageAssets, textVisibleRange, blurCover, isCreatingPaidText, paidText, } = formData; const media = await multiUploadImage(imageAssets, 2); try { const body = { c_type: parseInt(price) ? 1 : 0, is_ironfan_visible: isFreeForIronfan ? 1 : 0, m_type: 2, text: content, media_component: media, text_visible_range: textVisibleRange ? parseInt(textVisibleRange, 10) : 999, is_blurring_cover: blurCover ? 1 : 0, price: parseFloat(price) ? parseInt(parseFloat(price) * 100, 10) : null, is_creating_paid_text: isCreatingPaidText && price > 0 ? 1 : 0, paid_text: isCreatingPaidText && price > 0 ? paidText : null, }; const data = await requireAPI("POST", "/api/zone_moment/create", { body, }); 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 ? (为了空间良性发展,请保持免费/付费比例为1/1
已发布免费动态:{postCount?.free_count || 0}条
已发布付费动态:{postCount?.paid_count || 0}条
可发布付费动态: {postCount?.paid_limit || 0}条
审核未通过动态: {postCount?.rejected_count || 0}条
动态内容
{ setPriceEdit(false); setFormData((old) => ({ ...old, ...priceEditData })); }} > 保存