mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-15 05:10:47 +08:00
Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev
This commit is contained in:
commit
81c93b1c60
@ -14,18 +14,19 @@ class Footer extends Component {
|
||||
'background': 'url(./image/footer-bac.jpg)'
|
||||
}
|
||||
return (
|
||||
<div className = 'footer' style = {style}>
|
||||
|
||||
<div className = 'footContent'>
|
||||
{ this.props.footList.map(function(item,i){
|
||||
return <FootItem key = { i } linkList = { item.linkList } title = { item.title } iconType = { item.iconType } ></FootItem>
|
||||
}) }
|
||||
<div className = 'copyRight'>
|
||||
<h4>Copyright © 2017</h4>
|
||||
YMFF出品 @ YMFF
|
||||
<div className = 'footer-wrapper'>
|
||||
<div className = 'footer' style = {style}>
|
||||
<div className = 'footContent'>
|
||||
{ this.props.footList.map(function(item,i){
|
||||
return <FootItem key = { i } linkList = { item.linkList } title = { item.title } iconType = { item.iconType } ></FootItem>
|
||||
}) }
|
||||
<div className = 'copyRight'>
|
||||
<h4>Copyright © 2017</h4>
|
||||
YMFF出品 @ YMFF
|
||||
</div>
|
||||
</div>
|
||||
<div className='footerMask'></div>
|
||||
</div>
|
||||
<div className='footerMask'></div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
@import '../../styles/common.scss';
|
||||
@import '../../styles/mixin.scss';
|
||||
|
||||
.footer-wrapper{
|
||||
width: 100%;
|
||||
}
|
||||
.footer{
|
||||
@include wrap-width-limit;
|
||||
margin: 0px auto;
|
||||
margin: 0 auto;
|
||||
clear: both;
|
||||
font-size: 12px;
|
||||
background: #000c15;
|
||||
@ -25,7 +28,7 @@
|
||||
.footerMask{
|
||||
@include wrap-width-limit;
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
top: 0;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background-color: #404040;
|
||||
@ -34,8 +37,8 @@
|
||||
}
|
||||
.footContent{
|
||||
@include row-width-limit;
|
||||
width:90%;
|
||||
margin:0px auto;
|
||||
//width:90%;
|
||||
margin:0 auto;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
@ -45,7 +48,7 @@
|
||||
width: 25%;
|
||||
float: left;
|
||||
div{
|
||||
margin: 6px 0px;
|
||||
margin: 6px 0;
|
||||
}
|
||||
a{
|
||||
font-weight: 200;
|
||||
@ -68,6 +71,6 @@
|
||||
margin: 0 auto 12px;
|
||||
font-weight: 500;
|
||||
position: relative;
|
||||
text-indent: 0em;
|
||||
text-indent: 0;
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,8 @@ import QueueAnim from 'rc-queue-anim';
|
||||
const oneAnim = { y: '+=30', opacity: 0, type: 'from', ease: 'easeOutQuad' };
|
||||
const imgAnim = { y: '+=50', opacity: 0, type: 'from', ease: 'easeOutQuad', duration: '1500'};
|
||||
const style = {
|
||||
'height':'100%',
|
||||
// 'height':'100%',
|
||||
// 'height':'7rem',
|
||||
'width':'100%',
|
||||
'background': 'url(./image/bg-img.jpg) no-repeat',
|
||||
'backgroundSize':'100% 100%'
|
||||
@ -37,19 +38,17 @@ const HomeGuest = (props) => (
|
||||
<Col span={8} className="main-one-left">
|
||||
<Login/>
|
||||
</Col>
|
||||
<OverPack>
|
||||
<TweenOne
|
||||
key="feat-motion-one"
|
||||
animation={imgAnim}
|
||||
>
|
||||
<Col span={16} className="main-one-right">
|
||||
|
||||
<div className="img-container">
|
||||
<img src="./image/demo-img.png"/>
|
||||
</div>
|
||||
</Col>
|
||||
</TweenOne>
|
||||
</OverPack>
|
||||
<Col span={16} className="main-one-right">
|
||||
<OverPack>
|
||||
<TweenOne
|
||||
key="feat-motion-one"
|
||||
animation={imgAnim}
|
||||
className="img-container"
|
||||
>
|
||||
<img src="./image/demo-img.png"/>
|
||||
</TweenOne>
|
||||
</OverPack>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -27,6 +27,8 @@ $color-black-lighter: #404040;
|
||||
color: $color-white;
|
||||
}
|
||||
.img-container{
|
||||
width: 100%;
|
||||
//height: 5rem;
|
||||
margin-bottom: -.3rem;
|
||||
img{
|
||||
width: 100%;
|
||||
|
140
doc/build/api.html
vendored
140
doc/build/api.html
vendored
@ -131,6 +131,10 @@
|
||||
<li >
|
||||
<a href="#-user-search">/user/search</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-user-nav">/user/nav</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
@ -252,7 +256,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/group.js.html#12" target="_blank">./server/controllers/group.js:12</a>
|
||||
<a href="./static/server/controllers/group.js.html#10" target="_blank">./server/controllers/group.js:10</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -335,7 +339,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/group.js.html#54" target="_blank">./server/controllers/group.js:54</a>
|
||||
<a href="./static/server/controllers/group.js.html#64" target="_blank">./server/controllers/group.js:64</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -397,7 +401,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/group.js.html#74" target="_blank">./server/controllers/group.js:74</a>
|
||||
<a href="./static/server/controllers/group.js.html#83" target="_blank">./server/controllers/group.js:83</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -469,7 +473,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/group.js.html#108" target="_blank">./server/controllers/group.js:108</a>
|
||||
<a href="./static/server/controllers/group.js.html#120" target="_blank">./server/controllers/group.js:120</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -569,7 +573,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#14" target="_blank">./server/controllers/user.js:14</a>
|
||||
<a href="./static/server/controllers/user.js.html#17" target="_blank">./server/controllers/user.js:17</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -656,7 +660,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#58" target="_blank">./server/controllers/user.js:58</a>
|
||||
<a href="./static/server/controllers/user.js.html#62" target="_blank">./server/controllers/user.js:62</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -689,7 +693,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#151" target="_blank">./server/controllers/user.js:151</a>
|
||||
<a href="./static/server/controllers/user.js.html#159" target="_blank">./server/controllers/user.js:159</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -785,7 +789,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#224" target="_blank">./server/controllers/user.js:224</a>
|
||||
<a href="./static/server/controllers/user.js.html#228" target="_blank">./server/controllers/user.js:228</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -882,7 +886,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#286" target="_blank">./server/controllers/user.js:286</a>
|
||||
<a href="./static/server/controllers/user.js.html#300" target="_blank">./server/controllers/user.js:300</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -952,7 +956,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#315" target="_blank">./server/controllers/user.js:315</a>
|
||||
<a href="./static/server/controllers/user.js.html#328" target="_blank">./server/controllers/user.js:328</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1014,7 +1018,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#350" target="_blank">./server/controllers/user.js:350</a>
|
||||
<a href="./static/server/controllers/user.js.html#366" target="_blank">./server/controllers/user.js:366</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1076,7 +1080,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#377" target="_blank">./server/controllers/user.js:377</a>
|
||||
<a href="./static/server/controllers/user.js.html#397" target="_blank">./server/controllers/user.js:397</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1168,7 +1172,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#426" target="_blank">./server/controllers/user.js:426</a>
|
||||
<a href="./static/server/controllers/user.js.html#456" target="_blank">./server/controllers/user.js:456</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1226,6 +1230,94 @@
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-user-nav" class="page-header subject">
|
||||
/user/nav
|
||||
|
||||
<span class="ui-badge">GET</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-user-nav">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
根据路由id获取面包屑数据
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#502" target="_blank">./server/controllers/user.js:502</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>type</td>
|
||||
<td>String</td>
|
||||
<td>可选group|interface|project</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>id</td>
|
||||
<td>Number</td>
|
||||
<td></td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</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">"interface_id"</span><span class="token punctuation">:</span> <span class="token number">2746</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"interface_name"</span><span class="token punctuation">:</span> <span class="token string">"/a/c"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"project_id"</span><span class="token punctuation">:</span> <span class="token number">2481</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"project_name"</span><span class="token punctuation">:</span> <span class="token string">"www.xxx.com/api"</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">"group_name"</span><span class="token punctuation">:</span> <span class="token string">"YMFE"</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@ -1249,7 +1341,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#42" target="_blank">./server/controllers/project.js:42</a>
|
||||
<a href="./static/server/controllers/project.js.html#34" target="_blank">./server/controllers/project.js:34</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1390,7 +1482,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#114" target="_blank">./server/controllers/project.js:114</a>
|
||||
<a href="./static/server/controllers/project.js.html#115" target="_blank">./server/controllers/project.js:115</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1474,7 +1566,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#146" target="_blank">./server/controllers/project.js:146</a>
|
||||
<a href="./static/server/controllers/project.js.html#147" target="_blank">./server/controllers/project.js:147</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1558,7 +1650,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#179" target="_blank">./server/controllers/project.js:179</a>
|
||||
<a href="./static/server/controllers/project.js.html#180" target="_blank">./server/controllers/project.js:180</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1636,7 +1728,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#207" target="_blank">./server/controllers/project.js:207</a>
|
||||
<a href="./static/server/controllers/project.js.html#208" target="_blank">./server/controllers/project.js:208</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1719,7 +1811,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#231" target="_blank">./server/controllers/project.js:231</a>
|
||||
<a href="./static/server/controllers/project.js.html#232" target="_blank">./server/controllers/project.js:232</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -2198,7 +2290,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#394" target="_blank">./server/controllers/project.js:394</a>
|
||||
<a href="./static/server/controllers/project.js.html#402" target="_blank">./server/controllers/project.js:402</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -2607,7 +2699,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/interface.js.html#81" target="_blank">./server/controllers/interface.js:81</a>
|
||||
<a href="./static/server/controllers/interface.js.html#99" target="_blank">./server/controllers/interface.js:99</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -2672,7 +2764,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/interface.js.html#104" target="_blank">./server/controllers/interface.js:104</a>
|
||||
<a href="./static/server/controllers/interface.js.html#124" target="_blank">./server/controllers/interface.js:124</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -2737,7 +2829,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/interface.js.html#128" target="_blank">./server/controllers/interface.js:128</a>
|
||||
<a href="./static/server/controllers/interface.js.html#149" target="_blank">./server/controllers/interface.js:149</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -2970,7 +3062,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/interface.js.html#197" target="_blank">./server/controllers/interface.js:197</a>
|
||||
<a href="./static/server/controllers/interface.js.html#250" target="_blank">./server/controllers/interface.js:250</a>
|
||||
</p>
|
||||
|
||||
|
||||
|
42
doc/build/index.html
vendored
42
doc/build/index.html
vendored
@ -58,8 +58,46 @@
|
||||
<div class="ydoc-container-content " id="readme">
|
||||
|
||||
<article class="markdown-body">
|
||||
<h3 class="subject" id="Yapi是一个高效,易用,功能强大的api管理系统">Yapi是一个高效,易用,功能强大的api管理系统 <a class="hashlink" href="#Yapi是一个高效,易用,功能强大的api管理系统">#</a></h3><h4 class="subject" id="后台server如何启动和热更新?">后台server如何启动和热更新? <a class="hashlink" href="#后台server如何启动和热更新?">#</a></h4><ol>
|
||||
<li>npm install</li><li>npm run dev-server</li></ol>
|
||||
<h1 class="subject" id="YApi">YApi <a class="hashlink" href="#YApi">#</a></h1><h2 class="subject" id="平台介绍">平台介绍 <a class="hashlink" href="#平台介绍">#</a></h2><p>YApi是高效、易用、功能强大的api管理平台,旨在为开发、产品、测试人员提供更优雅的接口管理服务。可以帮助开发者轻松创建、发布、维护、监控和保护任意规模的 API,而且yapi为用户提供了优秀的交互体验,开发人员只需利用平台提供的接口数据写入工具以及简单的点击操作就可以实现接口的创建。</p>
|
||||
<h2 class="subject" id="功能">功能 <a class="hashlink" href="#功能">#</a></h2><ol>
|
||||
<li><p>项目接口管理</p>
|
||||
<p> 提供基本的项目分组,项目管理,接口管理功能</p>
|
||||
</li><li><p>mockServer服务</p>
|
||||
<p> 用户只需在项目配置线上域名和接口基本路径,通过将线上域名指到我们的yapi平台服务器,就可使用mockServer服务</p>
|
||||
</li><li><p>用户管理</p>
|
||||
<p> 提供基本的用户注册登录管理等功能,集成了去哪儿QSSO登录</p>
|
||||
</li></ol>
|
||||
<h2 class="subject" id="快速开始">快速开始 <a class="hashlink" href="#快速开始">#</a></h2><h3 class="subject" id="1 接口管理架构">1 接口管理架构 <a class="hashlink" href="#1 接口管理架构">#</a></h3><p>平台以<strong>项目分组</strong> -> <strong>项目</strong> -> <strong>接口</strong>的划分进行接口组织管理。</p>
|
||||
<p><img src="http://upload-images.jianshu.io/upload_images/842107-305ba49a60ee1ff5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt=""></p>
|
||||
<h4 class="subject" id="1.1 项目分组">1.1 项目分组 <a class="hashlink" href="#1.1 项目分组">#</a></h4><p>登录之后进到项目首页,左边侧边栏显示的即分组列表。</p>
|
||||
<p><img src="http://upload-images.jianshu.io/upload_images/842107-d90ca4b3242fa760.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="分组列表"></p>
|
||||
<p>管理员有权限添加或删除分组。
|
||||
<img src="http://upload-images.jianshu.io/upload_images/842107-a0d4d9a98003896a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="添加分组"></p>
|
||||
<blockquote>
|
||||
<p>分组名称具有唯一性</p>
|
||||
</blockquote>
|
||||
<h4 class="subject" id="1.2 项目">1.2 项目 <a class="hashlink" href="#1.2 项目">#</a></h4><p>选中不同的分组,右边会显示该分组下的项目列表。</p>
|
||||
<p><img src="http://upload-images.jianshu.io/upload_images/842107-137bcae58b84715e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="项目列表"></p>
|
||||
<p>创建项目需要填写项目名称,项目线上域名(添加完成后可配置项目其他环境域名),项目接口基本路径(接口路径前面相同的部分)以及项目描述。
|
||||
<img src="http://upload-images.jianshu.io/upload_images/842107-360a50ddb746f73d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="创建项目"></p>
|
||||
<blockquote>
|
||||
<p>项目『线上域名 + 基本路径』具有唯一性</p>
|
||||
</blockquote>
|
||||
<h4 class="subject" id="1.3 接口">1.3 接口 <a class="hashlink" href="#1.3 接口">#</a></h4><p>点击项目名称,进入该项目接口列表。
|
||||
<img src="http://upload-images.jianshu.io/upload_images/842107-e858005f714f4889.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="接口列表"></p>
|
||||
<p>点击编辑,进入接口详情页(之后接口详情页和编辑也会分开),可以编辑接口或者请求测试真实接口。</p>
|
||||
<p><img src="http://upload-images.jianshu.io/upload_images/842107-78c0ea839619d068.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="接口详情"></p>
|
||||
<p><img src="http://upload-images.jianshu.io/upload_images/842107-2ee7171d707e91ff.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="请求真实接口"></p>
|
||||
<h4 class="subject" id="Mock功能">Mock功能 <a class="hashlink" href="#Mock功能">#</a></h4><p>   yapi的Mock功能可以根据用户的输入接口信息如协议、URL、接口名、请求头、请求参数、mock规则生成Mock接口,这些接口会自动生成模拟数据,支持复杂的生成逻辑,创建者可以自由构造需要的数据。而且与常见的Mock方式如将Mock写在代码里和JS拦截等相比yapi的Mock在使用场景和效率和复杂度上是相差甚远的,正是由于yapi的Mock是一个第三方平台那么在 团队开发时任何人都可以权限许可下创建、修改接口信息等操作,这对于团队开发是很有好处的。</p>
|
||||
<h5 class="subject" id="第一步:添加接口">第一步:添加接口 <a class="hashlink" href="#第一步:添加接口">#</a></h5><p>通过点击页面上的"+添加接口"</p>
|
||||
<p><img src="http://note.youdao.com/yws/api/personal/file/WEB613bd4f29db038f2b41c03dcfceda2b6?method=download&shareKey=29bfc2b855f6f26ce0079baf567e54cc" alt="接口添加"></p>
|
||||
<h5 class="subject" id="第二步:输入协议、URL、接口名、请求头、请求参数、mock规则等信息,然后点击右上角的"Mock"按钮。">第二步:输入协议、URL、接口名、请求头、请求参数、mock规则等信息,然后点击右上角的"Mock"按钮。 <a class="hashlink" href="#第二步:输入协议、URL、接口名、请求头、请求参数、mock规则等信息,然后点击右上角的"Mock"按钮。">#</a></h5><p><img src="http://note.youdao.com/yws/api/personal/file/WEB0759331a53e095d910cfb4024ea657d5?method=download&shareKey=a86046f0bd2353d4763a9c962d747e5b" alt="接口详情"></p>
|
||||
<h5 class="subject" id="第三步:当点击"Mock"按钮之后,就会在页面下方生成一个mock结果并产生一个API接口。点击"复制"按钮即可复制,用户拿到接口后就可以发请求了。">第三步:当点击"Mock"按钮之后,就会在页面下方生成一个mock结果并产生一个API接口。点击"复制"按钮即可复制,用户拿到接口后就可以发请求了。 <a class="hashlink" href="#第三步:当点击"Mock"按钮之后,就会在页面下方生成一个mock结果并产生一个API接口。点击"复制"按钮即可复制,用户拿到接口后就可以发请求了。">#</a></h5><p><img src="http://note.youdao.com/yws/api/personal/file/WEB265d4bf7cc979bda06d07639d1b84557?method=download&shareKey=64d41dea0371e38761f494d7899b3b35" alt="Mock结果"></p>
|
||||
<h5 class="subject" id="第四步:当拿到复制好接口之后就可以发起一个请求了,先将请求的信息填写完善如:请求方法(post、get等)、URL、请求头、请求的数据等。然后就点击"发送",然后在"返回结果"出可以看到接口返回的数据。">第四步:当拿到复制好接口之后就可以发起一个请求了,先将请求的信息填写完善如:请求方法(post、get等)、URL、请求头、请求的数据等。然后就点击"发送",然后在"返回结果"出可以看到接口返回的数据。 <a class="hashlink" href="#第四步:当拿到复制好接口之后就可以发起一个请求了,先将请求的信息填写完善如:请求方法(post、get等)、URL、请求头、请求的数据等。然后就点击"发送",然后在"返回结果"出可以看到接口返回的数据。">#</a></h5><p><img src="http://note.youdao.com/yws/api/personal/file/WEB1c22d5c4062be5f10be0b1cdfae86621?method=download&shareKey=93be3a4f1fe56219b89ea2c5ba04014d" alt="请求接口"></p>
|
||||
<p>你也可以通过点击"管理成员"来添加和删除项目的成员,便于团队管理。</p>
|
||||
<p><img src="http://note.youdao.com/yws/api/personal/file/WEB1b9defdf0cb884f46c2bd6c30ceb02fb?method=download&shareKey=218b9326659208ec564b9fff3ea8c6c3" alt="成员管理"></p>
|
||||
<h2 class="subject" id="未来计划推出功能">未来计划推出功能 <a class="hashlink" href="#未来计划推出功能">#</a></h2><ol>
|
||||
<li>可视化JSON编辑器,可定义JSON_Schema和mockjs</li><li>支持HTTP和RPC协议</li><li>自动化测试</li><li>多人协作</li></ol>
|
||||
|
||||
</article>
|
||||
</div>
|
||||
|
101
doc/build/static/server/controllers/base.js.html
vendored
101
doc/build/static/server/controllers/base.js.html
vendored
@ -25,23 +25,22 @@
|
||||
<div class="ydoc-container-content">
|
||||
<div class="static-code-content" role="main">
|
||||
<pre class="brush: js;">
|
||||
import yapi from '../yapi.js'
|
||||
import projectModel from '../models/project.js'
|
||||
import userModel from '../models/user.js'
|
||||
import yapi from '../yapi.js';
|
||||
import projectModel from '../models/project.js';
|
||||
import userModel from '../models/user.js';
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
|
||||
class baseController{
|
||||
constructor(ctx){
|
||||
class baseController {
|
||||
constructor(ctx) {
|
||||
this.ctx = ctx;
|
||||
//网站上线后,role对象key是不能修改的,value可以修改
|
||||
this.roles = {
|
||||
admin: 'Admin',
|
||||
member: '网站会员'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async init(ctx){
|
||||
async init(ctx) {
|
||||
this.$user = null;
|
||||
let ignoreRouter = [
|
||||
'/user/login_by_token',
|
||||
@ -49,76 +48,98 @@ class baseController{
|
||||
'/user/reg',
|
||||
'/user/status',
|
||||
'/user/logout'
|
||||
]
|
||||
if(ignoreRouter.indexOf(ctx.path) > -1){
|
||||
];
|
||||
if (ignoreRouter.indexOf(ctx.path) > -1) {
|
||||
this.$auth = true;
|
||||
}else{
|
||||
await this.checkLogin(ctx)
|
||||
} else {
|
||||
await this.checkLogin(ctx);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
getUid(ctx){
|
||||
return this.$uid;
|
||||
getUid() {
|
||||
return parseInt(this.$uid, 10);
|
||||
}
|
||||
|
||||
async checkLogin(ctx){
|
||||
async checkLogin(ctx) {
|
||||
let token = ctx.cookies.get('_yapi_token');
|
||||
let uid = ctx.cookies.get('_yapi_uid');
|
||||
try{
|
||||
if(!token || !uid) return false;
|
||||
let uid = ctx.cookies.get('_yapi_uid');
|
||||
|
||||
try {
|
||||
if (!token || !uid) return false;
|
||||
let userInst = yapi.getInst(userModel); //创建user实体
|
||||
let result = await userInst.findById(uid);
|
||||
let decoded = jwt.verify(token, result.passsalt)
|
||||
if(decoded.uid == uid){
|
||||
let decoded = jwt.verify(token, result.passsalt);
|
||||
|
||||
if (decoded.uid == uid) {
|
||||
this.$uid = uid;
|
||||
this.$auth = true;
|
||||
this.$user = result;
|
||||
this.$user = result;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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']));
|
||||
async getLoginStatus(ctx) {
|
||||
if (await this.checkLogin(ctx) === true) {
|
||||
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.');
|
||||
|
||||
return ctx.body = yapi.commons.resReturn(null, 300, 'Please login.');
|
||||
}
|
||||
|
||||
getRole(){
|
||||
getRole() {
|
||||
return this.$user.role;
|
||||
}
|
||||
|
||||
async jungeProjectAuth(id){
|
||||
async jungeProjectAuth(id) {
|
||||
let model = yapi.getInst(projectModel);
|
||||
if(this.getRole() === 'admin') return true;
|
||||
if(!id) return false;
|
||||
let result = await model.get(id);
|
||||
if(result.uid === this.getUid()){
|
||||
|
||||
if (this.getRole() === 'admin') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let result = await model.get(id);
|
||||
|
||||
if (result.uid === this.getUid()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async jungeMemberAuth(id, member_uid){
|
||||
async jungeMemberAuth(id, member_uid) {
|
||||
let model = yapi.getInst(projectModel);
|
||||
if(this.getRole() === 'admin') return true;
|
||||
if(!id || !member_uid) return false;
|
||||
let result = await model.checkMemberRepeat(id, member_uid);
|
||||
if(result > 0){
|
||||
|
||||
if (this.getRole() === 'admin') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!id || !member_uid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let result = await model.checkMemberRepeat(id, member_uid);
|
||||
|
||||
if (result > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = baseController
|
||||
module.exports = baseController;
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
130
doc/build/static/server/controllers/group.js.html
vendored
130
doc/build/static/server/controllers/group.js.html
vendored
@ -25,17 +25,15 @@
|
||||
<div class="ydoc-container-content">
|
||||
<div class="static-code-content" role="main">
|
||||
<pre class="brush: js;">
|
||||
import groupModel from '../models/group.js'
|
||||
import yapi from '../yapi.js'
|
||||
import baseController from './base.js'
|
||||
import projectModel from '../models/project.js'
|
||||
import groupModel from '../models/group.js';
|
||||
import yapi from '../yapi.js';
|
||||
import baseController from './base.js';
|
||||
import projectModel from '../models/project.js';
|
||||
|
||||
//
|
||||
class groupController extends baseController{
|
||||
constructor(ctx){
|
||||
super(ctx)
|
||||
class groupController extends baseController {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
@ -50,33 +48,45 @@ class groupController extends baseController{
|
||||
*/
|
||||
async add(ctx) {
|
||||
let params = ctx.request.body;
|
||||
if(this.getRole() !== 'admin'){
|
||||
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
|
||||
|
||||
params = yapi.commons.handleParams(params, {
|
||||
group_name: 'string',
|
||||
group_desc: 'string'
|
||||
});
|
||||
|
||||
if (this.getRole() !== 'admin') {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '没有权限');
|
||||
}
|
||||
if(!params.group_name){
|
||||
|
||||
if (!params.group_name) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组名不能为空');
|
||||
}
|
||||
var groupInst = yapi.getInst(groupModel);
|
||||
|
||||
var checkRepeat = await groupInst.checkRepeat(params.group_name);
|
||||
if(checkRepeat > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '项目分组名已存在');
|
||||
|
||||
let groupInst = yapi.getInst(groupModel);
|
||||
|
||||
let checkRepeat = await groupInst.checkRepeat(params.group_name);
|
||||
|
||||
if (checkRepeat > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '项目分组名已存在');
|
||||
}
|
||||
|
||||
let data = {
|
||||
group_name: params.group_name,
|
||||
group_desc: params.group_desc,
|
||||
uid: '0',
|
||||
uid: this.getUid(),
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
}
|
||||
try{
|
||||
};
|
||||
|
||||
try {
|
||||
let result = await groupInst.save(data);
|
||||
|
||||
result = yapi.commons.fieldSelect(result, ['_id', 'group_name', 'group_desc', 'uid']);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,14 +98,13 @@ class groupController extends baseController{
|
||||
* @returns {Object}
|
||||
* @example ./api/group/list.json
|
||||
*/
|
||||
|
||||
async list(ctx) {
|
||||
try{
|
||||
try {
|
||||
var groupInst = yapi.getInst(groupModel);
|
||||
let result = await groupInst.list();
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,27 +118,30 @@ class groupController extends baseController{
|
||||
* @returns {Object}
|
||||
* @example ./api/group/del.json
|
||||
*/
|
||||
async del(ctx) {
|
||||
if (this.getRole() !== 'admin') {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '没有权限');
|
||||
}
|
||||
|
||||
async del(ctx){
|
||||
if(this.getRole() !== 'admin'){
|
||||
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
|
||||
}
|
||||
try{
|
||||
var groupInst = yapi.getInst(groupModel);
|
||||
var projectInst = yapi.getInst(projectModel);
|
||||
let id = ctx.request.body.id;
|
||||
if(!id){
|
||||
try {
|
||||
let groupInst = yapi.getInst(groupModel);
|
||||
let projectInst = yapi.getInst(projectModel);
|
||||
let id = ctx.request.body.id;
|
||||
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, 'id不能为空');
|
||||
}
|
||||
let count = await projectInst.countByGroupId(id);
|
||||
if(count > 0){
|
||||
|
||||
let count = await projectInst.countByGroupId(id);
|
||||
|
||||
if (count > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 403, '请先删除该分组下的项目');
|
||||
}
|
||||
|
||||
let result = await groupInst.del(id);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(err){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (err) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, err.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,31 +157,35 @@ class groupController extends baseController{
|
||||
* @returns {Object}
|
||||
* @example ./api/group/up.json
|
||||
*/
|
||||
|
||||
async up(ctx){
|
||||
if(this.getRole() !== 'admin'){
|
||||
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
|
||||
async up(ctx) {
|
||||
if (this.getRole() !== 'admin') {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '没有权限');
|
||||
}
|
||||
try{
|
||||
var groupInst = yapi.getInst(groupModel);
|
||||
|
||||
try {
|
||||
|
||||
ctx.request.body = yapi.commons.handleParams(ctx.request.body, {
|
||||
id: 'number',
|
||||
group_name: 'string',
|
||||
group_desc: 'string'
|
||||
});
|
||||
let groupInst = yapi.getInst(groupModel);
|
||||
let id = ctx.request.body.id;
|
||||
let data = {};
|
||||
ctx.request.body.group_name && (data.group_name = ctx.request.body.group_name)
|
||||
ctx.request.body.group_desc && (data.group_desc = ctx.request.body.group_desc)
|
||||
if(Object.keys(data).length === 0 ){
|
||||
ctx.request.body.group_name && (data.group_name = ctx.request.body.group_name);
|
||||
ctx.request.body.group_desc && (data.group_desc = ctx.request.body.group_desc);
|
||||
if (Object.keys(data).length === 0) {
|
||||
ctx.body = yapi.commons.resReturn(null, 404, '分组名和分组描述不能为空');
|
||||
}
|
||||
let result = await groupInst.up(id, data);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(err){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (err) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = groupController
|
||||
|
||||
module.exports = groupController;
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -25,13 +25,13 @@
|
||||
<div class="ydoc-container-content">
|
||||
<div class="static-code-content" role="main">
|
||||
<pre class="brush: js;">
|
||||
import interfaceModel from '../models/interface.js'
|
||||
import baseController from './base.js'
|
||||
import yapi from '../yapi.js'
|
||||
import interfaceModel from '../models/interface.js';
|
||||
import baseController from './base.js';
|
||||
import yapi from '../yapi.js';
|
||||
|
||||
class interfaceController extends baseController{
|
||||
constructor(ctx){
|
||||
super(ctx)
|
||||
class interfaceController extends baseController {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
this.Model = yapi.getInst(interfaceModel);
|
||||
}
|
||||
|
||||
@ -62,25 +62,39 @@ class interfaceController extends baseController{
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/add.json
|
||||
*/
|
||||
async add(ctx){
|
||||
async add(ctx) {
|
||||
let params = ctx.request.body;
|
||||
|
||||
params = yapi.commons.handleParams(params, {
|
||||
project_id: 'number',
|
||||
title: 'string',
|
||||
path: 'string',
|
||||
method: 'string',
|
||||
desc: 'string'
|
||||
});
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase()
|
||||
params.method = params.method.toUpperCase();
|
||||
params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json';
|
||||
if(!params.project_id){
|
||||
|
||||
if (!params.project_id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
|
||||
if(!params.path){
|
||||
if (!params.path) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口请求路径不能为空');
|
||||
}
|
||||
|
||||
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 + ']');
|
||||
}
|
||||
if (!yapi.commons.verifyPath(params.path)) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/');
|
||||
}
|
||||
|
||||
try{
|
||||
let checkRepeat = await this.Model.checkRepeat(params.project_id, params.path, params.method);
|
||||
|
||||
if (checkRepeat > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
|
||||
}
|
||||
|
||||
try {
|
||||
let data = {
|
||||
project_id: params.project_id,
|
||||
title: params.title,
|
||||
@ -89,20 +103,24 @@ class interfaceController extends baseController{
|
||||
method: params.method,
|
||||
req_headers: params.req_headers,
|
||||
req_params_type: params.req_params_type,
|
||||
res_body: params.res_body,
|
||||
res_body: params.res_body,
|
||||
res_body_type: params.res_body_type,
|
||||
uid: this.getUid(),
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
};
|
||||
|
||||
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.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);
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,16 +134,18 @@ class interfaceController extends baseController{
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/get.json
|
||||
*/
|
||||
async get(ctx){
|
||||
async get(ctx) {
|
||||
let params = ctx.request.query;
|
||||
if(!params.id){
|
||||
|
||||
if (!params.id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
|
||||
}
|
||||
try{
|
||||
|
||||
try {
|
||||
let result = await this.Model.get(params.id);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,17 +159,18 @@ class interfaceController extends baseController{
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/list.json
|
||||
*/
|
||||
|
||||
async list(ctx){
|
||||
async list(ctx) {
|
||||
let project_id = ctx.request.query.project_id;
|
||||
if(!project_id){
|
||||
|
||||
if (!project_id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
try{
|
||||
|
||||
try {
|
||||
let result = await this.Model.list(project_id);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(err){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (err) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, err.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,44 +201,76 @@ class interfaceController extends baseController{
|
||||
* @example ./api/interface/up.json
|
||||
*/
|
||||
|
||||
async up(ctx){
|
||||
async up(ctx) {
|
||||
let params = ctx.request.body;
|
||||
|
||||
params = yapi.commons.handleParams(params, {
|
||||
title: 'string',
|
||||
path: 'string',
|
||||
method: 'string',
|
||||
desc: 'string'
|
||||
});
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase()
|
||||
params.method = params.method.toUpperCase();
|
||||
|
||||
let id = ctx.request.body.id;
|
||||
if(!id){
|
||||
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
|
||||
}
|
||||
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 + ']');
|
||||
|
||||
if (params.path && !yapi.commons.verifyPath(params.path)) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/');
|
||||
}
|
||||
|
||||
if (params.path && params.path !== interfaceData.path && params.method !== interfaceData.method) {
|
||||
let checkRepeat = await this.Model.checkRepeat(interfaceData.project_id, params.path, params.method);
|
||||
if (checkRepeat > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let data = {
|
||||
up_time: yapi.commons.time()
|
||||
};
|
||||
|
||||
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.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_headers) data.req_headers = params.req_headers;
|
||||
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.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;
|
||||
if (params.res_body_type) {
|
||||
data.res_body_type = params.res_body_type;
|
||||
}
|
||||
if (params.res_body) {
|
||||
data.res_body = params.res_body;
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
let result = await this.Model.up(id, data);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
|
||||
}
|
||||
@ -233,27 +286,27 @@ class interfaceController extends baseController{
|
||||
* @example ./api/interface/del.json
|
||||
*/
|
||||
|
||||
async del(ctx){
|
||||
try{
|
||||
let id = ctx.request.body.id;
|
||||
|
||||
if(!id){
|
||||
async del(ctx) {
|
||||
try {
|
||||
let id = ctx.request.body.id;
|
||||
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
|
||||
}
|
||||
|
||||
let data = await this.Model.get(params.id);
|
||||
let data = await this.Model.get(ctx.request.body.id);
|
||||
|
||||
if(data.uid != this.getUid()){
|
||||
if(await this.jungeProjectAuth(data.project_id) !== true){
|
||||
if (data.uid != this.getUid()) {
|
||||
if (await this.jungeProjectAuth(data.project_id) !== true) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
let result = await this.Model.del(id);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(err){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (err) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,19 +55,20 @@ class logController extends baseController {
|
||||
page = ctx.request.query.page || 1,
|
||||
limit = ctx.request.query.limit || 10;
|
||||
|
||||
if(!uid){
|
||||
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)
|
||||
});
|
||||
} catch (err) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, err.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
333
doc/build/static/server/controllers/project.js.html
vendored
333
doc/build/static/server/controllers/project.js.html
vendored
@ -25,43 +25,35 @@
|
||||
<div class="ydoc-container-content">
|
||||
<div class="static-code-content" role="main">
|
||||
<pre class="brush: js;">
|
||||
import projectModel from '../models/project.js'
|
||||
import yapi from '../yapi.js'
|
||||
import baseController from './base.js'
|
||||
import interfaceModel from '../models/interface.js'
|
||||
import groupModel from '../models/group'
|
||||
import commons from '../utils/commons.js'
|
||||
import userModel from '../models/user.js'
|
||||
import projectModel from '../models/project.js';
|
||||
import yapi from '../yapi.js';
|
||||
import baseController from './base.js';
|
||||
import interfaceModel from '../models/interface.js';
|
||||
import groupModel from '../models/group';
|
||||
import commons from '../utils/commons.js';
|
||||
import userModel from '../models/user.js';
|
||||
|
||||
class projectController extends baseController {
|
||||
|
||||
constructor(ctx){
|
||||
super(ctx)
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
this.Model = yapi.getInst(projectModel);
|
||||
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)){
|
||||
handleBasepath(basepath) {
|
||||
if (!basepath) return false;
|
||||
if (basepath[0] !== '/') basepath = '/' + basepath;
|
||||
if (basepath[basepath.length - 1] === '/') basepath = basepath.substr(0, basepath.length - 1);
|
||||
if (!yapi.commons.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)){
|
||||
verifyDomain(domain) {
|
||||
if (!domain) return false;
|
||||
if (/^[a-zA-Z0-9\-_\.]+?\.[a-zA-Z0-9\-_\.]*?[a-zA-Z]{2,6}$/.test(domain)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -78,46 +70,55 @@ class projectController extends baseController {
|
||||
* @param {String} prd_host 项目线上域名,不能为空。可通过配置的域名访问到mock数据
|
||||
* @param {String} protocol 线上域名协议,不能为空
|
||||
* @param {Number} group_id 项目分组id,不能为空
|
||||
* @param {String} [desc] 项目描述
|
||||
* @returns {Object}
|
||||
* @param {String} [desc] 项目描述
|
||||
* @returns {Object}
|
||||
* @example ./api/project/add.json
|
||||
*/
|
||||
async add(ctx) {
|
||||
let params = ctx.request.body;
|
||||
|
||||
if(!params.group_id){
|
||||
params = yapi.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
basepath: 'string',
|
||||
prd_host: 'string',
|
||||
protocol: 'string',
|
||||
group_id: 'number',
|
||||
desc: 'string'
|
||||
});
|
||||
if (!params.group_id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
|
||||
}
|
||||
|
||||
if(!params.name){
|
||||
if (!params.name) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目名不能为空');
|
||||
}
|
||||
|
||||
let checkRepeat = await this.Model.checkNameRepeat(params.name);
|
||||
if(checkRepeat > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名');
|
||||
|
||||
if (checkRepeat > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名');
|
||||
}
|
||||
|
||||
if(!params.basepath){
|
||||
if (!params.basepath) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目basepath不能为空');
|
||||
}
|
||||
if(!params.prd_host){
|
||||
if (!params.prd_host) {
|
||||
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 ((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 (!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');
|
||||
|
||||
if (checkRepeatDomain > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
|
||||
}
|
||||
|
||||
|
||||
let data = {
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
@ -129,78 +130,78 @@ class projectController extends baseController {
|
||||
group_id: params.group_id,
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
};
|
||||
|
||||
try {
|
||||
let result = await this.Model.save(data);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
|
||||
try{
|
||||
let result = await this.Model.save(data);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 添加项目
|
||||
* @interface /project/add_member
|
||||
* @method POST
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @param {String} member_uid 项目成员uid,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/project/add_member.json
|
||||
*/
|
||||
async addMember(ctx){
|
||||
/**
|
||||
* 添加项目
|
||||
* @interface /project/add_member
|
||||
* @method POST
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @param {String} member_uid 项目成员uid,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/project/add_member.json
|
||||
*/
|
||||
async addMember(ctx) {
|
||||
let params = ctx.request.body;
|
||||
if(!params.member_uid){
|
||||
if (!params.member_uid) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目成员uid不能为空');
|
||||
}
|
||||
if(!params.id){
|
||||
if (!params.id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
|
||||
var check = await this.Model.checkMemberRepeat(params.id, params.member_uid);
|
||||
if(check > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目成员已存在');
|
||||
if (check > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目成员已存在');
|
||||
}
|
||||
try{
|
||||
try {
|
||||
let result = await this.Model.addMember(params.id, params.member_uid);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 添加项目
|
||||
* @interface /project/del_member
|
||||
* @method POST
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @param {member_uid} uid 项目成员uid,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/project/del_member.json
|
||||
*/
|
||||
/**
|
||||
* 添加项目
|
||||
* @interface /project/del_member
|
||||
* @method POST
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @param {member_uid} uid 项目成员uid,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/project/del_member.json
|
||||
*/
|
||||
|
||||
async delMember(ctx){
|
||||
async delMember(ctx) {
|
||||
let params = ctx.request.body;
|
||||
if(!params.member_uid){
|
||||
if (!params.member_uid) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目成员uid不能为空');
|
||||
}
|
||||
if(!params.id){
|
||||
if (!params.id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
var check = await this.Model.checkMemberRepeat(params.id, params.member_uid);
|
||||
if(check === 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目成员不存在');
|
||||
if (check === 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目成员不存在');
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
let result = await this.Model.delMember(params.id, params.member_uid);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,7 +218,7 @@ class projectController extends baseController {
|
||||
|
||||
async getMemberList(ctx) {
|
||||
let params = ctx.request.query;
|
||||
if(!params.id) {
|
||||
if (!params.id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
|
||||
@ -227,32 +228,32 @@ class projectController extends baseController {
|
||||
let result = await userInst.findByUids(project.members);
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目
|
||||
* @interface /project/get
|
||||
* @method GET
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/project/get.json
|
||||
*/
|
||||
/**
|
||||
* 添加项目
|
||||
* @interface /project/get
|
||||
* @method GET
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/project/get.json
|
||||
*/
|
||||
|
||||
async get(ctx){
|
||||
async get(ctx) {
|
||||
let params = ctx.request.query;
|
||||
if(!params.id){
|
||||
if (!params.id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
try{
|
||||
try {
|
||||
let result = await this.Model.get(params.id);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,7 +266,7 @@ class projectController extends baseController {
|
||||
* @param {Number} group_id 项目group_id,不能为空
|
||||
* @param {Number} [page] 分页页码
|
||||
* @param {Number} [limit] 每页数据条目,默认为10
|
||||
* @returns {Object}
|
||||
* @returns {Object}
|
||||
* @example ./api/project/list.json
|
||||
*/
|
||||
|
||||
@ -274,32 +275,31 @@ class projectController extends baseController {
|
||||
page = ctx.request.query.page || 1,
|
||||
limit = ctx.request.query.limit || 10;
|
||||
|
||||
if(!group_id){
|
||||
if (!group_id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
let result = await this.Model.listWithPaging(group_id, page, limit);
|
||||
let count = await this.Model.listCount(group_id);
|
||||
let uids = [];
|
||||
result.forEach( (item)=> {
|
||||
if(uids.indexOf(item.uid) !== -1){
|
||||
uids.push(item.uid)
|
||||
result.forEach((item) => {
|
||||
if (uids.indexOf(item.uid) === -1) {
|
||||
uids.push(item.uid);
|
||||
}
|
||||
|
||||
} )
|
||||
|
||||
});
|
||||
let _users = {}, users = await yapi.getInst(userModel).findByUids(uids);
|
||||
users.forEach((item)=> {
|
||||
users.forEach((item) => {
|
||||
_users[item._id] = item;
|
||||
} )
|
||||
});
|
||||
ctx.body = yapi.commons.resReturn({
|
||||
total: Math.ceil(count / limit),
|
||||
list: result,
|
||||
userinfo: _users
|
||||
})
|
||||
}catch(err){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
});
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -310,29 +310,29 @@ class projectController extends baseController {
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @returns {Object}
|
||||
* @returns {Object}
|
||||
* @example ./api/project/del.json
|
||||
*/
|
||||
|
||||
async del(ctx){
|
||||
try{
|
||||
async del(ctx) {
|
||||
try {
|
||||
let id = ctx.request.body.id;
|
||||
if(!id){
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
let interfaceInst = yapi.getInst(interfaceModel);
|
||||
let count = await interfaceInst.countByProjectId(id);
|
||||
if(count > 0){
|
||||
if (count > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '请先删除该项目下所有接口');
|
||||
}
|
||||
|
||||
if(await this.jungeProjectAuth(id) !== true){
|
||||
if (await this.jungeProjectAuth(id) !== true) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
}
|
||||
let result = await this.Model.del(id);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(err){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
} catch (err) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, err.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -346,76 +346,84 @@ class projectController extends baseController {
|
||||
* @param {String} name 项目名称,不能为空
|
||||
* @param {String} basepath 项目基本路径,不能为空
|
||||
* @param {String} prd_host 项目线上域名,不能为空。可通过配置的域名访问到mock数据
|
||||
* @param {String} [desc] 项目描述
|
||||
* @param {String} [desc] 项目描述
|
||||
* @param {Array} [env] 项目环境配置
|
||||
* @param {String} [env[].name] 环境名称
|
||||
* @param {String} [env[].domain] 环境域名
|
||||
* @returns {Object}
|
||||
* @returns {Object}
|
||||
* @example ./api/project/up.json
|
||||
*/
|
||||
|
||||
async up(ctx){
|
||||
try{
|
||||
async up(ctx) {
|
||||
try {
|
||||
let id = ctx.request.body.id;
|
||||
let params = ctx.request.body;
|
||||
if(!id){
|
||||
params = yapi.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
basepath: 'string',
|
||||
prd_host: 'string',
|
||||
protocol: 'string',
|
||||
group_id: 'number',
|
||||
desc: 'string'
|
||||
});
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空');
|
||||
}
|
||||
|
||||
if(await this.jungeMemberAuth(id, this.getUid()) !== true){
|
||||
if (await this.jungeMemberAuth(id, this.getUid()) !== true) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
}
|
||||
|
||||
|
||||
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 ((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 (!this.verifyDomain(params.prd_host)) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '线上域名格式有误');
|
||||
}
|
||||
|
||||
if(projectData.name === params.name){
|
||||
|
||||
if (projectData.name === params.name) {
|
||||
delete params.name;
|
||||
}
|
||||
if(projectData.basepath === params.basepath && projectData.prd_host === params.prd_host){
|
||||
delete params.basepath
|
||||
delete params.prd_host
|
||||
if (projectData.basepath === params.basepath && projectData.prd_host === params.prd_host) {
|
||||
delete params.basepath;
|
||||
delete params.prd_host;
|
||||
}
|
||||
|
||||
if(params.name){
|
||||
if (params.name) {
|
||||
let checkRepeat = await this.Model.checkNameRepeat(params.name);
|
||||
if(checkRepeat > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名');
|
||||
if (checkRepeat > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名');
|
||||
}
|
||||
}
|
||||
|
||||
if(params.basepath && params.prd_host){
|
||||
if (params.basepath && params.prd_host) {
|
||||
let checkRepeatDomain = await this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
||||
if(checkRepeatDomain > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
|
||||
if (checkRepeatDomain > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
|
||||
}
|
||||
}
|
||||
|
||||
let data= {
|
||||
let data = {
|
||||
uid: this.getUid(),
|
||||
up_time: yapi.commons.time()
|
||||
}
|
||||
};
|
||||
|
||||
if(params.name) data.name = params.name;
|
||||
if(params.desc) data.desc = params.desc;
|
||||
if(params.prd_host && params.basepath){
|
||||
if (params.name) data.name = params.name;
|
||||
if (params.desc) data.desc = params.desc;
|
||||
if (params.prd_host && params.basepath) {
|
||||
data.prd_host = params.prd_host;
|
||||
data.basepath = params.basepath;
|
||||
}
|
||||
if(params.protocol) data.protocol = params.protocol;
|
||||
if(params.env) data.env = params.env;
|
||||
if (params.protocol) data.protocol = params.protocol;
|
||||
if (params.env) data.env = params.env;
|
||||
|
||||
let result = await this.Model.up(id, data);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -433,11 +441,11 @@ class projectController extends baseController {
|
||||
const { q } = ctx.request.query;
|
||||
|
||||
if (!q) {
|
||||
return ctx.body = yapi.commons.resReturn(void 0, 400, 'No keyword.')
|
||||
return ctx.body = yapi.commons.resReturn(void 0, 400, 'No keyword.');
|
||||
}
|
||||
|
||||
if (!yapi.commons.validateSearchKeyword(q)) {
|
||||
return ctx.body = yapi.commons.resReturn(void 0, 400, 'Bad query.')
|
||||
return ctx.body = yapi.commons.resReturn(void 0, 400, 'Bad query.');
|
||||
}
|
||||
|
||||
let projectList = await this.Model.search(q);
|
||||
@ -457,12 +465,12 @@ class projectController extends baseController {
|
||||
let groupRules = [
|
||||
'_id',
|
||||
'uid',
|
||||
{ key: 'group_name', alias: 'groupName'},
|
||||
{ key: 'group_name', alias: 'groupName' },
|
||||
{ key: 'group_desc', alias: 'groupDesc' },
|
||||
{ key: 'add_time', alias: 'addTime' },
|
||||
{ key: 'up_time', alias: 'upTime' }
|
||||
];
|
||||
|
||||
|
||||
projectList = commons.filterRes(projectList, projectRules);
|
||||
groupList = commons.filterRes(groupList, groupRules);
|
||||
|
||||
@ -470,12 +478,13 @@ class projectController extends baseController {
|
||||
project: projectList,
|
||||
group: groupList
|
||||
};
|
||||
|
||||
return ctx.body = yapi.commons.resReturn(queryList, 0, 'ok')
|
||||
|
||||
return ctx.body = yapi.commons.resReturn(queryList, 0, 'ok');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = projectController;
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
218
doc/build/static/server/controllers/user.js.html
vendored
218
doc/build/static/server/controllers/user.js.html
vendored
@ -25,18 +25,21 @@
|
||||
<div class="ydoc-container-content">
|
||||
<div class="static-code-content" role="main">
|
||||
<pre class="brush: js;">
|
||||
import userModel from '../models/user.js'
|
||||
import yapi from '../yapi.js'
|
||||
import baseController from './base.js'
|
||||
import mongoose from 'mongoose'
|
||||
import request from 'request'
|
||||
import common from '../utils/commons.js'
|
||||
import userModel from '../models/user.js';
|
||||
import yapi from '../yapi.js';
|
||||
import baseController from './base.js';
|
||||
import request from 'request';
|
||||
import common from '../utils/commons.js';
|
||||
|
||||
import interfaceModel from '../models/interface.js'
|
||||
import groupModel from '../models/group.js'
|
||||
import projectModel from '../models/project.js'
|
||||
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
class userController extends baseController {
|
||||
constructor(ctx) {
|
||||
super(ctx)
|
||||
super(ctx);
|
||||
this.Model = yapi.getInst(userModel);
|
||||
}
|
||||
/**
|
||||
@ -68,14 +71,15 @@ class userController extends baseController {
|
||||
if (!result) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 404, '该用户不存在');
|
||||
} else if (yapi.commons.generatePassword(password, result.passsalt) === result.password) {
|
||||
this.setLoginCookie(result._id, result.passsalt)
|
||||
this.setLoginCookie(result._id, result.passsalt);
|
||||
|
||||
return ctx.body = yapi.commons.resReturn({
|
||||
username: result.username,
|
||||
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 {
|
||||
@ -115,45 +119,45 @@ class userController extends baseController {
|
||||
let ret = {
|
||||
email: result.userId + '@qunar.com',
|
||||
username: result.data.userInfo.name
|
||||
}
|
||||
resolve(ret)
|
||||
};
|
||||
resolve(ret);
|
||||
} else {
|
||||
reject(result)
|
||||
reject(result);
|
||||
}
|
||||
}
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
tokenField: 'token',
|
||||
}
|
||||
tokenField: 'token'
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
async loginByToken(ctx) {
|
||||
let config = this.thirdQunarLogin();
|
||||
|
||||
let token = ctx.request.body[config.tokenField] || ctx.request.query[config.tokenField];
|
||||
|
||||
try {
|
||||
let ret = await config.request(token);
|
||||
let login = await this.handleThirdLogin(ret.email, ret.username);
|
||||
|
||||
if (login === true) {
|
||||
yapi.commons.log('login success');
|
||||
ctx.redirect('/')
|
||||
ctx.redirect('/');
|
||||
}
|
||||
} catch (e) {
|
||||
yapi.commons.log(e.message, 'error')
|
||||
ctx.redirect('/')
|
||||
yapi.commons.log(e.message, 'error');
|
||||
ctx.redirect('/');
|
||||
}
|
||||
}
|
||||
|
||||
async handleThirdLogin(email, username) {
|
||||
let user, data, passsalt;
|
||||
var userInst = yapi.getInst(userModel);
|
||||
let userInst = yapi.getInst(userModel);
|
||||
|
||||
try {
|
||||
user = await userInst.findByEmail(email);
|
||||
|
||||
if (!user || !user._id) {
|
||||
passsalt = yapi.commons.randStr();
|
||||
data = {
|
||||
@ -164,14 +168,18 @@ class userController extends baseController {
|
||||
role: 'member',
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
}
|
||||
};
|
||||
user = await userInst.save(data);
|
||||
yapi.commons.sendMail({
|
||||
to: email,
|
||||
contents: `<h3>亲爱的用户:</h3><p>您好,感谢使用YApi,系统检测您是第一次用Qsso账号登录YApi服务,您的Email是: ${email} ,初始化密码为:${passsalt}</p>`
|
||||
});
|
||||
}
|
||||
|
||||
this.setLoginCookie(user._id, user.passsalt)
|
||||
this.setLoginCookie(user._id, user.passsalt);
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.error(e.message)
|
||||
console.error('third_login:', e.message); // eslint-disable-line
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -228,27 +236,23 @@ class userController extends baseController {
|
||||
}
|
||||
}
|
||||
|
||||
async forgetPassword(ctx) {
|
||||
async forgetPassword() { }
|
||||
|
||||
}
|
||||
|
||||
async resetPassword(ctx) {
|
||||
|
||||
}
|
||||
async resetPassword() { }
|
||||
|
||||
setLoginCookie(uid, passsalt) {
|
||||
let token = jwt.sign({ uid: uid }, passsalt, { expiresIn: '7 days' });
|
||||
|
||||
this.ctx.cookies.set('_yapi_token', token, {
|
||||
expires: yapi.commons.expireDate(7),
|
||||
httpOnly: true
|
||||
})
|
||||
});
|
||||
this.ctx.cookies.set('_yapi_uid', uid, {
|
||||
expires: yapi.commons.expireDate(7),
|
||||
httpOnly: true
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户注册接口
|
||||
* @interface /user/reg
|
||||
@ -262,16 +266,25 @@ class userController extends baseController {
|
||||
* @example ./api/user/login.json
|
||||
*/
|
||||
async reg(ctx) { //注册
|
||||
var userInst = yapi.getInst(userModel);
|
||||
let userInst = yapi.getInst(userModel);
|
||||
let params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码
|
||||
|
||||
params = yapi.commons.handleParams(params, {
|
||||
username: 'string',
|
||||
password: 'string',
|
||||
email: 'string'
|
||||
});
|
||||
|
||||
if (!params.email) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '邮箱不能为空');
|
||||
}
|
||||
|
||||
if (!params.password) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '密码不能为空');
|
||||
}
|
||||
|
||||
var checkRepeat = await userInst.checkRepeat(params.email);//然后检查是否已经存在该用户
|
||||
let checkRepeat = await userInst.checkRepeat(params.email);//然后检查是否已经存在该用户
|
||||
|
||||
if (checkRepeat > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '该email已经注册');
|
||||
}
|
||||
@ -285,14 +298,16 @@ class userController extends baseController {
|
||||
role: 'member',
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
}
|
||||
};
|
||||
|
||||
if (!data.username) {
|
||||
data.username = data.email.substr(0, data.email.indexOf('@'));
|
||||
}
|
||||
|
||||
try {
|
||||
let user = await userInst.save(data);
|
||||
this.setLoginCookie(user._id, user.passsalt)
|
||||
|
||||
this.setLoginCookie(user._id, user.passsalt);
|
||||
ctx.body = yapi.commons.resReturn({
|
||||
uid: user._id,
|
||||
email: user.email,
|
||||
@ -302,15 +317,14 @@ class userController extends baseController {
|
||||
role: 'member'
|
||||
});
|
||||
yapi.commons.sendMail({
|
||||
to: params.email,
|
||||
contents: `欢迎注册,您的账号 ${params.email} 已经注册成功`
|
||||
})
|
||||
to: user.email,
|
||||
contents: `<h3>亲爱的用户:</h3><p>您好,感谢使用YApi,您的账号 ${params.email} 已经注册成功</p>`
|
||||
});
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 401, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @interface /user/list
|
||||
@ -322,11 +336,10 @@ class userController extends baseController {
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
async list(ctx){
|
||||
async list(ctx) {
|
||||
let page = ctx.request.query.page || 1,
|
||||
limit = ctx.request.query.limit || 10;
|
||||
|
||||
|
||||
const userInst = yapi.getInst(userModel);
|
||||
try {
|
||||
let user = await userInst.listWithPaging(page, limit);
|
||||
@ -335,8 +348,8 @@ class userController extends baseController {
|
||||
total: Math.ceil(count / limit),
|
||||
list: user
|
||||
});
|
||||
} catch(e) {
|
||||
return ctx.body = yapi.commons.resReturn(null,402,e.message);
|
||||
} catch (e) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,19 +363,22 @@ class userController extends baseController {
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
async findById(ctx) { //根据id获取用户信息
|
||||
try {
|
||||
var userInst = yapi.getInst(userModel);
|
||||
let userInst = yapi.getInst(userModel);
|
||||
let id = ctx.request.query.id;
|
||||
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空');
|
||||
}
|
||||
|
||||
let result = await userInst.findById(id);
|
||||
if(!result){
|
||||
return ctx.body = yapi.commons.resReturn(null,402,"不存在的用户");
|
||||
|
||||
if (!result) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, '不存在的用户');
|
||||
}
|
||||
return ctx.body = yapi.commons.resReturn({
|
||||
|
||||
return ctx.body = yapi.commons.resReturn({
|
||||
uid: result._id,
|
||||
username: result.username,
|
||||
email: result.email,
|
||||
@ -370,8 +386,8 @@ class userController extends baseController {
|
||||
add_time: result.add_time,
|
||||
up_time: result.up_time
|
||||
});
|
||||
}catch(e){
|
||||
return ctx.body = yapi.commons.resReturn(null,402,e.message);
|
||||
} catch (e) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -386,16 +402,20 @@ class userController extends baseController {
|
||||
* @example
|
||||
*/
|
||||
async del(ctx) { //根据id删除一个用户
|
||||
try {
|
||||
try {
|
||||
if (this.getRole() !== 'admin') {
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, 'Without permission.');
|
||||
}
|
||||
var userInst = yapi.getInst(userModel);
|
||||
|
||||
let userInst = yapi.getInst(userModel);
|
||||
let id = ctx.request.body.id;
|
||||
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空');
|
||||
}
|
||||
|
||||
let result = await userInst.del(id);
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
@ -415,26 +435,36 @@ class userController extends baseController {
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
async update(ctx){ //更新用户信息
|
||||
try{
|
||||
async update(ctx) { //更新用户信息
|
||||
try {
|
||||
let params = ctx.request.body;
|
||||
if(this.getRole() !== 'admin' && params.uid != this.getUid()){
|
||||
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
|
||||
|
||||
params = yapi.commons.handleParams(params, {
|
||||
username: 'string',
|
||||
email: 'string'
|
||||
});
|
||||
|
||||
if (this.getRole() !== 'admin' && params.uid != this.getUid()) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '没有权限');
|
||||
}
|
||||
var userInst = yapi.getInst(userModel);
|
||||
|
||||
let userInst = yapi.getInst(userModel);
|
||||
let id = params.uid;
|
||||
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空');
|
||||
}
|
||||
let data ={
|
||||
|
||||
let data = {
|
||||
up_time: yapi.commons.time()
|
||||
};
|
||||
if(this.getRole() === 'admin'){
|
||||
params.role && (data.role = params.role)
|
||||
|
||||
if (this.getRole() === 'admin') {
|
||||
params.role && (data.role = params.role);
|
||||
}
|
||||
params.username && (data.username = params.username)
|
||||
params.email && (data.email = params.email)
|
||||
|
||||
params.username && (data.username = params.username);
|
||||
params.email && (data.email = params.email);
|
||||
|
||||
if (data.email) {
|
||||
var checkRepeat = await userInst.checkRepeat(data.email);//然后检查是否已经存在该用户
|
||||
@ -443,8 +473,8 @@ class userController extends baseController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let result = await userInst.update(id, data);
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
@ -492,10 +522,58 @@ class userController extends baseController {
|
||||
];
|
||||
|
||||
let filteredRes = common.filterRes(queryList, rules);
|
||||
console.log(queryList)
|
||||
console.log(queryList); // eslint-disable-line
|
||||
|
||||
return ctx.body = yapi.commons.resReturn(filteredRes, 0, 'ok');
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据路由id获取面包屑数据
|
||||
* @interface /user/nav
|
||||
* @method GET
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @param {String} type 可选group|interface|project
|
||||
* @param {Number} id
|
||||
* @return {Object}
|
||||
* @example ./api/user/nav.json
|
||||
*/
|
||||
async nav(ctx) {
|
||||
let { id, type } = ctx.request.query;
|
||||
let result = {};
|
||||
try {
|
||||
if (type === 'interface') {
|
||||
let interfaceInst = yapi.getInst(interfaceModel);
|
||||
let interfaceData = await interfaceInst.get(id)
|
||||
result["interface_id"] = interfaceData._id;
|
||||
result["interface_name"] = interfaceData.path;
|
||||
type = 'project';
|
||||
id = interfaceData.project_id;
|
||||
}
|
||||
|
||||
if (type === 'project') {
|
||||
let projectInst = yapi.getInst(projectModel);
|
||||
let projectData = await projectInst.get(id);
|
||||
result["project_id"] = projectData._id;
|
||||
result["project_name"] = projectData.prd_host + projectData.basepath;
|
||||
type = 'group';
|
||||
id = projectData.group_id
|
||||
}
|
||||
|
||||
if (type === 'group') {
|
||||
let groupInst = yapi.getInst(groupModel);
|
||||
let groupData = await groupInst.get(id);
|
||||
result["group_id"] = groupData._id;
|
||||
result["group_name"] = groupData.group_name;
|
||||
}
|
||||
|
||||
return ctx.body = yapi.commons.resReturn(result)
|
||||
}
|
||||
catch (e) {
|
||||
return ctx.body = yapi.commons.resReturn(result, 422, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = userController;
|
||||
|
12
exampleCode/api/user/nav.json
Normal file
12
exampleCode/api/user/nav.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"errcode": 0,
|
||||
"errmsg": "success",
|
||||
"data": {
|
||||
"interface_id": 2746,
|
||||
"interface_name": "/a/c",
|
||||
"project_id": 2481,
|
||||
"project_name": "www.xxx.com/api",
|
||||
"group_id": 181,
|
||||
"group_name": "YMFE"
|
||||
}
|
||||
}
|
@ -4,6 +4,10 @@ import baseController from './base.js';
|
||||
import request from 'request';
|
||||
import common from '../utils/commons.js';
|
||||
|
||||
import interfaceModel from '../models/interface.js'
|
||||
import groupModel from '../models/group.js'
|
||||
import projectModel from '../models/project.js'
|
||||
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
class userController extends baseController {
|
||||
@ -72,6 +76,7 @@ class userController extends baseController {
|
||||
ctx.body = yapi.commons.resReturn('ok');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 第三方登录需要提供一个request方法和 token字段,暂时只支持qunar第三方
|
||||
* @return {email: String, username: String}
|
||||
@ -442,7 +447,7 @@ class userController extends baseController {
|
||||
}
|
||||
|
||||
let result = await userInst.update(id, data);
|
||||
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
@ -494,6 +499,54 @@ class userController extends baseController {
|
||||
|
||||
return ctx.body = yapi.commons.resReturn(filteredRes, 0, 'ok');
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据路由id获取面包屑数据
|
||||
* @interface /user/nav
|
||||
* @method GET
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @param {String} type 可选group|interface|project
|
||||
* @param {Number} id
|
||||
* @return {Object}
|
||||
* @example ./api/user/nav.json
|
||||
*/
|
||||
async nav(ctx) {
|
||||
let { id, type } = ctx.request.query;
|
||||
let result = {};
|
||||
try {
|
||||
if (type === 'interface') {
|
||||
let interfaceInst = yapi.getInst(interfaceModel);
|
||||
let interfaceData = await interfaceInst.get(id)
|
||||
result["interface_id"] = interfaceData._id;
|
||||
result["interface_name"] = interfaceData.path;
|
||||
type = 'project';
|
||||
id = interfaceData.project_id;
|
||||
}
|
||||
|
||||
if (type === 'project') {
|
||||
let projectInst = yapi.getInst(projectModel);
|
||||
let projectData = await projectInst.get(id);
|
||||
result["project_id"] = projectData._id;
|
||||
result["project_name"] = projectData.prd_host + projectData.basepath;
|
||||
type = 'group';
|
||||
id = projectData.group_id
|
||||
}
|
||||
|
||||
if (type === 'group') {
|
||||
let groupInst = yapi.getInst(groupModel);
|
||||
let groupData = await groupInst.get(id);
|
||||
result["group_id"] = groupData._id;
|
||||
result["group_name"] = groupData.group_name;
|
||||
}
|
||||
|
||||
return ctx.body = yapi.commons.resReturn(result)
|
||||
}
|
||||
catch (e) {
|
||||
return ctx.body = yapi.commons.resReturn(result, 422, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = userController;
|
@ -21,6 +21,12 @@ class groupModel extends baseModel {
|
||||
return m.save();
|
||||
}
|
||||
|
||||
get(id) {
|
||||
return this.model.findOne({
|
||||
_id: id
|
||||
}).exec();
|
||||
}
|
||||
|
||||
checkRepeat(name) {
|
||||
return this.model.count({
|
||||
group_name: name
|
||||
|
@ -50,6 +50,7 @@ createAction('user', 'logout', 'get', 'logout');
|
||||
createAction('user', 'login_by_token', 'post', 'loginByToken');
|
||||
createAction('user', 'change_password', 'post', 'changePassword');
|
||||
createAction('user', 'search', 'get', 'search');
|
||||
createAction('user', 'nav', 'get', 'nav')
|
||||
|
||||
|
||||
//project
|
||||
|
@ -52,6 +52,18 @@ var _commons = require('../utils/commons.js');
|
||||
|
||||
var _commons2 = _interopRequireDefault(_commons);
|
||||
|
||||
var _interface = require('../models/interface.js');
|
||||
|
||||
var _interface2 = _interopRequireDefault(_interface);
|
||||
|
||||
var _group = require('../models/group.js');
|
||||
|
||||
var _group2 = _interopRequireDefault(_group);
|
||||
|
||||
var _project = require('../models/project.js');
|
||||
|
||||
var _project2 = _interopRequireDefault(_project);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var jwt = require('jsonwebtoken');
|
||||
@ -1037,6 +1049,106 @@ var userController = function (_baseController) {
|
||||
|
||||
return search;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 根据路由id获取面包屑数据
|
||||
* @interface /user/nav
|
||||
* @method GET
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @param {String} type 可选group|interface|project
|
||||
* @param {Number} id
|
||||
* @return {Object}
|
||||
* @example ./api/user/nav.json
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'nav',
|
||||
value: function () {
|
||||
var _ref14 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee14(ctx) {
|
||||
var _ctx$request$query, id, type, result, interfaceInst, interfaceData, projectInst, projectData, groupInst, groupData;
|
||||
|
||||
return _regenerator2.default.wrap(function _callee14$(_context14) {
|
||||
while (1) {
|
||||
switch (_context14.prev = _context14.next) {
|
||||
case 0:
|
||||
_ctx$request$query = ctx.request.query, id = _ctx$request$query.id, type = _ctx$request$query.type;
|
||||
result = {};
|
||||
_context14.prev = 2;
|
||||
|
||||
if (!(type === 'interface')) {
|
||||
_context14.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
interfaceInst = _yapi2.default.getInst(_interface2.default);
|
||||
_context14.next = 7;
|
||||
return interfaceInst.get(id);
|
||||
|
||||
case 7:
|
||||
interfaceData = _context14.sent;
|
||||
|
||||
result["interface_id"] = interfaceData._id;
|
||||
result["interface_name"] = interfaceData.path;
|
||||
type = 'project';
|
||||
id = interfaceData.project_id;
|
||||
|
||||
case 12:
|
||||
if (!(type === 'project')) {
|
||||
_context14.next = 21;
|
||||
break;
|
||||
}
|
||||
|
||||
projectInst = _yapi2.default.getInst(_project2.default);
|
||||
_context14.next = 16;
|
||||
return projectInst.get(id);
|
||||
|
||||
case 16:
|
||||
projectData = _context14.sent;
|
||||
|
||||
result["project_id"] = projectData._id;
|
||||
result["project_name"] = projectData.prd_host + projectData.basepath;
|
||||
type = 'group';
|
||||
id = projectData.group_id;
|
||||
|
||||
case 21:
|
||||
if (!(type === 'group')) {
|
||||
_context14.next = 28;
|
||||
break;
|
||||
}
|
||||
|
||||
groupInst = _yapi2.default.getInst(_group2.default);
|
||||
_context14.next = 25;
|
||||
return groupInst.get(id);
|
||||
|
||||
case 25:
|
||||
groupData = _context14.sent;
|
||||
|
||||
result["group_id"] = groupData._id;
|
||||
result["group_name"] = groupData.group_name;
|
||||
|
||||
case 28:
|
||||
return _context14.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result));
|
||||
|
||||
case 31:
|
||||
_context14.prev = 31;
|
||||
_context14.t0 = _context14['catch'](2);
|
||||
return _context14.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result, 422, _context14.t0.message));
|
||||
|
||||
case 34:
|
||||
case 'end':
|
||||
return _context14.stop();
|
||||
}
|
||||
}
|
||||
}, _callee14, this, [[2, 31]]);
|
||||
}));
|
||||
|
||||
function nav(_x13) {
|
||||
return _ref14.apply(this, arguments);
|
||||
}
|
||||
|
||||
return nav;
|
||||
}()
|
||||
}]);
|
||||
return userController;
|
||||
}(_base2.default);
|
||||
|
@ -60,6 +60,13 @@ var groupModel = function (_baseModel) {
|
||||
var m = new this.model(data);
|
||||
return m.save();
|
||||
}
|
||||
}, {
|
||||
key: 'get',
|
||||
value: function get(id) {
|
||||
return this.model.findOne({
|
||||
_id: id
|
||||
}).exec();
|
||||
}
|
||||
}, {
|
||||
key: 'checkRepeat',
|
||||
value: function checkRepeat(name) {
|
||||
|
@ -81,6 +81,7 @@ createAction('user', 'logout', 'get', 'logout');
|
||||
createAction('user', 'login_by_token', 'post', 'loginByToken');
|
||||
createAction('user', 'change_password', 'post', 'changePassword');
|
||||
createAction('user', 'search', 'get', 'search');
|
||||
createAction('user', 'nav', 'get', 'nav');
|
||||
|
||||
//project
|
||||
createAction('project', 'add', 'post', 'add');
|
||||
|
Loading…
Reference in New Issue
Block a user