react實(shí)現(xiàn)消息顯示器
本文實(shí)例為大家分享了react實(shí)現(xiàn)消息顯示器的具體代碼,供大家參考,具體內(nèi)容如下
效果
代碼實(shí)現(xiàn)
完整代碼:
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:'', ? ? ? ? }; ? ? } ? ? //渲染前調(diào)用 ? ? componentWillMount() { } ? ? //渲染后調(diào)用 ? ? componentDidMount() { ? ? ? ? this.getunreadDatas(); ? ? } ? ? //調(diào)用接口獲取未讀數(shù)據(jù) ? ? 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) } }); ? ? } ? ? //接口回調(diào)方法 ? ? unreadCallback(e) { ? ? ? ? this.setState({ ? ? ? ? ? ? unreadList:e ? ? ? ? }) ? ? } ? ? //查看詳情 ? ? showInfo(e) { ? ? ? ? let { dispatch } = this.props; ? ? ? ? let userid = localStorage.getItem('userid'); ? ? ? ? let params = { ? ? ? ? ? ? id:e.id, ? ? ? ? ? ? userId:userid, ? ? ? ? } ? ? ? ? //調(diào)用接口標(biāo)記已讀 ? ? ? ? dispatch({ type: 'InformationModel/getreadData', payload: { params: params, callback: this.readCallback.bind(this) } }); ? ? ? ? this.setState({ ? ? ? ? ? ? infoTitle:e.name, ? ? ? ? ? ? infoContent:e.text ? ? ? ? }) ? ? } ? ? //標(biāo)記接口回調(diào)函數(shù) ? ? readCallback(e){ ? ? ? ? this.setState({ ? ? ? ? ? ? visible: true, ? ? ? ? }); ? ? ? ? //刷新列表 ? ? ? ? this.getunreadDatas(); ? ? } ? ? //顯示全部 ? ? showAllInfo(){ ? ? ? ? router.push({ ? ? ? ? ? ? pathname: `/cs/InformationMoreList`, ? ? ? ? ? ? query: { ? ? ? ? ? ? }, ? ? ? ? }); ? ? } ? ? //彈框確認(rèn)按鈕 ? ? 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;
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
React項(xiàng)目中動(dòng)態(tài)插入HTML內(nèi)容的實(shí)現(xiàn)
本文主要介紹了React項(xiàng)目中動(dòng)態(tài)插入HTML內(nèi)容的實(shí)現(xiàn),通過(guò)使用React的dangerouslySetInnerHTML屬性,我們可以將HTML內(nèi)容插入到組件中,具有一定的參考價(jià)值,感興趣的可以了解一下2023-10-10React應(yīng)用框架Dva數(shù)據(jù)流向原理總結(jié)分析
這篇文章主要為大家介紹了React 應(yīng)用框架Dva數(shù)據(jù)流向原理總結(jié)分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12詳解react內(nèi)聯(lián)樣式使用webpack將px轉(zhuǎn)rem
這篇文章主要介紹了詳解react內(nèi)聯(lián)樣式使用webpack將px轉(zhuǎn)rem,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-09-09React?跨端動(dòng)態(tài)化核心技術(shù)實(shí)例分析
這篇文章主要為大家介紹了React?跨端動(dòng)態(tài)化核心技術(shù)實(shí)例分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10react antd實(shí)現(xiàn)動(dòng)態(tài)增減表單
antd是react流行的ui框架庫(kù),本文主要介紹了react antd實(shí)現(xiàn)動(dòng)態(tài)增減表單,分享給大家,感興趣的小伙伴們可以參考一下2021-06-06React Hooks - useContetx和useReducer的使用實(shí)例詳解
這篇文章主要介紹了React Hooks - useContetx和useReducer的基本使用,本文通過(guò)實(shí)例代碼給大家講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-11-11React-hook-form-mui基本使用教程(入門(mén)篇)
react-hook-form-mui可以幫助開(kāi)發(fā)人員更輕松地構(gòu)建表單,它結(jié)合了React?Hook?Form和Material-UI組件庫(kù),使用react-hook-form-mui,開(kāi)發(fā)人員可以更快速地構(gòu)建表單,并且可以輕松地進(jìn)行表單驗(yàn)證和數(shù)據(jù)處理,本文介紹React-hook-form-mui基本使用,感興趣的朋友一起看看吧2024-02-02react 頁(yè)面加載完成后自動(dòng)執(zhí)行標(biāo)簽的點(diǎn)擊事件的兩種操作方法
這篇文章主要介紹了react 頁(yè)面加載完成后自動(dòng)執(zhí)行標(biāo)簽的點(diǎn)擊事件,本文給大家分享兩種操作方法結(jié)合示例代碼給大家講解的非常詳細(xì),需要的朋友可以參考下2022-12-12react頁(yè)面中存在多個(gè)input時(shí)巧妙設(shè)置value屬性方式
這篇文章主要介紹了react頁(yè)面中存在多個(gè)input時(shí)巧妙設(shè)置value屬性方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05React Native 自定義下拉刷新上拉加載的列表的示例
本篇文章主要介紹了React Native 自定義下拉刷新上拉加載的列表的示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03