mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-15 05:10:47 +08:00
feat: 完善接口列表
This commit is contained in:
parent
223df4ac47
commit
1922ef3859
@ -105,7 +105,6 @@ class InterfaceEditForm extends Component {
|
||||
values.req_headers = values.req_headers.filter((item)=> item.name !== '')
|
||||
values.req_body_form = values.req_body_form.filter((item)=> item.name !== '')
|
||||
values.req_params = values.req_params.filter(item=>item.name !== '')
|
||||
|
||||
this.props.onSubmit(values)
|
||||
}
|
||||
});
|
||||
|
@ -1,16 +1,17 @@
|
||||
import React,{Component} from 'react'
|
||||
import React, { Component } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import axios from 'axios'
|
||||
import {
|
||||
Table
|
||||
Table, Tag
|
||||
} from 'antd';
|
||||
class InterfaceList extends Component{
|
||||
constructor(props){
|
||||
import { formatTime } from '../../../../common.js'
|
||||
class InterfaceList extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
data : [],
|
||||
data: [],
|
||||
sortedInfo: {
|
||||
order: 'descend',
|
||||
order: 'ascend',
|
||||
columnKey: 'title'
|
||||
}
|
||||
}
|
||||
@ -20,15 +21,15 @@ class InterfaceList extends Component{
|
||||
match: PropTypes.object
|
||||
}
|
||||
|
||||
handleRequest = async (props)=>{
|
||||
const {params} = props.match;
|
||||
if(!params.actionId){
|
||||
handleRequest = async (props) => {
|
||||
const { params } = props.match;
|
||||
if (!params.actionId) {
|
||||
let projectId = params.id;
|
||||
let r = await axios.get('/api/interface/list?project_id=' + projectId);
|
||||
this.setState({
|
||||
data: r.data.data
|
||||
})
|
||||
}else if(isNaN(params.actionId)){
|
||||
} else if (isNaN(params.actionId)) {
|
||||
let catid = params.actionId.substr(4)
|
||||
let r = await axios.get('/api/interface/list_cat?catid=' + catid);
|
||||
this.setState({
|
||||
@ -43,51 +44,76 @@ class InterfaceList extends Component{
|
||||
});
|
||||
}
|
||||
|
||||
componentWillMount(){
|
||||
componentWillMount() {
|
||||
this.actionId = this.props.match.params.actionId;
|
||||
this.handleRequest(this.props)
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps){
|
||||
componentWillReceiveProps(nextProps) {
|
||||
let _actionId = nextProps.match.params.actionId;
|
||||
if(this.actionId !== _actionId){
|
||||
this.actionId = _actionId;
|
||||
if (this.actionId !== _actionId) {
|
||||
this.actionId = _actionId;
|
||||
this.handleRequest(nextProps)
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
render() {
|
||||
let { sortedInfo } = this.state;
|
||||
sortedInfo = sortedInfo || {};
|
||||
const columns = [{
|
||||
title: '接口名称',
|
||||
dataIndex: 'title',
|
||||
key: 'title',
|
||||
sorter: (a, b) => b.title.length - a.title.length,
|
||||
sorter: (a, b) => {
|
||||
return a.title.localeCompare(b.title) === 1
|
||||
},
|
||||
sortOrder: sortedInfo.columnKey === 'title' && sortedInfo.order
|
||||
},{
|
||||
}, {
|
||||
title: '接口URL',
|
||||
dataIndex: 'path',
|
||||
key: 'path'
|
||||
},{
|
||||
}, {
|
||||
title: '请求方式',
|
||||
dataIndex: 'method',
|
||||
key: 'method'
|
||||
},{
|
||||
}, {
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
render: (item) => {
|
||||
return <div>{item === 'done' ?
|
||||
<Tag color="#87d068">完成</Tag>
|
||||
:
|
||||
<Tag color="#f50">未完成</Tag>
|
||||
}</div>
|
||||
},
|
||||
filters: [{
|
||||
text: '完成',
|
||||
value: 'done'
|
||||
}, {
|
||||
text: '未完成',
|
||||
value: 'undone'
|
||||
}],
|
||||
onFilter: (value, record) => record.status.indexOf(value) === 0
|
||||
}, {
|
||||
title: '更新日期',
|
||||
dataIndex: 'add_time',
|
||||
key: 'add_time'
|
||||
key: 'add_time',
|
||||
render: (item) => {
|
||||
return <span>{formatTime(item)}</span>
|
||||
}
|
||||
}]
|
||||
|
||||
const data = this.state.data.map(item=>{
|
||||
const data = this.state.data.map(item => {
|
||||
item.key = item._id;
|
||||
return item;
|
||||
});
|
||||
|
||||
|
||||
return (
|
||||
<section className="interface-table">
|
||||
<Table size="small" pagination={false} bordered={true} columns={columns} onChange={this.handleChange} dataSource={data} />
|
||||
</section>
|
||||
<div style={{padding:"15px"}}>
|
||||
<h2 style={{marginBottom: '10px'}}>接口列表</h2>
|
||||
<Table pagination={false} columns={columns} onChange={this.handleChange} dataSource={data} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -311,6 +311,10 @@ class interfaceController extends baseController {
|
||||
data.res_body = params.res_body;
|
||||
}
|
||||
|
||||
if(params.status){
|
||||
data.status = params.status;
|
||||
}
|
||||
|
||||
try {
|
||||
let result = await this.Model.up(id, data);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
|
@ -622,29 +622,33 @@ var interfaceController = function (_baseController) {
|
||||
data.res_body = params.res_body;
|
||||
}
|
||||
|
||||
_context6.prev = 32;
|
||||
_context6.next = 35;
|
||||
if (params.status) {
|
||||
data.status = params.status;
|
||||
}
|
||||
|
||||
_context6.prev = 33;
|
||||
_context6.next = 36;
|
||||
return this.Model.up(id, data);
|
||||
|
||||
case 35:
|
||||
case 36:
|
||||
result = _context6.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context6.next = 42;
|
||||
_context6.next = 43;
|
||||
break;
|
||||
|
||||
case 39:
|
||||
_context6.prev = 39;
|
||||
_context6.t0 = _context6['catch'](32);
|
||||
case 40:
|
||||
_context6.prev = 40;
|
||||
_context6.t0 = _context6['catch'](33);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context6.t0.message);
|
||||
|
||||
case 42:
|
||||
case 43:
|
||||
case 'end':
|
||||
return _context6.stop();
|
||||
}
|
||||
}
|
||||
}, _callee6, this, [[32, 39]]);
|
||||
}, _callee6, this, [[33, 40]]);
|
||||
}));
|
||||
|
||||
function up(_x6) {
|
||||
|
Loading…
Reference in New Issue
Block a user