網站首頁 編程語言 正文
本文實例為大家分享了react實現消息顯示器的具體代碼,供大家參考,具體內容如下
效果
代碼實現
完整代碼:
import React from 'react';
import styles from './styles.less';
import badgeImg from '@/assets/leftmenu/badgeImg.png';
import router from 'umi/router';
import { connect } from 'dva';
import { Popover, Badge, Button, Modal } from 'antd';
function mapStateToProps({ InformationModel }) {
? ? return {
? ? ? ? InformationModel: InformationModel,
? ? };
}
@connect(mapStateToProps)
class Information extends React.Component {
? ? constructor(props) {
? ? ? ? super(props);
? ? ? ? this.state = {
? ? ? ? ? ? visible: false,
? ? ? ? ? ? unreadList: [],
? ? ? ? ? ? infoTitle: '',
? ? ? ? ? ? infoContent:'',
? ? ? ? };
? ? }
? ? //渲染前調用
? ? componentWillMount() { }
? ? //渲染后調用
? ? componentDidMount() {
? ? ? ? this.getunreadDatas();
? ? }
? ? //調用接口獲取未讀數據
? ? getunreadDatas() {
? ? ? ? let { dispatch } = this.props;
? ? ? ? let userid = localStorage.getItem('userid');
? ? ? ? let params = {
? ? ? ? ? ? id: userid,
? ? ? ? ? ? pageNum: 0,
? ? ? ? ? ? pageSize: 0
? ? ? ? }
? ? ? ? dispatch({ type: 'InformationModel/getunreadData', payload: { params: params, callback: this.unreadCallback.bind(this) } });
? ? }
? ? //接口回調方法
? ? unreadCallback(e) {
? ? ? ? this.setState({
? ? ? ? ? ? unreadList:e
? ? ? ? })
? ? }
? ? //查看詳情
? ? showInfo(e) {
? ? ? ? let { dispatch } = this.props;
? ? ? ? let userid = localStorage.getItem('userid');
? ? ? ? let params = {
? ? ? ? ? ? id:e.id,
? ? ? ? ? ? userId:userid,
? ? ? ? }
? ? ? ? //調用接口標記已讀
? ? ? ? dispatch({ type: 'InformationModel/getreadData', payload: { params: params, callback: this.readCallback.bind(this) } });
? ? ? ? this.setState({
? ? ? ? ? ? infoTitle:e.name,
? ? ? ? ? ? infoContent:e.text
? ? ? ? })
? ? }
? ? //標記接口回調函數
? ? readCallback(e){
? ? ? ? this.setState({
? ? ? ? ? ? visible: true,
? ? ? ? });
? ? ? ? //刷新列表
? ? ? ? this.getunreadDatas();
? ? }
? ? //顯示全部
? ? showAllInfo(){
? ? ? ? router.push({
? ? ? ? ? ? pathname: `/cs/InformationMoreList`,
? ? ? ? ? ? query: {
? ? ? ? ? ? },
? ? ? ? });
? ? }
? ? //彈框確認按鈕
? ? handleOk = e => {
? ? ? ? console.log(e);
? ? ? ? this.setState({
? ? ? ? ? ? visible: false,
? ? ? ? });
? ? };
? ? //彈框取消按鈕
? ? handleCancel = e => {
? ? ? ? console.log(e);
? ? ? ? this.setState({
? ? ? ? ? ? visible: false,
? ? ? ? });
? ? };
? ? render() {
? ? ? ? const content = (
? ? ? ? ? ? <div className={styles.infoTabs}>
? ? ? ? ? ? ? ? <div className={styles.infoList}>
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? this.state.unreadList.map((item,index)=>{
? ? ? ? ? ? ? ? ? ? ? ? ? ? return <div className={styles.infoRow} onClick={this.showInfo.bind(this,item)}>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <div className={styles.infoTitle}>{item.name}</div>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <div className={styles.infoContent}>{item.text}</div>
? ? ? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? <div className={styles.showAll}>
? ? ? ? ? ? ? ? ? ? <Button onClick={this.showAllInfo.bind(this)} className={styles.showAllBtn}>查看全部</Button>
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? </div>
? ? ? ? );
? ? ? ? return (
? ? ? ? ? ? <React.Fragment>
? ? ? ? ? ? ? ? <div className={styles.allBox}>
? ? ? ? ? ? ? ? ? ? <Popover onMouseEnter={this.getunreadDatas.bind(this)} content={content} title="消息">
? ? ? ? ? ? ? ? ? ? ? ? <Badge count={this.state.unreadList.length} showZero>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <img src={badgeImg}></img>
? ? ? ? ? ? ? ? ? ? ? ? </Badge>
? ? ? ? ? ? ? ? ? ? </Popover>
? ? ? ? ? ? ? ? ? ? <Modal
? ? ? ? ? ? ? ? ? ? ? ? title={this.state.infoTitle}
? ? ? ? ? ? ? ? ? ? ? ? visible={this.state.visible}
? ? ? ? ? ? ? ? ? ? ? ? onOk={this.handleOk}
? ? ? ? ? ? ? ? ? ? ? ? onCancel={this.handleCancel}
? ? ? ? ? ? ? ? ? ? ? ? footer={null}
? ? ? ? ? ? ? ? ? ? >
? ? ? ? ? ? ? ? ? ? ? ? <p>{this.state.infoContent}</p>
? ? ? ? ? ? ? ? ? ? </Modal>
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? </React.Fragment>
? ? ? ? );
? ? }
}
export default Information;
原文鏈接:https://blog.csdn.net/a82048195/article/details/109326638
相關推薦
- 2022-07-12 CSS樣式:彈性容器上的樣式
- 2022-10-31 Python3邏輯運算符與成員運算符_python
- 2022-02-03 Windows10 可以上網(會斷)顯示無Internet鏈接
- 2022-05-13 C++ std::thread 線程的傳參方式
- 2022-06-06 在使用element-ui中的el-table組件時,怎么自定義合并表頭和合并行
- 2022-09-26 Python?Celery定時任務詳細講解_python
- 2022-10-10 GO必知必會的常見面試題匯總_Golang
- 2023-07-24 前端終止請求的三種方式(ajax、axios)
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支