mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-06 12:45:22 +08:00
Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev
This commit is contained in:
commit
ff1d162d0e
@ -9,7 +9,7 @@ import { checkLoginState } from './actions/login'
|
||||
|
||||
const LOADING_STATUS = 0;
|
||||
const GUEST_STATUS = 1;
|
||||
const MEMBER_STATUS = 2;
|
||||
// const MEMBER_STATUS = 2;
|
||||
|
||||
|
||||
class App extends Component {
|
||||
@ -21,7 +21,8 @@ class App extends Component {
|
||||
}
|
||||
}
|
||||
static propTypes = {
|
||||
checkLoginState:PropTypes.func
|
||||
checkLoginState:PropTypes.func,
|
||||
loginState:PropTypes.number
|
||||
}
|
||||
route = (status) => {
|
||||
let r;
|
||||
@ -61,34 +62,18 @@ class App extends Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.props.checkLoginState().then((res) => {
|
||||
console.log(res);
|
||||
if (res.payload.data.errcode === 0 && res.payload.data.data._id > 0) {
|
||||
this.setState({
|
||||
login: MEMBER_STATUS
|
||||
})
|
||||
} else {
|
||||
this.setState({
|
||||
login: GUEST_STATUS
|
||||
})
|
||||
}
|
||||
}).catch((err) => {
|
||||
this.setState({
|
||||
login: GUEST_STATUS
|
||||
});
|
||||
console.log(err)
|
||||
});
|
||||
this.props.checkLoginState();
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.route(this.state.login)
|
||||
return this.route(this.props.loginState)
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
state => {
|
||||
return{
|
||||
login:state.login.isLogin
|
||||
loginState:state.login.loginState
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -6,12 +6,19 @@ import {
|
||||
} from '../constants/action-types.js';
|
||||
import axios from 'axios';
|
||||
|
||||
|
||||
const checkLoginState = () => {
|
||||
return {
|
||||
type: GET_LOGIN_STATE,
|
||||
// payload 可以返回 Promise,异步请求使用 axios 即可
|
||||
payload: axios.get('/user/status')
|
||||
};
|
||||
return(dispatch)=> {
|
||||
axios.get('/user/status').then((res) => {
|
||||
console.log(res);
|
||||
dispatch({
|
||||
type: GET_LOGIN_STATE,
|
||||
payload: res
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const loginActions = (data) => {
|
||||
@ -24,7 +31,6 @@ const loginActions = (data) => {
|
||||
data: res
|
||||
}
|
||||
});
|
||||
location.reload();
|
||||
} else {
|
||||
console.log('登录失败,errcode不为0');
|
||||
}
|
||||
@ -58,7 +64,6 @@ const logoutActions = () => {
|
||||
dispatch({
|
||||
type: LOGIN_OUT
|
||||
})
|
||||
location.reload();
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
|
82
client/app.js
Normal file
82
client/app.js
Normal file
@ -0,0 +1,82 @@
|
||||
import React, { Component } from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Route, HashRouter, Redirect, Switch } from 'react-router-dom'
|
||||
import { Home, ProjectGroups, Interface, News, AddInterface } from './containers/index'
|
||||
import User from './containers/User/User.js'
|
||||
import Header from './components/Header/Header'
|
||||
import { checkLoginState } from './actions/login'
|
||||
|
||||
const LOADING_STATUS = 0;
|
||||
const GUEST_STATUS = 1;
|
||||
// const MEMBER_STATUS = 2;
|
||||
|
||||
|
||||
class App extends Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
login: LOADING_STATUS
|
||||
}
|
||||
}
|
||||
static propTypes = {
|
||||
checkLoginState:PropTypes.func,
|
||||
loginState:PropTypes.number
|
||||
}
|
||||
route = (status) => {
|
||||
let r;
|
||||
if (status === LOADING_STATUS) {
|
||||
return <span>loading...</span>
|
||||
} else if (status === GUEST_STATUS) {
|
||||
r = (
|
||||
<HashRouter>
|
||||
<div className="router-main">
|
||||
<Header />
|
||||
<Switch>
|
||||
<Route
|
||||
path="/"
|
||||
component={Home}/>
|
||||
<Redirect from="(/:str)" to="/" />
|
||||
</Switch>
|
||||
</div>
|
||||
</HashRouter>
|
||||
)
|
||||
} else {
|
||||
r = (
|
||||
<HashRouter>
|
||||
<div className="router-main">
|
||||
<Header />
|
||||
<Route path="/" component={Home} exact />
|
||||
<Route path="/ProjectGroups" component={ProjectGroups} />
|
||||
<Route path="/Interface" component={Interface} />
|
||||
<Route path="/user" component={User} />
|
||||
<Route path="/News" component={News} />
|
||||
<Route path="/AddInterface" component={ AddInterface } />
|
||||
</div>
|
||||
</HashRouter>
|
||||
)
|
||||
}
|
||||
return r
|
||||
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.props.checkLoginState();
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.route(this.props.loginState)
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
state => {
|
||||
return{
|
||||
loginState:state.login.loginState
|
||||
}
|
||||
},
|
||||
{
|
||||
checkLoginState
|
||||
}
|
||||
)(App)
|
@ -124,7 +124,6 @@ class HeaderCom extends Component {
|
||||
}
|
||||
render () {
|
||||
const { login, user, msg, uid, curKey } = this.props;
|
||||
console.log(curKey);
|
||||
return (
|
||||
<acticle className="header-box">
|
||||
<Layout className="'layout">
|
||||
|
@ -5,10 +5,15 @@ import {
|
||||
GET_LOGIN_STATE
|
||||
} from '../../constants/action-types';
|
||||
|
||||
const LOADING_STATUS = 0;
|
||||
const GUEST_STATUS = 1;
|
||||
const MEMBER_STATUS = 2;
|
||||
|
||||
const initialState = {
|
||||
isLogin: false,
|
||||
userName: null,
|
||||
uid: null,
|
||||
loginState:LOADING_STATUS,
|
||||
loginWrapActiveKey:"1"
|
||||
};
|
||||
|
||||
@ -18,6 +23,7 @@ export default (state = initialState, action) => {
|
||||
return {
|
||||
...state,
|
||||
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
|
||||
};
|
||||
}
|
||||
@ -25,6 +31,7 @@ export default (state = initialState, action) => {
|
||||
return {
|
||||
...state,
|
||||
isLogin: true,
|
||||
loginState: MEMBER_STATUS,
|
||||
uid: action.payload.data.uid,
|
||||
userName: action.payload.data.userName
|
||||
};
|
||||
@ -33,6 +40,7 @@ export default (state = initialState, action) => {
|
||||
return{
|
||||
...state,
|
||||
isLogin: false,
|
||||
loginState: GUEST_STATUS,
|
||||
userName: null,
|
||||
uid: null
|
||||
}
|
||||
|
@ -5,10 +5,15 @@ import {
|
||||
GET_LOGIN_STATE
|
||||
} from '../../constants/action-types';
|
||||
|
||||
const LOADING_STATUS = 0;
|
||||
const GUEST_STATUS = 1;
|
||||
const MEMBER_STATUS = 2;
|
||||
|
||||
const initialState = {
|
||||
isLogin: false,
|
||||
userName: null,
|
||||
uid: null,
|
||||
loginState:LOADING_STATUS,
|
||||
loginWrapActiveKey:"1"
|
||||
};
|
||||
|
||||
@ -18,6 +23,7 @@ export default (state = initialState, action) => {
|
||||
return {
|
||||
...state,
|
||||
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
|
||||
};
|
||||
}
|
||||
@ -25,6 +31,7 @@ export default (state = initialState, action) => {
|
||||
return {
|
||||
...state,
|
||||
isLogin: true,
|
||||
loginState: MEMBER_STATUS,
|
||||
uid: action.payload.data.uid,
|
||||
userName: action.payload.data.userName
|
||||
};
|
||||
@ -33,6 +40,7 @@ export default (state = initialState, action) => {
|
||||
return{
|
||||
...state,
|
||||
isLogin: false,
|
||||
loginState: GUEST_STATUS,
|
||||
userName: null,
|
||||
uid: null
|
||||
}
|
||||
|
346
doc/build/api.html
vendored
346
doc/build/api.html
vendored
@ -207,6 +207,20 @@
|
||||
<li >
|
||||
<a href="#-interface-del">/interface/del</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- <li > -->
|
||||
<li >
|
||||
|
||||
<a href="#node">node</a>
|
||||
</li>
|
||||
|
||||
<ul class="nav docs-sidenav-extend" >
|
||||
|
||||
<li >
|
||||
<a href="#-node-list">/node/list</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
@ -1235,7 +1249,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#16" target="_blank">./server/controllers/project.js:16</a>
|
||||
<a href="./static/server/controllers/project.js.html#42" target="_blank">./server/controllers/project.js:42</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1376,7 +1390,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#80" target="_blank">./server/controllers/project.js:80</a>
|
||||
<a href="./static/server/controllers/project.js.html#114" target="_blank">./server/controllers/project.js:114</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1460,7 +1474,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#112" target="_blank">./server/controllers/project.js:112</a>
|
||||
<a href="./static/server/controllers/project.js.html#146" target="_blank">./server/controllers/project.js:146</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1544,7 +1558,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#145" target="_blank">./server/controllers/project.js:145</a>
|
||||
<a href="./static/server/controllers/project.js.html#179" target="_blank">./server/controllers/project.js:179</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1622,7 +1636,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#173" target="_blank">./server/controllers/project.js:173</a>
|
||||
<a href="./static/server/controllers/project.js.html#207" target="_blank">./server/controllers/project.js:207</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1705,7 +1719,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#197" target="_blank">./server/controllers/project.js:197</a>
|
||||
<a href="./static/server/controllers/project.js.html#231" target="_blank">./server/controllers/project.js:231</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1952,7 +1966,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#244" target="_blank">./server/controllers/project.js:244</a>
|
||||
<a href="./static/server/controllers/project.js.html#278" target="_blank">./server/controllers/project.js:278</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -2024,7 +2038,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#277" target="_blank">./server/controllers/project.js:277</a>
|
||||
<a href="./static/server/controllers/project.js.html#311" target="_blank">./server/controllers/project.js:311</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -2128,7 +2142,7 @@
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>env[].host</td>
|
||||
<td>env[].domain</td>
|
||||
<td>String</td>
|
||||
<td>环境域名</td>
|
||||
<td>
|
||||
@ -2184,7 +2198,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#351" target="_blank">./server/controllers/project.js:351</a>
|
||||
<a href="./static/server/controllers/project.js.html#394" target="_blank">./server/controllers/project.js:394</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -2319,6 +2333,18 @@
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>title</td>
|
||||
<td>String</td>
|
||||
<td>接口标题,不能为空</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>path</td>
|
||||
<td>String</td>
|
||||
@ -2404,7 +2430,7 @@
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params</td>
|
||||
<td>req_params_form</td>
|
||||
<td>Mixed</td>
|
||||
<td>请求参数,如果请求方式是form,参数是Array数组,其他格式请求参数是字符串</td>
|
||||
<td>
|
||||
@ -2414,7 +2440,7 @@
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params[].name</td>
|
||||
<td>req_params_form[].name</td>
|
||||
<td>String</td>
|
||||
<td>请求参数名</td>
|
||||
<td>
|
||||
@ -2424,7 +2450,7 @@
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params[].value</td>
|
||||
<td>req_params_form[].value</td>
|
||||
<td>String</td>
|
||||
<td>请求参数值,可填写生成规则(mock)。如@email,随机生成一条email</td>
|
||||
<td>
|
||||
@ -2434,7 +2460,7 @@
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params[].type</td>
|
||||
<td>req_params_form[].type</td>
|
||||
<td>String</td>
|
||||
<td>请求参数类型,有["text", "file"]两种</td>
|
||||
<td>
|
||||
@ -2443,6 +2469,16 @@
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params_other</td>
|
||||
<td>String</td>
|
||||
<td>非form类型的请求参数可保存到此字段</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>res_body_type</td>
|
||||
<td>String</td>
|
||||
@ -2483,6 +2519,7 @@
|
||||
<span class="token comment" spellcheck="true">//header Content-Type:application/json</span>
|
||||
|
||||
<span class="token punctuation">{</span>
|
||||
<span class="token string">"title"</span><span class="token punctuation">:</span> <span class="token string">"testapi"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"api"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"method"</span><span class="token punctuation">:</span> <span class="token string">"post"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"path"</span><span class="token punctuation">:</span> <span class="token string">"/testapi"</span><span class="token punctuation">,</span>
|
||||
@ -2517,6 +2554,7 @@
|
||||
<span class="token string">"data"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
|
||||
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">422</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"title"</span><span class="token punctuation">:</span> <span class="token string">"testapi"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"project_id"</span><span class="token punctuation">:</span> <span class="token number">8</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"path"</span><span class="token punctuation">:</span> <span class="token string">"/testapi"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"api"</span><span class="token punctuation">,</span>
|
||||
@ -2569,7 +2607,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/interface.js.html#77" target="_blank">./server/controllers/interface.js:77</a>
|
||||
<a href="./static/server/controllers/interface.js.html#81" target="_blank">./server/controllers/interface.js:81</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -2629,12 +2667,12 @@
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
添加项目分组
|
||||
接口列表
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/interface.js.html#100" target="_blank">./server/controllers/interface.js:100</a>
|
||||
<a href="./static/server/controllers/interface.js.html#104" target="_blank">./server/controllers/interface.js:104</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -2694,12 +2732,12 @@
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
添加项目分组
|
||||
编辑接口
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/interface.js.html#124" target="_blank">./server/controllers/interface.js:124</a>
|
||||
<a href="./static/server/controllers/interface.js.html#128" target="_blank">./server/controllers/interface.js:128</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -2817,7 +2855,7 @@
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params</td>
|
||||
<td>req_params_form</td>
|
||||
<td>Mixed</td>
|
||||
<td>请求参数,如果请求方式是form,参数是Array数组,其他格式请求参数是字符串</td>
|
||||
<td>
|
||||
@ -2827,7 +2865,7 @@
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params[].name</td>
|
||||
<td>req_params_form[].name</td>
|
||||
<td>String</td>
|
||||
<td>请求参数名</td>
|
||||
<td>
|
||||
@ -2837,7 +2875,7 @@
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params[].value</td>
|
||||
<td>req_params_form[].value</td>
|
||||
<td>String</td>
|
||||
<td>请求参数值,可填写生成规则(mock)。如@email,随机生成一条email</td>
|
||||
<td>
|
||||
@ -2847,7 +2885,7 @@
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params[].type</td>
|
||||
<td>req_params_form[].type</td>
|
||||
<td>String</td>
|
||||
<td>请求参数类型,有["text", "file"]两种</td>
|
||||
<td>
|
||||
@ -2856,6 +2894,16 @@
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params_other</td>
|
||||
<td>String</td>
|
||||
<td>非form类型的请求参数可保存到此字段</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>res_body_type</td>
|
||||
<td>String</td>
|
||||
@ -2922,7 +2970,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/interface.js.html#189" target="_blank">./server/controllers/interface.js:189</a>
|
||||
<a href="./static/server/controllers/interface.js.html#197" target="_blank">./server/controllers/interface.js:197</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -2977,6 +3025,256 @@
|
||||
</div>
|
||||
|
||||
|
||||
<h2 id="node" class="page-header subject">node<a class="hashlink" href="#node">#</a></h2>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-node-list" class="page-header subject">
|
||||
/node/list
|
||||
|
||||
<span class="ui-badge">GET</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-node-list">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
获取节点列表
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/log.js.html#12" target="_blank">./server/controllers/log.js:12</a>
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
<small class="text-muted">参数:</small>
|
||||
</p>
|
||||
<div class="docs-table">
|
||||
<table class="yo-table yo-table-border">
|
||||
<colgroup>
|
||||
<col class="c1">
|
||||
<col class="c2">
|
||||
<col class="c3">
|
||||
<col class="c4">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr class="active">
|
||||
<th>参数名</th>
|
||||
<th>类型</th>
|
||||
<th>描述</th>
|
||||
<th>必选</th>
|
||||
<th>支持版本</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tr>
|
||||
<td>uid</td>
|
||||
<td>Number</td>
|
||||
<td>用户id, 不能为空</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>page</td>
|
||||
<td>Number</td>
|
||||
<td>分页页码</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>limit</td>
|
||||
<td>Number</td>
|
||||
<td>分页大小</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<div>示例:</div>
|
||||
<pre class="ydoc-example" data-foldnumber=10><code><span class="token punctuation">{</span>
|
||||
<span class="token string">"errcode"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">"success"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"data"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
|
||||
<span class="token string">"total"</span><span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"list"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
|
||||
<span class="token punctuation">{</span>
|
||||
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">529</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"yapi"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"aaa"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"http://www.yapi.com"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"/a/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500465369</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500522419</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
|
||||
<span class="token string">"107"</span>
|
||||
<span class="token punctuation">]</span>
|
||||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||||
<span class="token punctuation">{</span>
|
||||
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">558</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"12"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"21\n"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"http://11/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"12/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500466250</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500466250</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
|
||||
<span class="token string">"107"</span>
|
||||
<span class="token punctuation">]</span>
|
||||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||||
<span class="token punctuation">{</span>
|
||||
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">626</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"1233"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"123"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"http://1234/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"1234/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500471230</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500471230</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
|
||||
<span class="token string">"107"</span>
|
||||
<span class="token punctuation">]</span>
|
||||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||||
<span class="token punctuation">{</span>
|
||||
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">665</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"222"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"222"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"http://222/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"222/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500471668</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500471668</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
|
||||
<span class="token string">"107"</span>
|
||||
<span class="token punctuation">]</span>
|
||||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||||
<span class="token punctuation">{</span>
|
||||
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">704</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"333"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"222333"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"http://333/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"333/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500471674</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500471674</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
|
||||
<span class="token string">"107"</span>
|
||||
<span class="token punctuation">]</span>
|
||||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||||
<span class="token punctuation">{</span>
|
||||
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">743</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"444"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"444"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"https://444/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"444/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500471695</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500471695</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
|
||||
<span class="token string">"107"</span>
|
||||
<span class="token punctuation">]</span>
|
||||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||||
<span class="token punctuation">{</span>
|
||||
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">763</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"122333"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"3/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"http://33/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"33/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500481743</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500481743</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
|
||||
<span class="token string">"107"</span>
|
||||
<span class="token punctuation">]</span>
|
||||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||||
<span class="token punctuation">{</span>
|
||||
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">778</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"555"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"555"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"https://555/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"555/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500519203</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500519203</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
|
||||
<span class="token string">"107"</span>
|
||||
<span class="token punctuation">]</span>
|
||||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||||
<span class="token punctuation">{</span>
|
||||
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">823</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"5"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"5"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"http://5/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"5/"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500519769</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500519769</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
|
||||
<span class="token string">"107"</span>
|
||||
<span class="token punctuation">]</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">]</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"userinfo"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
|
||||
<span class="token string">"107"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
|
||||
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"username"</span><span class="token punctuation">:</span> <span class="token string">"admin"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"email"</span><span class="token punctuation">:</span> <span class="token string">"admin@admin.com"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"role"</span><span class="token punctuation">:</span> <span class="token string">"admin"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500280333</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500373530</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@ -42,6 +42,7 @@ class interfaceController extends baseController{
|
||||
* @category interface
|
||||
* @foldnumber 10
|
||||
* @param {Number} project_id 项目id,不能为空
|
||||
* @param {String} title 接口标题,不能为空
|
||||
* @param {String} path 接口请求路径,不能为空
|
||||
* @param {String} method 请求方式
|
||||
* @param {Array} [req_headers] 请求的header信息
|
||||
@ -50,10 +51,11 @@ class interfaceController extends baseController{
|
||||
* @param {Boolean} [req_headers[].required] 是否是必须,默认为否
|
||||
* @param {String} [req_headers[].desc] header描述
|
||||
* @param {String} [req_params_type] 请求参数方式,有["form", "json", "text", "xml"]四种
|
||||
* @param {Mixed} [req_params] 请求参数,如果请求方式是form,参数是Array数组,其他格式请求参数是字符串
|
||||
* @param {String} [req_params[].name] 请求参数名
|
||||
* @param {String} [req_params[].value] 请求参数值,可填写生成规则(mock)。如@email,随机生成一条email
|
||||
* @param {String} [req_params[].type] 请求参数类型,有["text", "file"]两种
|
||||
* @param {Mixed} [req_params_form] 请求参数,如果请求方式是form,参数是Array数组,其他格式请求参数是字符串
|
||||
* @param {String} [req_params_form[].name] 请求参数名
|
||||
* @param {String} [req_params_form[].value] 请求参数值,可填写生成规则(mock)。如@email,随机生成一条email
|
||||
* @param {String} [req_params_form[].type] 请求参数类型,有["text", "file"]两种
|
||||
* @param {String} [req_params_other] 非form类型的请求参数可保存到此字段
|
||||
* @param {String} [res_body_type] 相应信息的数据格式,有["json", "text", "xml"]三种
|
||||
* @param {String} [res_body] 响应信息,可填写任意字符串,如果res_body_type是json,则会调用mock功能
|
||||
* @param {String} [desc] 接口描述
|
||||
@ -63,6 +65,7 @@ class interfaceController extends baseController{
|
||||
async add(ctx){
|
||||
let params = ctx.request.body;
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase()
|
||||
params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json';
|
||||
if(!params.project_id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
@ -80,6 +83,7 @@ class interfaceController extends baseController{
|
||||
try{
|
||||
let data = {
|
||||
project_id: params.project_id,
|
||||
title: params.title,
|
||||
path: params.path,
|
||||
desc: params.desc,
|
||||
method: params.method,
|
||||
@ -92,8 +96,8 @@ class interfaceController extends baseController{
|
||||
up_time: yapi.commons.time()
|
||||
}
|
||||
|
||||
if(data.req_params_type === 'form') data.req_params_form = params.req_params;
|
||||
else data.req_params_other = params.req_params;
|
||||
if(params.req_params_form) data.req_params_form = params.req_params_form;
|
||||
if(params.req_params_other) data.req_params_other = params.req_params_other;
|
||||
|
||||
let result = await this.Model.save(data);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
@ -126,7 +130,7 @@ class interfaceController extends baseController{
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* 接口列表
|
||||
* @interface /interface/list
|
||||
* @method GET
|
||||
* @category interface
|
||||
@ -150,7 +154,7 @@ class interfaceController extends baseController{
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* 编辑接口
|
||||
* @interface /interface/up
|
||||
* @method POST
|
||||
* @category interface
|
||||
@ -164,10 +168,11 @@ class interfaceController extends baseController{
|
||||
* @param {Boolean} [req_headers[].required] 是否是必须,默认为否
|
||||
* @param {String} [req_headers[].desc] header描述
|
||||
* @param {String} [req_params_type] 请求参数方式,有["form", "json", "text", "xml"]四种
|
||||
* @param {Mixed} [req_params] 请求参数,如果请求方式是form,参数是Array数组,其他格式请求参数是字符串
|
||||
* @param {String} [req_params[].name] 请求参数名
|
||||
* @param {String} [req_params[].value] 请求参数值,可填写生成规则(mock)。如@email,随机生成一条email
|
||||
* @param {String} [req_params[].type] 请求参数类型,有["text", "file"]两种
|
||||
* @param {Mixed} [req_params_form] 请求参数,如果请求方式是form,参数是Array数组,其他格式请求参数是字符串
|
||||
* @param {String} [req_params_form[].name] 请求参数名
|
||||
* @param {String} [req_params_form[].value] 请求参数值,可填写生成规则(mock)。如@email,随机生成一条email
|
||||
* @param {String} [req_params_form[].type] 请求参数类型,有["text", "file"]两种
|
||||
* @param {String} [req_params_other] 非form类型的请求参数可保存到此字段
|
||||
* @param {String} [res_body_type] 相应信息的数据格式,有["json", "text", "xml"]三种
|
||||
* @param {String} [res_body] 响应信息,可填写任意字符串,如果res_body_type是json,则会调用mock功能
|
||||
* @param {String} [desc] 接口描述
|
||||
@ -178,11 +183,13 @@ class interfaceController extends baseController{
|
||||
async up(ctx){
|
||||
let params = ctx.request.body;
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase()
|
||||
let id = ctx.request.body.id;
|
||||
if(!id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
|
||||
}
|
||||
if(params.path){
|
||||
let interfaceData = await this.Model.get(id);
|
||||
if(params.path && params.path !== interfaceData.path && params.method !== interfaceData.method){
|
||||
let checkRepeat = await this.Model.checkRepeat(params.path, params.method);
|
||||
if(checkRepeat > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
|
||||
@ -194,13 +201,14 @@ class interfaceController extends baseController{
|
||||
}
|
||||
|
||||
if(params.path) data.path = params.path;
|
||||
if(params.title) data.title = params.title;
|
||||
if(params.desc) data.desc = params.desc;
|
||||
if(params.method) data.method = params.method;
|
||||
|
||||
if(params.req_headers) data.req_headers = params.req_headers;
|
||||
|
||||
if(params.req_params_type === 'form') data.req_params_form = params.req_params;
|
||||
else data.req_params_other = params.req_params;
|
||||
if(params.req_params_form) data.req_params_form = params.req_params_form;
|
||||
if(params.req_params_other) data.req_params_other = params.req_params_other;
|
||||
|
||||
if(params.res_body_type) data.res_body_type = params.res_body_type;
|
||||
if(params.res_body) data.res_body = params.res_body;
|
||||
|
114
doc/build/static/server/controllers/log.js.html
vendored
Normal file
114
doc/build/static/server/controllers/log.js.html
vendored
Normal file
@ -0,0 +1,114 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
|
||||
<title>yapi : ./server/controllers/log.js</title>
|
||||
<link type="text/css" rel="stylesheet" href="../../../source/code.css"/>
|
||||
<script type="text/javascript" src="../../../source/shCore.js"></script>
|
||||
<script type="text/javascript" src="../../../source/shBrush-js.js"></script>
|
||||
<style>
|
||||
.syntaxhighlighter .number1 .spaces,.syntaxhighlighter .toolbar{ display: none;}
|
||||
.syntaxhighlighter table td.gutter .line.highlight { background-color: #6ce26c !important; color: white; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="ydoc">
|
||||
<div class="ydoc-banner-bg">
|
||||
<div class="ydoc-banner" id="content" tabindex="-1">
|
||||
<div class="ydoc-banner-area">
|
||||
<h1>yapi : ./server/controllers/log.js</h1>
|
||||
<p>源代码</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ydoc-container">
|
||||
<div class="ydoc-container-content">
|
||||
<div class="static-code-content" role="main">
|
||||
<pre class="brush: js;">
|
||||
import logModel from '../models/log.js';
|
||||
import yapi from '../yapi.js';
|
||||
import baseController from './base.js';
|
||||
import groupModel from '../models/group';
|
||||
|
||||
class logController extends baseController {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
this.Model = yapi.getInst(logModel);
|
||||
this.groupModel = yapi.getInst(groupModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点列表
|
||||
* @interface /node/list
|
||||
* @method GET
|
||||
* @category node
|
||||
* @foldnumber 10
|
||||
* @param {Number} uid 用户id, 不能为空
|
||||
* @param {Number} [page] 分页页码
|
||||
* @param {Number} [limit] 分页大小
|
||||
* @returns {Object}
|
||||
* @example ./api/project/list.json
|
||||
*/
|
||||
|
||||
async list(ctx) {
|
||||
let uid = ctx.request.query.uid,
|
||||
page = ctx.request.query.page || 1,
|
||||
limit = ctx.request.query.limit || 10;
|
||||
|
||||
if(!uid){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '用户id不能为空');
|
||||
}
|
||||
|
||||
try {
|
||||
let result = await this.Model.listWithPaging(uid, page, limit);
|
||||
let count = await this.Model.listCount(uid);
|
||||
ctx.body = yapi.commons.resReturn({
|
||||
total: Math.ceil(count / limit),
|
||||
list: result
|
||||
})
|
||||
} catch(err) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = logController;
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="docs-header" id="content" tabindex="-1">
|
||||
<div class="container">
|
||||
<h1>yapi : ./server/controllers/log.js</h1>
|
||||
<p>源代码</p>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<footer class="docs-footer" role="contentinfo">
|
||||
<div class="container">
|
||||
<p></p>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
SyntaxHighlighter.all();
|
||||
|
||||
function getTop(node){
|
||||
return node.offsetTop + (node.offsetParent ? getTop(node.offsetParent) : 0);
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
setTimeout(function() {
|
||||
try {
|
||||
var lineNum = (parseInt(location.hash.replace(/#/g, '')) - 1) || 0,
|
||||
node = document.querySelectorAll('div.line')[lineNum];
|
||||
document.body.scrollTop = getTop(node);
|
||||
node.className += ' highlight';
|
||||
} catch(e) {}
|
||||
}, 500);
|
||||
}, false);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -41,6 +41,32 @@ class projectController extends baseController {
|
||||
this.groupModel = yapi.getInst(groupModel);
|
||||
}
|
||||
|
||||
handleBasepath(basepath){
|
||||
if(!basepath) return false;
|
||||
if(basepath[0] !== '/') basepath = '/' + basepath;
|
||||
if(basepath[basepath.length -1] === '/') basepath = basepath.substr(0, basepath.length -1)
|
||||
if(!this.verifyPath(basepath)){
|
||||
return false;
|
||||
}
|
||||
return basepath;
|
||||
}
|
||||
|
||||
verifyPath(path){
|
||||
if(/^[a-zA-Z0-9\-\/_:]+$/.test(path)){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
verifyDomain(domain){
|
||||
if(!domain) return false;
|
||||
if(/^[a-zA-Z0-9\-_\.]+[a-zA-Z]{2,6}$/.test(domain)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* @interface /project/add
|
||||
@ -79,6 +105,14 @@ class projectController extends baseController {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目domain不能为空');
|
||||
}
|
||||
|
||||
if((params.basepath = this.handleBasepath(params.basepath)) === false){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误')
|
||||
}
|
||||
|
||||
if(!this.verifyDomain(params.prd_host)){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '线上域名格式有误')
|
||||
}
|
||||
|
||||
let checkRepeatDomain = await this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
||||
if(checkRepeatDomain > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
|
||||
@ -315,7 +349,7 @@ class projectController extends baseController {
|
||||
* @param {String} [desc] 项目描述
|
||||
* @param {Array} [env] 项目环境配置
|
||||
* @param {String} [env[].name] 环境名称
|
||||
* @param {String} [env[].host] 环境域名
|
||||
* @param {String} [env[].domain] 环境域名
|
||||
* @returns {Object}
|
||||
* @example ./api/project/up.json
|
||||
*/
|
||||
@ -333,6 +367,15 @@ class projectController extends baseController {
|
||||
}
|
||||
|
||||
let projectData = await this.Model.get(id);
|
||||
|
||||
if(params.basepath = (this.handleBasepath(params.basepath)) === false){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误')
|
||||
}
|
||||
|
||||
if(!this.verifyDomain(params.prd_host)){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '线上域名格式有误')
|
||||
}
|
||||
|
||||
if(projectData.name === params.name){
|
||||
delete params.name;
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import bodyParser from 'koa-bodyparser'
|
||||
import router from './router.js'
|
||||
|
||||
yapi.connect = dbModule.connect()
|
||||
|
||||
const app = new Koa()
|
||||
app.use(mockServer)
|
||||
app.use(bodyParser())
|
||||
|
@ -322,7 +322,7 @@ class projectController extends baseController {
|
||||
* @param {String} [desc] 项目描述
|
||||
* @param {Array} [env] 项目环境配置
|
||||
* @param {String} [env[].name] 环境名称
|
||||
* @param {String} [env[].host] 环境域名
|
||||
* @param {String} [env[].domain] 环境域名
|
||||
* @returns {Object}
|
||||
* @example ./api/project/up.json
|
||||
*/
|
||||
|
@ -70,7 +70,7 @@ class interfaceModel extends baseModel{
|
||||
list (project_id){
|
||||
return this.model.find({
|
||||
project_id: project_id
|
||||
}).exec()
|
||||
}).sort({_id: -1}).exec()
|
||||
}
|
||||
|
||||
del(id){
|
||||
|
@ -65,7 +65,7 @@ class projectModel extends baseModel{
|
||||
list (group_id){
|
||||
return this.model.find({
|
||||
group_id: group_id
|
||||
}).exec()
|
||||
}).sort({_id: -1}).exec()
|
||||
}
|
||||
|
||||
listWithPaging(group_id, page, limit) {
|
||||
@ -73,7 +73,7 @@ class projectModel extends baseModel{
|
||||
limit = parseInt(limit);
|
||||
return this.model.find({
|
||||
group_id: group_id
|
||||
}).skip((page - 1) * limit).limit(limit).exec();
|
||||
}).sort({_id: -1}).skip((page - 1) * limit).limit(limit).exec();
|
||||
}
|
||||
|
||||
listCount(group_id) {
|
||||
|
@ -47,7 +47,7 @@ class userModel extends baseModel{
|
||||
listWithPaging(page, limit) {
|
||||
page = parseInt(page);
|
||||
limit = parseInt(limit);
|
||||
return this.model.find().skip((page - 1) * limit).limit(limit).select("_id username email role add_time up_time").exec();
|
||||
return this.model.find().sort({_id: -1}).skip((page - 1) * limit).limit(limit).select("_id username email role add_time up_time").exec();
|
||||
}
|
||||
listCount() {
|
||||
return this.model.count();
|
||||
|
@ -42,7 +42,6 @@ _yapi2.default.commons = _commons2.default;
|
||||
|
||||
|
||||
_yapi2.default.connect = _db2.default.connect();
|
||||
|
||||
var app = new _koa2.default();
|
||||
app.use(_mockServer2.default);
|
||||
app.use((0, _koaBodyparser2.default)());
|
||||
|
@ -114,7 +114,7 @@ var interfaceModel = function (_baseModel) {
|
||||
value: function list(project_id) {
|
||||
return this.model.find({
|
||||
project_id: project_id
|
||||
}).exec();
|
||||
}).sort({ _id: -1 }).exec();
|
||||
}
|
||||
}, {
|
||||
key: 'del',
|
||||
|
@ -106,7 +106,7 @@ var projectModel = function (_baseModel) {
|
||||
value: function list(group_id) {
|
||||
return this.model.find({
|
||||
group_id: group_id
|
||||
}).exec();
|
||||
}).sort({ _id: -1 }).exec();
|
||||
}
|
||||
}, {
|
||||
key: 'listWithPaging',
|
||||
@ -115,7 +115,7 @@ var projectModel = function (_baseModel) {
|
||||
limit = parseInt(limit);
|
||||
return this.model.find({
|
||||
group_id: group_id
|
||||
}).skip((page - 1) * limit).limit(limit).exec();
|
||||
}).sort({ _id: -1 }).skip((page - 1) * limit).limit(limit).exec();
|
||||
}
|
||||
}, {
|
||||
key: 'listCount',
|
||||
|
@ -99,7 +99,7 @@ var userModel = function (_baseModel) {
|
||||
value: function listWithPaging(page, limit) {
|
||||
page = parseInt(page);
|
||||
limit = parseInt(limit);
|
||||
return this.model.find().skip((page - 1) * limit).limit(limit).select("_id username email role add_time up_time").exec();
|
||||
return this.model.find().sort({ _id: -1 }).skip((page - 1) * limit).limit(limit).select("_id username email role add_time up_time").exec();
|
||||
}
|
||||
}, {
|
||||
key: 'listCount',
|
||||
|
Loading…
Reference in New Issue
Block a user