react實現(xiàn)消息顯示器
本文實例為大家分享了react實現(xiàn)消息顯示器的具體代碼,供大家參考,具體內(nèi)容如下
效果


代碼實現(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;以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
React項目中動態(tài)插入HTML內(nèi)容的實現(xiàn)
本文主要介紹了React項目中動態(tài)插入HTML內(nèi)容的實現(xiàn),通過使用React的dangerouslySetInnerHTML屬性,我們可以將HTML內(nèi)容插入到組件中,具有一定的參考價值,感興趣的可以了解一下2023-10-10
React應(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,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09
React Hooks - useContetx和useReducer的使用實例詳解
這篇文章主要介紹了React Hooks - useContetx和useReducer的基本使用,本文通過實例代碼給大家講解的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-11-11
React-hook-form-mui基本使用教程(入門篇)
react-hook-form-mui可以幫助開發(fā)人員更輕松地構(gòu)建表單,它結(jié)合了React?Hook?Form和Material-UI組件庫,使用react-hook-form-mui,開發(fā)人員可以更快速地構(gòu)建表單,并且可以輕松地進(jìn)行表單驗證和數(shù)據(jù)處理,本文介紹React-hook-form-mui基本使用,感興趣的朋友一起看看吧2024-02-02
react 頁面加載完成后自動執(zhí)行標(biāo)簽的點擊事件的兩種操作方法
這篇文章主要介紹了react 頁面加載完成后自動執(zhí)行標(biāo)簽的點擊事件,本文給大家分享兩種操作方法結(jié)合示例代碼給大家講解的非常詳細(xì),需要的朋友可以參考下2022-12-12
react頁面中存在多個input時巧妙設(shè)置value屬性方式
這篇文章主要介紹了react頁面中存在多個input時巧妙設(shè)置value屬性方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05
React Native 自定義下拉刷新上拉加載的列表的示例
本篇文章主要介紹了React Native 自定義下拉刷新上拉加載的列表的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03

