会话列表: 搜索会话

dev/mobile
Lei OT 2 years ago
parent 5b724f1542
commit 1444ae70c3

@ -28,7 +28,7 @@ const ChatWindow = () => {
<Sider <Sider
width={240} width={240}
theme={'light'} theme={'light'}
className='h-full overflow-y-auto' className='h-full overflow-y-auto h-parent'
style={{ maxHeight: 'calc(100vh - 198px)', height: 'calc(100vh - 198px)' }} style={{ maxHeight: 'calc(100vh - 198px)', height: 'calc(100vh - 198px)' }}
collapsible={true} collapsible={true}
breakpoint='xl' breakpoint='xl'

@ -1,12 +1,12 @@
import { useEffect, useState } from 'react'; import { useEffect, useState, useRef } from 'react';
import { useParams, useNavigate, useLocation } from 'react-router-dom'; import { useParams, useNavigate, useLocation } from 'react-router-dom';
import { Button, Dropdown } from 'antd'; import { Button, Dropdown, Input } from 'antd';
import { MoreOutlined } from '@ant-design/icons'; import { MoreOutlined } from '@ant-design/icons';
import { fetchOrderConversationsList, fetchConversationItemClose, fetchMessages } from '@/actions/ConversationActions'; import { fetchOrderConversationsList, fetchConversationItemClose, fetchMessages } from '@/actions/ConversationActions';
import { ChatList, ChatItem } from 'react-chat-elements'; import { ChatList, ChatItem } from 'react-chat-elements';
import { isEmpty } from '@/utils/utils'; import { isEmpty } from '@/utils/utils';
import useConversationStore from '@/stores/ConversationStore'; import useConversationStore from '@/stores/ConversationStore';
import useAuthStore from '@/stores/AuthStore' import useAuthStore from '@/stores/AuthStore';
/** /**
* [] * []
@ -16,7 +16,7 @@ const Conversations = () => {
const { coli_guest_WhatsApp } = orderRow || {}; const { coli_guest_WhatsApp } = orderRow || {};
const { order_sn } = useParams(); const { order_sn } = useParams();
const navigate = useNavigate(); const navigate = useNavigate();
const userId = useAuthStore(state => state.loginUser.userId); const userId = useAuthStore((state) => state.loginUser.userId);
const initialState = useConversationStore((state) => state.initialState); const initialState = useConversationStore((state) => state.initialState);
const activeConversations = useConversationStore((state) => state.activeConversations); const activeConversations = useConversationStore((state) => state.activeConversations);
const currentConversation = useConversationStore((state) => state.currentConversation); const currentConversation = useConversationStore((state) => state.currentConversation);
@ -27,6 +27,8 @@ const Conversations = () => {
const receivedMessageList = useConversationStore((state) => state.receivedMessageList); const receivedMessageList = useConversationStore((state) => state.receivedMessageList);
const setMsgLoading = useConversationStore((state) => state.setMsgLoading); const setMsgLoading = useConversationStore((state) => state.setMsgLoading);
const [dataSource, setDataSource] = useState(conversationsList);
const [switchToC, setSwitchToC] = useState({}); const [switchToC, setSwitchToC] = useState({});
const [shouldFetchCList, setShouldFetchCList] = useState(true); const [shouldFetchCList, setShouldFetchCList] = useState(true);
useEffect(() => { useEffect(() => {
@ -91,14 +93,44 @@ const Conversations = () => {
navigate(`/order/chat`, { replace: true }); navigate(`/order/chat`, { replace: true });
} }
}; };
const searchInputRef = useRef(null);
const [searchContent, setSearchContent] = useState('');
const handleSearchConversations = (val) => {
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.coli_id.toLowerCase()).includes(val.toLowerCase().trim())
);
setDataSource(res);
return false;
}
setDataSource(conversationsList);
};
return ( return (
<> <div className='flex flex-col h-inherit'>
<div className=' overflow-x-hidden'> <div className=''>
{conversationsList.map((item) => ( <Input.Search
className=''
ref={searchInputRef}
onSearch={handleSearchConversations}
allowClear
value={searchContent}
onChange={(e) => {
setSearchContent(e.target.value);
handleSearchConversations(e.target.value);
}}
placeholder='搜索名称'
/>
</div>
<div className='flex-1 overflow-x-hidden overflow-y-auto relative'>
{dataSource.map((item) => (
<Dropdown <Dropdown
key={item.sn} key={item.sn}
menu={{ menu={{
items: [{ label: '关闭会话', key: 'close', danger: true, }], items: [{ label: '关闭会话', key: 'close', danger: true }],
onClick: ({ key, domEvent }) => { onClick: ({ key, domEvent }) => {
domEvent.stopPropagation(); domEvent.stopPropagation();
switch (key) { switch (key) {
@ -115,19 +147,21 @@ const Conversations = () => {
{...item} {...item}
key={item.sn} key={item.sn}
id={item.sn} id={item.sn}
letterItem={{id: item.whatsapp_name.trim() || item.whatsapp_phone_number, letter: (item.whatsapp_name.trim() || item.whatsapp_phone_number).slice(0, 5)}} letterItem={{ id: item.whatsapp_name.trim() || item.whatsapp_phone_number, letter: (item.whatsapp_name.trim() || item.whatsapp_phone_number).slice(0, 5) }}
alt={`${item.whatsapp_name.trim()}`} alt={`${item.whatsapp_name.trim()}`}
title={item.whatsapp_name.trim() || item.whatsapp_phone_number} title={item.whatsapp_name.trim() || item.whatsapp_phone_number}
subtitle={item.coli_id} subtitle={item.coli_id}
date={item.last_received_time} date={item.last_received_time}
unread={item.unread_msg_count} unread={item.unread_msg_count}
className={String(item.sn) === String(currentConversation.sn) ? '__active text-primary border-y-0 border-e-0 border-s-4 border-solid border-whatsapp-bg bg-whatsapp-bg' : ''} className={
String(item.sn) === String(currentConversation.sn) ? '__active text-primary border-y-0 border-e-0 border-s-4 border-solid border-whatsapp-bg bg-whatsapp-bg' : ''
}
onClick={() => onSwitchConversation(item)} onClick={() => onSwitchConversation(item)}
/> />
</Dropdown> </Dropdown>
))} ))}
</div> </div>
</> </div>
); );
}; };
export default Conversations; export default Conversations;

@ -42,6 +42,9 @@
} }
/** Chat Window */ /** Chat Window */
.chatwindow-wrapper .h-parent .ant-layout-side-children, .chatwindow-wrapper .h-inherit{
height: inherit;
}
.chatwindow-wrapper .rce-container-mbox .rce-mbox{ .chatwindow-wrapper .rce-container-mbox .rce-mbox{
max-width: 500px; max-width: 500px;
} }

Loading…
Cancel
Save