mirror of
https://github.com/YMFE/yapi.git
synced 2025-04-12 15:10:23 +08:00
Merge branch 'dev' of http://gitlab.corp.qunar.com/mfe/yapi into dev
This commit is contained in:
commit
c1586b8088
@ -4,6 +4,7 @@ import PropTypes from 'prop-types'
|
||||
import { Button, Input, Select, Card, Alert, Spin, Icon, Collapse, Radio, Tooltip, message } from 'antd'
|
||||
import { autobind } from 'core-decorators';
|
||||
import crossRequest from 'cross-request';
|
||||
import mockEditor from '../../containers/Project/Interface/InterfaceList/mockEditor'
|
||||
// import { withRouter } from 'react-router';
|
||||
// import axios from 'axios';
|
||||
import URL from 'url';
|
||||
@ -12,7 +13,7 @@ import URL from 'url';
|
||||
// import {
|
||||
// } from '../../../reducer/modules/group.js'
|
||||
|
||||
// import './Run.scss'
|
||||
import './Postman.scss'
|
||||
|
||||
const { TextArea } = Input;
|
||||
const InputGroup = Input.Group;
|
||||
@ -130,26 +131,28 @@ export default class Run extends Component {
|
||||
data: bodyType === 'form' ? this.arrToObj(bodyForm) : bodyOther,
|
||||
files: bodyType === 'form' ? this.getFiles(bodyForm) : {},
|
||||
success: (res, header) => {
|
||||
// try {
|
||||
// res = JSON.parse(res)
|
||||
// header = JSON.parse(header)
|
||||
// } catch (e) {
|
||||
// message.error(e.message)
|
||||
// }
|
||||
try {
|
||||
res = typeof res === 'object' ? res : JSON.parse(res)
|
||||
header = typeof header === 'object' ? header : JSON.parse(header)
|
||||
} catch (e) {
|
||||
message.error(e.message)
|
||||
}
|
||||
message.success('请求完成')
|
||||
this.setState({res, resHeader: header})
|
||||
this.setState({ loading: false })
|
||||
this.bindAceEditor()
|
||||
},
|
||||
error: (err, header) => {
|
||||
// try {
|
||||
// err = JSON.parse(err)
|
||||
// header = JSON.parse(header)
|
||||
// } catch (e) {
|
||||
// message.error(e.message)
|
||||
// }
|
||||
try {
|
||||
err = typeof err === 'object' ? err : JSON.parse(err)
|
||||
header = typeof header === 'object' ? header : JSON.parse(header)
|
||||
} catch (e) {
|
||||
message.error(e.message)
|
||||
}
|
||||
message.success('请求完成')
|
||||
this.setState({res: err || '请求失败', resHeader: header})
|
||||
this.setState({ loading: false })
|
||||
this.bindAceEditor()
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -354,6 +357,22 @@ export default class Run extends Component {
|
||||
return headersObj;
|
||||
}
|
||||
|
||||
bindAceEditor = () => {
|
||||
console.log(mockEditor)
|
||||
mockEditor({
|
||||
container: 'res-body-pretty',
|
||||
data: JSON.stringify(this.state.res, null, 2),
|
||||
readOnly:true,
|
||||
onChange: function () {}
|
||||
})
|
||||
mockEditor({
|
||||
container: 'res-headers-pretty',
|
||||
data: JSON.stringify(this.state.resHeader, null, 2),
|
||||
readOnly:true,
|
||||
onChange: function () {}
|
||||
})
|
||||
}
|
||||
|
||||
@autobind
|
||||
fileChange(e, index) {
|
||||
console.log(e)
|
||||
@ -371,7 +390,7 @@ export default class Run extends Component {
|
||||
const search = decodeURIComponent(URL.format({query: this.getQueryObj(query)}));
|
||||
|
||||
return (
|
||||
<div className="interface-test">
|
||||
<div className="interface-test postman">
|
||||
<div className="has-plugin">
|
||||
{
|
||||
hasPlugin ? '' :
|
||||
@ -543,16 +562,18 @@ export default class Run extends Component {
|
||||
<div className="res-code"></div>
|
||||
<Collapse defaultActiveKey={['0', '1']} bordered={true}>
|
||||
<Panel header="BODY" key="0" >
|
||||
<TextArea
|
||||
{/*<TextArea
|
||||
value={typeof this.state.res === 'object' ? JSON.stringify(this.state.res, null, 2) : this.state.res.toString()}
|
||||
autosize={{ minRows: 2, maxRows: 10 }}
|
||||
></TextArea>
|
||||
></TextArea>*/}
|
||||
<div id="res-body-pretty" className="pretty-editor" style={{height: 200}}></div>
|
||||
</Panel>
|
||||
<Panel header="HEADERS" key="1" >
|
||||
<TextArea
|
||||
{/*<TextArea
|
||||
value={typeof this.state.resHeader === 'object' ? JSON.stringify(this.state.resHeader, null, 2) : this.state.resHeader.toString()}
|
||||
autosize={{ minRows: 2, maxRows: 10 }}
|
||||
></TextArea>
|
||||
></TextArea>*/}
|
||||
<div id="res-headers-pretty" className="pretty-editor" style={{height: 200}}></div>
|
||||
</Panel>
|
||||
</Collapse>
|
||||
</Spin>
|
||||
|
6
client/components/Postman/Postman.scss
Normal file
6
client/components/Postman/Postman.scss
Normal file
@ -0,0 +1,6 @@
|
||||
.postman {
|
||||
.pretty-editor {
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 4px;
|
||||
}
|
||||
}
|
@ -244,7 +244,7 @@ export default class GroupList extends Component {
|
||||
</div>
|
||||
<div className="group-operate">
|
||||
<div className="search">
|
||||
<Search onChange={this.searchGroup} onSearch={(v) => this.searchGroup(null, v)}/>
|
||||
<Search placeholder="Filter by name" onChange={this.searchGroup} onSearch={(v) => this.searchGroup(null, v)}/>
|
||||
</div>
|
||||
{
|
||||
this.props.curUserRole === "admin"?(<Button type="primary" onClick={this.showModal}>添加分组</Button>):''
|
||||
|
@ -89,13 +89,13 @@ class InterfaceMenu extends Component {
|
||||
|
||||
|
||||
onSelect = (selectedKeys) => {
|
||||
const {history, match} = this.props;
|
||||
const { history, match } = this.props;
|
||||
let curkey = selectedKeys[0];
|
||||
if(!curkey || !selectedKeys) return false;
|
||||
if (!curkey || !selectedKeys) return false;
|
||||
let basepath = "/project/" + match.params.id + "/interface/api";
|
||||
if(curkey === 'root'){
|
||||
if (curkey === 'root') {
|
||||
history.push(basepath)
|
||||
}else{
|
||||
} else {
|
||||
history.push(basepath + '/' + curkey)
|
||||
}
|
||||
}
|
||||
@ -162,7 +162,7 @@ class InterfaceMenu extends Component {
|
||||
that.props.history.push('/project/' + that.props.match.params.id + '/interface/api')
|
||||
ref.destroy()
|
||||
},
|
||||
async onCancel() {
|
||||
async onCancel() {
|
||||
ref.destroy()
|
||||
}
|
||||
});
|
||||
@ -201,12 +201,37 @@ class InterfaceMenu extends Component {
|
||||
|
||||
render() {
|
||||
const matchParams = this.props.match.params;
|
||||
let menuList = this.props.list;
|
||||
|
||||
|
||||
const defaultExpandedKeys = () => {
|
||||
const { router, inter, list } = this.props, rNull = { expands: [], selects: [] };
|
||||
if (list.length === 0) return rNull;
|
||||
if (router) {
|
||||
if (!isNaN(router.params.actionId)) {
|
||||
let _actionId = parseInt(router.params.actionId, 10)
|
||||
if (!inter._id || inter._id !== _actionId) return rNull;
|
||||
return {
|
||||
expands: ['cat_' + inter.catid],
|
||||
selects: [inter._id + ""]
|
||||
}
|
||||
} else {
|
||||
let catid = router.params.actionId.substr(4);
|
||||
return {
|
||||
expands: ['cat_' + catid],
|
||||
selects: ['cat_' + catid]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
expands: ['cat_' + list[0]._id],
|
||||
selects: ['root']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const item_interface_create = (item) => {
|
||||
let color, filter = this.state.filter;
|
||||
if (filter && item.title.indexOf(filter) === -1 && item.path.indexOf(filter) === -1) {
|
||||
return null;
|
||||
}
|
||||
let color;
|
||||
switch (item.method) {
|
||||
case 'GET': color = "green"; break;
|
||||
case 'POST': color = "blue"; break;
|
||||
@ -249,34 +274,22 @@ class InterfaceMenu extends Component {
|
||||
</Menu>
|
||||
};
|
||||
|
||||
const defaultExpandedKeys = ()=>{
|
||||
const {router, inter, list} = this.props, rNull = {expands: [], selects: []};
|
||||
if(list.length === 0) return rNull;
|
||||
if(router){
|
||||
if(!isNaN(router.params.actionId)){
|
||||
let _actionId = parseInt(router.params.actionId, 10)
|
||||
if(!inter._id || inter._id !== _actionId)return rNull;
|
||||
return {
|
||||
expands: ['cat_' + inter.catid],
|
||||
selects: [inter._id+""]
|
||||
}
|
||||
}else{
|
||||
let catid = router.params.actionId.substr(4);
|
||||
return {
|
||||
expands: ['cat_' + catid],
|
||||
selects: ['cat_' + catid]
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return {
|
||||
expands: ['cat_' + list[0]._id],
|
||||
selects: ['root']
|
||||
|
||||
|
||||
let currentKes = defaultExpandedKeys();
|
||||
if (this.state.filter) {
|
||||
let arr = [];
|
||||
menuList = this.props.list.filter(item => {
|
||||
if (item.name.indexOf(this.state.filter) === -1) {
|
||||
return false;
|
||||
}
|
||||
arr.push('cat_' + item._id)
|
||||
return true;
|
||||
})
|
||||
if(arr.length > 0){
|
||||
currentKes.expands = arr;
|
||||
}
|
||||
}
|
||||
|
||||
const currentKes = defaultExpandedKeys();
|
||||
|
||||
return <div>
|
||||
<div className="interface-filter">
|
||||
<Input onChange={this.onFilter} value={this.state.filter} placeholder="Filter by name" style={{ width: "70%" }} />
|
||||
@ -305,15 +318,15 @@ class InterfaceMenu extends Component {
|
||||
<AddInterfaceCatForm catdata={this.state.curCatdata} onCancel={() => this.changeModal('change_cat_modal_visible', false)} onSubmit={this.handleChangeInterfaceCat} />
|
||||
</Modal>
|
||||
</div>
|
||||
{this.props.list.length > 0 ?
|
||||
{menuList.length > 0 ?
|
||||
<Tree
|
||||
className="interface-list"
|
||||
defaultExpandedKeys={currentKes.expands}
|
||||
defaultSelectedKeys={currentKes.selects}
|
||||
expandedKeys={currentKes.expands}
|
||||
selectedKeys={currentKes.selects}
|
||||
onSelect={this.onSelect}
|
||||
>
|
||||
<TreeNode title={<Link style={{ fontSize: '14px' }} to={"/project/" + matchParams.id + "/interface/api"}><Icon type="folder-open" style={{ marginRight: 5 }} />全部接口</Link>} key="root" />
|
||||
{this.props.list.map((item) => {
|
||||
{menuList.map((item) => {
|
||||
return <TreeNode title={<div>
|
||||
<Link className="interface-item" to={"/project/" + matchParams.id + "/interface/api/cat_" + item._id} ><Icon type="folder-open" style={{ marginRight: 5 }} />{item.name}</Link>
|
||||
<Dropdown overlay={menu(item)}>
|
||||
|
9081
npm-shrinkwrap.json
generated
9081
npm-shrinkwrap.json
generated
File diff suppressed because it is too large
Load Diff
@ -198,7 +198,7 @@ class interfaceController extends baseController {
|
||||
let result = await this.catModel.list(project_id), newResult = [];
|
||||
for(let i=0, item, list;i< result.length; i++){
|
||||
item = result[i].toObject()
|
||||
list = await this.Model.listByCatid(item._id, '_id title method')
|
||||
list = await this.Model.listByCatid(item._id, '_id title method path')
|
||||
for(let j=0; j< list.length; j++){
|
||||
list[j] = list[j].toObject()
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ class userController extends baseController {
|
||||
|
||||
if (login === true) {
|
||||
yapi.commons.log('login success');
|
||||
ctx.redirect('/');
|
||||
ctx.redirect('/group');
|
||||
}
|
||||
} catch (e) {
|
||||
yapi.commons.log(e.message, 'error');
|
||||
|
@ -454,7 +454,7 @@ var interfaceController = function (_baseController) {
|
||||
|
||||
item = result[i].toObject();
|
||||
_context5.next = 13;
|
||||
return this.Model.listByCatid(item._id, '_id title method');
|
||||
return this.Model.listByCatid(item._id, '_id title method path');
|
||||
|
||||
case 13:
|
||||
list = _context5.sent;
|
||||
|
@ -271,7 +271,7 @@ var userController = function (_baseController) {
|
||||
|
||||
if (login === true) {
|
||||
_yapi2.default.commons.log('login success');
|
||||
ctx.redirect('/');
|
||||
ctx.redirect('/group');
|
||||
}
|
||||
_context3.next = 16;
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user