最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

react封裝全局彈框的方法

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

本文實(shí)例為大家分享了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動(dòng)畫組件設(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)閉時(shí)候返回信息,可要可不要,根據(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>進(jìn)度詳情:</p>
        <p></p>
      </div>
    </div>)
  }

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

相關(guān)文章

  • React通過hook實(shí)現(xiàn)封裝表格常用功能

    React通過hook實(shí)現(xiàn)封裝表格常用功能

    這篇文章主要為大家詳細(xì)介紹了React通過hook封裝表格常用功能的使用,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,有需要的小伙伴可以參考下
    2023-12-12
  • 關(guān)于React動(dòng)態(tài)修改元素樣式的三種方式

    關(guān)于React動(dòng)態(tài)修改元素樣式的三種方式

    這篇文章主要介紹了關(guān)于React動(dòng)態(tài)修改元素樣式的三種方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • react-native 實(shí)現(xiàn)購(gòu)物車滑動(dòng)刪除效果的示例代碼

    react-native 實(shí)現(xiàn)購(gòu)物車滑動(dòng)刪除效果的示例代碼

    這篇文章主要介紹了react-native 實(shí)現(xiàn)購(gòu)物車滑動(dòng)刪除效果的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • React簡(jiǎn)便獲取經(jīng)緯度信息的方法詳解

    React簡(jiǎn)便獲取經(jīng)緯度信息的方法詳解

    在現(xiàn)代的Web應(yīng)用程序中,獲取用戶的地理位置信息是一項(xiàng)常見的需求,本文我們將介紹如何在React應(yīng)用程序中簡(jiǎn)便地獲取用戶的經(jīng)緯度信息,需要的可以參考下
    2023-11-11
  • React中useEffect Hook常見問題及解決

    React中useEffect Hook常見問題及解決

    React的useEffect Hook它允許我們?cè)诤瘮?shù)組件中執(zhí)行副作用操作,但在使用過程中可能會(huì)遇到一些常見的錯(cuò)誤,本文就來介紹一下常見問題及解決,感興趣的可以了解一下
    2023-10-10
  • React native ListView 增加頂部下拉刷新和底下點(diǎn)擊刷新示例

    React native ListView 增加頂部下拉刷新和底下點(diǎn)擊刷新示例

    這篇文章主要介紹了React native ListView 增加頂部下拉刷新和底下點(diǎn)擊刷新示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-04-04
  • React如何以Hook的方式使用Echarts

    React如何以Hook的方式使用Echarts

    這篇文章主要介紹了React如何以Hook的方式使用Echarts問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • React commit源碼分析詳解

    React commit源碼分析詳解

    前兩章講到了,react 在 render 階段的 completeUnitWork 執(zhí)行完畢后,就執(zhí)行 commitRoot 進(jìn)入到了 commit 階段,本章將講解 commit 階段執(zhí)行過程源碼
    2022-11-11
  • React的事件處理你了解嗎

    React的事件處理你了解嗎

    這篇文章主要為大家詳細(xì)介紹了React的事件處理,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-03-03
  • react.js使用webpack搭配環(huán)境的入門教程

    react.js使用webpack搭配環(huán)境的入門教程

    本文主要介紹了react 使用webpack搭配環(huán)境的入門教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2017-08-08

最新評(píng)論

台东市| 萨迦县| 隆子县| 罗定市| 中宁县| 秦皇岛市| 普宁市| 青神县| 通道| 壶关县| 南通市| 舞阳县| 监利县| 汝州市| 张掖市| 沁阳市| 克山县| 安新县| 西城区| 苍山县| 镇远县| 玉林市| 沈丘县| 建德市| 开原市| 平凉市| 葵青区| 洮南市| 定西市| 和龙市| 武威市| 定远县| 沁源县| 平原县| 丘北县| 蒙山县| 临朐县| 正安县| 高邑县| 保定市| 漯河市|