开发: 修改页面

This commit is contained in:
zhengw
2023-04-14 17:31:45 +08:00
parent b2bf2ade21
commit f4644b6ba2
11 changed files with 889 additions and 156 deletions

View File

@@ -1,13 +1,16 @@
import { post } from '@/services/ajax';
import { DownOutlined, UpOutlined } from '@ant-design/icons';
import { PageContainer } from '@ant-design/pro-components';
import { Form, Input, Modal, Tabs } from 'antd';
import { Drawer, Form, Input, Tabs } from 'antd';
import Spin from 'antd/lib/spin';
import { stringify } from 'qs';
import React, { useEffect, useRef, useState } from 'react';
import { DepartmentMembersDetail } from '../DepartmentsList/components/DepartmentMemberDetail';
import { IChat, ICustFollow, IGroup, IGroupMembers, IStaffsItem } from './ChatLogsType';
import { adminList, formatTags, groupMembersCount, groupMembersCount2 } from './ChatUtils';
import { ChatBar } from './components/ChatBar';
import { ChatTime } from './components/ChatTime';
import { Gender } from './components/Gender';
import styles from './index.module.scss';
interface ISearchWord {
'0': string;
@@ -70,7 +73,7 @@ const ChatLogs: React.FC = () => {
},
]);
const groupStatus = {
const groupStatus: any = {
'0': '跟进人正常',
'1': '跟进人离职',
'2': '离职继承中',
@@ -84,6 +87,8 @@ 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<any>();
@@ -95,6 +100,7 @@ const ChatLogs: React.FC = () => {
setFlolowsBox(false);
}
// 监听DOM变动
const callback = function (mutationsList: any) {
// Use traditional 'for loops' for IE 11
for (let mutation of mutationsList) {
@@ -128,9 +134,9 @@ const ChatLogs: React.FC = () => {
const getStaffsList = () => {
post({ url: '/Staffs/Data' }).then((res) => {
if (res.err_code == 0) {
if (Array.isArray(res.data)) {
if (Array.isArray(res.data) && res.data.length) {
// setSelectStaff(res.data[0]);
// selectStaffRef.current = res.data[0];
// selectStaffRef.current = res.data[0];
res.data.forEach((element: IStaffsItem) => {
if (element.user_id == 'yangxb') {
setSelectStaff(element);
@@ -156,7 +162,6 @@ const ChatLogs: React.FC = () => {
} else {
param.room_id = selectGroupRef.current?.group_id + '';
}
timeShowRef.current = false;
getChatLogsList();
};
@@ -183,27 +188,28 @@ const ChatLogs: React.FC = () => {
} else {
arr = [...temp, mark, ...chatLogs];
}
if (arr) {
let show_time = '';
arr.forEach((el, i) => {
el.show_time = false;
if (i == 0) {
el.show_time = true;
} else {
if (show_time == '') {
show_time = el.msg_time;
} else {
if (
new Date(el.msg_time).getTime() - new Date(show_time).getTime() >
5 * 60 * 1000
) {
el.show_time = true;
show_time = el.msg_time;
}
}
}
});
}
// 5分钟外显示时间
// if (arr) {
// let show_time = '';
// arr.forEach((el, i) => {
// el.show_time = false;
// if (i == 0) {
// el.show_time = true;
// } else {
// if (show_time == '') {
// show_time = el.msg_time;
// } else {
// if (
// new Date(el.msg_time).getTime() - new Date(show_time).getTime() >
// 5 * 60 * 1000
// ) {
// el.show_time = true;
// show_time = el.msg_time;
// }
// }
// }
// });
// }
setChatLogs(arr);
}
}
@@ -296,7 +302,22 @@ const ChatLogs: React.FC = () => {
}}
style={{ display: item.name.includes(searchWord['0']) ? '' : 'none' }}
>
<div className={styles.avatar}>{item.name[0]}</div>
<div className={styles.avatar}>
{item.avatar ? (
<img
src={item.avatar}
alt=""
style={{
maxWidth: '100%',
maxHeight: '100%',
objectFit: 'cover',
borderRadius: 4,
}}
/>
) : (
<>{item.name[0]}</>
)}
</div>
<div className={styles.chatAMsg}>
<div className={styles.chatAName} title={item.name}>
{item.name}
@@ -317,6 +338,7 @@ const ChatLogs: React.FC = () => {
<>
{custFollowsList.length ? (
custFollowsList.map((item) => {
if (item.state == 0) return null;
return (
<div
key={item.cust_id}
@@ -358,6 +380,68 @@ const ChatLogs: React.FC = () => {
</div>
)}
<div
className={`${styles.delFollowList} ${
delFollowListShow ? styles.delFollowListShow : ''
}`}
>
<div
className={styles.delFollowListBar}
onClick={() => {
setDelFollowListShow(!delFollowListShow);
}}
>
<span></span>
{delFollowListShow ? <UpOutlined /> : <DownOutlined />}
</div>
<div
className={`${styles.delFollowListBox} ${
delFollowListShow ? styles.delFollowListBoxShow : ''
}`}
>
{custFollowsList.map((item) => {
if (item.state == 1) return null;
return (
<div
key={item.cust_id}
className={`${styles.chatB} ${item.state == 0 ? styles.state0 : ''} ${
selectCustFollow?.cust_id == item.cust_id ? styles.active : ''
}`}
onClick={() => {
tabKeyRef.current = tabKey;
setSelectInnerStaff(undefined);
selectInnerStaffRef.current = undefined;
setSelectGroup(undefined);
selectGroupRef.current = undefined;
setSelectCustFollow(item);
selectCustFollowRef.current = item;
page(1);
}}
style={{ display: item.name.includes(searchWord['1']) ? '' : 'none' }}
>
<div
className={styles.avatar}
style={{ background: item?.avatar ? '#fff' : '' }}
>
<img
src={item.avatar}
alt=""
style={{ maxWidth: '100%', maxHeight: '100%', objectFit: 'cover' }}
/>
</div>
<div className={styles.chatAMsg} style={{ flexDirection: 'column' }}>
<div className={styles.chatAName} title={item.name}>
{item.name}
</div>
<div>{item.remark}</div>
</div>
</div>
);
})}
</div>
</div>
</>
);
} else {
@@ -365,6 +449,7 @@ const ChatLogs: React.FC = () => {
<>
{groupList.length ? (
groupList.map((item) => {
if (item.state == 0) return null;
return (
<div
key={item.group_id}
@@ -398,53 +483,62 @@ const ChatLogs: React.FC = () => {
</div>
)}
<div
className={`${styles.delFollowList} ${
delGroupListShow ? styles.delFollowListShow : ''
}`}
>
<div
className={styles.delFollowListBar}
onClick={() => {
setDelGroupListShow(!delGroupListShow);
}}
>
<span></span>
{delGroupListShow ? <UpOutlined /> : <DownOutlined />}
</div>
<div
className={`${styles.delFollowListBox} ${
delGroupListShow ? styles.delFollowListBoxShow : ''
}`}
>
{groupList.map((item) => {
if (item.state == 1) return null;
return (
<div
key={item.group_id}
className={`${styles.chatB} ${item.state == 0 ? styles.state0 : ''} ${
selectGroup?.group_id == item.group_id ? styles.active : ''
}`}
onClick={() => {
tabKeyRef.current = tabKey;
setSelectCustFollow(undefined);
selectCustFollowRef.current = undefined;
setSelectInnerStaff(undefined);
selectInnerStaffRef.current = undefined;
setSelectGroup(item);
selectGroupRef.current = item;
getGroupMembersList();
}}
style={{ display: item.name.includes(searchWord['2']) ? '' : 'none' }}
>
<div className={styles.avatar}>{item.name ? item.name[0] : '群'}</div>
<div className={styles.chatAMsg} style={{ flexDirection: 'column' }}>
<div className={styles.chatAName} title={item.name}>
{item.name || '未定义群名'}
</div>
<div style={{ color: '#999' }}>{groupStatus[item.status]}</div>
</div>
</div>
);
})}
</div>
</div>
</>
);
}
};
const formatTags = () => {
if (selectCustFollow?.tags) {
try {
const tags = JSON.parse(selectCustFollow?.tags);
if (Array.isArray(tags)) {
return (
<>
{tags.map((item) => {
return (
<div key={`${item.group_name}_${item.tag_name}`}>
{item.group_name}{item.tag_name}
</div>
);
})}
</>
);
}
} catch (e) {}
}
return <></>;
};
function adminList() {
if (selectGroupRef.current?.admin_list) {
try {
const msg = JSON.parse(selectGroupRef.current?.admin_list);
if (Array.isArray(msg) && msg.length) {
let arr: any = [];
msg.forEach((el) => {
arr.push(groupMembersObjRef.current[el.userid]?.name);
});
return <div>{arr.join('')}</div>;
}
} catch (e) {
return <></>;
}
}
return <></>;
}
return (
<PageContainer>
<div className={styles.box}>
@@ -470,9 +564,24 @@ const ChatLogs: React.FC = () => {
getCustFollowsList();
getGroupList();
}}
style={{ background: selectStaff?.user_id == item.user_id ? '#e6f4ff' : '' }}
style={{ background: selectStaff?.user_id == item.user_id ? '#bae0ff' : '' }}
>
<div className={styles.avatar}>{item.name[0]}</div>
<div className={styles.avatar}>
{item.avatar ? (
<img
src={item.avatar}
alt=""
style={{
maxWidth: '100%',
maxHeight: '100%',
objectFit: 'cover',
borderRadius: 4,
}}
/>
) : (
<>{item.name[0]}</>
)}
</div>
<div className={styles.chatAMsg}>
<div className={styles.chatAName} title={item.name}>
{item.name}
@@ -491,7 +600,22 @@ const ChatLogs: React.FC = () => {
>
{selectStaff ? (
<>
<div className={styles.avatar}>{selectStaff.name[0]}</div>
<div className={styles.avatar}>
{selectStaff.avatar ? (
<img
src={selectStaff.avatar}
alt=""
style={{
maxWidth: '100%',
maxHeight: '100%',
objectFit: 'cover',
borderRadius: 4,
}}
/>
) : (
<>{selectStaff.name[0]}</>
)}
</div>
<div className={styles.chatAMsg}>
<div className={styles.chatAName} title={selectStaff.name}>
{selectStaff.name}
@@ -529,7 +653,7 @@ const ChatLogs: React.FC = () => {
<div style={{ flex: 1 }}>
<div className={styles.logTop}>
<div
style={{ cursor: 'pointer' }}
style={{ cursor: 'pointer', fontSize: 18 }}
onClick={() => {
setOpen(true);
}}
@@ -539,43 +663,34 @@ const ChatLogs: React.FC = () => {
) : tabKeyRef.current == '1' ? (
<>{selectCustFollowRef.current?.name}</>
) : (
<>{selectGroupRef.current ? selectGroupRef.current?.name || '未定义群名' : ''}</>
<>
{selectGroupRef.current ? selectGroupRef.current?.name || '未定义群名' : ''}
{selectGroupRef.current ? <>{groupMembersList.length}</> : null}
</>
)}
</div>
<Modal
<Drawer
title={
tabKeyRef.current == '0' ? (
<>{selectInnerStaffRef.current?.name} </>
) : tabKeyRef.current == '1' ? (
<>{selectCustFollowRef.current?.name} </>
) : (
<>{selectGroupRef.current?.name || '未定义群名'} </>
<>
{selectGroupRef.current?.name || '未定义群名'} {groupMembersList.length}
</>
)
}
open={open}
centered
onCancel={() => setOpen(false)}
width={600}
onClose={() => setOpen(false)}
footer={false}
>
{tabKeyRef.current == '0' ? (
<div>
<div
style={{
display: 'flex',
borderBottom: '1px solid #ddd',
paddingBottom: 12,
marginBottom: 12,
}}
>
<div className={styles.modalAvatar}>{selectInnerStaff?.name[0]}</div>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<div style={{ fontSize: 16 }}>{selectInnerStaff?.name}</div>
</div>
</div>
<div>{selectInnerStaff?.name}</div>
<div>{selectInnerStaff?.telephone}</div>
<div>{selectInnerStaff?.position}</div>
</div>
<DepartmentMembersDetail
record={selectInnerStaff as IStaffsItem}
></DepartmentMembersDetail>
) : tabKeyRef.current == '1' ? (
<div>
<div
@@ -592,38 +707,39 @@ const ChatLogs: React.FC = () => {
<div style={{ display: 'flex', flexDirection: 'column' }}>
<div style={{ fontSize: 16 }}>
<span style={{ marginRight: 8 }}>{selectCustFollow?.name}</span>
{selectCustFollow?.gender == 1 ? (
<svg viewBox="0 0 1024 1024" width="16" height="16">
<path
d="M828.875 765.657c-191.159-16.86-202.516-102.922-202.516-102.922v-85.997c111.656-43.063 145.76-207.699 145.76-207.699 0-65.457-32.153-67.281-32.153-67.281V195.093c7.486-177.753-100.33-136.61-102.25-136.61-1.791 0-60.466-46.774-60.466-46.774-41.751-31.8-134.499 11.262-134.499 11.262l-3.839 0.064c-104.937 2.751-132.387 78.479-132.387 78.479l1.92 196.437c-54.804 0-47.35 76.719-47.35 76.719 0 84.142 147.616 200.148 147.616 200.148 9.47 110.472-49.174 166.46-49.174 166.46s-100.266 3.711-213.84 37.432c-2.72 0.863-5.344 1.6-7.967 2.463C30.617 817.421 0 920.855 0 920.855v101.033l463.579 1.888 68.465-1.92h491.732V943.25c1.92-115.815-194.901-177.593-194.901-177.593z m-244.65 129.22l-71.25 128.675-69.616-128.676-16.124-64.05 30.68-136.354h111.656l29.178 136.354-14.525 64.05z"
fill="#1890ff"
></path>
</svg>
) : (
<svg viewBox="0 0 1025 1024" width="16" height="16">
<path
d="M613.312 626.496v-11.2h151.296V318.08c0-124.736-113.152-225.856-252.608-225.856S259.392 193.344 259.392 318.08v297.216h151.36v11.072h-0.256L115.648 820.16v107.136H908.48v-105.92l-295.168-194.88z m7.68 186.752c-72.192 69.824-109.504-36.416-109.504-36.416s-37.312 106.24-109.568 36.416c0 0-31.744-20.544-35.136-158.208l144.704 121.728L656.192 655.04c-3.392 137.6-35.2 158.208-35.2 158.208z"
fill="#1890ff"
></path>
</svg>
)}
<Gender gender={selectCustFollow?.gender}></Gender>
</div>
<div style={{ color: '#666' }}>{selectCustFollow?.description}</div>
</div>
</div>
<div>{selectCustFollow?.remark}</div>
{formatTags()}
{formatTags(selectCustFollow?.tags)}
</div>
) : (
<div>
<div>
{groupMembersObjRef.current[selectGroupRef.current?.owner]?.name}
<div style={{ marginBottom: 8, textIndent: '2em' }}>
{groupMembersObjRef.current[selectGroupRef.current?.owner]?.name}
</div>
<div style={{ marginBottom: 8 }}>
{adminList(selectGroupRef.current?.admin_list, groupMembersObjRef.current)}
</div>
<div style={{ marginBottom: 8 }}>
{selectGroupRef.current?.create_time}
</div>
<div style={{ textIndent: '1em' }}>{selectGroupRef.current?.notice}</div>
<div
style={{
fontWeight: 'bold',
marginTop: 24,
marginBottom: 8,
borderBottom: '1px solid #ddd',
paddingBottom: 8,
}}
>
{groupMembersList.length}
</div>
<div>{adminList()}</div>
<div>{selectGroupRef.current?.create_time}</div>
<div>{selectGroupRef.current?.notice}</div>
<div style={{ fontWeight: 'bold', marginTop: 8, marginBottom: 8 }}>:</div>
{groupMembersList.map((item) => {
if (item.group_members_type == '2' || item.state == 0) return null;
return (
<div
key={item.user_id}
@@ -631,7 +747,7 @@ const ChatLogs: React.FC = () => {
display: 'inline-flex',
justifyContent: 'flex-start',
alignItems: 'center',
width: 64,
width: 80,
flexDirection: 'column',
verticalAlign: 'top',
marginTop: 12,
@@ -662,7 +778,133 @@ const ChatLogs: React.FC = () => {
minWidth: 0,
textOverflow: 'ellipsis',
overflow: 'hidden',
width: 56,
width: 72,
textAlign: 'center',
}}
title={item.name}
>
{item.name}
</div>
</div>
);
})}
{groupMembersCount2(groupMembersList, '2', 1) != 0 ? (
<div
style={{
fontWeight: 'bold',
marginTop: 24,
marginBottom: 8,
borderBottom: '1px solid #ddd',
paddingBottom: 8,
}}
>
</div>
) : null}
{groupMembersList.map((item) => {
if (item.group_members_type == '1' || item.state == 0) return null;
return (
<div
key={item.user_id}
style={{
display: 'inline-flex',
justifyContent: 'flex-start',
alignItems: 'center',
width: 80,
flexDirection: 'column',
verticalAlign: 'top',
marginTop: 12,
}}
>
<div className={styles.avatar}>
{item.avatar ? (
<img
style={{
maxWidth: '100%',
maxHeight: '100%',
objectFit: 'cover',
borderRadius: 4,
}}
src={item.avatar}
alt=""
/>
) : item.name ? (
item.name[0]
) : (
''
)}
</div>
<div
style={{
padding: '0 4px',
whiteSpace: 'nowrap',
minWidth: 0,
textOverflow: 'ellipsis',
overflow: 'hidden',
width: 72,
textAlign: 'center',
}}
title={item.name}
>
{item.name}
</div>
</div>
);
})}
{groupMembersCount(groupMembersList, 0) != 0 ? (
<div
style={{
fontWeight: 'bold',
marginTop: 24,
marginBottom: 8,
borderBottom: '1px solid #ddd',
paddingBottom: 8,
}}
>
</div>
) : null}
{groupMembersList.map((item) => {
if (item.state == 1) return null;
return (
<div
key={item.user_id}
style={{
display: 'inline-flex',
justifyContent: 'flex-start',
alignItems: 'center',
width: 80,
flexDirection: 'column',
verticalAlign: 'top',
marginTop: 12,
}}
>
<div className={styles.avatar}>
{item.avatar ? (
<img
style={{
maxWidth: '100%',
maxHeight: '100%',
objectFit: 'cover',
borderRadius: 4,
}}
src={item.avatar}
alt=""
/>
) : item.name ? (
item.name[0]
) : (
''
)}
</div>
<div
style={{
padding: '0 4px',
whiteSpace: 'nowrap',
minWidth: 0,
textOverflow: 'ellipsis',
overflow: 'hidden',
width: 72,
textAlign: 'center',
}}
title={item.name}
@@ -674,9 +916,9 @@ const ChatLogs: React.FC = () => {
})}
</div>
)}
</Modal>
</Drawer>
</div>
<Spin spinning={chatLogLoading} style={{ display: 'block' }}>
<Spin spinning={chatLogLoading} style={{ display: 'block' }} size="large">
<div
className={styles.chatLogBox}
ref={chatBoxRef}
@@ -707,7 +949,8 @@ const ChatLogs: React.FC = () => {
} else {
return (
<div key={item.msg_id}>
{item.show_time ? <ChatTime msgtime={item.msg_time}></ChatTime> : null}
{/* {item.show_time ? <ChatTime msgtime={item.msg_time}></ChatTime> : null} */}
<ChatTime msgtime={item.msg_time}></ChatTime>
{tabKey == '2' ? (
<ChatBar
from={selectStaff}
@@ -715,7 +958,15 @@ const ChatLogs: React.FC = () => {
chat={item}
></ChatBar>
) : (
<ChatBar from={selectStaff} to={selectCustFollow} chat={item}></ChatBar>
<ChatBar
from={selectStaff}
to={
tabKeyRef.current == '0'
? selectInnerStaffRef.current
: selectCustFollowRef.current
}
chat={item}
></ChatBar>
)}
</div>
);