From 9b85ccb8bbf27c84b4331c840dfe824f49b0b47a Mon Sep 17 00:00:00 2001 From: anln Date: Tue, 12 Nov 2024 18:01:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=B9=BF=E5=9C=BA=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/page.js | 34 +++- app/space/[id]/page.js | 15 +- app/space/createImagePost/page.jsx | 1 + app/space/createVideoPost/page.jsx | 1 + app/space/editSpacePost/{ => [zid]}/page.jsx | 85 ++++++-- app/space/setting/{ => [mid]}/page.js | 25 ++- .../spaceIntroSetting/{ => [mid]}/page.jsx | 11 +- .../setting/spacePaymentSetting/page.jsx | 2 +- app/streamerPosts/createPost/page.jsx | 189 ++++++++++++++++++ components/PostItem/index.js | 8 +- components/UploadImgs/index.js | 30 ++- 11 files changed, 334 insertions(+), 67 deletions(-) rename app/space/editSpacePost/{ => [zid]}/page.jsx (89%) rename app/space/setting/{ => [mid]}/page.js (91%) rename app/space/setting/spaceIntroSetting/{ => [mid]}/page.jsx (92%) create mode 100644 app/streamerPosts/createPost/page.jsx diff --git a/app/page.js b/app/page.js index 4c3d105..c8228c9 100644 --- a/app/page.js +++ b/app/page.js @@ -11,6 +11,7 @@ import { Tabs, Swiper, Toast, InfiniteScroll, List, Image } from "antd-mobile"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faRefresh } from "@fortawesome/free-solid-svg-icons"; import PostItem from "../components/PostItem"; +import { useRouter } from "next/navigation"; // import { sleep } from "antd-mobile/es/utils/sleep"; import "./index.css"; import PostItemSkeleton from "@/components/skeletons/PostItemSkeleton"; @@ -30,12 +31,23 @@ const tabItems = [ ]; export default function Home() { + const router = useRouter(); const recommPostRef = useRef(); const followPostRef = useRef(); const swiperRef = useRef(null); const [activeIndex, setActiveIndex] = useState(0); + const [streamerInfo, setStreamerInfo] = useState(null); const [scrollHeight, setScrollHeight] = useState(0); + + useEffect(() => { + const info = get("account"); + console.log("info",info) + if (info) { + setStreamerInfo(info); + } + }, [] + ) const childrenFunc = () => { if (!activeIndex) { recommPostRef.current?.doRefresh(); @@ -97,7 +109,7 @@ export default function Home() {
@@ -107,6 +119,25 @@ export default function Home() { style={{ maxWidth: "20px" }} />
+ {streamerInfo?.role === 3 && ( +
setIsCreatePostModalVisible(!isCreatePostModalVisible)} + className="fixed right-6 bottom-16" + style={{ zIndex: 999 }} + onClick={() => { + router.push("/streamerPosts/createPost"); + }} + > + +
+ )} @@ -122,6 +153,7 @@ const RecommPostList = forwardRef(({ scrollHeight }, ref) => { // setCommenPostList(res); // setHasMore(true) // }); + }, []); useImperativeHandle( ref, diff --git a/app/space/[id]/page.js b/app/space/[id]/page.js index 7e3e100..988214f 100644 --- a/app/space/[id]/page.js +++ b/app/space/[id]/page.js @@ -189,20 +189,7 @@ export default function PersonSpace() {
router.push( - "setting?data=" + - encodeURIComponent( - JSON.stringify({ - mid: streamerInfo?.mid, - id: streamerInfo?.id, - ct: streamerInfo?.streamer_ext?.ct, - user_id: streamerInfo?.streamer_ext?.user_id, - name: streamerInfo?.streamer_ext?.name, - visitor_role: streamerInfo?.visitor_role, - avatar: - streamerInfo?.streamer_ext?.avatar?.images[0]?.urls[0], - admission_price: streamerInfo?.admission_price, - }) - ) + "setting/" + streamerInfo?.mid ) } > diff --git a/app/space/createImagePost/page.jsx b/app/space/createImagePost/page.jsx index 3d58d67..6eee05b 100644 --- a/app/space/createImagePost/page.jsx +++ b/app/space/createImagePost/page.jsx @@ -287,6 +287,7 @@ export default function CreateImagePost() {
{ diff --git a/app/space/createVideoPost/page.jsx b/app/space/createVideoPost/page.jsx index 04c96ef..f1a71c9 100644 --- a/app/space/createVideoPost/page.jsx +++ b/app/space/createVideoPost/page.jsx @@ -254,6 +254,7 @@ export default function CreateVideoPost() {
setFormData((old) => ({ ...old, imageAssets: imgs })) diff --git a/app/space/editSpacePost/page.jsx b/app/space/editSpacePost/[zid]/page.jsx similarity index 89% rename from app/space/editSpacePost/page.jsx rename to app/space/editSpacePost/[zid]/page.jsx index 4d31dd1..59e9725 100644 --- a/app/space/editSpacePost/page.jsx +++ b/app/space/editSpacePost/[zid]/page.jsx @@ -4,12 +4,12 @@ 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, useSearchParams } from "next/navigation"; +import { useRouter, useSearchParams, useParams } from "next/navigation"; import { multiUploadImage } from "@/utils/upload"; import UploadImgs from "@/components/UploadImgs"; import OwnInput from "@/components/OwnInput"; export default function EditSpacePost() { - const searchParams = useSearchParams(); + const params = useParams(); const [data, setData] = useState(null); const [isSubmitting, setIsSubmitting] = useState(false); const [priceEdit, setPriceEdit] = useState(false); @@ -32,27 +32,67 @@ export default function EditSpacePost() { }); const router = useRouter(); useEffect(() => { - const dataStr = searchParams.get("data"); - const data = JSON.parse(decodeURIComponent(dataStr)); - setData(data); - const publicData = { - price: data?.price ? data?.price / 100 : 0, - imageVisibleRange: data?.media_visible_range, - isCreatingPaidText: data?.is_creating_paid_text, - isFreeForIronfan: data?.is_ironfan_visible, - blurCover: data?.is_blurring_cover == 1, - }; - // const imgs = getExistImgs(data); - setFormData({ - content: data?.paid_text - ? data?.text.slice(0, data?.text.length - data?.paid_text.length) - : data?.text, - paidText: data?.paid_text, - imageAssets: [], - ...publicData, - }); - setPriceEditData(publicData); + // const dataStr = searchParams.get("data"); + // const data = JSON.parse(decodeURIComponent(dataStr)); + const { zid } = params; + console.log("zid", zid); + getData(parseInt(zid, 10)); }, []); + const getData = async (zid) => { + try { + const body = { + ids: [zid], + }; + + 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 == "") { @@ -287,6 +327,7 @@ export default function EditSpacePost() { {data?.m_type && (
{ (async () => { - const currentData = searchParams.get("data"); - if (currentData) { - let data = await JSON.parse(decodeURIComponent(currentData)); - - await getSpaceData(Number(data.mid)).then((res) => { - setStreamerInfo({ ...data, refund_enable: res?.refund_enable }); + const {mid} = params; + if (mid) { + const info = await getStreamerInfo(Number(mid)); + await getSpaceData(Number(mid)).then((res) => { + setStreamerInfo({ ...info, refund_enable: res?.refund_enable }); }); } })(); @@ -126,7 +125,7 @@ export default function Setting() { className="flex justify-between items-center" onClick={() => { router.push( - "setting/spaceIntroSetting?data=" + searchParams.get("data") + "spaceIntroSetting/" + streamerInfo.mid ); }} > @@ -191,7 +190,7 @@ export default function Setting() {
  • - router.push("setting/spaceMember?zid=" + streamerInfo.id) + router.push("spaceMember?zid=" + streamerInfo.id) } className="flex justify-between" > @@ -208,7 +207,7 @@ export default function Setting() {
    router.push( - "setting/spacePaymentSetting?zid=" + streamerInfo.id + "spacePaymentSetting?zid=" + streamerInfo.id ) } className="flex justify-between" @@ -231,7 +230,7 @@ export default function Setting() {
    router.push( - "setting/spaceRefund?mid=" + + "spaceRefund?mid=" + streamerInfo.mid + "&id=" + streamerInfo.id diff --git a/app/space/setting/spaceIntroSetting/page.jsx b/app/space/setting/spaceIntroSetting/[mid]/page.jsx similarity index 92% rename from app/space/setting/spaceIntroSetting/page.jsx rename to app/space/setting/spaceIntroSetting/[mid]/page.jsx index 4542492..0774f83 100644 --- a/app/space/setting/spaceIntroSetting/page.jsx +++ b/app/space/setting/spaceIntroSetting/[mid]/page.jsx @@ -3,21 +3,22 @@ import OwnInput from "@/components/OwnInput"; import { Button, Divider, TextArea, Toast } from "antd-mobile"; import React, { useEffect, useState } from "react"; -import { useRouter, useSearchParams } from "next/navigation"; +import { useRouter, useSearchParams,useParams } from "next/navigation"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faAngleRight, faAngleLeft } from "@fortawesome/free-solid-svg-icons"; import { getStreamerInfo } from "@/api/space"; import requireAPI from "@/utils/requireAPI"; export default function SpaceIntroSetting() { - const searchParams = useSearchParams(); + const params = useParams(); const router = useRouter(); const [data, setData] = useState({}); const [isSubmitting, setIsSubmitting] = useState(false); //空间介绍 const [spaceIntro, setSpaceIntro] = useState(""); useEffect(() => { - const _data = decodeURIComponent(searchParams.get("data")); - getStreamerInfo(_data.mid).then((res) => { + // const _data = decodeURIComponent(searchParams.get("data")); + const {mid} = params + getStreamerInfo(parseInt(mid,10)).then((res) => { setData(res); setSpaceIntro(res?.profile); }); @@ -93,7 +94,7 @@ export default function SpaceIntroSetting() { />
    router.push("spaceIntroSetting/editStreamerMedia")} + onClick={() => router.push("editStreamerMedia")} className="flex justify-between py-2" >

    diff --git a/app/space/setting/spacePaymentSetting/page.jsx b/app/space/setting/spacePaymentSetting/page.jsx index 7f6350d..239e7a2 100644 --- a/app/space/setting/spacePaymentSetting/page.jsx +++ b/app/space/setting/spacePaymentSetting/page.jsx @@ -414,7 +414,7 @@ export default function spacePaymentSetting() {

    空间付费设置

    {/* 内容 */} -
    +

    diff --git a/app/streamerPosts/createPost/page.jsx b/app/streamerPosts/createPost/page.jsx new file mode 100644 index 0000000..d23f22b --- /dev/null +++ b/app/streamerPosts/createPost/page.jsx @@ -0,0 +1,189 @@ +"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 } = formData; + const newMedia = imageAssets.filter((it) => it.id == undefined); + const media = await multiUploadImage(newMedia, 1); + // const media = await multiUploadImage(imageAssets); + 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); + 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 ( +

    + {/* 头部标题 */} +
    +
    + { + router.back(); + }} + /> +
    +

    广场动态

    + {isSubmitting ? ( + + ) : ( + + 发布 + + )} +
    + {/* 内容 */} +
    +
    +

    动态内容

    +
    +