2017-07-18 12:53:53 +08:00
|
|
|
import React, { Component } from 'react'
|
2017-07-27 20:06:49 +08:00
|
|
|
import { Card } from 'antd'
|
2017-07-24 19:43:13 +08:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import PropTypes from 'prop-types'
|
2017-07-31 21:07:24 +08:00
|
|
|
import Mock from 'mockjs'
|
2017-08-07 16:50:47 +08:00
|
|
|
import parseCommon from '../../../parseCommon';
|
2017-07-24 19:43:13 +08:00
|
|
|
@connect(
|
|
|
|
state => {
|
|
|
|
return {
|
|
|
|
resParams: state.addInterface.resParams,
|
|
|
|
reqParams: state.addInterface.reqParams
|
|
|
|
}
|
2017-07-18 12:53:53 +08:00
|
|
|
}
|
2017-07-24 19:43:13 +08:00
|
|
|
)
|
|
|
|
class Result extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
resParams: PropTypes.string,
|
2017-07-25 14:35:46 +08:00
|
|
|
reqParams: PropTypes.string,
|
2017-07-26 12:31:42 +08:00
|
|
|
isSave: PropTypes.bool,
|
|
|
|
mockJson: PropTypes.string
|
2017-07-18 12:53:53 +08:00
|
|
|
}
|
|
|
|
|
2017-07-24 19:43:13 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
}
|
2017-07-18 12:53:53 +08:00
|
|
|
|
2017-07-24 19:43:13 +08:00
|
|
|
render () {
|
2017-07-31 21:07:24 +08:00
|
|
|
const { mockJson, resParams } = this.props
|
|
|
|
let json, j;
|
|
|
|
try{
|
|
|
|
json = JSON.parse(resParams);
|
2017-08-07 16:50:47 +08:00
|
|
|
json = parseCommon.regexp_parse(json);
|
2017-07-31 21:07:24 +08:00
|
|
|
}catch(e){
|
|
|
|
json = false;
|
|
|
|
}
|
|
|
|
if(json !== false){
|
2017-08-02 18:32:01 +08:00
|
|
|
try{
|
|
|
|
j = JSON.stringify(Mock.mock(json), null, " ");
|
|
|
|
}catch(e){
|
|
|
|
j = ""
|
|
|
|
}
|
|
|
|
|
2017-07-31 21:07:24 +08:00
|
|
|
}else{
|
|
|
|
j = mockJson
|
|
|
|
}
|
|
|
|
|
2017-07-26 19:07:29 +08:00
|
|
|
|
2017-07-18 12:53:53 +08:00
|
|
|
return (
|
|
|
|
<div className="result">
|
2017-07-27 20:06:49 +08:00
|
|
|
<Card title="Mock 结果" style={{ width: 500 }}>
|
2017-07-31 21:07:24 +08:00
|
|
|
<pre>{j}</pre>
|
2017-07-27 20:06:49 +08:00
|
|
|
</Card>
|
2017-07-18 12:53:53 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 19:43:13 +08:00
|
|
|
export default Result
|