diff --git a/src/stores/ConversationStore.js b/src/stores/ConversationStore.js index 376ccd0..ad9cb34 100644 --- a/src/stores/ConversationStore.js +++ b/src/stores/ConversationStore.js @@ -1,6 +1,6 @@ import { create } from 'zustand'; import { RealTimeAPI } from '@/channel/realTimeAPI'; -import { olog, isEmpty, groupBy } from '@/utils/commons'; +import { olog, isEmpty, groupBy, sortArrayByOrder } from '@/utils/commons'; import { receivedMsgTypeMapped, handleNotification } from '@/channel/bubbleMsgUtils'; import { fetchConversationsList, fetchTemplates, fetchConversationsSearch, UNREAD_MARK, fetchTags } from '@/actions/ConversationActions'; import { devtools } from 'zustand/middleware'; @@ -299,9 +299,9 @@ const conversationSlice = (set, get) => ({ totalNotify: state.totalNotify - (conversation.unread_msg_count || 0), currentConversation: Object.assign({}, conversation, targetItemFromList), referenceMsg: {}, - topList: mergedListMapped['1'] || [], - pageList: mergedListMapped['0'] || [], - conversationsList: [...conversationsList], + // topList: mergedListMapped['1'] || [], + // pageList: mergedListMapped['0'] || [], + // conversationsList: [...conversationsList], })); }, updateCurrentConversation: (conversation) => set((state) => ({ currentConversation: { ...state.currentConversation, ...conversation } })), diff --git a/src/stores/OrderStore.js b/src/stores/OrderStore.js index bd7d23c..bfc3576 100644 --- a/src/stores/OrderStore.js +++ b/src/stores/OrderStore.js @@ -55,13 +55,13 @@ export const useOrderStore = create(devtools((set, get) => ({ if (json.errcode === 0 && json.result.length > 0) { const orderResult = json.result[0] set(() => ({ - orderDetail: orderResult, + orderDetail: {...orderResult, coli_sn: colisn }, customerDetail: orderResult.contact.length > 0 ? orderResult.contact[0] : {}, lastQuotation: orderResult.quotes.length > 0 ? orderResult.quotes[0] : {}, quotationList: orderResult.quotes, })) return { - orderDetail: orderResult, + orderDetail: {...orderResult, coli_sn: colisn }, customerDetail: orderResult.contact.length > 0 ? orderResult.contact[0] : {}, lastQuotation: orderResult.quotes.length > 0 ? orderResult.quotes[0] : {}, quotationList: orderResult.quotes, diff --git a/src/views/Conversations/Online/ConversationsList.jsx b/src/views/Conversations/Online/ConversationsList.jsx index e76a56b..23c61ea 100644 --- a/src/views/Conversations/Online/ConversationsList.jsx +++ b/src/views/Conversations/Online/ConversationsList.jsx @@ -106,26 +106,32 @@ const Conversations = () => { } useEffect(() => { + // console.log('effect []'); if (mobile !== false) { setCurrentConversation({}); + } else + if (order_sn ) { + setCurrentConversation({ coli_sn: Number(order_sn), sn: null }) + // updateCurrentConversation({ coli_sn: Number(order_sn) }); } return () => {}; }, []); - useEffect(() => { - if (order_sn && shouldFetchCList) { - setCurrentConversation({ coli_sn: Number(order_sn) }) - // updateCurrentConversation({ coli_sn: Number(order_sn) }); - } else { - // setCurrentConversation({ coli_sn: order_sn }) - } + // useEffect(() => { + // if (order_sn && shouldFetchCList) { + // setCurrentConversation({ coli_sn: Number(order_sn) }) + // // updateCurrentConversation({ coli_sn: Number(order_sn) }); + // } else { + // // setCurrentConversation({ coli_sn: order_sn }) + // } - return () => {} - }, [order_sn]) + // return () => {} + // }, [order_sn]) useEffect(() => { + // console.log('effect isVisible', isVisible); if (isVisible && initialState) { refreshConversationList(new Date()); // 无感刷新, 不显示上面的loading, } @@ -134,6 +140,7 @@ const Conversations = () => { }, [isVisible]); useEffect(() => { + // console.log('effect activeList'); if (isVisible && initialState) { refreshConversationList(); // 显示loading } @@ -150,15 +157,17 @@ const Conversations = () => { setDataSource([...topList, ...pageList]); // setDataSource(activeList ? conversationsList: closedConversationsList); return () => {}; - }, [conversationsList, listUpdateFlag, currentConversation.unread_msg_count]); + }, [conversationsList, topList, pageList, listUpdateFlag, currentConversation.unread_msg_count]); useEffect(() => { + // console.log('effect get order c'); + if (isEmpty(currentConversation.sn) && order_sn && shouldFetchCList && initialState) { getOrderConversationList(order_sn) } return () => {} - }, [order_sn, initialState, customerDetail.email]) + }, [initialState, customerDetail.email]) const getOrderConversationList = async (colisn) => { @@ -184,7 +193,7 @@ const Conversations = () => { findCurrent = findCurrentOrderChats[findCurrentIndex]; if (findCurrentIndex !== -1) { - addToConversationList(findCurrentOrderChats); + addToConversationList(findCurrentOrderChats, 'top'); } else // if (!isEmpty(whatsappID)) { try { @@ -201,8 +210,8 @@ const Conversations = () => { } } } - // else - if (isEmpty(whatsappID)) { + else { + // if (isEmpty(whatsappID) && findCurrentIndex === undefined) { // 刷新页面 findCurrentIndex = conversationsList.findIndex((item) => `${item.coli_sn}` === `${colisn}`); findCurrent = conversationsList[findCurrentIndex]; @@ -219,6 +228,8 @@ const Conversations = () => { const onSwitchConversation = async (item) => { setCurrentConversation(item); + + setShouldFetchCList(false); if (isEmpty(item.coli_sn)) { navigate(routePrefix, { replace: true }); } else { @@ -308,7 +319,7 @@ const Conversations = () => { /> )} - { refreshConversationList() }}