diff --git a/src/actions/ConversationActions.js b/src/actions/ConversationActions.js index 620cf1e..d8d036c 100644 --- a/src/actions/ConversationActions.js +++ b/src/actions/ConversationActions.js @@ -36,11 +36,19 @@ export const fetchOrderConversationsList = async (params) => { return list; }; +/** + * + * @param {object} body { opisn, conversationid } + * @returns + */ export const fetchConversationItemClose = async (body) => { const { result } = await fetchJSON(`${API_HOST}/closeconversation`, body); return result; }; +/** + * @param {object} params { opisn, whatsappid } + */ export const fetchCleanUnreadMsgCount = async (params) => { const { errcode, result } = await fetchJSON(`${API_HOST}/clean_unread_msg_count`, params); return errcode !== 0 ? {} : result; diff --git a/src/stores/ConversationStore.js b/src/stores/ConversationStore.js index cc6f808..8dcd70a 100644 --- a/src/stores/ConversationStore.js +++ b/src/stores/ConversationStore.js @@ -298,10 +298,14 @@ export const useConversationStore = create( setInitial(true); - for (const chatItem of conversationsList) { + const autoGetMsgs = conversationsList.length > 5 ? 5 : conversationsList.length; + for (let index = 0; index < autoGetMsgs; index++) { + const chatItem = conversationsList[index]; const msgData = await fetchMessages({ opisn: chatItem.opi_sn, whatsappid: chatItem.whatsapp_phone_number }); receivedMessageList(chatItem.sn, msgData); } + // for (const chatItem of conversationsList) { + // } }, })) ); diff --git a/src/views/Conversations/Components/ConversationsList.jsx b/src/views/Conversations/Components/ConversationsList.jsx index 0b1e35b..84e3835 100644 --- a/src/views/Conversations/Components/ConversationsList.jsx +++ b/src/views/Conversations/Components/ConversationsList.jsx @@ -2,7 +2,7 @@ import { useEffect, useState, useRef } from 'react'; import { useParams, useNavigate, useLocation } from 'react-router-dom'; import { Button, Dropdown, Input } from 'antd'; import { MoreOutlined } from '@ant-design/icons'; -import { fetchOrderConversationsList, fetchConversationItemClose, fetchMessages } from '@/actions/ConversationActions'; +import { fetchOrderConversationsList, fetchConversationItemClose, fetchMessages, fetchCleanUnreadMsgCount } from '@/actions/ConversationActions'; import { ChatList, ChatItem } from 'react-chat-elements'; import { isEmpty } from '@/utils/utils'; import useConversationStore from '@/stores/ConversationStore'; @@ -28,6 +28,10 @@ const Conversations = () => { const setMsgLoading = useConversationStore((state) => state.setMsgLoading); const [dataSource, setDataSource] = useState(conversationsList); + useEffect(() => { + setDataSource(conversationsList); + return () => {}; + }, [conversationsList]); const [switchToC, setSwitchToC] = useState({}); const [shouldFetchCList, setShouldFetchCList] = useState(true); @@ -65,9 +69,10 @@ const Conversations = () => { receivedMessageList(item.sn, data); }; const switchConversation = async (item) => { + fetchCleanUnreadMsgCount({ opisn: item.opi_sn, whatsappid: item.whatsapp_phone_number }); const messagesList = activeConversations[`${item.sn}`] || []; if (messagesList.length < 20) { - await getMessages(item); + getMessages(item); } if (String(item.sn) === String(currentConversation.sn)) { return false; @@ -75,7 +80,7 @@ const Conversations = () => { setCurrentConversation(item); }; - const onSwitchConversation = (item) => { + const onSwitchConversation = async (item) => { if (!isEmpty(item.coli_sn)) { setSwitchToC(item); setShouldFetchCList(false); @@ -100,7 +105,7 @@ const Conversations = () => { if (val.toLowerCase().trim() !== '') { const res = conversationsList.filter( (item) => (item.whatsapp_name.toLowerCase()).includes(val.toLowerCase().trim()) - || (item.whatsapp_name.toLowerCase()).includes(val.toLowerCase().trim()) + || (item.whatsapp_phone_number.toLowerCase()).includes(val.toLowerCase().trim()) || (item.coli_id.toLowerCase()).includes(val.toLowerCase().trim()) ); setDataSource(res); @@ -122,6 +127,12 @@ const Conversations = () => { setSearchContent(e.target.value); handleSearchConversations(e.target.value); }} + onPressEnter={(e) => { + handleSearchConversations(e.target.value); + searchInputRef.current.blur(); + onSwitchConversation(dataSource[0]); + return false; + }} placeholder='搜索名称' />