tiefen_space_h5/app/noticeDetail/page.js

211 lines
5.8 KiB
JavaScript
Raw Normal View History

2024-12-13 18:24:36 +08:00
"use client";
2024-12-20 20:47:20 +08:00
import React, { useEffect, useRef, useState } from "react";
2025-01-03 11:42:14 +08:00
import { Tabs, Swiper, Toast, Dialog } from "antd-mobile";
2024-12-13 18:24:36 +08:00
import Link from "next/link";
import requireAPI from "@/utils/requireAPI";
import MessageList from "./components/MessageList";
import { get } from "@/utils/storeInfo";
2024-12-20 20:47:20 +08:00
import OwnIcon from "@/components/OwnIcon";
2024-12-13 18:24:36 +08:00
const tabItems = [{ key: "space", title: "消息" }];
// const scrollHeight = 700;
// const scrollHeight = window.innerHeight-126
export default function Space() {
const [activeIndex, setActiveIndex] = useState(0);
const [dataList, setDataList] = useState([]);
// const [spacePost, setSpacePost] = useState([]);
2024-12-24 12:14:28 +08:00
// const [hasMore, setHasMore] = useState(1);
// const [scrollHeight, setScrollHeight] = useState(0);
2024-12-13 18:24:36 +08:00
const [offset, setOffset] = useState(0);
const mesListEl = useRef(null);
const [account, setAccount] = useState(null);
// 获取屏幕高度
// const scrollHeight = 600;
useEffect(() => {
setAccount(get("account"));
2024-12-24 12:14:28 +08:00
// setScrollHeight(window.innerHeight - 57 - 44);
2024-12-13 18:24:36 +08:00
// const handleResize = () => {
// setScrollHeight(window.innerHeight - 126);
// };
// window.addEventListener("resize", handleResize);
// return () => {
// // window.removeEventListener("resize", handleResize);
// };
}, []);
useEffect(() => {
firstRequest();
}, [activeIndex]);
const firstRequest = () => {
resetOffset();
if (activeIndex === 0) {
getSpaceList();
}
if (activeIndex === 1) {
getSpacePosts(0).then((res) => {
res && setDataList(res);
});
}
};
const resetOffset = () => {
setOffset(0);
// setDataList([]);
};
const getSpaceList = async () => {
// setLoading(true);
try {
const data = await requireAPI("POST", "/api/zone/list_by_visitor_mid");
// setLoading(false);
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
}
//在末尾添加元素以展示查看更多卡片
if (data.data.list.length !== 0) {
const finalData = [...data.data.list];
setDataList(finalData);
return;
}
} catch (error) {
// console.error(error);
}
};
const getSpacePosts = async (offset) => {
// setLoading(true);
try {
const data = await requireAPI(
"POST",
"/api/zone_moment/list_by_visitor_mid",
{
body: { offset, limit: 4 },
}
);
// setLoading(false);
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
}
//在末尾添加元素以展示查看更多卡片
2024-12-24 12:14:28 +08:00
// setHasMore(data.data.more);
2024-12-13 18:24:36 +08:00
setOffset(data.data.offset);
if (data.data.list.length !== 0) {
const finalData = [...data.data.list];
return finalData;
}
} catch (error) {
// console.error(error);
}
};
async function loadMore() {
if (!offset) return;
const append = await getSpacePosts(offset);
if (append) {
setDataList((val) => [...val, ...append]);
// setHasMore(append.length > 0);
}
}
2024-12-17 17:31:50 +08:00
const handleReadAll = () => {
2025-01-03 11:42:14 +08:00
const showMobal = Dialog.show({
title: "提示",
2025-01-04 11:11:23 +08:00
content: <div className="text-center">是否确认清除所有未读消息</div>,
2025-01-03 11:42:14 +08:00
bodyStyle: {
maxHeight: "none",
width: "80vw",
position: "fixed",
top: "200px",
left: "10vw",
"--text-color": "#fff",
color: "#fff",
},
// cancelText:"确认",
// confirmText:"取消",
style: {
"--text-color": "#fff",
},
closeOnAction: true,
actions: [
[
{
key: "close",
text: "取消",
bold: true,
style: { color: "#ffffff80" },
onClick: () => {
showMobal?.close();
},
},
{
key: "submit",
text: "确认",
style: { color: "#fff" },
onClick: () => {
if (mesListEl.current) mesListEl.current.readAllMsg([0, 1, 2, 3]);
},
},
],
],
});
2024-12-17 17:31:50 +08:00
};
2025-01-03 11:42:14 +08:00
2024-12-13 18:24:36 +08:00
return (
<div className="">
<div className="flex justify-between items-center px-2 custom-tabs text-gray-400 sticky top-0 z-10 bg-deepBg">
<Tabs
activeKey={tabItems[activeIndex].key}
onChange={(key) => {
const index = tabItems.findIndex((item) => item.key === key);
setActiveIndex(index);
// swiperRef.current?.swipeTo(index);
}}
>
{tabItems.map((item) => (
<Tabs.Tab
forceRender={false}
title={item.title}
key={item.key}
className="text-left"
/>
))}
</Tabs>
2025-01-04 10:06:34 +08:00
<div className="flex space-x-4 mt-1">
2024-12-13 18:24:36 +08:00
<Link
href="search"
className="w-9 h-9 flex items-center justify-center bg-[#FFFFFF1A] rounded-full"
>
2024-12-20 20:47:20 +08:00
<OwnIcon src="/icons/search.png" className="scale-90" />
2024-12-13 18:24:36 +08:00
</Link>
<div
2025-01-04 10:06:34 +08:00
className="w-10 h-10 flex items-center justify-center rounded-full"
2024-12-13 18:24:36 +08:00
onClick={handleReadAll}
>
2025-01-04 10:06:34 +08:00
<OwnIcon
src="/icons/32DP/remove.png"
className="w-full h-full -mt-1 -ml-1"
/>
2024-12-13 18:24:36 +08:00
</div>
</div>
</div>
<Swiper
direction="horizontal"
indicator={() => null}
// ref={swiperRef}
defaultIndex={activeIndex}
onIndexChange={(index) => {
setActiveIndex(index);
}}
>
<Swiper.Item>
<MessageList ref={mesListEl} mid={account?.mid} />
</Swiper.Item>
</Swiper>
</div>
);
}