diff --git a/src/pages/ChatLogs/ChatLogsType.ts b/src/pages/ChatLogs/ChatLogsType.ts index cc2a9f8..930cd1b 100644 --- a/src/pages/ChatLogs/ChatLogsType.ts +++ b/src/pages/ChatLogs/ChatLogsType.ts @@ -66,6 +66,7 @@ export interface ICustFollow { export interface IGroup { admin_list: string; + avatar?: string; adminUserIDs: string[]; create_time: string; group_id: string; @@ -77,6 +78,7 @@ export interface IGroup { status: number; sync_time: string; notice: string; + type: number; } export interface IGroupMembers { diff --git a/src/pages/ChatLogs/GroupList.tsx b/src/pages/ChatLogs/GroupList.tsx new file mode 100644 index 0000000..8cd158f --- /dev/null +++ b/src/pages/ChatLogs/GroupList.tsx @@ -0,0 +1,147 @@ +import { groupStatus } from '@/services/config'; +import { DownOutlined, UpOutlined } from '@ant-design/icons'; +import { useEffect, useState } from 'react'; +import { IGroup } from './ChatLogsType'; +import styles from './index.module.scss'; + +type IProps = { + groupList: IGroup[]; + searchWord: string; + selectGroup: IGroup | undefined; + onClick: Function; +}; + +type IGroupObj = { + inner: IGroup[]; + outer: IGroup[]; + diss: IGroup[]; +}; + +export const GroupListWidget: React.FC = (props) => { + const [groupObj, setGroupObj] = useState({ + inner: [], + outer: [], + diss: [], + }); + + const [visible, setVisible] = useState('inner'); + const [overflow, setOverflow] = useState('inner'); + + const groupListItem = (item: IGroup) => { + return ( +
{ + props.onClick(item); + }} + > +
{item.name ? item.name[0] : '群'}
+
+
+ {item.name || '未知群名'} +
+
{groupStatus[item.status]}
+
+
+ ); + }; + + useEffect(() => { + let groupObjT: IGroupObj = { inner: [], outer: [], diss: [] }; + props.groupList.forEach((item) => { + item.name = item.name || '未知群聊'; + if (item.state == 0 && item.name.includes(props.searchWord)) { + groupObjT.diss.push(item); + } else if (item.state == 1 && item.type == 1 && item.name.includes(props.searchWord)) { + groupObjT.inner.push(item); + } else if (item.state == 1 && item.type == 2 && item.name.includes(props.searchWord)) { + groupObjT.outer.push(item); + } + }); + + setGroupObj(groupObjT); + }, [props.groupList, props.searchWord]); + + return ( +
+
{ + setVisible('inner'); + setOverflow(''); + setTimeout(() => { + setOverflow('inner'); + }, 300); + }} + > + 内部群聊 + {visible == 'inner' ? : } +
+
+ {groupObj.inner.map((item) => { + return groupListItem(item); + })} +
+ {groupObj.inner.length == 0 ? '暂无内部群聊' : ''} +
+
+
{ + setVisible('outer'); + setOverflow(''); + setTimeout(() => { + setOverflow('outer'); + }, 300); + }} + > + 外部群聊 + {visible == 'outer' ? : } +
+
+ {groupObj.outer.map((item) => { + return groupListItem(item); + })} +
+ {groupObj.outer.length == 0 ? '暂无外部群聊' : ''} +
+
+
{ + setVisible('diss'); + setOverflow(''); + setTimeout(() => { + setOverflow('diss'); + }, 300); + }} + > + 已解散群聊 + {visible == 'diss' ? : } +
+
+ {groupObj.diss.map((item) => { + return groupListItem(item); + })} +
+ {groupObj.diss.length == 0 ? '暂无已解散群聊' : ''} +
+
+
+ ); +}; diff --git a/src/pages/ChatLogs/components/ChatVote.tsx b/src/pages/ChatLogs/components/ChatVote.tsx index aceed2c..eb1d85e 100644 --- a/src/pages/ChatLogs/components/ChatVote.tsx +++ b/src/pages/ChatLogs/components/ChatVote.tsx @@ -31,7 +31,9 @@ export const ChatVote: React.FC = (props) => { {Array.isArray(msg?.voteitem) ? [0, 1, 2].map((item) => { return msg?.voteitem[item] ? ( -
{msg?.voteitem[item]}
+
+ {msg?.voteitem[item]} +
) : ( <> ); diff --git a/src/pages/ChatLogs/components/index.module.scss b/src/pages/ChatLogs/components/index.module.scss index 32521b3..536b6bd 100644 --- a/src/pages/ChatLogs/components/index.module.scss +++ b/src/pages/ChatLogs/components/index.module.scss @@ -22,8 +22,8 @@ border-radius: 4px; img { - max-width: 100%; - max-height: 100%; + width: 100%; + height: 100%; object-fit: cover; background-color: #fff; border-radius: 4px; diff --git a/src/pages/ChatLogs/index.module.scss b/src/pages/ChatLogs/index.module.scss index 31230a5..bb83ad1 100644 --- a/src/pages/ChatLogs/index.module.scss +++ b/src/pages/ChatLogs/index.module.scss @@ -22,9 +22,7 @@ padding: 0 12px; border-bottom: 1px solid #ddd; cursor: pointer; - &:first-child { - margin-top: 1px; - } + &:hover { background-color: #bae0ff; } @@ -66,6 +64,7 @@ justify-content: center; width: 40px; height: 40px; + overflow: hidden; line-height: 1; background-color: #69b1ff; border-radius: 4px; @@ -77,13 +76,32 @@ overflow: auto; } +.groupMenu { + position: relative; + height: calc(100vh - 212px - 164px); + + .groupListContent { + height: 0; + overflow: hidden; + transition: height 0.3s; + } + + .groupListContentShow { + height: calc(100% - 34px * 3); + } + + .groupListContentShowOver { + overflow: auto; + } +} + .delFollowList { position: absolute; top: calc(100% - 34px); z-index: 1; width: 100%; height: 34px; - background-color: #fff; + background-color: #f5f5f5; transition: top 0.3s, height 0.3s; .chatB { margin-top: 0; @@ -94,6 +112,7 @@ } } +.groupNav, .delFollowListBar { z-index: 1; display: flex; @@ -102,6 +121,7 @@ height: 34px; padding: 0 12px; color: #1890ff; + background: #fff; cursor: pointer; &:hover { diff --git a/src/pages/ChatLogs/index.tsx b/src/pages/ChatLogs/index.tsx index 4ed1871..00361ac 100644 --- a/src/pages/ChatLogs/index.tsx +++ b/src/pages/ChatLogs/index.tsx @@ -1,5 +1,4 @@ import { post } from '@/services/ajax'; -import { groupStatus } from '@/services/config'; import { DownOutlined, UpOutlined } from '@ant-design/icons'; import { PageContainer } from '@ant-design/pro-components'; import { Drawer, Form, Input, Tabs } from 'antd'; @@ -18,6 +17,7 @@ import { } from './ChatUtils'; import { ChatBar } from './components/ChatBar'; import { ChatTime } from './components/ChatTime'; +import { GroupListWidget } from './GroupList'; import styles from './index.module.scss'; const ChatLogs: React.FC = () => { @@ -41,16 +41,19 @@ const ChatLogs: React.FC = () => { const [innerStaffsList, setInnerStaffsList] = useState([]); const selectInnerStaffRef = useRef(); const [selectInnerStaff, setSelectInnerStaff] = useState(); + const [loadingInner, setLoadingInner] = useState(false); // 外部联系人 const [custFollowsList, setCustFollowsList] = useState([]); const [selectCustFollow, setSelectCustFollow] = useState(); const selectCustFollowRef = useRef(); + const [loadingOuter, setLoadingOuter] = useState(false); // 群聊 const [groupList, setGroupList] = useState([]); const selectGroupRef = useRef(); const [selectGroup, setSelectGroup] = useState(); + const [loadingGroup, setLoadingGroup] = useState(false); // 群成员 const [groupMembersList, setGroupMembersList] = useState([]); @@ -84,7 +87,6 @@ const ChatLogs: React.FC = () => { const [flolowsBoxShow, setFlolowsBox] = useState(false); const [delFollowListShow, setDelFollowListShow] = useState(false); - const [delGroupListShow, setDelGroupListShow] = useState(false); const timeShowRef = useRef(false); const chatBoxRef = useRef(); @@ -161,10 +163,12 @@ const ChatLogs: React.FC = () => { }; const getGroupList = () => { + setLoadingGroup(true); post({ url: '/Groups/ChatGroups', data: stringify({ user_id: selectStaffRef.current?.user_id }), }).then((res) => { + setLoadingGroup(false); if (res.err_code == 0) { if (Array.isArray(res.data)) { setGroupList(res.data); @@ -210,10 +214,12 @@ const ChatLogs: React.FC = () => { }; const getCustFollowsList = () => { + setLoadingOuter(true); post({ url: '/CustFollows/List', data: stringify({ user_id: selectStaffRef.current?.user_id }), }).then((res) => { + setLoadingOuter(false); if (res.err_code == 0) { if (Array.isArray(res.data)) { setCustFollowsList(res.data); @@ -229,7 +235,9 @@ const ChatLogs: React.FC = () => { // 获取员工 const getStaffsList = () => { + setLoadingInner(true); post({ url: '/Staffs/Data' }).then((res) => { + setLoadingInner(false); if (res.err_code == 0) { if (Array.isArray(res.data) && res.data.length) { setSelectStaff(res.data[0]); @@ -275,7 +283,7 @@ const ChatLogs: React.FC = () => { }, []); // 外部联系人Item - const custFollowsListItem = (item: ICustFollow) => { + const custFollowsListItem = (item: ICustFollow, i: number) => { return (
{ selectCustFollowRef.current = item; page(1); }} - style={{ display: item.name.includes(searchWord['1']) ? '' : 'none' }} + style={{ + display: item.name.includes(searchWord['1']) ? '' : 'none', + marginTop: i == 0 && item.state == 1 ? 1 : 0, + }} >
{ ); }; - // 客户群聊列表项 - const groupListItem = (item: IGroup) => { - return ( -
{ - tabKeyRef.current = tabKey; - setSelectCustFollow(undefined); - selectCustFollowRef.current = undefined; - setSelectInnerStaff(undefined); - selectInnerStaffRef.current = undefined; - setSelectGroup(item); - selectGroupRef.current = item; - selectGroupRef.current.adminUserIDs = getAdminList(item.admin_list); + const checkCustFollowsIsEmpty = (state: number) => { + for (const el of custFollowsList) { + if (el.name.includes(searchWord['1']) && el.state == state) { + return 1; + } + } + return 0; + }; - getGroupMembersList(); - }} - style={{ display: item.name.includes(searchWord['2']) ? '' : 'none' }} - > -
{item.name ? item.name[0] : '群'}
-
-
- {item.name || '未知群名'} -
-
{groupStatus[item.status]}
-
-
- ); + const checkInnerIsEmpty = () => { + for (const el of innerStaffsList) { + if (el.name.includes(searchWord['0']) && selectInnerStaff?.user_id != el.user_id) { + return 1; + } + } + return 0; }; // const { notification } = App.useApp(); @@ -351,90 +347,95 @@ const ChatLogs: React.FC = () => { if (tabKey == '0') { // 内部联系人 return ( - <> - {innerStaffsList.length ? ( - innerStaffsList.map((item) => { - if (item.user_id == selectStaff?.user_id) { - return null; - } - return ( -
{ - tabKeyRef.current = tabKey; + + {innerStaffsList.length + ? innerStaffsList.map((item) => { + if (item.user_id == selectStaff?.user_id) { + return null; + } + return ( +
{ + tabKeyRef.current = tabKey; - setSelectCustFollow(undefined); - selectCustFollowRef.current = undefined; - setSelectGroup(undefined); - selectGroupRef.current = undefined; + setSelectCustFollow(undefined); + selectCustFollowRef.current = undefined; + setSelectGroup(undefined); + selectGroupRef.current = undefined; - setSelectInnerStaff(item); - selectInnerStaffRef.current = item; - page(1); - }} - style={{ display: item.name.includes(searchWord['0']) ? '' : 'none' }} - > -
- {item.avatar ? ( - - ) : ( - <>{item.name[0]} - )} -
-
-
- {item.name} + setSelectInnerStaff(item); + selectInnerStaffRef.current = item; + page(1); + }} + style={{ display: item.name.includes(searchWord['0']) ? '' : 'none' }} + > +
+ {item.avatar ? ( + + ) : ( + <>{item.name[0]} + )} +
+
+
+ {item.name} +
-
- ); - }) - ) : ( -
- 暂无内部联系人 -
- )} - + ); + }) + : null} +
+ {checkInnerIsEmpty() == 0 ? '暂无内部联系人' : ''} +
+ ); } else if (tabKey == '1') { return ( - <> - {custFollowsList.length ? ( - custFollowsList.map((item) => { - return item.state == 0 ? null : custFollowsListItem(item); - }) - ) : ( -
- 暂无外部联系人 -
- )} - + + {custFollowsList.length + ? custFollowsList.map((item, i) => { + return item.state == 0 ? null : custFollowsListItem(item, i); + }) + : null} +
+ {checkCustFollowsIsEmpty(1) == 0 ? '暂无外部联系人' : ''} +
+
); } else { return ( - <> - {groupList.length ? ( - groupList.map((item) => { - return item.state == 0 ? null : groupListItem(item); - }) - ) : ( -
- 暂无客户群聊 -
- )} - + + { + tabKeyRef.current = tabKey; + setSelectCustFollow(undefined); + selectCustFollowRef.current = undefined; + setSelectInnerStaff(undefined); + selectInnerStaffRef.current = undefined; + setSelectGroup(item); + selectGroupRef.current = item; + selectGroupRef.current.adminUserIDs = getAdminList(item.admin_list); + getGroupMembersList(); + }} + selectGroup={selectGroup} + /> + ); } }; @@ -462,37 +463,17 @@ const ChatLogs: React.FC = () => { delFollowListShow ? styles.delFollowListBoxShow : '' }`} > - {custFollowsList.map((item) => { - return item.state == 1 ? null : custFollowsListItem(item); + {custFollowsList.map((item, i) => { + return item.state == 1 ? null : custFollowsListItem(item, i); })} +
+ {checkCustFollowsIsEmpty(0) == 0 ? '暂无已删联系人' : ''} +
); } else { - return ( -
-
{ - setDelGroupListShow(!delGroupListShow); - }} - > - 已解散的群 - {delGroupListShow ? : } -
-
- {groupList.map((item) => { - return item.state == 1 ? null : groupListItem(item); - })} -
-
- ); + return <>; } };