diff --git a/src/components/Common/PersonCenter/PersonCenter.js b/src/components/Common/PersonCenter/PersonCenter.js index 64f132c..682f59e 100644 --- a/src/components/Common/PersonCenter/PersonCenter.js +++ b/src/components/Common/PersonCenter/PersonCenter.js @@ -15,9 +15,12 @@ import { } from '@ant-design/icons'; import { Form } from '@ant-design/compatible'; -// import '@ant-design/compatible/assets/index.css'; +import '@ant-design/compatible/assets/index.css'; -import { Button, Input, Modal, Menu, Badge, message, Dropdown, Space, notification, Popover, Tabs } from 'antd-v4'; +import BraftEditor from 'braft-editor'; +import 'braft-editor/dist/index.css'; + +import { Button, Input, Modal, Menu, Badge, message, Dropdown, Space, notification, Popover, Tabs, Checkbox } from 'antd'; import styles from '@/routes/indexPage.less'; import config from '@/utils/config'; import * as commonUtils from '@/utils/utils'; @@ -54,6 +57,8 @@ class PersonCenter extends Component { addFaceVisible: false, sUserName: props.app.userinfo.sUserName, menuSearchPopoverVisible: false, + noticeVisible: false, // 新增:公告弹窗显示状态 + noticeChecked: false, // 新增:复选框选中状态 }; } componentWillMount() { @@ -67,6 +72,8 @@ class PersonCenter extends Component { message.warn(changePwd, 10); } + // 检查是否有公告数据需要显示 + this.checkNoticeData(); } componentWillReceiveProps(nextProps) { @@ -77,6 +84,8 @@ class PersonCenter extends Component { audio.play(); } } + // 检查是否有新的公告数据 + this.checkNoticeData(nextProps); } shouldComponentUpdate(nextProps) { const { pwdVisible } = this.state; @@ -188,6 +197,116 @@ class PersonCenter extends Component { dispatch({ type: 'app/addPane', payload: { pane } }); }; + + // 检查公告数据 + checkNoticeData = async (nextProps = null) => { + const props = nextProps || this.props; + const { noticeVisible = false } = this.state; + const msg = props.app.unRead; + const { sModelsId, formSrcRoute = '' } = props; + const msgObj = commonUtils.isJSON(msg) ? JSON.parse(msg) : {}; + const msgData = msgObj.data; /* 推送信息 */ + + // 如果有公告数据且尚未显示过,则显示公告弹窗 + if (commonUtils.isNotEmptyObject(msgData) && commonUtils.isNotEmptyObject(msgData.COPYTO) && + msgData.COPYTO.sMsgId && !noticeVisible) { + /* 根据sMsgId, sSlaveId 获取接口 */ + // eslint-disable-next-line prefer-destructuring + const sMsgId = msgData.COPYTO.sMsgId; + const sMsgSlaveId = msgData.COPYTO.sSlaveId; + // 1. 在调用接口前先检查是否已经显示过该公告 + const noticeKey = `${sMsgId}_${sMsgSlaveId}`; + + const shownNotices = JSON.parse(localStorage.getItem('shownNotices') || '[]'); + + // 如果已经显示过,直接返回,不调用接口 + if (shownNotices.includes(noticeKey)) { + console.log('公告已显示过,跳过接口调用:', noticeKey); + return; + } + + const dataUrl = `${commonConfig.server_host}notice/getNoticeDetail?sModelsId=${sModelsId}&sName=${formSrcRoute}`; + const condition = { + sMsgId, + sSlaveId: sMsgSlaveId, + }; + const configReturn = (await commonServices.postValueService(props.app?.token, condition, dataUrl)).data; + if (configReturn?.code === 1) { + const dataReturn = configReturn.dataset.rows; + + if (commonUtils.isNotEmptyArr(dataReturn) && commonUtils.isNotEmptyObject(dataReturn[0])) { + const noticeData = dataReturn[0]; + + // 3. 再次确认是否已显示(防止并发请求) + const currentShownNotices = JSON.parse(localStorage.getItem('shownNotices') || '[]'); + console.log('currentShownNotices1', currentShownNotices); + if (!currentShownNotices.includes(noticeKey)) { + this.setState({ + noticeVisible: true, + noticeData, + noticeTitle: noticeData?.msgData?.sTitle, + noticeChecked: false, + sMsgId, + sMsgSlaveId, + }); + } + } + } + } + } + + // 处理公告弹窗确定按钮点击 + handleNoticeConfirm = async () => { + if (this.state.noticeChecked) { + /* 调用接口把数据更新为已读 */ + const { app } = this.props; + const { sMsgId, sMsgSlaveId } = this.state; + + const { token } = app; + const configUrl = `${config.server_host}notice/updateNotice?sModelsId=${100}`; + const condition = { + sMsgId, + sSlaveId: sMsgSlaveId, + }; + const configReturn = (await commonServices.postValueService(token, condition, configUrl)).data; + if (configReturn?.code === 1) { + message.success('公告已阅读'); + // 在用户确认阅读后,才将公告记录存储到shownNotices中 + const noticeKey = `${sMsgId}_${sMsgSlaveId}`; + const currentShownNotices = JSON.parse(localStorage.getItem('shownNotices') || '[]'); + + if (!currentShownNotices.includes(noticeKey)) { + currentShownNotices.push(noticeKey); + // 限制存储最近100条记录,防止localStorage过大 + if (currentShownNotices.length > 100) { + currentShownNotices.shift(); + } + localStorage.setItem('shownNotices', JSON.stringify(currentShownNotices)); + } + } else { + message.error(configReturn?.msg); + } + this.setState({ + noticeVisible: false, + }); + } + } + + // 处理公告弹窗取消按钮点击 + handleNoticeCancel = () => { + this.setState({ + noticeVisible: false, + }); + } + + // 处理复选框变化 + handleNoticeCheckChange = (e) => { + this.setState({ + noticeChecked: e.target.checked, + }); + } + + handleSubmitPwd = (e) => { /* 阻止表单提交动作 */ e.preventDefault(); @@ -618,6 +737,14 @@ class PersonCenter extends Component { handleCancel={this.handleCancel} /> } + {/* 新增公告弹窗组件 */} + ); } @@ -894,13 +1021,13 @@ const PersonCenterOnlineUser = Form.create({ const gdsconfigformslaveNew = gdsconfigformslave.map(column => { const { sLanguage } = userinfo || {}; let showName = column.sChinese; // 默认中文 - + if (sLanguage === 'sEnglish' && column.sEnglishName) { showName = column.sEnglishName; } else if (sLanguage === 'sBig5' && column.sBig5Name) { showName = column.sBig5Name; } - + return { ...column, showName @@ -975,4 +1102,226 @@ const PersonCenterOnlineUser = Form.create({ ); }); +// 新增公告弹窗组件 +const PersonCenterNotice = Form.create({ + mapPropsToFields(props) { + }, +})((props) => { + const { + handleNoticeConfirm, + handleNoticeCancel, + handleNoticeCheckChange, + noticeVisible, + noticeData = {}, + noticeChecked, + app, + } = props; + + const noticeMsgData = noticeData?.msgData ; + + + const noticeFileData = noticeData?.fileData || [] ; + + + const NoticeTitle = noticeMsgData?.sTitle; + const NoticeContent = noticeMsgData?.sAbstractfullmemo || '暂无内容'; + + const Confirm = commonUtils.isNotEmptyObject(commonFunc.showMessage(app.commonConst, 'Confirm')) + ? commonFunc.showMessage(app.commonConst, 'Confirm') + : '确定'; + const Cancel = commonUtils.isNotEmptyObject(commonFunc.showMessage(app.commonConst, 'Cancel')) + ? commonFunc.showMessage(app.commonConst, 'Cancel') + : '取消'; + const NoticeAgree = commonUtils.isNotEmptyObject(commonFunc.showMessage(app.commonConst, 'NoticeAgree')) + ? commonFunc.showMessage(app.commonConst, 'NoticeAgree') + : '我已阅读并同意'; + + return ( +
+ { + noticeVisible ? + + + {NoticeAgree} + + +
+ ]} + > +
+ {/* 富文本内容区域 */} + {NoticeContent ? ( +
+ +
+ ) : ( +
+ 暂无公告内容 +
+ )} + + {/* 附件区域 - 与富文本区域明显分隔 */} + {commonUtils.isNotEmptyArr(noticeFileData) && ( +
+
+ {/* 左侧"附件"文字 */} +
+ 附件: +
+ + {/* 右侧附件链接区域 */} +
+ {noticeFileData.map(item => { + const {sId: uid, sFileName: name, sPicturePath} = item; + const fileUrl = `${commonConfig.server_host}file/download?savePathStr=${sPicturePath}&sModelsId=100`; + + return ( + e.currentTarget.style.textDecoration = 'underline'} + onMouseOut={(e) => e.currentTarget.style.textDecoration = 'none'} + > + + + + {name} + + ); + })} +
+
+
+ )} +
+ + + : '' + } + + ); +}); + export default PersonCenter;