2017-07-26 16:25:34 +08:00
|
|
|
import '../AddInterface.scss'
|
|
|
|
import React, { Component } from 'react'
|
2017-07-31 19:43:08 +08:00
|
|
|
import { message } from 'antd'
|
2017-07-26 16:25:34 +08:00
|
|
|
import Clipboard from 'clipboard'
|
|
|
|
import PropTypes from 'prop-types'
|
2017-07-31 19:43:08 +08:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import {
|
|
|
|
addInterfaceClipboard
|
2017-08-08 10:07:55 +08:00
|
|
|
} from '../../../reducer/modules/addInterface.js'
|
2017-07-26 16:25:34 +08:00
|
|
|
|
|
|
|
const success = () => {
|
|
|
|
message.success('复制成功!')
|
|
|
|
}
|
|
|
|
|
2017-07-31 19:43:08 +08:00
|
|
|
@connect(
|
|
|
|
() => {
|
|
|
|
return {}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
addInterfaceClipboard
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2017-07-26 16:25:34 +08:00
|
|
|
class MockUrl extends Component {
|
|
|
|
static propTypes = {
|
2017-07-27 20:35:19 +08:00
|
|
|
mockURL: PropTypes.string,
|
2017-07-28 10:29:20 +08:00
|
|
|
serverIp: PropTypes.string,
|
|
|
|
mockData: PropTypes.string,
|
2017-07-28 12:06:11 +08:00
|
|
|
showMock: PropTypes.string,
|
2017-07-31 19:43:08 +08:00
|
|
|
projectData: PropTypes.object,
|
|
|
|
addInterfaceClipboard: PropTypes.func
|
2017-07-26 16:25:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
2017-07-31 19:43:08 +08:00
|
|
|
this.props.addInterfaceClipboard(this.clipboard)
|
2017-07-26 16:25:34 +08:00
|
|
|
setTimeout(this.clipboard, 500)
|
|
|
|
}
|
|
|
|
|
|
|
|
clipboard () {
|
2017-07-31 19:43:08 +08:00
|
|
|
document.querySelector('#clipboard-button').innerHTML = '<button id="mock-clipboard">复制</button>'
|
2017-07-26 16:25:34 +08:00
|
|
|
const btn = document.querySelector('#mock-clipboard')
|
|
|
|
const txt = document.querySelector('#mock-p').innerHTML
|
2017-08-07 19:34:34 +08:00
|
|
|
|
2017-07-26 16:25:34 +08:00
|
|
|
new Clipboard(btn, {
|
|
|
|
text: () => txt,
|
|
|
|
target () {
|
|
|
|
success()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2017-07-28 12:06:11 +08:00
|
|
|
const { serverIp, showMock } = this.props
|
2017-07-31 19:43:08 +08:00
|
|
|
|
2017-07-26 16:25:34 +08:00
|
|
|
return (
|
2017-07-28 12:06:11 +08:00
|
|
|
<section className={`mock-url-box ${showMock}`}>
|
2017-07-27 21:10:22 +08:00
|
|
|
<span className="title">mock地址 : </span>
|
2017-07-26 16:25:34 +08:00
|
|
|
<p id="mock-p">{this.props.mockURL}</p>
|
2017-07-31 19:43:08 +08:00
|
|
|
<span id="clipboard-button"></span>
|
2017-07-31 21:18:14 +08:00
|
|
|
<div className="host"><label>请配置host:</label> { serverIp } {this.props.projectData.prd_host} </div>
|
2017-07-26 16:25:34 +08:00
|
|
|
</section>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 12:06:11 +08:00
|
|
|
export default MockUrl
|