diff --git a/app/messageDetail/page.js b/app/messageDetail/page.js index d485f99..f4f7002 100644 --- a/app/messageDetail/page.js +++ b/app/messageDetail/page.js @@ -21,7 +21,10 @@ export default function MessageDetail({}) { // const [hasMore, setHasMore] = useState(true); const router = useRouter(); const searchParams = useSearchParams(); - const [oldMessages, setOldMessages] = useState([]); + const [oldMessages, setOldMessages] = useState({ + list: [], + isGetHistory: false, + }); const [messages, setMessages] = useState([]); const [handledmessages, setHandledmessages] = useState([]); const [sessionId, setSessionId] = useState(); @@ -61,9 +64,10 @@ export default function MessageDetail({}) { }, []); useEffect(() => { const intervalId = setInterval(() => { + // debugger; // console.log("oldMessages[0]", oldMessages[0]); - if (oldMessages[0]) { - updateMessages(oldMessages[0]?.id, 0, oldMessages); + if (oldMessages.list[0]) { + updateMessages(oldMessages.list[0]?.id, 0, oldMessages.list); // toScrollBottom.current = 1; } }, 3000); // 间隔时间为3秒 @@ -72,13 +76,14 @@ export default function MessageDetail({}) { return () => { clearInterval(intervalId); }; - }, [oldMessages]); + }, [oldMessages.list]); useEffect(() => { - if (toScrollBottom.current) { + // debugger; + if (toScrollBottom.current && !oldMessages.isGetHistory) { scrollBox.current?.scrollTo(0, scrollBox.current.scrollHeight + 50); toScrollBottom.current = 0; } - }, [messages]); + }, [oldMessages.list, oldMessages.isGetHistory]); useEffect(() => { if (sessionId && userInfo.mid) { loadEarlierHistory().then((res) => { @@ -191,7 +196,10 @@ export default function MessageDetail({}) { } setOffset(data.data.offset); 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]); setLoading(false); return mathNewMessages; @@ -269,7 +277,7 @@ export default function MessageDetail({}) { } } - const handleData = (list) => { + const handleData = (list, isGetHistory) => { // console.log("list", list); const account = get("account"); const temMessages = list.map((item) => { @@ -297,7 +305,9 @@ export default function MessageDetail({}) { user: { _id: 0, 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("[...messages, ...temMessages]", 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 mathNewMessages = newMessages.reduce( (accumulator, currentValue, index, sourceArray) => { @@ -445,7 +464,7 @@ export default function MessageDetail({}) { } // data.m_type===1?it?.text.split("|")it?.text }, - [sessionId] + [sessionId, oldMessages.list] ); return (
diff --git a/app/my/setting/feedback/page.js b/app/my/setting/feedback/page.js index 43e9a06..876c04d 100644 --- a/app/my/setting/feedback/page.js +++ b/app/my/setting/feedback/page.js @@ -43,8 +43,6 @@ export default function Feedback() { // console.log("media",media) const account = await get("account"); - debugger; - try { const data = await requireAPI( "POST", diff --git a/app/noticeDetail/components/MessageList/index.jsx b/app/noticeDetail/components/MessageList/index.jsx index 4f2af66..6fe1885 100644 --- a/app/noticeDetail/components/MessageList/index.jsx +++ b/app/noticeDetail/components/MessageList/index.jsx @@ -250,7 +250,9 @@ const MessageList = ({ mid, changeNoticeCount, refInstance, noticeCount }) => {

- {data?.recent_contact_cs_msg || "暂无新消息"} + {(data?.recent_contact_cs_msg?.includes("|") + ? data?.recent_contact_cs_msg?.split("|")[0] + : data?.recent_contact_cs_msg) || "暂无新消息"}