mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-06 12:45:22 +08:00
Merge branch 'dev' of http://gitlab.corp.qunar.com/mfe/yapi into dev
This commit is contained in:
commit
496c166243
@ -1,74 +0,0 @@
|
||||
import {
|
||||
FETCH_ADD_INTERFACE_INPUT,
|
||||
FETCH_ADD_INTERFACE_TAG_VALUE,
|
||||
FETCH_ADD_INTERFACE_HEADER_VALUE,
|
||||
ADD_INTERFACE_SEQ_HEADER,
|
||||
DELETE_INTERFACE_SEQ_HEADER,
|
||||
GET_INTERFACE_REQ_PARAMS,
|
||||
GET_INTERFACE_RES_PARAMS,
|
||||
PUSH_INTERFACE_NAME,
|
||||
PUSH_INTERFACE_METHOD
|
||||
} from '../constants/action-types.js'
|
||||
|
||||
export function pushInputValue (value) {
|
||||
return {
|
||||
type: FETCH_ADD_INTERFACE_INPUT,
|
||||
payload: value
|
||||
};
|
||||
}
|
||||
|
||||
export function reqTagValue (value) {
|
||||
return {
|
||||
type: FETCH_ADD_INTERFACE_TAG_VALUE,
|
||||
payload: value
|
||||
};
|
||||
}
|
||||
|
||||
export function reqHeaderValue (value) {
|
||||
return {
|
||||
type: FETCH_ADD_INTERFACE_HEADER_VALUE,
|
||||
payload: value
|
||||
};
|
||||
}
|
||||
|
||||
export function addReqHeader (value) {
|
||||
return {
|
||||
type: ADD_INTERFACE_SEQ_HEADER,
|
||||
payload: value
|
||||
};
|
||||
}
|
||||
|
||||
export function deleteReqHeader (value) {
|
||||
return {
|
||||
type: DELETE_INTERFACE_SEQ_HEADER,
|
||||
payload: value
|
||||
};
|
||||
}
|
||||
|
||||
export function getReqParams (value) {
|
||||
return {
|
||||
type: GET_INTERFACE_REQ_PARAMS,
|
||||
payload: value
|
||||
};
|
||||
}
|
||||
|
||||
export function getResParams (value) {
|
||||
return {
|
||||
type: GET_INTERFACE_RES_PARAMS,
|
||||
payload: value
|
||||
};
|
||||
}
|
||||
|
||||
export function pushInterfaceName (value) {
|
||||
return {
|
||||
type: PUSH_INTERFACE_NAME,
|
||||
payload: value
|
||||
}
|
||||
}
|
||||
|
||||
export function pushInterfaceMethod (value) {
|
||||
return {
|
||||
type: PUSH_INTERFACE_METHOD,
|
||||
payload: value
|
||||
}
|
||||
}
|
@ -7,8 +7,10 @@ import {
|
||||
GET_INTERFACE_REQ_PARAMS,
|
||||
GET_INTERFACE_RES_PARAMS,
|
||||
PUSH_INTERFACE_NAME,
|
||||
PUSH_INTERFACE_METHOD
|
||||
PUSH_INTERFACE_METHOD,
|
||||
FETCH_INTERFACE_PROJECT
|
||||
} from '../constants/action-types.js'
|
||||
import axios from 'axios'
|
||||
|
||||
export function pushInputValue (value) {
|
||||
return {
|
||||
@ -72,3 +74,10 @@ export function pushInterfaceMethod (value) {
|
||||
payload: value
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchInterfaceProject(id) {
|
||||
return {
|
||||
type: FETCH_INTERFACE_PROJECT,
|
||||
payload: axios.get('/project/get', { params: {id}})
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ export const DELETE_INTERFACE_SEQ_HEADER = 'DELETE_INTERFACE_SEQ_HEADER'
|
||||
export const GET_INTERFACE_REQ_PARAMS = 'GET_INTERFACE_REQ_PARAMS'
|
||||
export const GET_INTERFACE_RES_PARAMS = 'GET_INTERFACE_RES_PARAMS'
|
||||
export const PUSH_INTERFACE_METHOD = 'PUSH_INTERFACE_METHOD'
|
||||
export const FETCH_INTERFACE_PROJECT = 'FETCH_INTERFACE_PROJECT'
|
||||
|
||||
// group
|
||||
export const FETCH_GROUP_LIST = 'FETCH_GROUP_LIST'
|
||||
|
@ -10,13 +10,16 @@ import ReqHeader from './ReqHeader/ReqHeader.js'
|
||||
import ReqParams from './ReqParams/ReqParams.js'
|
||||
import ResParams from './ResParams/ResParams.js'
|
||||
import Result from './Result/Result.js'
|
||||
import {
|
||||
import InterfaceTest from './InterfaceTest/InterfaceTest.js'
|
||||
import {
|
||||
saveForms,
|
||||
getResParams,
|
||||
getReqParams,
|
||||
addReqHeader,
|
||||
pushInputValue,
|
||||
pushInterfaceName
|
||||
pushInterfaceName,
|
||||
fetchInterfaceProject,
|
||||
pushInterfaceMethod
|
||||
} from '../../actions/addInterface.js'
|
||||
|
||||
const success = () => {
|
||||
@ -40,7 +43,9 @@ const success = () => {
|
||||
getResParams,
|
||||
addReqHeader,
|
||||
pushInputValue,
|
||||
pushInterfaceName
|
||||
pushInterfaceName,
|
||||
fetchInterfaceProject,
|
||||
pushInterfaceMethod
|
||||
}
|
||||
)
|
||||
|
||||
@ -105,12 +110,14 @@ class AddInterface extends Component {
|
||||
|
||||
editState (data) {
|
||||
const props = this.props
|
||||
const { path, title, req_params_other, res_body, req_headers} = data
|
||||
const { path, title, req_params_other, res_body, req_headers, project_id, method } = data
|
||||
props.pushInputValue(path)
|
||||
props.pushInterfaceMethod(method)
|
||||
props.pushInterfaceName(title)
|
||||
props.getReqParams(req_params_other)
|
||||
props.getResParams(res_body)
|
||||
props.addReqHeader(req_headers)
|
||||
props.fetchInterfaceProject(project_id)
|
||||
}
|
||||
|
||||
initInterfaceData (interfaceId) {
|
||||
@ -204,7 +211,9 @@ class AddInterface extends Component {
|
||||
<Result isSave={isSave} />
|
||||
</TabPane>
|
||||
<TabPane tab="Mock" key="2">mock</TabPane>
|
||||
<TabPane tab="测试" key="3">测试</TabPane>
|
||||
<TabPane tab="测试" key="3">
|
||||
<InterfaceTest />
|
||||
</TabPane>
|
||||
</Tabs>
|
||||
</div>
|
||||
<div className={`loading ${isLoading}`}></div>
|
||||
@ -214,5 +223,3 @@ class AddInterface extends Component {
|
||||
}
|
||||
|
||||
export default AddInterface
|
||||
|
||||
|
||||
|
120
client/containers/AddInterface/InterfaceTest/InterfaceTest.js
Normal file
120
client/containers/AddInterface/InterfaceTest/InterfaceTest.js
Normal file
@ -0,0 +1,120 @@
|
||||
import React, { Component } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { connect } from 'react-redux'
|
||||
import { Button, Input } from 'antd'
|
||||
import { autobind } from 'core-decorators';
|
||||
import crossRequest from 'cross-request';
|
||||
import { withRouter } from 'react-router';
|
||||
import URL from 'url';
|
||||
|
||||
import {
|
||||
} from '../../../actions/group.js'
|
||||
|
||||
import './InterfaceTest.scss'
|
||||
|
||||
@connect(
|
||||
state => ({
|
||||
reqParams: state.addInterface.reqParams,
|
||||
method: state.addInterface.method,
|
||||
url: state.addInterface.url,
|
||||
seqGroup: state.addInterface.seqGroup,
|
||||
interfaceName: state.addInterface.interfaceName,
|
||||
interfaceProject: state.addInterface.project
|
||||
}),
|
||||
{
|
||||
}
|
||||
)
|
||||
@withRouter
|
||||
export default class InterfaceTest extends Component {
|
||||
|
||||
static propTypes = {
|
||||
reqParams: PropTypes.string,
|
||||
method: PropTypes.string,
|
||||
url: PropTypes.string,
|
||||
interfaceName: PropTypes.string,
|
||||
seqGroup: PropTypes.array,
|
||||
match: PropTypes.object,
|
||||
interfaceProject: PropTypes.object
|
||||
}
|
||||
|
||||
state = {
|
||||
res: {},
|
||||
header: {}
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
|
||||
}
|
||||
|
||||
@autobind
|
||||
testInterface() {
|
||||
crossRequest({
|
||||
url: 'http://petstore.swagger.io/v2/swagger.json',
|
||||
method: 'GET',
|
||||
data: {
|
||||
a:1
|
||||
},
|
||||
success: (res, header) => {
|
||||
this.setState({res})
|
||||
console.log(header)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
render () {
|
||||
const { method, url, seqGroup, interfaceName, interfaceProject } = this.props;
|
||||
const { prd_host, basepath, protocol } = interfaceProject;
|
||||
const reqParams = JSON.parse(this.props.reqParams);
|
||||
let query = {};
|
||||
|
||||
if (method === 'GET') {
|
||||
Object.keys(reqParams).forEach(key => {
|
||||
const value = typeof reqParams[key] === 'object' ? JSON.stringify(reqParams) : reqParams.toString();
|
||||
query[key] = value;
|
||||
})
|
||||
}
|
||||
|
||||
const href = URL.format({
|
||||
protocol: protocol || 'http',
|
||||
host: prd_host,
|
||||
pathname: URL.resolve(basepath, url),
|
||||
query
|
||||
});
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>接口名:{interfaceName}</div>
|
||||
<div>
|
||||
METHOD: <Input value={method} disabled />
|
||||
URL: <Input value={href} />
|
||||
HEADERS: <Input value={JSON.stringify(seqGroup, 2)} />
|
||||
请求参数:
|
||||
<div>
|
||||
{
|
||||
Object.keys(reqParams).map((key, index) => {
|
||||
const value = typeof reqParams[key] === 'object' ? JSON.stringify(reqParams) : reqParams.toString();
|
||||
return (
|
||||
<div key={index}>
|
||||
<Input value={key} style={{display: 'inline-block', width: 200}} />{' = '}
|
||||
<Input value={value} style={{display: 'inline-block', width: 200}} />
|
||||
</div>
|
||||
)
|
||||
})
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<Button onClick={this.testInterface}>发送跨域请求</Button>
|
||||
<div>
|
||||
返回结果:
|
||||
{JSON.stringify(this.state.res, 2)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
@ -75,6 +75,9 @@ class InterfaceTable extends Component {
|
||||
<Button type="primary">
|
||||
<Link to={`/AddInterface/edit/${data._id}`}>编辑</Link>
|
||||
</Button>
|
||||
<Button type="primary">
|
||||
<Link to={`/AddInterface/edit/${data._id}`}>测试</Link>
|
||||
</Button>
|
||||
<Button type="danger" onClick={deleteInterface}>删除</Button>
|
||||
</span>
|
||||
)
|
||||
|
@ -203,11 +203,11 @@ export default class GroupList extends Component {
|
||||
<div className="group-bar">
|
||||
<div className="curr-group">
|
||||
<div className="curr-group-name">
|
||||
{currGroup.group_name}
|
||||
<div className="text" title={currGroup.group_name}>{currGroup.group_name}</div>
|
||||
<Icon className="edit-group" type="edit" title="编辑分组" onClick={() => this.showModal(TYPE_EDIT)}/>
|
||||
<Icon className="delete-group" type="delete" title="删除分组" onClick={this.deleteGroup}/>
|
||||
</div>
|
||||
<div className="curr-group-desc">简介:{currGroup.group_desc}</div>
|
||||
<div className="curr-group-desc" title={currGroup.group_desc}>简介:{currGroup.group_desc}</div>
|
||||
</div>
|
||||
<div className="group-operate">
|
||||
<div className="search">
|
||||
|
@ -5,12 +5,25 @@
|
||||
border-radius: 4px 4px 0 0;
|
||||
padding: 32px 24px;
|
||||
.curr-group-name {
|
||||
.text {
|
||||
display: inline-block;
|
||||
overflow:hidden;
|
||||
white-space:nowrap;
|
||||
text-overflow:ellipsis;
|
||||
max-width: 150px;
|
||||
}
|
||||
color: #fff;
|
||||
font-size: 24px;
|
||||
}
|
||||
.curr-group-desc {
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
max-height: 54px;
|
||||
text-overflow:ellipsis;
|
||||
overflow:hidden;
|
||||
-webkit-line-clamp: 3;
|
||||
-webkit-box-orient: vertical;
|
||||
display: -webkit-box;
|
||||
}
|
||||
.delete-group, .edit-group {
|
||||
font-size: 18px;
|
||||
|
@ -141,8 +141,9 @@ class UpDateModal extends Component {
|
||||
// can use data-binding to set
|
||||
form.setFieldsValue({
|
||||
envs: envs.filter(key => {
|
||||
const realKey = key._id ? key._id : key
|
||||
console.log(key);
|
||||
return key._id !== id;
|
||||
return realKey !== id;
|
||||
})
|
||||
});
|
||||
}
|
||||
@ -183,7 +184,7 @@ class UpDateModal extends Component {
|
||||
getFieldDecorator('envs', { initialValue: envMessage });
|
||||
const envs = getFieldValue('envs');
|
||||
const formItems = envs.map((k, index) => {
|
||||
// console.log(k);
|
||||
console.log(k);
|
||||
const secondIndex = 'next' + index; // 为保证key的唯一性
|
||||
return (
|
||||
<Row key={index} type="flex" justify="space-between" align={index === 0 ? 'middle' : 'top'}>
|
||||
@ -229,7 +230,7 @@ class UpDateModal extends Component {
|
||||
>
|
||||
{getFieldDecorator(`envs-domain-${index}`, {
|
||||
validateTrigger: ['onChange', 'onBlur'],
|
||||
initialValue: envMessage.length !== 0 ? k.domain.split('\/\/')[1] : '',
|
||||
initialValue: envMessage.length !== 0 && k.domain ? k.domain.split('\/\/')[1] : '',
|
||||
rules: [{
|
||||
required: false,
|
||||
whitespace: true,
|
||||
@ -269,7 +270,7 @@ class UpDateModal extends Component {
|
||||
<Icon
|
||||
className="dynamic-delete-button"
|
||||
type="minus-circle-o"
|
||||
onClick={() => this.remove(k._id)}
|
||||
onClick={() => this.remove(k._id ? k._id : k)}
|
||||
/>
|
||||
) : null}
|
||||
</Col>
|
||||
|
@ -7,7 +7,8 @@ import {
|
||||
GET_INTERFACE_REQ_PARAMS,
|
||||
GET_INTERFACE_RES_PARAMS,
|
||||
PUSH_INTERFACE_NAME,
|
||||
PUSH_INTERFACE_METHOD
|
||||
PUSH_INTERFACE_METHOD,
|
||||
FETCH_INTERFACE_PROJECT
|
||||
} from '../../constants/action-types.js'
|
||||
|
||||
const initialState = {
|
||||
@ -23,7 +24,8 @@ const initialState = {
|
||||
}
|
||||
],
|
||||
reqParams: '',
|
||||
resParams: ''
|
||||
resParams: '',
|
||||
project: {}
|
||||
}
|
||||
|
||||
export default (state = initialState, action) => {
|
||||
@ -73,6 +75,11 @@ export default (state = initialState, action) => {
|
||||
...state,
|
||||
method: action.payload
|
||||
}
|
||||
case FETCH_INTERFACE_PROJECT:
|
||||
return {
|
||||
...state,
|
||||
project: action.payload.data.data
|
||||
}
|
||||
default:
|
||||
return state
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
"babel-plugin-transform-decorators-legacy": "^1.3.4",
|
||||
"copy-webpack-plugin": "^4.0.1",
|
||||
"core-decorators": "^0.17.0",
|
||||
"cross-request": "^1.0.1",
|
||||
"fs-extra": "^3.0.1",
|
||||
"jsoneditor": "^5.9.3",
|
||||
"jsonwebtoken": "^7.4.1",
|
||||
@ -52,6 +53,7 @@
|
||||
"sha1": "^1.1.1",
|
||||
"string-replace-webpack-plugin": "^0.1.3",
|
||||
"universal-cookie": "^2.0.8",
|
||||
"url": "^0.11.0",
|
||||
"wangeditor": "^3.0.4",
|
||||
"ykit-config-antd": "^0.1.3",
|
||||
"ykit-config-react": "^0.4.4"
|
||||
|
@ -26,7 +26,7 @@ class projectController extends baseController {
|
||||
|
||||
verifyDomain(domain){
|
||||
if(!domain) return false;
|
||||
if(/^[a-zA-Z0-9\-_\.]+[a-zA-Z]{2,6}$/.test(domain)){
|
||||
if(/^[a-zA-Z0-9\-_\.]+?\.[a-zA-Z0-9\-_\.]*?[a-zA-Z]{2,6}$/.test(domain)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -332,7 +332,7 @@ class projectController extends baseController {
|
||||
|
||||
let projectData = await this.Model.get(id);
|
||||
|
||||
if(params.basepath = (this.handleBasepath(params.basepath)) === false){
|
||||
if((params.basepath = this.handleBasepath(params.basepath)) === false){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误')
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ var projectController = function (_baseController) {
|
||||
key: 'verifyDomain',
|
||||
value: function verifyDomain(domain) {
|
||||
if (!domain) return false;
|
||||
if (/^[a-zA-Z0-9\-_\.]+[a-zA-Z]{2,6}$/.test(domain)) {
|
||||
if (/^[a-zA-Z0-9\-_\.]+?\.[a-zA-Z0-9\-_\.]*?[a-zA-Z]{2,6}$/.test(domain)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -778,7 +778,7 @@ var projectController = function (_baseController) {
|
||||
case 12:
|
||||
projectData = _context8.sent;
|
||||
|
||||
if (!(params.basepath = this.handleBasepath(params.basepath) === false)) {
|
||||
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
|
||||
_context8.next = 15;
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user