欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

react實(shí)現(xiàn)消息顯示器

 更新時(shí)間:2022年08月25日 16:03:58   作者:丶酸酸  
這篇文章主要為大家詳細(xì)介紹了react實(shí)現(xiàn)消息顯示器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(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)文章

最新評(píng)論