"use client"; import React, { useState, useEffect, useMemo, useCallback } 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, useParams } from "next/navigation"; import { multiUploadImage } from "@/utils/upload"; import UploadImgs from "@/components/UploadImgs"; import OwnInput from "@/components/OwnInput"; export default function EditSpacePost() { const params = useParams(); const [data, setData] = useState(null); const [isSubmitting, setIsSubmitting] = useState(false); const [priceEdit, setPriceEdit] = useState(false); //价格 const [formData, setFormData] = useState({ price: "", content: "", paidText: "", imageAssets: [], imageVisibleRange: 0, isCreatingPaidText: false, isFreeForIronfan: false, }); const [priceEditData, setPriceEditData] = useState({ price: "", imageVisibleRange: 1, isCreatingPaidText: false, isFreeForIronfan: false, blurCover: true, }); const router = useRouter(); useEffect(() => { const { zid } = params; getData(parseInt(zid, 10)); }, []); const getData = async () => { const ids = [parseInt(params.zid, 10)]; try { const body = { ids, }; const _data = await requireAPI( "POST", "/api/zone_moment/list_by_ids_from_creater", { body, }, true ); if (_data.ret === -1) { Toast.show({ icon: "fail", content: _data.msg, position: "top", }); return; } setData(_data.data.list[0]); const { text, paid_text, price, media_visible_range, is_creating_paid_text, is_ironfan_visible, is_blurring_cover, } = _data.data.list[0]; const publicData = { price: price ? price / 100 : 0, imageVisibleRange: media_visible_range, isCreatingPaidText: is_creating_paid_text, isFreeForIronfan: is_ironfan_visible, blurCover: is_blurring_cover == 1, }; setFormData({ content: paid_text ? text.slice(0, text.length - paid_text.length) : text, paidText: paid_text, imageAssets: [], ...publicData, }); setPriceEditData(publicData); } catch (error) { console.error(error); } finally { setIsSubmitting(false); } }; //发布内容 const handleSubmit = async () => { if (formData.content == "") { Toast.show({ icon: "fail", content: "动态内容不能为空", position: "top", }); return; } if (data?.m_type && formData.imageAssets.length === 0) { Toast.show({ icon: "fail", content: "请上传至少一张图片", position: "top", }); return; } if (data?.m_type == 1) { if ( parseFloat(formData.price) && formData.imageAssets.length <= parseInt(formData.imageVisibleRange, 10) ) { 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, imageVisibleRange, isCreatingPaidText, paidText, blurCover, } = formData; const mType = data?.m_type; const newMedia = imageAssets.filter((it) => it.id == undefined); const media = await multiUploadImage(newMedia, mType); if (mType == 1) { media.image_ids = [ ...imageAssets.filter((it) => it.id != undefined).map((it) => it.id), ...media.image_ids, ]; } else { media.video_ids = [ ...imageAssets.filter((it) => it.id != undefined).map((it) => it.id), ...media.video_ids, ]; } try { const body = { id: data.id, c_type: parseInt(price) ? 1 : 0, is_ironfan_visible: isFreeForIronfan ? 1 : 0, m_type: mType, text: content, media_component: media, text_visible_range: textVisibleRange ? parseInt(textVisibleRange, 10) : 999, media_visible_range: imageVisibleRange ? parseInt(imageVisibleRange, 10) : 1, 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/update", { body, }, false, 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); } }; const getExistImgs = useMemo(() => { if (data) { const list = data?.m_type === 1 ? data.media_component.images : data.media_component.videos; const imgs = list.map((it, index) => data?.m_type === 1 ? { url: it.urls[0], id: data.media_component.image_ids[index], } : { url: it.cover_urls[0], id: data.media_component.video_ids[index], } ); return imgs; } return []; }, [data]); useEffect(() => { setFormData((old) => ({ ...old, imageAssets: getExistImgs })); }, [getExistImgs]); return (
{/* 头部标题 */}
{ router.back(); }} />

重新编辑

{isSubmitting ? ( ) : ( 发布 )}
{/* 内容 */}
{data?.status === 3 && (data.text_audit_opinion || data.image_audit_opinion || data.manually_review_opinion) && (
违规详情
{data.text_audit_opinion && (

文案违规原因: {data.text_audit_opinion}

)} {data.image_audit_opinion && (

图片/视频违规原因: {data.image_audit_opinion}

)} {data.manually_review_opinion && (

运营追加: {data.manually_review_opinion}

)}
)}

动态内容