From c080970da51be466601206a110f09c20a5bd39a5 Mon Sep 17 00:00:00 2001
From: pengm <674192343@qq.com>
Date: Mon, 20 Oct 2025 10:33:53 +0800
Subject: [PATCH] 1.企业公告发布的内容。需要窗口弹出。即登录进去弹出公告内容,内容强制查看,确认已查看,未确认不能关闭,
---
src/components/Common/PersonCenter/PersonCenter.js | 357 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 353 insertions(+), 4 deletions(-)
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}
/>
}
+ {/* 新增公告弹窗组件 */}
+