Commit 2b3e9680 by zhanghaozhe

更新popup通用组件

parent 0814d87a
import React, { Component } from 'react' import React from 'react'
import ReactDOM from 'react-dom'
import './index.scss' import './index.scss'
import classnames from 'classnames' import classnames from 'classnames'
import propTypes from 'prop-types'
class ClosablePopup extends Component { function ClosablePopup({
title, content, className, closable = true, close = function () {
state = {
visible: this.props.visible
} }
} = {}) {
close = () => { function unmountComponent() {
const {close} = this.props ReactDOM.unmountComponentAtNode(div)
close ? close() : this.setState({visible: false}) if (div && div.parentNode) {
div.parentNode.removeChild(div)
}
} }
componentDidUpdate(prevProps, prevState) { function _close() {
const {visible} = this.props let _c = close()
if (prevState.visible !== this.props.visible) { if (_c && _c.then) {
this.setState({ _c.then(() => {
visible unmountComponent()
}) })
} else {
unmountComponent()
} }
} }
render() { const closablePopup = (
const {title, className, children, closable = true} = this.props <div className={'closable-popup-mask'}>
return ( <div className={classnames(['popup-container', className])}>
this.state.visible <div className="title">{title}</div>
? <div className="content">
<div className={'closable-popup-mask'}> {content}
<div className={classnames(['popup-container', className])}>
<div className="title">{title}</div>
<div className="content">
{children}
</div>
{
closable && <i className={'close iconfont iconiconfront-2'} onClick={this.close}/>
}
</div>
</div> </div>
: null {
) closable && <i className={'close iconfont iconiconfront-2'} onClick={_close}/>
} }
} </div>
</div>
)
const div = document.createElement('div')
document.body.appendChild(div)
ClosablePopup.propTypes = { ReactDOM.render(closablePopup, div)
title: propTypes.string.isRequired,
visible: propTypes.bool,
closable: propTypes.string,
close: propTypes.func
} }
export default ClosablePopup export default ClosablePopup
...@@ -16,8 +16,6 @@ class Live extends Component { ...@@ -16,8 +16,6 @@ class Live extends Component {
tabs: [], tabs: [],
lives: {}, lives: {},
preheatLives: [], preheatLives: [],
visible: false,
qrcode: '',
today: '', today: '',
isApp: getParam('version') isApp: getParam('version')
} }
...@@ -80,9 +78,9 @@ class Live extends Component { ...@@ -80,9 +78,9 @@ class Live extends Component {
const {data} = res const {data} = res
if (data.code == 200) { if (data.code == 200) {
QRCode.toDataURL(data.data.url, (err, url) => { QRCode.toDataURL(data.data.url, (err, url) => {
this.setState({ Popup({
qrcode: url, title: '扫码关注“七月在线”服务号即可预约',
visible: true content: <img id={'live-qr-code'} src={url} alt=""/>
}) })
}) })
} else { } else {
...@@ -92,14 +90,9 @@ class Live extends Component { ...@@ -92,14 +90,9 @@ class Live extends Component {
} }
render() { render() {
const {tabs, lives, visible, qrcode, preheatLives, today} = this.state const {tabs, lives, preheatLives, today} = this.state
return ( return (
<div id={'live'}> <div id={'live'}>
<Popup title={'扫码关注“七月在线”服务号即可预约'}
visible={visible}
>
<img id={'live-qr-code'} src={qrcode} alt=""/>
</Popup>
<div className="title"> <div className="title">
<img src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/title-decorate-left.png" alt=""/> <img src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/title-decorate-left.png" alt=""/>
<span>大咖直播</span> <span>大咖直播</span>
......
#live { #live {
margin-top: 30px; margin-top: 30px;
.title { .title {
display: flex; display: flex;
justify-content: center; justify-content: center;
...@@ -175,22 +176,6 @@ ...@@ -175,22 +176,6 @@
} }
.popup-container {
.title {
color: #525C65;
}
.content {
display: flex;
justify-content: center;
img {
width: 120px;
height: 120px;
}
}
}
.am-tabs { .am-tabs {
width: 330px; width: 330px;
margin: 0 auto; margin: 0 auto;
...@@ -234,3 +219,20 @@ ...@@ -234,3 +219,20 @@
} }
} }
.popup-container {
.title {
color: #525C65;
}
.content {
display: flex;
justify-content: center;
img {
width: 120px;
height: 120px;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment