亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

react封裝全局彈框的方法

 更新時間:2021年10月15日 16:35:55   作者:冰丫頭  
這篇文章主要為大家詳細介紹了react封裝全局彈框的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了react封裝全局彈框的具體代碼,供大家參考,具體內(nèi)容如下

彈框效果圖

文件布局

index.js

/* eslint-disable react/no-render-return-value */
import React, { Component } from 'react'
import { is, fromJS } from 'immutable'
import ReactDOM from 'react-dom'
import './alert.less'

const close = require('../images/guanbi.png')
const line = require('../images/line.png')

const defaultState = {
  alertStatus: false,
  alertTip: null,
  alertTitle: '詳情',
  closeAlert: () => {}
}

class Toptips extends Component {
  state = {
    ...defaultState
  }

  // css動畫組件設(shè)置為目標(biāo)組件
  FirstChild = props => {
    const childrenArray = React.Children.toArray(props.children)
    return childrenArray[0] || null
  }

  // 關(guān)閉彈框
  confirm = () => {
    const that = this
    console.log(that)
    this.setState(
      {
        alertStatus: false
      },
      () => {
        that.state.closeAlert()
      }
    )
  }

  open = data => {
    const options = data || {}
    options.alertStatus = true
    this.setState({
      ...defaultState,
      ...options
    })
  }

  close = () => {
    const that = this
    that.state.closeAlert()
    this.setState({
      ...defaultState
    })
  }

  shouldComponentUpdate = (nextProps, nextState) => {
    return (
      !is(fromJS(this.props), fromJS(nextProps)) ||
      !is(fromJS(this.state), fromJS(nextState))
    )
  }

  render() {
    const { alertStatus, alertTip, alertTitle } = this.state
    console.log(alertTip, alertTitle)
    return (
        <div
          className="alert-con"
          style={alertStatus ? { display: 'block' } : { display: 'none' }}
        >
          <div className="alert-context">
            <div className="alert-content-title">{alertTitle}</div>
            <img className="alert-content-line" src={line} alt="line" />
            <div className="alert-content-detail">{alertTip}</div>
            <img
              role="presentation"
              onClick={() => {
                this.confirm()
              }}
              className="alert-close"
              src={close}
              alt="關(guān)閉"
            />
          </div>
        </div>
    )
  }
}

const div = document.createElement('div')
const props = {}
document.body.appendChild(div)

const Box = ReactDOM.render(React.createElement(Toptips, props), div)

export default Box

less

.alert-con {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.3);
  z-index: 222;
}
.alert-context {
  // background-color: #fff;
  // border-radius: 16px;
  position: relative;
  // height: 500px;
  height: 90%;
  width: 750px;
  margin: 40px auto 0;
  background: url(../images/alertBJ.png) no-repeat center;
  background-size: 100% 100%;
  .alert-close{
    width: 30px;
    height: 30px;
    position: absolute;
    right: 30px;
    top: 30px;
  }
  .alert-content-title{
    width: 100%;
    height: 80px;
    line-height: 80px;
    color: #fff;
    text-align: center;
    font-size: 36px;
    font-weight: bolder;
    // background: url(../images/line.png) no-repeat left bottom;
  }
  .alert-content-line{
    width: 100%;
    height: 20px;
    margin-top: -44px;
    margin-left: -6px;
  }
  .alert-detais-list{
    width: 102%;
    height: 100%;
    overflow-y: auto;
    padding: 20px 60px;
    .alert-detais-list-C{
      p{
        &:nth-child(1){
          font-size: 14px;
          line-height: 20px;
          color: #FFFFFF;
          letter-spacing: 1.4px;
        }
        &:nth-child(2){
          line-height: 24px;
          font-size: 18px;
          color: #FFFFFF;
        }
      }
    }
  }
  .alert-content-detail{
    // height: 100%;
    height: calc(100% - 100px);
    /* overflow-y: auto; */
    overflow: hidden;
    width: 98%;
    margin-top: -26px;
  }
  .alert-details-pdf{
    width: 102%;
    height: 100%;
    overflow-y: auto;
    padding: 20px 60px;
    .alert-details-button{
      display: flex;
      flex-direction: row;
      justify-content: flex-end;
      margin-bottom: 10px;
      p{
        color:#fff;
        line-height: 35px;
        font-size: 16px;
        margin-right: 20px;
      }
      a{
        line-height: 35px;
        font-size: 16px;
        margin-right: 20px;
      }
    }
  }
.cameraWrap{
  width: 100%;
  height: 102%;
  box-sizing: border-box;
  padding: 12px 4px 0 14px;
}
}

用法

  • alertTitle 彈框標(biāo)題
  • alertTip 彈框內(nèi)容,樣式自己自定義
  • closeAlert 關(guān)閉時候返回信息,可要可不要,根據(jù)自己需求。
import Toptips from "./Toptips"
Toptips.open({
      alertTitle: '批示詳情',
      alertTip: that.htms(val),
      closeAlert: function () {
        console.log("關(guān)閉了...");
      }
    });
  htms = val => {
    return (<div className="alert-detais-list">
      <div className="alert-detais-list-C">
        <p>批示內(nèi)容:</p>
        <p>{val.fdTitle}</p>
      </div>
      <div className="alert-detais-list-C">
        <p>批示詳述:</p>
        <p>{val.fdTitle}</p>
      </div>
      <div className="alert-detais-list-C">
        <p>措施及結(jié)果:</p>
        <p>{val.fdContent}</p>
      </div>
      <div className="alert-detais-list-C">
        <p>進度詳情:</p>
        <p></p>
      </div>
    </div>)
  }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • React中的useState如何改變值不重新渲染的問題

    React中的useState如何改變值不重新渲染的問題

    這篇文章主要介紹了React中的useState如何改變值不重新渲染的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • React18系列commit從0實現(xiàn)源碼解析

    React18系列commit從0實現(xiàn)源碼解析

    這篇文章主要為大家介紹了React18系列commit從0實現(xiàn)源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • React中memo useCallback useMemo方法作用及使用場景

    React中memo useCallback useMemo方法作用及使用場景

    這篇文章主要為大家介紹了React中三個hooks方法memo useCallback useMemo的作用及使用場景示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助
    2023-03-03
  • React父子組件互相通信的實現(xiàn)示例

    React父子組件互相通信的實現(xiàn)示例

    React中是單向數(shù)據(jù)流,數(shù)據(jù)只能從父組件通過屬性的方式傳給其子組件,本文主要介紹了React父子組件互相通信的實現(xiàn)示例,具有一定的參考價值,感興趣的可以了解一下
    2023-11-11
  • 詳解在React項目中安裝并使用Less(用法總結(jié))

    詳解在React項目中安裝并使用Less(用法總結(jié))

    這篇文章主要介紹了詳解在React項目中安裝并使用Less(用法總結(jié)),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • 詳解React中傳入組件的props改變時更新組件的幾種實現(xiàn)方法

    詳解React中傳入組件的props改變時更新組件的幾種實現(xiàn)方法

    這篇文章主要介紹了詳解React中傳入組件的props改變時更新組件的幾種實現(xiàn)方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-09-09
  • react解析html字符串方法實現(xiàn)

    react解析html字符串方法實現(xiàn)

    在使用reactjs庫的時候,會遇到將一段html的字符串,然后要將它插入頁面中以html的形式展現(xiàn),本文主要介紹了react解析html字符串方法實現(xiàn),感興趣的可以了解一下
    2023-12-12
  • 詳解React之父子組件傳遞和其它一些要點

    詳解React之父子組件傳遞和其它一些要點

    這篇文章主要介紹了詳解React之父子組件傳遞和其它一些要點,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-06-06
  • react antd實現(xiàn)動態(tài)增減表單

    react antd實現(xiàn)動態(tài)增減表單

    antd是react流行的ui框架庫,本文主要介紹了react antd實現(xiàn)動態(tài)增減表單,分享給大家,感興趣的小伙伴們可以參考一下
    2021-06-06
  • react中使用better-scroll滾動插件的實現(xiàn)示例

    react中使用better-scroll滾動插件的實現(xiàn)示例

    滾動在很多地方都可以使用,本文主要介紹了react中使用better-scroll滾動插件的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07

最新評論