Merge branch 'anln_2.1' into anln_2.2

This commit is contained in:
al 2025-03-12 18:24:34 +08:00
commit 267795caee
3 changed files with 33 additions and 14 deletions

View File

@ -21,7 +21,10 @@ export default function MessageDetail({}) {
// const [hasMore, setHasMore] = useState(true); // const [hasMore, setHasMore] = useState(true);
const router = useRouter(); const router = useRouter();
const searchParams = useSearchParams(); const searchParams = useSearchParams();
const [oldMessages, setOldMessages] = useState([]); const [oldMessages, setOldMessages] = useState({
list: [],
isGetHistory: false,
});
const [messages, setMessages] = useState([]); const [messages, setMessages] = useState([]);
const [handledmessages, setHandledmessages] = useState([]); const [handledmessages, setHandledmessages] = useState([]);
const [sessionId, setSessionId] = useState(); const [sessionId, setSessionId] = useState();
@ -61,9 +64,10 @@ export default function MessageDetail({}) {
}, []); }, []);
useEffect(() => { useEffect(() => {
const intervalId = setInterval(() => { const intervalId = setInterval(() => {
// debugger;
// console.log("oldMessages[0]", oldMessages[0]); // console.log("oldMessages[0]", oldMessages[0]);
if (oldMessages[0]) { if (oldMessages.list[0]) {
updateMessages(oldMessages[0]?.id, 0, oldMessages); updateMessages(oldMessages.list[0]?.id, 0, oldMessages.list);
// toScrollBottom.current = 1; // toScrollBottom.current = 1;
} }
}, 3000); // 间隔时间为3秒 }, 3000); // 间隔时间为3秒
@ -72,13 +76,14 @@ export default function MessageDetail({}) {
return () => { return () => {
clearInterval(intervalId); clearInterval(intervalId);
}; };
}, [oldMessages]); }, [oldMessages.list]);
useEffect(() => { useEffect(() => {
if (toScrollBottom.current) { // debugger;
if (toScrollBottom.current && !oldMessages.isGetHistory) {
scrollBox.current?.scrollTo(0, scrollBox.current.scrollHeight + 50); scrollBox.current?.scrollTo(0, scrollBox.current.scrollHeight + 50);
toScrollBottom.current = 0; toScrollBottom.current = 0;
} }
}, [messages]); }, [oldMessages.list, oldMessages.isGetHistory]);
useEffect(() => { useEffect(() => {
if (sessionId && userInfo.mid) { if (sessionId && userInfo.mid) {
loadEarlierHistory().then((res) => { loadEarlierHistory().then((res) => {
@ -191,7 +196,10 @@ export default function MessageDetail({}) {
} }
setOffset(data.data.offset); setOffset(data.data.offset);
setMore(data.data.more); setMore(data.data.more);
let mathNewMessages = handleData([...oldMessages, ...data.data.list]); let mathNewMessages = handleData(
[...oldMessages.list, ...data.data.list],
oldMessages.list.length > 0
);
// setMessages((prev) => [...prev, ...temMessages]); // setMessages((prev) => [...prev, ...temMessages]);
setLoading(false); setLoading(false);
return mathNewMessages; return mathNewMessages;
@ -269,7 +277,7 @@ export default function MessageDetail({}) {
} }
} }
const handleData = (list) => { const handleData = (list, isGetHistory) => {
// console.log("list", list); // console.log("list", list);
const account = get("account"); const account = get("account");
const temMessages = list.map((item) => { const temMessages = list.map((item) => {
@ -297,7 +305,9 @@ export default function MessageDetail({}) {
user: { user: {
_id: 0, _id: 0,
name: "客服", name: "客服",
avatar: process.env.NEXT_PUBLIC_WEB_ASSETS_URL + "/images/icon.png", avatar:
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/images/icon_border.png",
}, },
}; };
} }
@ -305,7 +315,16 @@ export default function MessageDetail({}) {
// console.log("handledmessages......", handledmessages); // console.log("handledmessages......", handledmessages);
// console.log("[...messages, ...temMessages]", temMessages); // console.log("[...messages, ...temMessages]", temMessages);
setHandledmessages(temMessages); setHandledmessages(temMessages);
setOldMessages(list); setOldMessages((old) => {
// debugger;
if (old.list.length === list.length) {
return old;
} else {
// debugger;
return { list, isGetHistory: !!isGetHistory };
}
});
let newMessages = temMessages.reverse(); let newMessages = temMessages.reverse();
let mathNewMessages = newMessages.reduce( let mathNewMessages = newMessages.reduce(
(accumulator, currentValue, index, sourceArray) => { (accumulator, currentValue, index, sourceArray) => {
@ -445,7 +464,7 @@ export default function MessageDetail({}) {
} }
// data.m_type===1?it?.text.split("|")it?.text // data.m_type===1?it?.text.split("|")it?.text
}, },
[sessionId] [sessionId, oldMessages.list]
); );
return ( return (
<div className="bg-[#13121F] h-screen overflow-y-auto" ref={scrollBox}> <div className="bg-[#13121F] h-screen overflow-y-auto" ref={scrollBox}>

View File

@ -43,8 +43,6 @@ export default function Feedback() {
// console.log("media",media) // console.log("media",media)
const account = await get("account"); const account = await get("account");
debugger;
try { try {
const data = await requireAPI( const data = await requireAPI(
"POST", "POST",

View File

@ -250,7 +250,9 @@ const MessageList = ({ mid, changeNoticeCount, refInstance, noticeCount }) => {
</div> </div>
</div> </div>
<p className="text-xs text-[#FFFFFFB2]"> <p className="text-xs text-[#FFFFFFB2]">
{data?.recent_contact_cs_msg || "暂无新消息"} {(data?.recent_contact_cs_msg?.includes("|")
? data?.recent_contact_cs_msg?.split("|")[0]
: data?.recent_contact_cs_msg) || "暂无新消息"}
</p> </p>
</div> </div>
<div> <div>