From ce3d942371031b0adbf7c40f7068ac69f86e3155 Mon Sep 17 00:00:00 2001 From: zhengw <247276359@qq.com> Date: Tue, 11 Apr 2023 15:29:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91:=20push?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.ts | 2 +- config/routes.ts | 8 +- src/app.tsx | 8 +- src/pages/ChatLogs/ChatBar.tsx | 271 ----------- src/pages/ChatLogs/ChatLogsType.ts | 36 ++ .../ChatLogs/components/ChatAgreeOrNot.tsx | 24 + src/pages/ChatLogs/components/ChatBar.tsx | 46 ++ src/pages/ChatLogs/components/ChatCard.tsx | 57 +++ src/pages/ChatLogs/components/ChatEmotion.tsx | 56 +++ src/pages/ChatLogs/components/ChatFile.tsx | 52 +++ src/pages/ChatLogs/components/ChatImage.tsx | 58 +++ src/pages/ChatLogs/components/ChatLink.tsx | 57 +++ .../ChatLogs/components/ChatLocation.tsx | 56 +++ src/pages/ChatLogs/components/ChatRecord.tsx | 52 +++ .../ChatLogs/components/ChatRedpacket.tsx | 63 +++ src/pages/ChatLogs/components/ChatRevoke.tsx | 21 + src/pages/ChatLogs/components/ChatText.tsx | 28 ++ src/pages/ChatLogs/components/ChatTime.tsx | 79 ++++ src/pages/ChatLogs/components/ChatVideo.tsx | 60 +++ src/pages/ChatLogs/components/ChatVoice.tsx | 56 +++ .../ChatLogs/components/index.module.scss | 111 +++++ src/pages/ChatLogs/index.module.scss | 199 ++++---- src/pages/ChatLogs/index.tsx | 421 +++++++++++------ src/pages/DepartmentsList/index.tsx | 429 +++++++----------- src/requestErrorConfig.ts | 20 +- src/services/ajax.ts | 13 +- src/services/utils.ts | 20 + 27 files changed, 1507 insertions(+), 796 deletions(-) delete mode 100644 src/pages/ChatLogs/ChatBar.tsx create mode 100644 src/pages/ChatLogs/ChatLogsType.ts create mode 100644 src/pages/ChatLogs/components/ChatAgreeOrNot.tsx create mode 100644 src/pages/ChatLogs/components/ChatBar.tsx create mode 100644 src/pages/ChatLogs/components/ChatCard.tsx create mode 100644 src/pages/ChatLogs/components/ChatEmotion.tsx create mode 100644 src/pages/ChatLogs/components/ChatFile.tsx create mode 100644 src/pages/ChatLogs/components/ChatImage.tsx create mode 100644 src/pages/ChatLogs/components/ChatLink.tsx create mode 100644 src/pages/ChatLogs/components/ChatLocation.tsx create mode 100644 src/pages/ChatLogs/components/ChatRecord.tsx create mode 100644 src/pages/ChatLogs/components/ChatRedpacket.tsx create mode 100644 src/pages/ChatLogs/components/ChatRevoke.tsx create mode 100644 src/pages/ChatLogs/components/ChatText.tsx create mode 100644 src/pages/ChatLogs/components/ChatTime.tsx create mode 100644 src/pages/ChatLogs/components/ChatVideo.tsx create mode 100644 src/pages/ChatLogs/components/ChatVoice.tsx create mode 100644 src/pages/ChatLogs/components/index.module.scss diff --git a/config/config.ts b/config/config.ts index 752cba6..d25bfef 100644 --- a/config/config.ts +++ b/config/config.ts @@ -59,7 +59,7 @@ export default defineConfig({ // proxy: proxy[REACT_APP_ENV as keyof typeof proxy], proxy: { '/api/': { - target: 'http://192.168.1.219:8183/', + target: 'http://192.168.1.138:8183/', changeOrigin: true, pathRewrite: { '^/api': '' }, }, diff --git a/config/routes.ts b/config/routes.ts index 98eab3b..823e3f4 100644 --- a/config/routes.ts +++ b/config/routes.ts @@ -55,11 +55,17 @@ export default [ component: './DepartmentsList', }, { - name: '聊天记录', + name: '成员聊天', icon: 'table', path: '/departments/page/list2', component: './ChatLogs', }, + { + name: '客户聊天', + icon: 'table', + path: '/departments/page/list3', + component: './ChatLogs', + }, ], }, // { diff --git a/src/app.tsx b/src/app.tsx index 51b63b1..c819e03 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -1,9 +1,9 @@ import Footer from '@/components/Footer'; -import { LinkOutlined, VerticalAlignTopOutlined } from '@ant-design/icons'; +import { LinkOutlined } from '@ant-design/icons'; import type { Settings as LayoutSettings } from '@ant-design/pro-components'; import type { RequestConfig, RunTimeLayoutConfig } from '@umijs/max'; import { history, Link } from '@umijs/max'; -import { App, FloatButton } from 'antd'; +import { App } from 'antd'; import React from 'react'; import defaultSettings from '../config/defaultSettings'; import { AvatarDropdown, AvatarName } from './components/RightContent/AvatarDropdown'; @@ -116,13 +116,13 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) = return ( <> {children} - } type="primary" onClick={() => { window.scrollTo(0, 0); }} - > + > */} {/* { - return ( -
-
-
- -
-
-
name
-
- 通过 message.useMessage 创建支持读取 context 的 - contextHolder。请注意,我们推荐通过顶层注册的方式代替 message - 静态方法,因为静态方法无法消费上下文,因而 ConfigProvider 的数据也不会生效。 - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -
-
-
-
-
-
name
-
- 通过 message.useMessage 创建支持读取 context 的 - contextHolder。请注意,我们推荐通过顶层注册的方式代替 message - 静态方法,因为静态方法无法消费上下文,因而 ConfigProvider 的数据也不会生效。 - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -
-
-
- -
-
-
- ); -}; - -interface IChatTimeProps { - msgtime: number; -} - -export const ChatTime: React.FC = (props) => { - function padWith(value: string | number) { - return `${value}`.padStart(2, '0'); - } - - const weekStr = ['日', '一', '二', '三', '四', '五', '六']; - - const formatTime = () => { - const now = new Date(); - const msgtime = new Date(props.msgtime); - console.log(msgtime.toLocaleString()); - - const yesterday = new Date(); - yesterday.setDate(yesterday.getDate() - 1); - const dayDiff = - (Date.parse( - `${now.getFullYear()}-${padWith(now.getMonth() + 1)}-${padWith(now.getDate())} 00:00:00`, - ) - - props.msgtime) / - (24 * 60 * 60 * 1000) + - 1; - - if (now.getFullYear() == msgtime.getFullYear()) { - if ( - now.getFullYear() == msgtime.getFullYear() && - now.getMonth() == msgtime.getMonth() && - now.getDate() == msgtime.getDate() - ) { - // 当天 - return `${padWith(msgtime.getHours())}:${padWith(msgtime.getMinutes())}`; - } else if ( - yesterday.getFullYear() == msgtime.getFullYear() && - yesterday.getMonth() == msgtime.getMonth() && - yesterday.getDate() == msgtime.getDate() - ) { - // 昨天 - return `昨天 ${padWith(msgtime.getHours())}:${padWith(msgtime.getMinutes())}`; - } else if (dayDiff < 7) { - // 星期 - return `星期${weekStr[msgtime.getDay()]} ${padWith(msgtime.getHours())}:${padWith( - msgtime.getMinutes(), - )}`; - } else { - // 超过7天 - return `${padWith(msgtime.getMonth() + 1)}月${padWith(msgtime.getDate())}日 ${padWith( - msgtime.getHours(), - )}:${padWith(msgtime.getMinutes())}`; - } - } else { - // 跨年 - return `${msgtime.getFullYear()}年${padWith(msgtime.getMonth() + 1)}月${padWith( - msgtime.getDate(), - )}日 ${padWith(msgtime.getHours())}:${padWith(msgtime.getMinutes())}`; - } - }; - - return ( -
-
- {formatTime()} -
-
- ); -}; - -export const ChatRevoke: React.FC = () => { - return ( -
- - "xxxxx" 撤回了一条消息 - -
- ); -}; - -export const ChatAgreeOrNot: React.FC = () => { - return ( -
- - 对方[不]同意存档会话内容,你将无法继续提供服务 - -
- ); -}; - -// 语音 -export const ChatVoice = () => { - return ( -
-
-
name
-
- 2" - - - -
-
-
- -
-
- ); -}; -// 视频 -export const ChatVideo = () => { - return ( -
-
-
name
-
- - 0:46 -
-
-
- -
-
- ); -}; - -// 名片 -export const ChatCard = () => { - return ( -
-
-
name
-
-
-
- -
-
腾讯
-
-
corpname
-
corpname2
-
个人名片
-
-
-
- -
-
- ); -}; - -// 表情 -export const ChatEmotion = () => { - return ( -
-
-
name
-
- -
-
-
- -
-
- ); -}; -// 文件 -export const ChatFile = () => { - return ( -
-
-
name
-
- -
-
-
- -
-
- ); -}; diff --git a/src/pages/ChatLogs/ChatLogsType.ts b/src/pages/ChatLogs/ChatLogsType.ts new file mode 100644 index 0000000..03a6b8a --- /dev/null +++ b/src/pages/ChatLogs/ChatLogsType.ts @@ -0,0 +1,36 @@ +export interface IStaffsItem { + user_id: string | number; + name: string; + telephone: string; + dep_name: string[]; + position: string; +} + +export interface ICustFollow { + cust_id: string; + cust_info: { + avatar: string; + cust_id: string; + gender: number; + name: string; + sync_time: string; + type: number; + }; +} + +export interface IChat { + action: string; + content: string; + msg_from: string; + msg_id: string; + msg_time: string; + msg_to_list: string; + msg_type: string; + room_id: string; +} +export interface IChatItem { + from?: IStaffsItem; + to?: ICustFollow; + group?: any; + chat?: IChat; +} diff --git a/src/pages/ChatLogs/components/ChatAgreeOrNot.tsx b/src/pages/ChatLogs/components/ChatAgreeOrNot.tsx new file mode 100644 index 0000000..45bdc39 --- /dev/null +++ b/src/pages/ChatLogs/components/ChatAgreeOrNot.tsx @@ -0,0 +1,24 @@ +interface IProps { + msg_type: string; +} +export const ChatAgreeOrNot: React.FC = (props) => { + return ( +
+ + 对方{props.msg_type == 'agree' ? '' : '不'}同意存档会话内容,你将无法继续提供服务 + +
+ ); +}; diff --git a/src/pages/ChatLogs/components/ChatBar.tsx b/src/pages/ChatLogs/components/ChatBar.tsx new file mode 100644 index 0000000..54d33fc --- /dev/null +++ b/src/pages/ChatLogs/components/ChatBar.tsx @@ -0,0 +1,46 @@ +import { IChatItem } from '../ChatLogsType'; +import { ChatAgreeOrNot } from './ChatAgreeOrNot'; +import { ChatCard } from './ChatCard'; +import { ChatEmotion } from './ChatEmotion'; +import { ChatFile } from './ChatFile'; +import { ChatImage } from './ChatImage'; +import { ChatLink } from './ChatLink'; +import { ChatLocation } from './ChatLocation'; +import { ChatRecord } from './ChatRecord'; +import { ChatRedpacket } from './ChatRedpacket'; +import { ChatRevoke } from './ChatRevoke'; +import { ChatText } from './ChatText'; +import { ChatVideo } from './ChatVideo'; +import { ChatVoice } from './ChatVoice'; + +export const ChatBar: React.FC = (props) => { + const { from, to, chat } = props; + if (chat?.msg_type == 'text') { + return ; + } else if (chat?.msg_type == 'file') { + return ; + } else if (chat?.msg_type == 'emotion') { + return ; + } else if (chat?.msg_type == 'card') { + return ; + } else if (chat?.msg_type == 'external_redpacket') { + return ; + } else if (chat?.msg_type == 'image') { + return ; + } else if (chat?.msg_type == 'link') { + return ; + } else if (chat?.msg_type == 'location') { + return ; + } else if (chat?.msg_type == 'video') { + return ; + } else if (chat?.msg_type == 'voice') { + return ; + } else if (chat?.msg_type == 'chatrecord') { + return ; + } else if (chat?.msg_type == 'revoke') { + return ; + } else if (chat?.msg_type == 'agree' || chat?.msg_type == 'disagree') { + return ; + } + return
; +}; diff --git a/src/pages/ChatLogs/components/ChatCard.tsx b/src/pages/ChatLogs/components/ChatCard.tsx new file mode 100644 index 0000000..765e6e7 --- /dev/null +++ b/src/pages/ChatLogs/components/ChatCard.tsx @@ -0,0 +1,57 @@ +import { IChatItem } from '../ChatLogsType'; +import styles from './index.module.scss'; +export const ChatCard: React.FC = (props) => { + function content() { + //
+ //
+ // + //
+ //
腾讯
+ //
+ //
corpname
+ //
corpname2
+ //
个人名片
+ try { + const msg = JSON.parse(props.chat?.content as string); + return ( +
+
{msg.corpname}
+
名片
+
+ ); + } catch (_e) { + return ( +
+
{props.chat?.content}
+
+ ); + } + } + + return ( + <> + {props.from?.user_id == props.chat?.msg_from ? ( +
+
+
{props.from?.name}
+
{content()}
+
+
{props.from?.name[0]}
+
+ ) : ( +
+
+ +
+
+
{props.to?.cust_info.name}
+
{content()}
+
+
+ )} + + ); +}; diff --git a/src/pages/ChatLogs/components/ChatEmotion.tsx b/src/pages/ChatLogs/components/ChatEmotion.tsx new file mode 100644 index 0000000..2e8373d --- /dev/null +++ b/src/pages/ChatLogs/components/ChatEmotion.tsx @@ -0,0 +1,56 @@ +import React from 'react'; +import { IChatItem } from '../ChatLogsType'; +import styles from './index.module.scss'; + +// 表情 +export const ChatEmotion: React.FC = (props) => { + function content() { + try { + const msg = JSON.parse(props.chat?.content as string); + + return ( +
+ +
+ ); + } catch (_e) { + return
{props.chat?.content}
; + } + } + + return ( + <> + {props.from?.user_id == props.chat?.msg_from ? ( +
+
+
{props.from?.name}
+
{content()}
+
+
{props.from?.name[0]}
+
+ ) : ( +
+
+ +
+
+
{props.to?.cust_info.name}
+
{content()}
+
+
+ )} + + ); +}; diff --git a/src/pages/ChatLogs/components/ChatFile.tsx b/src/pages/ChatLogs/components/ChatFile.tsx new file mode 100644 index 0000000..34fafcc --- /dev/null +++ b/src/pages/ChatLogs/components/ChatFile.tsx @@ -0,0 +1,52 @@ +import { FileTextFilled } from '@ant-design/icons'; +import { IChatItem } from '../ChatLogsType'; +import styles from './index.module.scss'; + +export const ChatFile: React.FC = (props) => { + function content() { + try { + const msg = JSON.parse(props.chat?.content as string); + return ( + +
{msg.file_name}
+ +
+ ); + } catch (_e) { + return ( +
+
{props.chat?.content}
+ +
+ ); + } + } + + return ( + <> + {props.from?.user_id == props.chat?.msg_from ? ( +
+
+
{props.from?.name}
+
{content()}
+
+
{props.from?.name[0]}
+
+ ) : ( +
+
+ +
+
+
{props.to?.cust_info.name}
+
{content()}
+
+
+ )} + + ); +}; diff --git a/src/pages/ChatLogs/components/ChatImage.tsx b/src/pages/ChatLogs/components/ChatImage.tsx new file mode 100644 index 0000000..70c7bba --- /dev/null +++ b/src/pages/ChatLogs/components/ChatImage.tsx @@ -0,0 +1,58 @@ +import { IChatItem } from '../ChatLogsType'; +import styles from './index.module.scss'; + +export const ChatImage: React.FC = (props) => { + function content() { + try { + const msg = JSON.parse(props.chat?.content as string); + + return ( +
+ +
+ ); + } catch (_e) { + return ( +
+
{props.chat?.content}
+
+ ); + } + } + + return ( + <> + {props.from?.user_id == props.chat?.msg_from ? ( +
+
+
{props.from?.name}
+
{content()}
+
+
{props.from?.name[0]}
+
+ ) : ( +
+
+ +
+
+
{props.to?.cust_info.name}
+
{content()}
+
+
+ )} + + ); +}; diff --git a/src/pages/ChatLogs/components/ChatLink.tsx b/src/pages/ChatLogs/components/ChatLink.tsx new file mode 100644 index 0000000..f961b65 --- /dev/null +++ b/src/pages/ChatLogs/components/ChatLink.tsx @@ -0,0 +1,57 @@ +import { IeSquareFilled } from '@ant-design/icons'; +import { IChatItem } from '../ChatLogsType'; +import styles from './index.module.scss'; + +export const ChatLink: React.FC = (props) => { + function content() { + try { + const msg = JSON.parse(props.chat?.content as string); + + return ( +
+
+
{msg.title}
+
{msg.description}
+ + {msg.link_url} + +
+ {msg.image_url ? ( + + ) : null} +
+ ); + } catch (_e) { + return ( +
+
{props.chat?.content}
+ +
+ ); + } + } + + return ( + <> + {props.from?.user_id == props.chat?.msg_from ? ( +
+
+
{props.from?.name}
+
{content()}
+
+
{props.from?.name[0]}
+
+ ) : ( +
+
+ +
+
+
{props.to?.cust_info.name}
+
{content()}
+
+
+ )} + + ); +}; diff --git a/src/pages/ChatLogs/components/ChatLocation.tsx b/src/pages/ChatLogs/components/ChatLocation.tsx new file mode 100644 index 0000000..d31e64b --- /dev/null +++ b/src/pages/ChatLogs/components/ChatLocation.tsx @@ -0,0 +1,56 @@ +import { EnvironmentFilled } from '@ant-design/icons'; +import { IChatItem } from '../ChatLogsType'; +import styles from './index.module.scss'; + +export const ChatLocation: React.FC = (props) => { + function content() { + try { + const msg = JSON.parse(props.chat?.content as string); + + return ( + +
+
{msg.title}
+
{msg.address}
+
+ +
+ ); + } catch (_e) { + return ( +
+
{props.chat?.content}
+ +
+ ); + } + } + + return ( + <> + {props.from?.user_id == props.chat?.msg_from ? ( +
+
+
{props.from?.name}
+
{content()}
+
+
{props.from?.name[0]}
+
+ ) : ( +
+
+ +
+
+
{props.to?.cust_info.name}
+
{content()}
+
+
+ )} + + ); +}; diff --git a/src/pages/ChatLogs/components/ChatRecord.tsx b/src/pages/ChatLogs/components/ChatRecord.tsx new file mode 100644 index 0000000..e0ed823 --- /dev/null +++ b/src/pages/ChatLogs/components/ChatRecord.tsx @@ -0,0 +1,52 @@ +import { FileTextFilled } from '@ant-design/icons'; +import { IChatItem } from '../ChatLogsType'; +import styles from './index.module.scss'; + +export const ChatRecord: React.FC = (props) => { + function content() { + try { + const msg = JSON.parse(props.chat?.content as string); + return ( + +
{msg.file_name}
+ +
+ ); + } catch (_e) { + return ( +
+
{props.chat?.content}
+ +
+ ); + } + } + + return ( + <> + {props.from?.user_id == props.chat?.msg_from ? ( +
+
+
{props.from?.name}
+
{content()}
+
+
{props.from?.name[0]}
+
+ ) : ( +
+
+ +
+
+
{props.to?.cust_info.name}
+
{content()}
+
+
+ )} + + ); +}; diff --git a/src/pages/ChatLogs/components/ChatRedpacket.tsx b/src/pages/ChatLogs/components/ChatRedpacket.tsx new file mode 100644 index 0000000..e6d0fa6 --- /dev/null +++ b/src/pages/ChatLogs/components/ChatRedpacket.tsx @@ -0,0 +1,63 @@ +import { RedEnvelopeFilled } from '@ant-design/icons'; +import { IChatItem } from '../ChatLogsType'; +import styles from './index.module.scss'; + +export const ChatRedpacket: React.FC = (props) => { + function content() { + try { + const msg = JSON.parse(props.chat?.content as string); + return ( +
+
+ +
+
{msg.wish}
+
+ {msg.totalcnt}个,{(msg.totalamount / 100).toFixed(2)}元 +
+
+
+
红包
+
+ ); + } catch (_e) { + return ( +
+
+ +
{props.chat?.content}
+
+
红包
+
+ ); + } + } + + return ( + <> + {props.from?.user_id == props.chat?.msg_from ? ( +
+
+
{props.from?.name}
+
{content()}
+
+
{props.from?.name[0]}
+
+ ) : ( +
+
+ +
+
+
{props.to?.cust_info.name}
+
{content()}
+
+
+ )} + + ); +}; diff --git a/src/pages/ChatLogs/components/ChatRevoke.tsx b/src/pages/ChatLogs/components/ChatRevoke.tsx new file mode 100644 index 0000000..39b7450 --- /dev/null +++ b/src/pages/ChatLogs/components/ChatRevoke.tsx @@ -0,0 +1,21 @@ +export const ChatRevoke: React.FC = () => { + return ( +
+ + 撤回了一条消息 + +
+ ); +}; diff --git a/src/pages/ChatLogs/components/ChatText.tsx b/src/pages/ChatLogs/components/ChatText.tsx new file mode 100644 index 0000000..5902dd8 --- /dev/null +++ b/src/pages/ChatLogs/components/ChatText.tsx @@ -0,0 +1,28 @@ +import { IChatItem } from '../ChatLogsType'; +import styles from './index.module.scss'; + +export const ChatText: React.FC = (props) => { + return ( +
+ {props.from?.user_id == props.chat?.msg_from ? ( +
+
+
{props.from?.name}
+
{props.chat?.content}
+
+
{props.from?.name[0]}
+
+ ) : ( +
+
+ +
+
+
{props.to?.cust_info.name}
+
{props.chat?.content}
+
+
+ )} +
+ ); +}; diff --git a/src/pages/ChatLogs/components/ChatTime.tsx b/src/pages/ChatLogs/components/ChatTime.tsx new file mode 100644 index 0000000..5892ebf --- /dev/null +++ b/src/pages/ChatLogs/components/ChatTime.tsx @@ -0,0 +1,79 @@ +interface IChatTimeProps { + msgtime: string; +} + +export const ChatTime: React.FC = (props) => { + function padWith(value: string | number) { + return `${value}`.padStart(2, '0'); + } + + const weekStr = ['日', '一', '二', '三', '四', '五', '六']; + + const formatTime = () => { + const now = new Date(); + const msgtime = new Date(props.msgtime); + + const yesterday = new Date(); + yesterday.setDate(yesterday.getDate() - 1); + const dayDiff = + (Date.parse( + `${now.getFullYear()}-${padWith(now.getMonth() + 1)}-${padWith(now.getDate())} 00:00:00`, + ) - + new Date(props.msgtime).getTime()) / + (24 * 60 * 60 * 1000) + + 1; + + if (now.getFullYear() == msgtime.getFullYear()) { + if ( + now.getFullYear() == msgtime.getFullYear() && + now.getMonth() == msgtime.getMonth() && + now.getDate() == msgtime.getDate() + ) { + // 当天 + return `${padWith(msgtime.getHours())}:${padWith(msgtime.getMinutes())}`; + } else if ( + yesterday.getFullYear() == msgtime.getFullYear() && + yesterday.getMonth() == msgtime.getMonth() && + yesterday.getDate() == msgtime.getDate() + ) { + // 昨天 + return `昨天 ${padWith(msgtime.getHours())}:${padWith(msgtime.getMinutes())}`; + } else if (dayDiff < 7) { + // 星期 + return `星期${weekStr[msgtime.getDay()]} ${padWith(msgtime.getHours())}:${padWith( + msgtime.getMinutes(), + )}`; + } else { + // 超过7天 + return `${padWith(msgtime.getMonth() + 1)}月${padWith(msgtime.getDate())}日 ${padWith( + msgtime.getHours(), + )}:${padWith(msgtime.getMinutes())}`; + } + } else { + // 跨年 + return `${msgtime.getFullYear()}年${padWith(msgtime.getMonth() + 1)}月${padWith( + msgtime.getDate(), + )}日 ${padWith(msgtime.getHours())}:${padWith(msgtime.getMinutes())}`; + } + }; + + return ( +
+
+ {formatTime()} +
+
+ ); +}; diff --git a/src/pages/ChatLogs/components/ChatVideo.tsx b/src/pages/ChatLogs/components/ChatVideo.tsx new file mode 100644 index 0000000..28c755d --- /dev/null +++ b/src/pages/ChatLogs/components/ChatVideo.tsx @@ -0,0 +1,60 @@ +import { PlayCircleOutlined } from '@ant-design/icons'; +import { IChatItem } from '../ChatLogsType'; +import styles from './index.module.scss'; + +export const ChatVideo: React.FC = (props) => { + function playLen(v: number) { + const len = Number(v) || 0; + if (len > 60) { + return `${Math.floor(len / 60) + .toString() + .padStart(2, '0')}:${(len % 60).toString().padStart(2, '0')}`; + } else { + return `00:${len.toString().padStart(2, '0')}`; + } + } + + function content() { + try { + const msg = JSON.parse(props.chat?.content as string); + // console.log(msg); + return ( + + + {playLen(msg.play_length)} + + ); + } catch (_e) { + return ( +
+
数据错误
+ +
+ ); + } + } + + return ( + <> + {props.from?.user_id == props.chat?.msg_from ? ( +
+
+
{props.from?.name}
+
{content()}
+
+
{props.from?.name[0]}
+
+ ) : ( +
+
+ +
+
+
{props.to?.cust_info.name}
+
{content()}
+
+
+ )} + + ); +}; diff --git a/src/pages/ChatLogs/components/ChatVoice.tsx b/src/pages/ChatLogs/components/ChatVoice.tsx new file mode 100644 index 0000000..b4113c6 --- /dev/null +++ b/src/pages/ChatLogs/components/ChatVoice.tsx @@ -0,0 +1,56 @@ +import { FileTextFilled } from '@ant-design/icons'; +import { IChatItem } from '../ChatLogsType'; +import styles from './index.module.scss'; + +export const ChatVoice: React.FC = (props) => { + function content() { + try { + const msg = JSON.parse(props.chat?.content as string); + + return ( + + + {msg.play_length}" + + + + + + ); + } catch (_e) { + return ( +
+
{props.chat?.content}
+ +
+ ); + } + } + + return ( + <> + {props.from?.user_id == props.chat?.msg_from ? ( +
+
+
{props.from?.name}
+
{content()}
+
+
{props.from?.name[0]}
+
+ ) : ( +
+
+ +
+
+
{props.to?.cust_info.name}
+
{content()}
+
+
+ )} + + ); +}; diff --git a/src/pages/ChatLogs/components/index.module.scss b/src/pages/ChatLogs/components/index.module.scss new file mode 100644 index 0000000..c8f0a08 --- /dev/null +++ b/src/pages/ChatLogs/components/index.module.scss @@ -0,0 +1,111 @@ +.chatLeft { + display: flex; + margin-bottom: 12px; + + .chatContentBox { + display: inline-flex; + flex-direction: column; + flex-shrink: 0; + max-width: 60%; + margin-left: 16px; + } +} + +.chatAvatar { + + flex-shrink: 0; + width: 34px; + height: 34px; + + img { + max-width: 100%; + max-height: 100%; + object-fit: cover; + background-color: #fff; + border-radius: 2px; + } +} + +.name { + margin-bottom: 8px; + color: #999; +} + +.content { + position: relative; + display: flex; + justify-content: center; + padding: 12px; + word-break: break-all; + background-color: #fff; + border-radius: 4px; + + &::before { + position: absolute; + top: 12px; + left: -6px; + width: 12px; + height: 12px; + background-color: #fff; + transform: rotate(45deg); + content: ''; + } + + &:hover, + &:hover::before { + background-color: #ebebeb; + } +} + +.chatRight { + display: flex; + justify-content: end; + margin-bottom: 12px; + + .name { + text-align: right; + } + + .chatContentBox { + display: inline-flex; + flex-direction: column; + flex-shrink: 0; + justify-content: end; + max-width: 60%; + margin-right: 16px; + } + + .content { + background-color: #95ec69; + + &::before { + right: -6px; + left: initial; + background-color: #95ec69; + } + + &:hover, + &:hover::before { + background-color: #89d961; + } + } +} + +.video { + position: relative; + display: flex; + align-items: center; + justify-content: center; + width: 176px; + height: 144px; + background-color: #333; + border-radius: 4px; + cursor: pointer; + + .videoTime { + position: absolute; + right: 8px; + bottom: 8px; + color: #fff; + } +} diff --git a/src/pages/ChatLogs/index.module.scss b/src/pages/ChatLogs/index.module.scss index 08c8688..bcf033d 100644 --- a/src/pages/ChatLogs/index.module.scss +++ b/src/pages/ChatLogs/index.module.scss @@ -1,109 +1,114 @@ -.chatLeft { +.box { display: flex; - - .chatContentBox { - display: inline-flex; - flex-direction: column; - flex-shrink: 0; - max-width: 60%; - margin-left: 16px; - } + border: 1px solid #ddd; } -.chatAvatar { - +.personnelBox { + position: relative; flex-shrink: 0; - width: 34px; - height: 34px; - - img { - max-width: 100%; - max-height: 100%; - object-fit: cover; - background-color: #fff; - border-radius: 2px; - } + width: 251px; + height: calc(100vh - 212px); + border-right: 1px solid #ddd; } -.name { - margin-bottom: 8px; - color: #999; -} - -.content { - position: relative; - display: flex; - justify-content: center; - padding: 12px; - word-break: break-all; - background-color: #fff; - border-radius: 4px; - - &::before { - position: absolute; - top: 12px; - left: -6px; - width: 12px; - height: 12px; - background-color: #fff; - transform: rotate(45deg); - content: ''; - } - - &:hover, - &:hover::before { - background-color: #ebebeb; - } -} - -.chatRight { - display: flex; - justify-content: end; - - .name { - text-align: right; - } - - .chatContentBox { - display: inline-flex; - flex-direction: column; - flex-shrink: 0; - justify-content: end; - max-width: 60%; - margin-right: 16px; - } - - .content { - background-color: #95ec69; - - &::before { - right: -6px; - left: initial; - background-color: #95ec69; - } - - &:hover, - &:hover::before { - background-color: #89d961; - } - } -} - -.video { - position: relative; +.chatA, +.chatB { display: flex; align-items: center; - justify-content: center; - width: 176px; - height: 144px; - background-color: #333; - border-radius: 4px; + justify-content: flex-start; + height: 65px; + margin-bottom: 12px; + padding: 0 12px; + border-bottom: 1px solid #ddd; cursor: pointer; - .videoTime { - position: absolute; - right: 8px; - bottom: 8px; - color: #fff; + &:hover { + background-color: #d6d6d7; + } + + &.active { + background-color: #c5c4c4; + } +} + +.chatB { + margin-bottom: 0; + border-bottom: none; +} + +.chatAMsg { + display: flex; + flex: 1; + align-items: flex-start; + min-width: 0; + height: 40px; + padding-left: 12px; + + .chatAName { + flex: 1; + flex-shrink: 0; + min-width: 0; + overflow: hidden; + font-size: 16px; + white-space: nowrap; + text-overflow: ellipsis; + } +} + +.avatar { + display: flex; + flex-shrink: 0; + align-items: center; + justify-content: center; + width: 40px; + height: 40px; + line-height: 1; + background-color: #fff; + border-radius: 4px; +} + + +.chatBBox { + height: calc(100vh - 212px - 164px); + overflow: auto; +} + +.chatLogBox { + height: calc(100vh - 212px - 66px); + padding: 12px; + overflow: auto; +} + +.logTop { + display: flex; + align-items: center; + width: 100%; + height: 65px; + padding: 0 12px; + border-bottom: 1px solid #ddd; +} + +.flolowsBox { + position: absolute; + top: 65px; + left: 0; + z-index: 1; + width: 100%; + max-height: 50vh; + overflow: auto; + background-color: #fff; + transform: translateY(20px); + visibility: hidden; + cursor: pointer; + opacity: 0; + transition: transform 0.3s, visibility 0.3s, opacity 0.3s; + pointer-events: none; + + &.show { + z-index: 1; + transform: translateY(0px); + visibility: visible; + opacity: 1; + pointer-events: all; } } diff --git a/src/pages/ChatLogs/index.tsx b/src/pages/ChatLogs/index.tsx index 5420bbd..dad0950 100644 --- a/src/pages/ChatLogs/index.tsx +++ b/src/pages/ChatLogs/index.tsx @@ -1,159 +1,306 @@ -import { SearchBarPlugin, SearchBottonsCardPlugin } from '@/components/SearchBarPlugin'; +import { post } from '@/services/ajax'; +import { DownOutlined, UpOutlined } from '@ant-design/icons'; import { PageContainer } from '@ant-design/pro-components'; -import { Button, Col, Form, Input, Pagination, Row, Select, Table } from 'antd'; -import React, { useState } from 'react'; -import { ChatBar, ChatTime } from './ChatBar'; - -interface DataType { - key: React.Key; - firstName: string; - lastName: string; - age: number; - address: string; - tags: string[]; -} +import { Form, Input, Tabs } from 'antd'; +import Spin from 'antd/lib/spin'; +import { stringify } from 'qs'; +import React, { useEffect, useRef, useState } from 'react'; +import { IChat, ICustFollow, IStaffsItem } from './ChatLogsType'; +import { ChatBar } from './components/ChatBar'; +import { ChatTime } from './components/ChatTime'; +import styles from './index.module.scss'; const ChatLogs: React.FC = () => { - const [param, setParam] = useState({ + const [param] = useState({ curr_page: 1, page_count: 20, + msg_from: '', + msg_to_list: '', }); + const tabKeyRef = useRef('0'); - const data: DataType[] = [ + const [selectStaff, setSelectStaff] = useState(); + const selectStaffRef = useRef(); + const [staffsList, setStaffsList] = useState([]); + const [custFollowsList, setCustFollowsList] = useState([]); + + const [selectCustFollow, setCustFollow] = useState(); + const selectCustFollowRef = useRef(); + const [chatLogs, setChatLogs] = useState([]); + + const [tabs] = useState([ + { + key: '0', + label: '内部联系人', + children: '', + }, { key: '1', - firstName: 'John', - lastName: 'Brown', - age: 32, - address: 'New York No. 1 Lake Park', - tags: ['nice', 'developer'], + label: '外部联系人', + children: '', }, { key: '2', - firstName: 'Jim', - lastName: 'Green', - age: 42, - address: 'London No. 1 Lake Park', - tags: ['loser'], + label: '客户群聊', + children: '', }, - { - key: '3', - firstName: 'Joe', - lastName: 'Black', - age: 32, - address: 'Sydney No. 1 Lake Park', - tags: ['cool', 'teacher'], - }, - ]; + ]); + + const [flolowsBoxShow, setFlolowsBox] = useState(false); + const timeDiffRef = useRef(''); + const timeShowRef = useRef(false); + const chatBoxRef = useRef(); + const isAllChatRef = useRef(false); + const chatLogLoadingRef = useRef(false); + const [chatLogLoading, setChatLogLoading] = useState(false); + + function show() { + setFlolowsBox(false); + } + + 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 }); + return () => { + document.removeEventListener('click', show, false); + observer.disconnect(); + }; + }, []); + + // 获取员工 + const getStaffsList = () => { + post({ url: '/Staffs/Data' }).then((res) => { + if (res.err_code == 0) { + if (Array.isArray(res.data)) { + // 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); + getCustFollowsList(); + } + } + }); + }; + + const page = (curr: number) => { + param.curr_page = curr; + param.msg_from = selectStaffRef.current?.user_id + ''; + param.msg_to_list = selectCustFollowRef.current?.cust_id + ''; + timeDiffRef.current = ''; + timeShowRef.current = false; + getChatLogsList(); + }; + + const getChatLogsList = () => { + chatLogLoadingRef.current = true; + setChatLogLoading(true); + post({ + url: '/ChatLogs/List', + data: stringify(param), + }).then((res) => { + const count = res.count || 0; + chatLogLoadingRef.current = false; + setChatLogLoading(false); + isAllChatRef.current = count < param.page_count * param.curr_page; + if (res.err_code == 0) { + if (Array.isArray(res.data)) { + if (param.curr_page == 1) { + setChatLogs([...res.data, { curr_page: param.curr_page }]); + } else { + setChatLogs([...res.data, { curr_page: param.curr_page }, ...chatLogs]); + } + } + } + }); + }; + + const getCustFollowsList = () => { + post({ + url: '/CustFollows/List', + data: stringify({ user_id: selectStaffRef.current?.user_id }), + }).then((res) => { + if (res.err_code == 0) { + if (Array.isArray(res.data)) { + setCustFollowsList(res.data); + if (res.data.length) { + setCustFollow(res.data[0]); + selectCustFollowRef.current = res.data[0]; + page(1); + } + } + } + }); + }; // const { notification } = App.useApp(); return ( - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - - - - - - - - -
+
+
+
+ {staffsList.map((item) => { + return ( +
{ + setSelectStaff({ ...item }); + selectStaffRef.current = { ...item }; + setFlolowsBox(false); + getCustFollowsList(); + }} + > +
{item.name[0]}
+
+
+ {item.name} +
+
+
+ ); + })} +
+
{ + e.stopPropagation(); + setFlolowsBox(!flolowsBoxShow); + }} + > + {selectStaff ? ( + <> +
{selectStaff.name[0]}
+
+
+ {selectStaff.name} +
+
+ {flolowsBoxShow ? : } + + ) : null} +
+
+ +
+ +
+ {custFollowsList.map((item) => { + return ( +
{ + setCustFollow(item); + selectCustFollowRef.current = item; + page(1); + }} + > +
+ +
+
+
+ {item.cust_info.name} +
+
+
+ ); + })} +
+
+
+
+
{selectCustFollowRef.current?.cust_info.name}
+
+ +
{ + if ( + e.target.scrollTop == 0 && + !isAllChatRef.current && + !chatLogLoadingRef.current + ) { + page(param.curr_page + 1); + } + }} + > + {isAllChatRef.current ? ( +
+ 没有更多聊天记录了 +
+ ) : null} + {chatLogs.map((item, i) => { + if (item.curr_page) { + return ( +
+ ); + } else { + if (timeDiffRef.current == '') { + timeDiffRef.current = item.msg_time; + timeShowRef.current = false; + } else { + if ( + Date.parse(item.msg_time) - Date.parse(timeDiffRef.current) > + 5 * 60 * 1000 + ) { + timeDiffRef.current = item.msg_time; + timeShowRef.current = true; + } else { + timeShowRef.current = false; + } + } - { - param.page_count = size; - setParam({ ...param }); - }} - showTotal={(total, range) => { - return 共{total}条; - }} - onChange={(page, pageSize) => { - param.curr_page = page; - setParam({ ...param }); - }} - /> + if (i == 0) { + timeShowRef.current = true; + } + + return ( +
+ {timeShowRef.current ? : null} + +
+ ); + } + })} +
+
+
+
); }; diff --git a/src/pages/DepartmentsList/index.tsx b/src/pages/DepartmentsList/index.tsx index 5bbc2ef..40986e4 100644 --- a/src/pages/DepartmentsList/index.tsx +++ b/src/pages/DepartmentsList/index.tsx @@ -1,187 +1,93 @@ import { SearchBarPlugin, SearchBottonsCardPlugin } from '@/components/SearchBarPlugin'; import { post } from '@/services/ajax'; -import { DeleteOutlined, FormOutlined } from '@ant-design/icons'; import { PageContainer } from '@ant-design/pro-components'; -import { - Button, - Col, - Form, - Input, - Modal, - Pagination, - Popconfirm, - Row, - Select, - Table, - Tree, -} from 'antd'; -import React, { useState } from 'react'; +import { Button, Col, Form, Input, Pagination, Row, Spin, Table, Tree } from 'antd'; +import { stringify } from 'qs'; +import React, { useEffect, useState } from 'react'; import styles from './index.module.scss'; -interface DataType { - key: React.Key; - firstName: string; - lastName: string; - age: number; - address: string; - tags: string[]; +interface IDepartment { + children: null | IDepartment[]; + department_leader: string; + id: number; + name: string; + parent_id: number; + sort: number; } +interface IStaffsItem { + user_id: string | number; + name: string; + telephone: string; + dep_name: string[]; + position: string; +} + +interface IStaffsData { + count: number; + data?: IStaffsItem[]; +} + +type Param = { + curr_page: number; + page_count: number; + dep_id: number; + name?: string; + position?: string; + telephone?: string; +}; + const DepartmentsList: React.FC = () => { - const [param, setParam] = useState({ + const [param] = useState({ curr_page: 1, page_count: 20, + dep_id: 0, }); - const [departmentID, setDepartmentsID] = useState(1); + const [departmentID, setDepartmentsID] = useState(0); + const [departmentsList, setDepartmentsList] = useState([]); + const [staffsData, setStaffsData] = useState({ count: 0, data: [] }); + const [loadingL, setLoadingL] = useState(false); + const [loading, setLoading] = useState(false); - const departments = [ - { - id: 1, - name: '福州晨丰科技有限公司', - parent_id: 0, - sort: 2147483447, - department_leader: 'chenf,LiXiang,CFRS', - children: [ - { - id: 2, - name: '总经办', - parent_id: 1, - sort: 2147483447, - department_leader: 'chenf', - children: null, - }, - { - id: 3, - name: '研发部', - parent_id: 1, - sort: 2147483247, - department_leader: 'yangxb', - children: [ - { - id: 18, - name: '.Net组', - parent_id: 3, - sort: 100005000, - department_leader: 'xief', - children: null, - }, - { - id: 19, - name: '平台组', - parent_id: 3, - sort: 100004000, - department_leader: 'yangxb', - children: null, - }, - { - id: 20, - name: 'CAD组', - parent_id: 3, - sort: 100003000, - department_leader: 'chenx', - children: null, - }, - { - id: 21, - name: '测试组', - parent_id: 3, - sort: 100001000, - department_leader: '', - children: null, - }, - { - id: 23, - name: '是的防守对方', - parent_id: 3, - sort: 100000000, - department_leader: '', - children: null, - }, - { - id: 24, - name: '12', - parent_id: 3, - sort: 99999000, - department_leader: '', - children: [ - { - id: 25, - name: '3', - parent_id: 24, - sort: 100000000, - department_leader: '', - children: null, - }, - ], - }, - { - id: 181, - name: '.Net组', - parent_id: 3, - sort: 100005000, - department_leader: 'xief', - children: null, - }, - { - id: 191, - name: '平台组', - parent_id: 3, - sort: 100004000, - department_leader: 'yangxb', - children: null, - }, - { - id: 201, - name: 'CAD组', - parent_id: 3, - sort: 100003000, - department_leader: 'chenx', - children: null, - }, - { - id: 211, - name: '测试组', - parent_id: 3, - sort: 100001000, - department_leader: '', - children: null, - }, - { - id: 231, - name: '是的防守对方是的防守对方是的防守对方是的防守对方', - parent_id: 3, - sort: 100000000, - department_leader: '', - children: null, - }, - ], - }, - ], - }, - ]; + const getDepartmentsList = () => { + setLoadingL(true); + post({ url: '/Departments/List' }).then((res) => { + setLoadingL(false); + if (res.err_code == 0) { + if (Array.isArray(res.data)) { + param.dep_id = res.data[0].id; + setDepartmentsID(param.dep_id); + setDepartmentsList(res.data); + getStaffsList(); + } + } + }); + }; + const getStaffsList = () => { + setLoading(true); + post({ url: '/Staffs/List', data: stringify(param) }).then((res) => { + setLoading(false); + if (res.err_code == 0) { + if (!Array.isArray(res.data)) { + res.data = []; + } + setStaffsData(res as IStaffsData); + } + }); + }; - const data: DataType[] = [ - { - key: '2', - firstName: 'Jim', - lastName: 'Green', - age: 42, - address: 'London No. 1 Lake Park', - tags: ['loser'], - }, - { - key: '3', - firstName: 'Joe', - lastName: 'Black', - age: 32, - address: 'Sydney No. 1 Lake Park', - tags: ['cool', 'teacher'], - }, - ]; + const page = (page: number) => { + param.curr_page = page; + getStaffsList(); + }; - const [open, setOpen] = useState(false); - const [popOpen, setPopOpen] = useState(-1); + useEffect(() => { + getDepartmentsList(); + }, []); + + // const [open, setOpen] = useState(false); + // const [popOpen, setPopOpen] = useState(-1); return ( @@ -200,28 +106,30 @@ const DepartmentsList: React.FC = () => { padding: '12px 0', }} > - { - console.log(selectedKeys); - if (selectedKeys.length) { - setDepartmentsID(Number(selectedKeys[0])); - } - }} - titleRender={(nodeData: any) => { - // console.log(nodeData); - return ( -
-
- {nodeData.name} -
-
+ + {departmentsList.length ? ( + { + if (selectedKeys.length) { + setDepartmentsID(Number(selectedKeys[0])); + param.dep_id = Number(selectedKeys[0]); + page(1); + } + }} + titleRender={(nodeData: any) => { + // console.log(nodeData); + return ( +
+
+ {nodeData.name} +
+ {/*
{ @@ -251,13 +159,15 @@ const DepartmentsList: React.FC = () => { className={styles.del} /> -
-
- ); - }} - >
+
*/} +
+ ); + }} + >
+ ) : null} + - setOpen(false)} @@ -269,12 +179,48 @@ const DepartmentsList: React.FC = () => { - + */}
-
+ - + + + { + param.name = e.target.value.trim(); + }} + allowClear + onPressEnter={() => page(1)} + > + + + + + { + param.position = e.target.value.trim(); + }} + allowClear + onPressEnter={() => page(1)} + > + + + + + { + param.telephone = e.target.value.trim(); + }} + allowClear + onPressEnter={() => page(1)} + > + + + {/* - - - - - - - - - - - - - - - - - - - - - - + */}
@@ -336,9 +242,7 @@ const DepartmentsList: React.FC = () => {
diff --git a/src/requestErrorConfig.ts b/src/requestErrorConfig.ts index 631fe36..54603a7 100644 --- a/src/requestErrorConfig.ts +++ b/src/requestErrorConfig.ts @@ -1,6 +1,6 @@ import type { RequestOptions } from '@@/plugin-request/request'; import type { RequestConfig } from '@umijs/max'; -import { message, notification } from 'antd'; +import { notificationError } from './services/utils'; // 错误处理方案: 错误类型 enum ErrorShowType { @@ -51,13 +51,13 @@ export const errorConfig: RequestConfig = { // do nothing break; case ErrorShowType.WARN_MESSAGE: - message.warning(errorMessage); + notificationError({ message: errorMessage }); break; case ErrorShowType.ERROR_MESSAGE: - message.error(errorMessage); + notificationError({ message: errorMessage }); break; case ErrorShowType.NOTIFICATION: - notification.open({ + notificationError({ description: errorMessage, message: errorCode, }); @@ -66,21 +66,23 @@ export const errorConfig: RequestConfig = { // TODO: redirect break; default: - message.error(errorMessage); + notificationError({ message: errorMessage }); } } } else if (error.response) { // Axios 的错误 // 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围 - message.error(`Response status:${error.response.status}`); + notificationError({ + message: `Response status:${error.response.status}`, + }); } else if (error.request) { // 请求已经成功发起,但没有收到响应 // \`error.request\` 在浏览器中是 XMLHttpRequest 的实例, // 而在node.js中是 http.ClientRequest 的实例 - message.error('None response! Please retry.'); + notificationError({ message: 'None response! Please retry.' }); } else { // 发送请求时出了点问题 - message.error('Request error, please retry.'); + notificationError({ message: 'Request error, please retry.' }); } }, }, @@ -102,7 +104,7 @@ export const errorConfig: RequestConfig = { const { data } = response as unknown as ResponseStructure; if (data?.success === false) { - message.error('请求失败!'); + notificationError({ message: '请求失败!' }); } return response; }, diff --git a/src/services/ajax.ts b/src/services/ajax.ts index 11556aa..811d33b 100644 --- a/src/services/ajax.ts +++ b/src/services/ajax.ts @@ -1,4 +1,5 @@ import { request } from '@umijs/max'; +import { notificationError } from './utils'; export interface IAjaxReturn { err_code: number; @@ -19,14 +20,10 @@ export const post = async (param: IPost) => { data: data, }).then((res: IAjaxReturn) => { if (res.err_code != 0 && showError) { - if (window.NotificationCF) { - window.NotificationCF.error({ - message: `${res.err_msg}`, - description: `${res.err_code}:${res.err_msg}`, - }); - } else { - console.log('window.NotificationCF未设置'); - } + notificationError({ + message: `${res.err_msg}`, + description: `${res.err_code}:${res.err_msg}`, + }); } return res; }); diff --git a/src/services/utils.ts b/src/services/utils.ts index ac292d3..2d4abb2 100644 --- a/src/services/utils.ts +++ b/src/services/utils.ts @@ -15,3 +15,23 @@ export const getDevice: IGetDevice = () => { return 'desktop'; } }; + +interface IError { + message: React.ReactNode; + description?: React.ReactNode; +} + +/** + * 只在ajax里面报错用 + * @param message IError + */ +export const notificationError = (message: IError) => { + if (window.NotificationCF) { + window.NotificationCF.error({ + message: message.message, + description: message.description || '', + }); + } else { + console.log('window.NotificationCF未绑定antd的notification'); + } +};