This commit is contained in:
qitmac000249 2017-07-27 18:19:22 +08:00
commit 526d5bdab3
8 changed files with 62 additions and 24 deletions

View File

@ -1,7 +1,7 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { Button, Input, Select, Card, Alert } from 'antd'
import { Button, Input, Select, Card, Alert, Spin } from 'antd'
import { autobind } from 'core-decorators';
import crossRequest from 'cross-request';
import { withRouter } from 'react-router';
@ -111,7 +111,8 @@ export default class InterfaceTest extends Component {
params,
paramsNotJson,
headers,
currDomain: domains.prd
currDomain: domains.prd,
loading: false
});
}
@ -128,6 +129,8 @@ export default class InterfaceTest extends Component {
query
});
this.setState({ loading: true })
crossRequest({
url: href,
method,
@ -135,7 +138,18 @@ export default class InterfaceTest extends Component {
data: params,
success: (res, header) => {
console.log(header)
try {
res = JSON.parse(res);
} catch (e) {
null;
}
this.setState({res})
this.setState({ loading: false })
},
error: (err, header) => {
console.log(header)
this.setState({res: err || '请求失败'})
this.setState({ loading: false })
}
})
}
@ -219,7 +233,12 @@ export default class InterfaceTest extends Component {
</Select>
<Input value={pathname+search} disabled style={{display: 'inline-block', width: 300}} />
</InputGroup>
<Button onClick={this.testInterface} type="primary" style={{marginLeft: 10}}>发送</Button>
<Button
onClick={this.testInterface}
type="primary"
style={{marginLeft: 10}}
loading={this.state.loading}
>发送</Button>
</div>
<Card title="HEADERS" noHovering style={{marginTop: 10}} className={Object.keys(headers).length ? '' : 'hidden'}>
<div className="req-row headers">
@ -272,15 +291,17 @@ export default class InterfaceTest extends Component {
</Card>
</div>
<Card title="返回结果" noHovering style={{marginTop: 10}}>
<div className="res-part">
<div>
<TextArea
value={this.state.res ? JSON.stringify(this.state.res, 2) : ''}
style={{margin: 10}}
autosize={{ minRows: 2, maxRows: 6 }}
></TextArea>
<Spin spinning={this.state.loading}>
<div className="res-part">
<div>
<TextArea
value={typeof this.state.res === 'object' ? JSON.stringify(this.state.res, null, 2) : this.state.res.toString()}
style={{margin: 10}}
autosize={{ minRows: 2, maxRows: 6 }}
></TextArea>
</div>
</div>
</div>
</Spin>
</Card>
</div>
)

View File

@ -19,8 +19,6 @@ const deleteConfirm = (id, props) => {
const { delProject, currGroup, fetchProjectList } = props;
const handle = () => {
delProject(id).then((res) => {
console.log(res);
console.log(fetchProjectList, currGroup._id);
if (res.payload.data.errcode == 0) {
message.success('删除成功!')
fetchProjectList(currGroup._id).then((res) => {
@ -43,6 +41,13 @@ const getColumns = (data, props) => {
render: (text, record) => {
return <Link to={`/Interface/${record._id}`}>{text}</Link>
}
},{
title: 'Mock链接',
key: 'domain',
render: (item) => {
return 'http://'+ item.prd_host + item.basepath;
}
}, {
title: '创建人',
dataIndex: 'owner',

View File

@ -26,7 +26,8 @@ export default (state = initialState, action) => {
isLogin: (action.payload.data.errcode == 0),
loginState: (action.payload.data.errcode == 0)?MEMBER_STATUS:GUEST_STATUS,
userName: action.payload.data.data ? action.payload.data.data.username : null,
uid: action.payload.data.data ? action.payload.data.data._id : null
uid: action.payload.data.data ? action.payload.data.data._id : null,
server_ip: action.payload.data.data.server_ip
};
}
case LOGIN: {
@ -36,7 +37,8 @@ export default (state = initialState, action) => {
isLogin: true,
loginState: MEMBER_STATUS,
uid: action.payload.data.data.uid,
userName: action.payload.data.data.username
userName: action.payload.data.data.username,
server_ip: action.payload.data.data.server_ip
};
} else {
return state;

View File

@ -26,7 +26,8 @@ export default (state = initialState, action) => {
isLogin: (action.payload.data.errcode == 0),
loginState: (action.payload.data.errcode == 0)?MEMBER_STATUS:GUEST_STATUS,
userName: action.payload.data.data ? action.payload.data.data.username : null,
uid: action.payload.data.data ? action.payload.data.data._id : null
uid: action.payload.data.data ? action.payload.data.data._id : null,
server_ip: action.payload.data.data.server_ip
};
}
case LOGIN: {
@ -36,7 +37,8 @@ export default (state = initialState, action) => {
isLogin: true,
loginState: MEMBER_STATUS,
uid: action.payload.data.data.uid,
userName: action.payload.data.data.username
userName: action.payload.data.data.username,
server_ip: action.payload.data.data.server_ip
};
} else {
return state;

View File

@ -60,7 +60,9 @@ class baseController {
async getLoginStatus(ctx) {
if (await this.checkLogin(ctx) === true) {
return ctx.body = yapi.commons.resReturn(yapi.commons.fieldSelect(this.$user, ['_id', 'username', 'email', 'up_time', 'add_time']));
let result = yapi.commons.fieldSelect(this.$user, ['_id', 'username', 'email', 'up_time', 'add_time']);
result.server_ip = yapi.WEBCONFIG.server_ip;
return ctx.body = yapi.commons.resReturn(result);
}
return ctx.body = yapi.commons.resReturn(null, 300, 'Please login.');
}

View File

@ -48,7 +48,8 @@ class userController extends baseController {
uid: result._id,
email: result.email,
add_time: result.add_time,
up_time: result.up_time
up_time: result.up_time,
server_ip: yapi.WEBCONFIG.server_ip
}, 0, 'logout success...');
} else {

View File

@ -154,6 +154,7 @@ var baseController = function () {
key: 'getLoginStatus',
value: function () {
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(ctx) {
var result;
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
@ -165,16 +166,19 @@ var baseController = function () {
_context3.t0 = _context3.sent;
if (!(_context3.t0 === true)) {
_context3.next = 5;
_context3.next = 7;
break;
}
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(_yapi2.default.commons.fieldSelect(this.$user, ['_id', 'username', 'email', 'up_time', 'add_time'])));
result = _yapi2.default.commons.fieldSelect(this.$user, ['_id', 'username', 'email', 'up_time', 'add_time']);
case 5:
result.server_ip = _yapi2.default.WEBCONFIG.server_ip;
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result));
case 7:
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 300, 'Please login.'));
case 6:
case 8:
case 'end':
return _context3.stop();
}

View File

@ -141,7 +141,8 @@ var userController = function (_baseController) {
uid: result._id,
email: result.email,
add_time: result.add_time,
up_time: result.up_time
up_time: result.up_time,
server_ip: _yapi2.default.WEBCONFIG.server_ip
}, 0, 'logout success...'));