mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-21 05:19:42 +08:00
fix: 修改预览页加载不显示
This commit is contained in:
parent
ba8b735f92
commit
4980723dcd
@ -57,6 +57,7 @@ function timeago(timestamp) {
|
||||
|
||||
@connect(
|
||||
state => {
|
||||
console.log(state);
|
||||
return {
|
||||
newsData: state.news.newsData,
|
||||
curpage: state.news.curpage,
|
||||
|
@ -5,7 +5,7 @@ import PropTypes from 'prop-types'
|
||||
import { Table } from 'antd'
|
||||
const mockEditor = require('./mockEditor.js')
|
||||
import { formatTime } from '../../../../common.js';
|
||||
|
||||
import ErrMsg from '../../../../components/ErrMsg/ErrMsg.js';
|
||||
// import { Card } from 'antd'
|
||||
// import { getMockUrl } from '../../reducer/modules/news.js'
|
||||
|
||||
@ -18,6 +18,9 @@ import { formatTime } from '../../../../common.js';
|
||||
class View extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
init: true
|
||||
}
|
||||
}
|
||||
static propTypes = {
|
||||
curData: PropTypes.object
|
||||
@ -25,12 +28,6 @@ class View extends Component {
|
||||
|
||||
req_body_form(req_body_type,req_body_form){
|
||||
if(req_body_type === 'json'){
|
||||
mockEditor({
|
||||
container: 'vreq_body_json',
|
||||
data: req_body_form,
|
||||
readOnly:true,
|
||||
onChange: function () {}
|
||||
})
|
||||
return <div className="colBody">
|
||||
<span className="colKey">请求Body:</span>
|
||||
<div id="vreq_body_json" style={{ minHeight: "300px" }}></div>
|
||||
@ -74,14 +71,14 @@ class View extends Component {
|
||||
|
||||
return <div className="colBody">
|
||||
<span className="colKey">请求Body:</span>
|
||||
<div style={{ minHeight: "300px" }}>file</div>
|
||||
<div>{this.props.curData.req_body_other}</div>
|
||||
</div>
|
||||
|
||||
}else if(req_body_type === 'raw'){
|
||||
|
||||
return <div className="colBody">
|
||||
<span className="colKey">请求Body:</span>
|
||||
<div style={{ minHeight: "300px" }}>raw</div>
|
||||
<div>{this.props.curData.req_body_other}</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@ -91,50 +88,7 @@ class View extends Component {
|
||||
<span className="colKey">返回Body:</span>
|
||||
<div id="vres_body_json" style={{ minHeight: "300px" }}></div>
|
||||
</div>
|
||||
|
||||
}else if(res_body_type === 'form'){
|
||||
|
||||
const columns = [{
|
||||
title: '参数名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name'
|
||||
}, {
|
||||
title: '参数值',
|
||||
dataIndex: 'value',
|
||||
key: 'value'
|
||||
}, {
|
||||
title: '备注',
|
||||
dataIndex: 'required',
|
||||
key: 'required',
|
||||
width: '45%'
|
||||
}];
|
||||
|
||||
const dataSource = [];
|
||||
if(res_body&&res_body.length){
|
||||
res_body.map((item,i)=>{
|
||||
dataSource.push({
|
||||
key: i,
|
||||
name: item.name,
|
||||
value: item.desc,
|
||||
required: item.required?"必须":"非必须"
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return <div className="colBody">
|
||||
<span className="colKey">返回Body:</span>
|
||||
<Table bordered size="small" pagination = {false} columns= {columns} dataSource = {dataSource} />
|
||||
</div>
|
||||
|
||||
}else if(res_body_type === 'file'){
|
||||
|
||||
return <div className="colBody">
|
||||
<span className="colKey">返回Body:</span>
|
||||
<div>{res_body}</div>
|
||||
</div>
|
||||
|
||||
}else if(res_body_type === 'raw'){
|
||||
|
||||
return <div className="colBody">
|
||||
<span className="colKey">返回Body:</span>
|
||||
<div>{res_body}</div>
|
||||
@ -172,16 +126,18 @@ class View extends Component {
|
||||
|
||||
return <Table bordered size="small" pagination = {false} columns= {columns} dataSource = {dataSource} />;
|
||||
}
|
||||
componentDidUpdate(){
|
||||
if(this.props.curData.req_body_type === "json"){
|
||||
|
||||
|
||||
bindAceEditor(){
|
||||
if(!this.state.init&&(this.props.curData.req_body_type === "json"&&this.props.curData.title)){
|
||||
mockEditor({
|
||||
container: 'vreq_body_json',
|
||||
data: this.props.curData.req_body_form,
|
||||
data: this.props.curData.req_body_other,
|
||||
readOnly:true,
|
||||
onChange: function () {}
|
||||
})
|
||||
}
|
||||
if(this.props.curData.res_body_type === "json"){
|
||||
if(!this.state.init&&(this.props.curData.res_body_type === "json"&&this.props.curData.title)){
|
||||
mockEditor({
|
||||
container: 'vres_body_json',
|
||||
data: this.props.curData.res_body,
|
||||
@ -190,8 +146,20 @@ class View extends Component {
|
||||
})
|
||||
}
|
||||
}
|
||||
componentDidMount(){
|
||||
if(!this.state.init){
|
||||
this.bindAceEditor.bind(this)();
|
||||
}
|
||||
}
|
||||
componentDidUpdate(){
|
||||
this.bindAceEditor.bind(this)();
|
||||
}
|
||||
componentWillUpdate(){
|
||||
if(!this.props.curData.title&&this.state.init){
|
||||
this.setState({init: false});
|
||||
}
|
||||
}
|
||||
render () {
|
||||
|
||||
const dataSource = [];
|
||||
if(this.props.curData.req_headers&&this.props.curData.req_headers.length){
|
||||
this.props.curData.req_headers.map((item,i)=>{
|
||||
@ -218,8 +186,11 @@ class View extends Component {
|
||||
key: 'required',
|
||||
width: '45%'
|
||||
}];
|
||||
|
||||
return this.props.curData.title?<div className="caseContainer">
|
||||
let status = {
|
||||
undone: "未完成",
|
||||
done: "完成"
|
||||
}
|
||||
let res = <div className="caseContainer">
|
||||
<div className="colName">
|
||||
<span className="colKey">接口名:</span>
|
||||
<span className="colValue">{this.props.curData.title}</span>
|
||||
@ -234,7 +205,7 @@ class View extends Component {
|
||||
</div>
|
||||
<div className="colstatus">
|
||||
<span className="colKey">状态:</span>
|
||||
<span className="colValue">{this.props.curData.status}</span>
|
||||
<span className="colValue">{status[this.props.curData.status]}</span>
|
||||
</div>
|
||||
<div className="colAddTime">
|
||||
<span className="colKey">创建时间:</span>
|
||||
@ -260,18 +231,21 @@ class View extends Component {
|
||||
<span className="colKey">请求Body类型:</span>
|
||||
<span className="colValue">{this.props.curData.req_body_type}</span>
|
||||
</div>
|
||||
{this.req_body_form("form",this.props.curData.req_body_form)}
|
||||
{this.req_body_form(this.props.curData.req_body_type,this.props.curData.req_body_form)}
|
||||
<div className="colreqBodyType">
|
||||
<span className="colKey">返回Body类型:</span>
|
||||
<span className="colValue">{this.props.curData.req_body_type}</span>
|
||||
<span className="colValue">{this.props.curData.res_body_type}</span>
|
||||
</div>
|
||||
{this.res_body("json",this.props.curData.res_body)}
|
||||
{/*{this.res_body("file",[{
|
||||
name: "key",
|
||||
desc: "123",
|
||||
required: 0
|
||||
}])}*/}
|
||||
</div>:<div className="caseContainer">接口不存在</div>;
|
||||
{this.res_body(this.props.curData.res_body_type,this.props.curData.res_body)}
|
||||
</div>;
|
||||
if(!this.props.curData.title){
|
||||
if(this.state.init){
|
||||
res = <div></div>;
|
||||
}else{
|
||||
res = <ErrMsg type="noData" />;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,8 +53,8 @@ export default (state = initialState, action) => {
|
||||
case FETCH_INTERFACE_LIST:
|
||||
return {
|
||||
...state,
|
||||
list: action.payload.data,
|
||||
curdata: {}
|
||||
list: action.payload.data
|
||||
// curdata: {}
|
||||
}
|
||||
default:
|
||||
return state
|
||||
|
Loading…
Reference in New Issue
Block a user