开发: 添加及修改路由

This commit is contained in:
zhengw
2023-04-17 17:47:31 +08:00
parent f4644b6ba2
commit bc8bb916ee
12 changed files with 711 additions and 145 deletions

View File

@@ -12,11 +12,7 @@ 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;
'1': string;
'2': string;
}
const ChatLogs: React.FC = () => {
const [param] = useState({
curr_page: 1,
@@ -80,7 +76,7 @@ const ChatLogs: React.FC = () => {
'3': '离职继承完成',
};
const [searchWord, setSearchWord] = useState<ISearchWord>({
const [searchWord, setSearchWord] = useState<any>({
'0': '',
'1': '',
'2': '',
@@ -100,72 +96,6 @@ const ChatLogs: React.FC = () => {
setFlolowsBox(false);
}
// 监听DOM变动
const callback = function (mutationsList: any) {
// Use traditional 'for loops' for IE 11
for (let mutation of mutationsList) {
if (mutation.type === 'childList') {
document.querySelector('.curr_page' + param.curr_page)?.scrollIntoView(true);
} else if (mutation.type === 'attributes') {
console.log('The ' + mutation.attributeName + ' attribute was modified.');
}
}
};
const observer = new MutationObserver(callback);
useEffect(() => {
document.addEventListener('click', show, false);
getStaffsList();
observer.observe(chatBoxRef.current, { childList: true });
const myScript = document.createElement('script');
myScript.src = '/public/scripts/amrnb.js';
myScript.async = false;
document.body.appendChild(myScript);
return () => {
document.removeEventListener('click', show, false);
observer.disconnect();
document.body.removeChild(myScript);
};
}, []);
// 获取员工
const getStaffsList = () => {
post({ url: '/Staffs/Data' }).then((res) => {
if (res.err_code == 0) {
if (Array.isArray(res.data) && res.data.length) {
// setSelectStaff(res.data[0]);
// selectStaffRef.current = res.data[0];
res.data.forEach((element: IStaffsItem) => {
if (element.user_id == 'yangxb') {
setSelectStaff(element);
selectStaffRef.current = element;
}
});
setStaffsList(res.data);
setInnerStaffsList(res.data);
getCustFollowsList();
getGroupList();
}
}
});
};
const page = (curr: number) => {
param.curr_page = curr;
param.msg_from = selectStaffRef.current?.user_id + '';
if (tabKey == '0') {
param.msg_to_list = selectInnerStaffRef.current?.user_id + '';
} else if (tabKey == '1') {
param.msg_to_list = selectCustFollowRef.current?.cust_id + '';
} else {
param.room_id = selectGroupRef.current?.group_id + '';
}
timeShowRef.current = false;
getChatLogsList();
};
const getChatLogsList = () => {
chatLogLoadingRef.current = true;
setChatLogLoading(true);
@@ -216,6 +146,20 @@ const ChatLogs: React.FC = () => {
});
};
const page = (curr: number) => {
param.curr_page = curr;
param.msg_from = selectStaffRef.current?.user_id + '';
if (tabKey == '0') {
param.msg_to_list = selectInnerStaffRef.current?.user_id + '';
} else if (tabKey == '1') {
param.msg_to_list = selectCustFollowRef.current?.cust_id + '';
} else {
param.room_id = selectGroupRef.current?.group_id + '';
}
timeShowRef.current = false;
getChatLogsList();
};
const getGroupList = () => {
post({
url: '/Groups/GroupsList',
@@ -271,6 +215,58 @@ const ChatLogs: React.FC = () => {
});
};
// 获取员工
const getStaffsList = () => {
post({ url: '/Staffs/Data' }).then((res) => {
if (res.err_code == 0) {
if (Array.isArray(res.data) && res.data.length) {
setSelectStaff(res.data[0]);
selectStaffRef.current = res.data[0];
// res.data.forEach((element: IStaffsItem) => {
// if (element.user_id == 'yangxb') {
// setSelectStaff(element);
// selectStaffRef.current = element;
// }
// });
setStaffsList(res.data);
setInnerStaffsList(res.data);
getCustFollowsList();
getGroupList();
}
}
});
};
// 监听DOM变动
const callback = function (mutationsList: any) {
// Use traditional 'for loops' for IE 11
for (let mutation of mutationsList) {
if (mutation.type === 'childList') {
document.querySelector('.curr_page' + param.curr_page)?.scrollIntoView(true);
} else if (mutation.type === 'attributes') {
console.log('The ' + mutation.attributeName + ' attribute was modified.');
}
}
};
const observer = new MutationObserver(callback);
useEffect(() => {
document.addEventListener('click', show, false);
getStaffsList();
observer.observe(chatBoxRef.current, { childList: true });
const myScript = document.createElement('script');
myScript.src = '/public/scripts/amrnb.js';
myScript.async = false;
document.body.appendChild(myScript);
return () => {
document.removeEventListener('click', show, false);
observer.disconnect();
document.body.removeChild(myScript);
};
}, []);
// const { notification } = App.useApp();
const tabContent = () => {
if (tabKey == '0') {
@@ -549,7 +545,7 @@ const ChatLogs: React.FC = () => {
<div
key={item.user_id}
className={styles.chatB}
onClick={(e) => {
onClick={() => {
setSelectCustFollow(undefined);
selectCustFollowRef.current = undefined;
setSelectInnerStaff(undefined);
@@ -637,7 +633,7 @@ const ChatLogs: React.FC = () => {
setSearchWord({ ...searchWord });
}}
allowClear
></Input>
/>
</Form>
<Tabs
items={tabs}
@@ -647,7 +643,7 @@ const ChatLogs: React.FC = () => {
onChange={(val) => {
setTabKey(val);
}}
></Tabs>
/>
<div className={styles.chatBBox}>{tabContent()}</div>
</div>
<div style={{ flex: 1 }}>
@@ -688,9 +684,7 @@ const ChatLogs: React.FC = () => {
footer={false}
>
{tabKeyRef.current == '0' ? (
<DepartmentMembersDetail
record={selectInnerStaff as IStaffsItem}
></DepartmentMembersDetail>
<DepartmentMembersDetail record={selectInnerStaff as IStaffsItem} />
) : tabKeyRef.current == '1' ? (
<div>
<div
@@ -707,7 +701,7 @@ const ChatLogs: React.FC = () => {
<div style={{ display: 'flex', flexDirection: 'column' }}>
<div style={{ fontSize: 16 }}>
<span style={{ marginRight: 8 }}>{selectCustFollow?.name}</span>
<Gender gender={selectCustFollow?.gender}></Gender>
<Gender gender={selectCustFollow?.gender} />
</div>
<div style={{ color: '#666' }}>{selectCustFollow?.description}</div>
</div>
@@ -718,7 +712,8 @@ const ChatLogs: React.FC = () => {
) : (
<div>
<div style={{ marginBottom: 8, textIndent: '2em' }}>
{groupMembersObjRef.current[selectGroupRef.current?.owner]?.name}
{groupMembersObjRef.current[selectGroupRef.current?.owner as string]?.name}
</div>
<div style={{ marginBottom: 8 }}>
{adminList(selectGroupRef.current?.admin_list, groupMembersObjRef.current)}
@@ -937,26 +932,26 @@ const ChatLogs: React.FC = () => {
</div>
) : null}
{chatLogs.map((item, i) => {
{chatLogs.map((item) => {
if (item.curr_page) {
return (
<div
key={item.curr_page}
className={`curr_page${param.curr_page}`}
style={{ height: 0 }}
></div>
/>
);
} else {
return (
<div key={item.msg_id}>
{/* {item.show_time ? <ChatTime msgtime={item.msg_time}></ChatTime> : null} */}
<ChatTime msgtime={item.msg_time}></ChatTime>
<ChatTime msgtime={item.msg_time} />
{tabKey == '2' ? (
<ChatBar
from={selectStaff}
to={groupMembersObjRef.current[item.msg_from]}
chat={item}
></ChatBar>
/>
) : (
<ChatBar
from={selectStaff}
@@ -966,7 +961,7 @@ const ChatLogs: React.FC = () => {
: selectCustFollowRef.current
}
chat={item}
></ChatBar>
/>
)}
</div>
);