mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-21 05:19:42 +08:00
Merge branch 'dev' of http://gitlab.corp.qunar.com/mfe/yapi into dev
This commit is contained in:
commit
e7967c2e86
@ -79,12 +79,11 @@ class MemberList extends Component {
|
||||
// 增 - 添加成员
|
||||
@autobind
|
||||
handleOk() {
|
||||
console.log(this.props.currGroup._id, this.state.inputUid);
|
||||
this.props.addMember({
|
||||
id: this.props.currGroup._id,
|
||||
member_uid: this.state.inputUid
|
||||
member_uid: this.state.inputUid,
|
||||
role: this.state.inputRole
|
||||
}).then((res) => {
|
||||
console.log(res);
|
||||
if (!res.payload.data.errcode) {
|
||||
message.success('添加成功!');
|
||||
this.reFetchList(); // 添加成功后重新获取分组成员列表
|
||||
@ -94,9 +93,9 @@ class MemberList extends Component {
|
||||
// 添加成员时 选择新增成员权限
|
||||
@autobind
|
||||
changeNewMemberRole(value) {
|
||||
return () => {
|
||||
console.log(this.props.currGroup._id, value);
|
||||
}
|
||||
this.setState({
|
||||
inputRole: value
|
||||
});
|
||||
}
|
||||
|
||||
// 删 - 删除分组成员
|
||||
@ -116,7 +115,6 @@ class MemberList extends Component {
|
||||
// 改 - 修改成员权限
|
||||
@autobind
|
||||
changeUserRole(e) {
|
||||
console.log(e);
|
||||
const id = this.props.currGroup._id;
|
||||
const role = e.split('-')[0];
|
||||
const member_uid = e.split('-')[1];
|
||||
@ -168,7 +166,6 @@ class MemberList extends Component {
|
||||
|
||||
@autobind
|
||||
onUserSelect(childState) {
|
||||
console.log(childState);
|
||||
this.setState({
|
||||
inputUid: childState.uid
|
||||
})
|
||||
|
@ -16,7 +16,7 @@ const dataTpl = {
|
||||
req_query: { name: "", required: "1", desc: "" },
|
||||
req_headers: { name: "", required: "1", desc: "" },
|
||||
req_params: { name: "", desc: "" },
|
||||
req_body_form: {name: "", type: "text", required: "1", desc: ""}
|
||||
req_body_form: { name: "", type: "text", required: "1", desc: "" }
|
||||
}
|
||||
|
||||
const mockEditor = require('./mockEditor.js');
|
||||
@ -46,6 +46,7 @@ class InterfaceEditForm extends Component {
|
||||
return item
|
||||
})
|
||||
}
|
||||
|
||||
this.state = Object.assign({
|
||||
title: '',
|
||||
path: '',
|
||||
@ -59,7 +60,7 @@ class InterfaceEditForm extends Component {
|
||||
desc: '',
|
||||
required: "1"
|
||||
}],
|
||||
|
||||
|
||||
req_headers: [{
|
||||
name: '',
|
||||
value: '', required: "1"
|
||||
@ -79,14 +80,13 @@ class InterfaceEditForm extends Component {
|
||||
res_body_mock: '',
|
||||
mockUrl: this.props.mockUrl
|
||||
}, curdata)
|
||||
|
||||
|
||||
}
|
||||
|
||||
handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
this.props.form.validateFields((err, values) => {
|
||||
if (!err) {
|
||||
console.log(values)
|
||||
if (values.res_body_type === 'json') values.res_body = this.state.res_body;
|
||||
values.req_params = this.state.req_params;
|
||||
values.req_body_other = this.state.req_body_other;
|
||||
@ -111,26 +111,26 @@ class InterfaceEditForm extends Component {
|
||||
value: isfile ? 'multipart/form-data' : 'application/x-www-form-urlencoded'
|
||||
})
|
||||
}
|
||||
}else if(values.req_body_type === 'json'){
|
||||
} else if (values.req_body_type === 'json') {
|
||||
values.req_headers.map((item) => {
|
||||
if (item.name === 'Content-Type') {
|
||||
item.value = 'application/json'
|
||||
isHavaContentType = true;
|
||||
}
|
||||
})
|
||||
if(isHavaContentType === false){
|
||||
if (isHavaContentType === false) {
|
||||
values.req_headers.unshift({
|
||||
name: 'Content-Type',
|
||||
value: 'application/json'
|
||||
})
|
||||
}
|
||||
}
|
||||
values.req_headers = values.req_headers ?values.req_headers.filter((item) => item.name !== '') : []
|
||||
values.req_body_form = values.req_body_form ? values.req_body_form.filter((item) => item.name !== ''): []
|
||||
values.req_params = values.req_params ? values.req_params.filter(item => item.name !== ''): []
|
||||
values.req_query = values.req_query ? values.req_query.filter(item => item.name !== ''): []
|
||||
values.req_headers = values.req_headers ? values.req_headers.filter((item) => item.name !== '') : []
|
||||
values.req_body_form = values.req_body_form ? values.req_body_form.filter((item) => item.name !== '') : []
|
||||
values.req_params = values.req_params ? values.req_params.filter(item => item.name !== '') : []
|
||||
values.req_query = values.req_query ? values.req_query.filter(item => item.name !== '') : []
|
||||
|
||||
if(HTTP_METHOD[values.method].request_body !== true){
|
||||
if (HTTP_METHOD[values.method].request_body !== true) {
|
||||
values.req_params = []
|
||||
}
|
||||
this.props.onSubmit(values)
|
||||
@ -211,7 +211,7 @@ class InterfaceEditForm extends Component {
|
||||
labelCol: { span: 4 },
|
||||
wrapperCol: { span: 18 }
|
||||
};
|
||||
|
||||
|
||||
const queryTpl = (data, index) => {
|
||||
return <Row key={index} className="interface-edit-item-content">
|
||||
<Col span="4">
|
||||
@ -384,7 +384,15 @@ class InterfaceEditForm extends Component {
|
||||
<FormItem
|
||||
className="interface-edit-item"
|
||||
{...formItemLayout}
|
||||
label="接口路径"
|
||||
label={(
|
||||
<span>
|
||||
接口路径
|
||||
<Tooltip title="接口路径,支持动态路由,例如:'/api/user/:id'">
|
||||
<Icon type="question" style={{ width: "10px" }} />
|
||||
</Tooltip>
|
||||
|
||||
</span>
|
||||
)}
|
||||
>
|
||||
<InputGroup compact>
|
||||
<Select value={this.state.method} onChange={val => this.setState({ method: val })} style={{ width: "15%" }}>
|
||||
@ -393,7 +401,7 @@ class InterfaceEditForm extends Component {
|
||||
})}
|
||||
</Select>
|
||||
|
||||
<Tooltip title="接口基本路径,可在项目配置里修改" style={{display: this.props.basepath == '' ? 'block': 'none'}}>
|
||||
<Tooltip title="接口基本路径,可在项目配置里修改" style={{ display: this.props.basepath == '' ? 'block' : 'none' }}>
|
||||
<Input disabled value={this.props.basepath} readOnly onChange={() => { }} style={{ width: '25%' }} />
|
||||
</Tooltip>
|
||||
{getFieldDecorator('path', {
|
||||
@ -402,9 +410,7 @@ class InterfaceEditForm extends Component {
|
||||
required: true, message: '清输入接口路径!'
|
||||
}]
|
||||
})(
|
||||
<Tooltip title="接口路径,支持动态路由,例如:'/api/user/:id'">
|
||||
<Input onBlur={this.handlePath} placeholder="/path" style={{ width: '60%' }} />
|
||||
</Tooltip>
|
||||
<Input onBlur={this.handlePath} placeholder="/path" style={{ width: '60%' }} />
|
||||
)}
|
||||
</InputGroup>
|
||||
<Row className="interface-edit-item">
|
||||
|
@ -82,12 +82,11 @@ class ProjectMember extends Component {
|
||||
// 增 - 添加成员
|
||||
@autobind
|
||||
handleOk() {
|
||||
console.log(this.props.projectId, this.state.inputUid);
|
||||
this.props.addMember({
|
||||
id: this.props.projectId,
|
||||
member_uid: this.state.inputUid
|
||||
member_uid: this.state.inputUid,
|
||||
role: this.state.inputRole
|
||||
}).then((res) => {
|
||||
console.log(res);
|
||||
if (!res.payload.data.errcode) {
|
||||
message.success('添加成功!');
|
||||
this.reFetchList(); // 添加成功后重新获取分组成员列表
|
||||
@ -97,9 +96,9 @@ class ProjectMember extends Component {
|
||||
// 添加成员时 选择新增成员权限
|
||||
@autobind
|
||||
changeNewMemberRole(value) {
|
||||
return () => {
|
||||
console.log(this.props.projectId, value);
|
||||
}
|
||||
this.setState({
|
||||
inputRole: value
|
||||
});
|
||||
}
|
||||
|
||||
// 删 - 删除分组成员
|
||||
@ -119,7 +118,6 @@ class ProjectMember extends Component {
|
||||
// 改 - 修改成员权限
|
||||
@autobind
|
||||
changeUserRole(e) {
|
||||
console.log(e);
|
||||
const id = this.props.projectId;
|
||||
const role = e.split('-')[0];
|
||||
const member_uid = e.split('-')[1];
|
||||
|
@ -1,42 +1,45 @@
|
||||
## 快速开始
|
||||
### 1 创建项目分组
|
||||
|
||||
|
||||
#### 1.1 项目分组
|
||||
|
||||
登录之后进到项目首页,左边侧边栏显示的即分组列表。
|
||||
|
||||
<img src="http://upload-images.jianshu.io/upload_images/842107-d90ca4b3242fa760.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width = "200" style="margin-left:170px;display:block;" alt="图片名称" align=center />
|
||||
<img src="./images/project_group.png" width = "200" style="margin-left:170px;display:block;" alt="图片名称" align=center />
|
||||
|
||||
管理员有权限添加或删除分组。
|
||||
联系管理员添加分组并且把你设置为组长或让组长邀请你加入到某项目分组
|
||||
|
||||
<img src="http://upload-images.jianshu.io/upload_images/842107-a0d4d9a98003896a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width = "500" style="margin-left:170px;display:block;" alt="图片名称" align=center />
|
||||
|
||||
> 分组名称具有唯一性
|
||||
|
||||
#### 1.2 项目
|
||||
#### 2 项目列表
|
||||
|
||||
选中不同的分组,右边会显示该分组下的项目列表。
|
||||
|
||||
<img src="http://upload-images.jianshu.io/upload_images/842107-137bcae58b84715e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center />
|
||||
<img src="./images/project_list.png" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center />
|
||||
|
||||
创建项目需要填写项目名称,项目线上域名(添加完成后可配置项目其他环境域名),项目接口基本路径(接口路径前面相同的部分)以及项目描述。
|
||||
### 3 添加项目
|
||||
|
||||
<img src="http://upload-images.jianshu.io/upload_images/842107-360a50ddb746f73d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center />
|
||||
#### 3.1 点击右上角的“+“号进入添加项目页面
|
||||
<img src="./images/project_add.png" width = "100%" style="margin:0px auto;display:block;" alt="图片名称" align=center />
|
||||
|
||||
> 项目『线上域名 + 基本路径』具有唯一性
|
||||
#### 3.2 添加项目页面
|
||||
<img src="./images/project_add_view.png" width = "100%" style="margin:0px auto;display:block;" alt="图片名称" align=center />
|
||||
添加完成后进去项目详情页面
|
||||
|
||||
#### 1.3 接口
|
||||
### 4 项目详情页面
|
||||
|
||||
点击项目名称,进入该项目接口列表。
|
||||
#### 4.1 添加接口分类
|
||||
|
||||
<img src="http://upload-images.jianshu.io/upload_images/842107-e858005f714f4889.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center />
|
||||
<img src="./images/interface_add_cat.png" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center />
|
||||
|
||||
点击编辑,进入接口详情页(之后接口详情页和编辑也会分开),可以编辑接口或者请求测试真实接口。
|
||||
添加完成后可以在左侧列表看到新添加的接口分类
|
||||
|
||||
<img src="http://upload-images.jianshu.io/upload_images/842107-78c0ea839619d068.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center />
|
||||
|
||||
<img src="http://upload-images.jianshu.io/upload_images/842107-2ee7171d707e91ff.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center />
|
||||
#### 4.2 添加接口
|
||||
鼠标移动到接口分类的菜单icon,点击添加接口
|
||||
|
||||
<img src="./images/interface_add.png" width="400" style="margin:0px auto;display:block;" alt="图片名称" align=center />
|
||||
|
||||
#### 4.3 接口编辑
|
||||
添加完接口点击新添加的接口,跳转到接口预览页面,可看到刚才填写的信息。接口的详细信息点击编辑功能进行添加
|
||||
|
||||
#### 4.4 测试接口
|
||||
点击运行tab,可进入到接口测试页面,首先安装chrome crossRequest扩展,才可正常使用此功能
|
||||
<img src="./images/interface_run.png" width="400" style="margin:0px auto;display:block;" alt="图片名称" align=center />
|
||||
点击保存按钮可把当前测试保存到测试集,方便下次调试
|
@ -40,7 +40,7 @@ class interfaceModel extends baseModel {
|
||||
}],
|
||||
req_body_type: {
|
||||
type: String,
|
||||
enum: ['form', 'json', 'text', 'file']
|
||||
enum: ['form', 'json', 'text', 'file', 'raw']
|
||||
},
|
||||
req_body_form: [{
|
||||
name: String, type: { type: String, enum: ['text', 'file'] }, desc: String, required: {
|
||||
@ -52,7 +52,7 @@ class interfaceModel extends baseModel {
|
||||
req_body_other: String,
|
||||
res_body_type: {
|
||||
type: String,
|
||||
enum: ['json', 'text', 'xml']
|
||||
enum: ['json', 'text', 'xml', 'raw']
|
||||
},
|
||||
res_body: String
|
||||
};
|
||||
|
@ -79,7 +79,7 @@ var interfaceModel = function (_baseModel) {
|
||||
}],
|
||||
req_body_type: {
|
||||
type: String,
|
||||
enum: ['form', 'json', 'text', 'file']
|
||||
enum: ['form', 'json', 'text', 'file', 'raw']
|
||||
},
|
||||
req_body_form: [{
|
||||
name: String, type: { type: String, enum: ['text', 'file'] }, desc: String, required: {
|
||||
@ -91,7 +91,7 @@ var interfaceModel = function (_baseModel) {
|
||||
req_body_other: String,
|
||||
res_body_type: {
|
||||
type: String,
|
||||
enum: ['json', 'text', 'xml']
|
||||
enum: ['json', 'text', 'xml', 'raw']
|
||||
},
|
||||
res_body: String
|
||||
};
|
||||
|
4856
static/doc/api.html
4856
static/doc/api.html
File diff suppressed because it is too large
Load Diff
@ -9,9 +9,7 @@
|
||||
<meta name="description" content="description of your site">
|
||||
<meta name="author" content="author of the site">
|
||||
<title>YApi 首页</title>
|
||||
<link rel="stylesheet" href="source/main.css" />
|
||||
|
||||
|
||||
<link rel="stylesheet" href="source/main.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="ydoc">
|
||||
@ -57,7 +55,7 @@
|
||||
<div class="ydoc-banner ydoc-banner-home">
|
||||
<div class="ydoc-banner-area">
|
||||
<h1 class="home-title">YApi</h1>
|
||||
<p class="desc home-desc">高效、易用、功能强大、的api管理平台,旨在为开发、产品、测试人员提供更优雅的接口管理服务。</p>
|
||||
<p class="desc home-desc">高效、易用、功能强大的api管理平台,旨在为开发、产品、测试人员提供更优雅的接口管理服务。</p>
|
||||
|
||||
|
||||
|
||||
@ -76,7 +74,7 @@
|
||||
|
||||
<div class="ydoc-container">
|
||||
|
||||
<div class="ydoc-container-content ydoc-container-home" id="readme">
|
||||
<div class="ydoc-container-content" id="readme">
|
||||
|
||||
|
||||
<h1 class="home-page-title">为API开发者设计的管理平台</h1>
|
||||
@ -95,8 +93,8 @@
|
||||
<img class="home-thumbnail-src" src=http://ojk406wln.bkt.clouddn.com/intro_muti.png alt="">
|
||||
</div>
|
||||
|
||||
<h3 class="home-thumbnail-name">项目接口管理</h3>
|
||||
<p class="home-thumbnail-desc">提供基本的项目分组,项目管理,接口管理功能</p>
|
||||
<h3 class="home-thumbnail-name">项目管理</h3>
|
||||
<p class="home-thumbnail-desc">无论是大企业还是创业团队,Yapi成熟的团队管理,项目权限和优化的交互都能满足您的需求</p>
|
||||
</div>
|
||||
|
||||
<div class="home-item">
|
||||
@ -105,8 +103,8 @@
|
||||
<img class="home-thumbnail-src" src=http://ojk406wln.bkt.clouddn.com/intro_md.png alt="">
|
||||
</div>
|
||||
|
||||
<h3 class="home-thumbnail-name">mockServer服务</h3>
|
||||
<p class="home-thumbnail-desc">用户只需在项目配置线上域名和接口基本路径,通过将线上域名指到我们的YApi平台服务器,就可使用mockServer服务</p>
|
||||
<h3 class="home-thumbnail-name">接口管理</h3>
|
||||
<p class="home-thumbnail-desc">友好的接口文档,基于websocket的多人协作接口编辑功能和类postman测试工具,让多人协作成倍提升开发效率</p>
|
||||
</div>
|
||||
|
||||
<div class="home-item">
|
||||
@ -115,8 +113,8 @@
|
||||
<img class="home-thumbnail-src" src=http://ojk406wln.bkt.clouddn.com/intro_theme.png alt="">
|
||||
</div>
|
||||
|
||||
<h3 class="home-thumbnail-name">用户管理</h3>
|
||||
<p class="home-thumbnail-desc">提供基本的用户注册登录管理等功能,集成了去哪儿QSSO登录</p>
|
||||
<h3 class="home-thumbnail-name">MockServer</h3>
|
||||
<p class="home-thumbnail-desc">基于Mockjs,使用简单,功能强大</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@ -9,9 +9,7 @@
|
||||
<meta name="description" content="description of your site">
|
||||
<meta name="author" content="author of the site">
|
||||
<title>YApi Mock功能</title>
|
||||
<link rel="stylesheet" href="source/main.css" />
|
||||
|
||||
|
||||
<link rel="stylesheet" href="source/main.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="ydoc">
|
||||
@ -65,11 +63,12 @@
|
||||
|
||||
<div class="ydoc-container">
|
||||
|
||||
<div class="ydoc-container-content " id="readme">
|
||||
<div class="ydoc-container-content" id="readme">
|
||||
|
||||
<article class="markdown-body">
|
||||
<h2 class="subject" id="Mock介绍">Mock介绍 <a class="hashlink" href="#Mock介绍">#</a></h2><p> <p style='text-indent:2em;line-height:1.8em'>yapi的Mock功能可以根据用户的输入接口信息如协议、URL、接口名、请求头、请求参数、mock规则(<a href="#mock">点击到Mock规则</a>)生成Mock接口,这些接口会自动生成模拟数据,创建者可以自由构造需要的数据。而且与常见的Mock方式如将Mock写在代码里和JS拦截等相比yapi的Mock在使用场景和效率和复杂度上是相差甚远的,正是由于yapi的Mock是一个第三方平台,那么在团队开发时任何人都可以权限许可下创建、修改接口信息等操作,这对于团队开发是很有好处的。</p>
|
||||
<p> <strong>mock地址解析</strong>:yapi平台网址+mock+<strong>您的项目id</strong>+<strong>接口实际请求path</strong></p>
|
||||
<p> 注:项目id可以在项目设置里查看到</p>
|
||||
<p> </p>
|
||||
<img src="./images/mock.jpg" style="width: 50%" /></p>
|
||||
<h3 class="subject" id="1 如何使用Mock?">1 如何使用Mock? <a class="hashlink" href="#1 如何使用Mock?">#</a></h3><h3 class="subject" id="1.1 最简单最直接的方式">1.1 最简单最直接的方式 <a class="hashlink" href="#1.1 最简单最直接的方式">#</a></h3><p>在代码直接请求yapi提供的mock地址,以jQuery为例:</p>
|
||||
@ -81,10 +80,11 @@ $<span class="token punctuation">.</span><span class="token function">post</span
|
||||
<h3 class="subject" id="1.2 基于本地服务器反向代理">1.2 基于本地服务器反向代理 <a class="hashlink" href="#1.2 基于本地服务器反向代理">#</a></h3><p>优点:不用修改项目代码</p>
|
||||
<h4 class="subject" id="1.2.1 基于nginx反向代理">1.2.1 基于nginx反向代理 <a class="hashlink" href="#1.2.1 基于nginx反向代理">#</a></h4><pre><code class="lang-nginx"><span class="token keyword">location</span> <span class="token operator">/</span>baseapi
|
||||
<span class="token punctuation">{</span>
|
||||
<span class="token keyword">proxy_pass</span> <span class="token keyword">http</span><span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span><span class="token keyword">http</span><span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>yapi<span class="token punctuation">.</span>local<span class="token punctuation">.</span>qunar<span class="token punctuation">.</span>com<span class="token punctuation">:</span><span class="token number">3000</span><span class="token operator">/</span>mock<span class="token operator">/</span><span class="token number">2817</span><span class="token operator">/</span><span class="token punctuation">;</span>
|
||||
<span class="token keyword">proxy_pass</span> <span class="token keyword">http</span><span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>yapi<span class="token punctuation">.</span>local<span class="token punctuation">.</span>qunar<span class="token punctuation">.</span>com<span class="token punctuation">:</span><span class="token number">3000</span><span class="token operator">/</span>mock<span class="token operator">/</span><span class="token number">2817</span><span class="token operator">/</span>baseapi<span class="token punctuation">;</span> <span class="token comment" spellcheck="true">#baseapi后面没有"/"</span>
|
||||
<span class="token punctuation">}</span>
|
||||
</code></pre>
|
||||
<h4 class="subject" id="1.2.2 基于ykit Jerry代理">1.2.2 基于ykit Jerry代理 <a class="hashlink" href="#1.2.2 基于ykit Jerry代理">#</a></h4><p><img src="./images/ykit.jpg" /></p>
|
||||
<h4 class="subject" id="1.2.2 基于ykit Jerry代理">1.2.2 基于ykit Jerry代理 <a class="hashlink" href="#1.2.2 基于ykit Jerry代理">#</a></h4><p>假设您本地服务器访问地址是: <a href="http://xxx.com">http://xxx.com</a></p>
|
||||
<p><img src="./images/ykit.jpg" /></p>
|
||||
<p><span id = "mock"></span></p>
|
||||
<h3 class="subject" id="2.1 Mock语法规范">2.1 Mock语法规范 <a class="hashlink" href="#2.1 Mock语法规范">#</a></h3><blockquote>
|
||||
<p>了解更多Mock详情:<a href="https://github.com/nuysoft/Mock/wiki/Syntax-Specification">Mock.js 官方文档</a></p>
|
||||
|
@ -132,6 +132,23 @@ $(document).ready(function() {
|
||||
$(item).addClass('ydoc-example');
|
||||
});
|
||||
|
||||
// $('code').each(function(i, block) {
|
||||
// if (block.innerHTML.indexOf('\n') != -1) {
|
||||
// var pn = block.parentNode;
|
||||
// if (pn.tagName.toUpperCase() == 'PRE') {
|
||||
// try {
|
||||
// hljs.highlightBlock(block);
|
||||
// } catch(e) {}
|
||||
// } else {
|
||||
// pn.innerHTML = '<pre><code>' + block.innerHTML + '</code></pre>';
|
||||
// try {
|
||||
// hljs.highlightBlock(pn.childNodes[0].childNodes[0]);
|
||||
// } catch(e) {}
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
var winHeight = $(window).height() - 44,
|
||||
sidebar = $('.docs-sidebar');
|
||||
var docSideNav = $('.docs-sidenav');
|
||||
@ -188,9 +205,46 @@ $(document).ready(function() {
|
||||
|
||||
// 退出全屏浏览器窗口大小改变,不触发resize
|
||||
$(window).on('resize', function(e) {
|
||||
resizeSidebar();
|
||||
$contentLeftWidth = $contentLeft.width() - 1;
|
||||
});
|
||||
|
||||
function resizeSidebar() {
|
||||
var winHeight = $(window).height() - 44,
|
||||
sidebar = $('.docs-sidebar');
|
||||
var docSideNav = $('.docs-sidenav');
|
||||
if (winWidth > 767) {
|
||||
docSideNav.width($contentLeftWidth);
|
||||
}
|
||||
if (sidebar.height() > winHeight) {
|
||||
sidebar.css('max-height', winHeight + 'px');
|
||||
$('.docs-sidenav').css('max-height', winHeight + 'px');
|
||||
$('.docs-sidenav').css({
|
||||
'overflow-y': 'scroll',
|
||||
'overflow-x': 'hidden'
|
||||
});
|
||||
var barScroll = false;
|
||||
|
||||
sidebar.on('mouseover', function() {
|
||||
barScroll = true;
|
||||
});
|
||||
|
||||
sidebar.on('mouseout', function() {
|
||||
barScroll = false;
|
||||
});
|
||||
// scroll
|
||||
if ($(window).scrollTop() > ($('.footer').offset().top - $(window).height())) {
|
||||
winHeight = $(window).height() - $('.footer').outerHeight() - 44;
|
||||
sidebar.css('max-height', winHeight + 'px');
|
||||
$('.docs-sidenav').css('max-height', winHeight + 'px');
|
||||
} else {
|
||||
winHeight = $(window).height() - 44;
|
||||
sidebar.css('max-height', winHeight + 'px');
|
||||
$('.docs-sidenav').css('max-height', winHeight + 'px');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sortAsOffset(propertyName) {
|
||||
return function(obj1, obj2) {
|
||||
var val1 = obj1[propertyName];
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -9,9 +9,7 @@
|
||||
<meta name="description" content="description of your site">
|
||||
<meta name="author" content="author of the site">
|
||||
<title>YApi 快速开始</title>
|
||||
<link rel="stylesheet" href="source/main.css" />
|
||||
|
||||
|
||||
<link rel="stylesheet" href="source/main.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="ydoc">
|
||||
@ -65,28 +63,25 @@
|
||||
|
||||
<div class="ydoc-container">
|
||||
|
||||
<div class="ydoc-container-content " id="readme">
|
||||
<div class="ydoc-container-content" id="readme">
|
||||
|
||||
<article class="markdown-body">
|
||||
<h2 class="subject" id="快速开始">快速开始 <a class="hashlink" href="#快速开始">#</a></h2><h3 class="subject" id="1 创建项目分组">1 创建项目分组 <a class="hashlink" href="#1 创建项目分组">#</a></h3><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" width = "200" style="margin-left:170px;display:block;" alt="图片名称" align=center /></p>
|
||||
<p>管理员有权限添加或删除分组。</p>
|
||||
<p><img src="http://upload-images.jianshu.io/upload_images/842107-a0d4d9a98003896a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width = "500" style="margin-left:170px;display:block;" alt="图片名称" align=center /></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" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center /></p>
|
||||
<p>创建项目需要填写项目名称,项目线上域名(添加完成后可配置项目其他环境域名),项目接口基本路径(接口路径前面相同的部分)以及项目描述。</p>
|
||||
<p><img src="http://upload-images.jianshu.io/upload_images/842107-360a50ddb746f73d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center /></p>
|
||||
<blockquote>
|
||||
<p>项目『线上域名 + 基本路径』具有唯一性</p>
|
||||
</blockquote>
|
||||
<h4 class="subject" id="1.3 接口">1.3 接口 <a class="hashlink" href="#1.3 接口">#</a></h4><p>点击项目名称,进入该项目接口列表。</p>
|
||||
<p><img src="http://upload-images.jianshu.io/upload_images/842107-e858005f714f4889.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center /></p>
|
||||
<p>点击编辑,进入接口详情页(之后接口详情页和编辑也会分开),可以编辑接口或者请求测试真实接口。</p>
|
||||
<p><img src="http://upload-images.jianshu.io/upload_images/842107-78c0ea839619d068.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center /></p>
|
||||
<p><img src="http://upload-images.jianshu.io/upload_images/842107-2ee7171d707e91ff.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center /></p>
|
||||
<h2 class="subject" id="快速开始">快速开始 <a class="hashlink" href="#快速开始">#</a></h2><h3 class="subject" id="1 创建项目分组">1 创建项目分组 <a class="hashlink" href="#1 创建项目分组">#</a></h3><p>登录之后进到项目首页,左边侧边栏显示的即分组列表。</p>
|
||||
<p><img src="./images/project_group.png" width = "200" style="margin-left:170px;display:block;" alt="图片名称" align=center /></p>
|
||||
<p>联系管理员添加分组并且把你设置为组长或让组长邀请你加入到某项目分组</p>
|
||||
<h4 class="subject" id="2 项目列表">2 项目列表 <a class="hashlink" href="#2 项目列表">#</a></h4><p>选中不同的分组,右边会显示该分组下的项目列表。</p>
|
||||
<p><img src="./images/project_list.png" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center /></p>
|
||||
<h3 class="subject" id="3 添加项目">3 添加项目 <a class="hashlink" href="#3 添加项目">#</a></h3><h4 class="subject" id="3.1 点击右上角的“+“号进入添加项目页面">3.1 点击右上角的“+“号进入添加项目页面 <a class="hashlink" href="#3.1 点击右上角的“+“号进入添加项目页面">#</a></h4><p><img src="./images/project_add.png" width = "100%" style="margin:0px auto;display:block;" alt="图片名称" align=center /></p>
|
||||
<h4 class="subject" id="3.2 添加项目页面">3.2 添加项目页面 <a class="hashlink" href="#3.2 添加项目页面">#</a></h4><p><img src="./images/project_add_view.png" width = "100%" style="margin:0px auto;display:block;" alt="图片名称" align=center />
|
||||
添加完成后进去项目详情页面</p>
|
||||
<h3 class="subject" id="4 项目详情页面">4 项目详情页面 <a class="hashlink" href="#4 项目详情页面">#</a></h3><h4 class="subject" id="4.1 添加接口分类">4.1 添加接口分类 <a class="hashlink" href="#4.1 添加接口分类">#</a></h4><p><img src="./images/interface_add_cat.png" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center /></p>
|
||||
<p>添加完成后可以在左侧列表看到新添加的接口分类</p>
|
||||
<h4 class="subject" id="4.2 添加接口">4.2 添加接口 <a class="hashlink" href="#4.2 添加接口">#</a></h4><p>鼠标移动到接口分类的菜单icon,点击添加接口</p>
|
||||
<p><img src="./images/interface_add.png" width="400" style="margin:0px auto;display:block;" alt="图片名称" align=center /></p>
|
||||
<h4 class="subject" id="4.3 接口编辑">4.3 接口编辑 <a class="hashlink" href="#4.3 接口编辑">#</a></h4><p>添加完接口点击新添加的接口,跳转到接口预览页面,可看到刚才填写的信息。接口的详细信息点击编辑功能进行添加</p>
|
||||
<h4 class="subject" id="4.4 测试接口">4.4 测试接口 <a class="hashlink" href="#4.4 测试接口">#</a></h4><p>点击运行tab,可进入到接口测试页面,首先安装chrome crossRequest扩展,才可正常使用此功能
|
||||
<img src="./images/interface_run.png" width="400" style="margin:0px auto;display:block;" alt="图片名称" align=center />
|
||||
点击保存按钮可把当前测试保存到测试集,方便下次调试</p>
|
||||
|
||||
</article>
|
||||
</div>
|
||||
|
@ -28,11 +28,13 @@
|
||||
import yapi from '../yapi.js';
|
||||
import baseController from './base.js';
|
||||
import followModel from '../models/follow';
|
||||
import projectModel from '../models/project';
|
||||
|
||||
class followController extends baseController {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
this.Model = yapi.getInst(followModel);
|
||||
this.projectModel = yapi.getInst(projectModel);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,13 +118,10 @@ class followController extends baseController {
|
||||
async add(ctx) {
|
||||
let params = ctx.request.body;
|
||||
params = yapi.commons.handleParams(params, {
|
||||
projectid: 'number',
|
||||
projectname: 'string',
|
||||
icon: 'string',
|
||||
color: 'string'
|
||||
projectid: 'number'
|
||||
});
|
||||
|
||||
let uid = this.getUid()
|
||||
let uid = this.getUid();
|
||||
|
||||
if (!params.projectid) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
@ -134,25 +133,15 @@ class followController extends baseController {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '项目已关注');
|
||||
}
|
||||
|
||||
if (!params.projectname) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目名不能为空');
|
||||
}
|
||||
if (!params.icon) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目图标标志不能为空');
|
||||
}
|
||||
if (!params.color) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目颜色不能为空');
|
||||
}
|
||||
|
||||
let data = {
|
||||
uid: uid,
|
||||
projectid: params.projectid,
|
||||
projectname: params.projectname,
|
||||
icon: params.icon,
|
||||
color: params.color
|
||||
};
|
||||
|
||||
try {
|
||||
let project = await this.projectModel.get(params.projectid);
|
||||
let data = {
|
||||
uid: uid,
|
||||
projectid: params.projectid,
|
||||
projectname: project.name,
|
||||
icon: project.icon,
|
||||
color: project.color
|
||||
};
|
||||
let result = await this.Model.save(data);
|
||||
result = yapi.commons.fieldSelect(result, ['_id', 'uid', 'projectid', 'projectname', 'icon', 'color']);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
|
@ -30,12 +30,14 @@ import interfaceCatModel from '../models/interfaceCat.js';
|
||||
import baseController from './base.js';
|
||||
import yapi from '../yapi.js';
|
||||
import userModel from '../models/user.js';
|
||||
import projectModel from '../models/project.js';
|
||||
|
||||
class interfaceController extends baseController {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
this.Model = yapi.getInst(interfaceModel);
|
||||
this.catModel = yapi.getInst(interfaceCatModel)
|
||||
this.catModel = yapi.getInst(interfaceCatModel);
|
||||
this.projectModel = yapi.getInst(projectModel);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,7 +70,6 @@ class interfaceController extends baseController {
|
||||
*/
|
||||
async add(ctx) {
|
||||
let params = ctx.request.body;
|
||||
|
||||
params = yapi.commons.handleParams(params, {
|
||||
project_id: 'number',
|
||||
title: 'string',
|
||||
@ -77,6 +78,11 @@ class interfaceController extends baseController {
|
||||
desc: 'string',
|
||||
catid: 'number'
|
||||
});
|
||||
|
||||
let auth = await this.checkAuth(params.project_id, 'project', 'edit')
|
||||
if (!auth) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase();
|
||||
params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json';
|
||||
@ -134,6 +140,16 @@ class interfaceController extends baseController {
|
||||
}
|
||||
|
||||
let result = await this.Model.save(data);
|
||||
let username = this.getUsername();
|
||||
// let project = await this.projectModel.get(params.project_id);
|
||||
let cate = await this.catModel.get(params.catid);
|
||||
yapi.commons.saveLog({
|
||||
content: `用户 "${username}" 为分类 "${cate.name}" 添加了接口 "${data.title}"`,
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: params.project_id
|
||||
});
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
@ -211,14 +227,14 @@ class interfaceController extends baseController {
|
||||
}
|
||||
try {
|
||||
let result = await this.catModel.list(project_id), newResult = [];
|
||||
for(let i=0, item, list;i< result.length; i++){
|
||||
for (let i = 0, item, list; i < result.length; i++) {
|
||||
item = result[i].toObject()
|
||||
list = await this.Model.listByCatid(item._id, '_id title method')
|
||||
for(let j=0; j< list.length; j++){
|
||||
list = await this.Model.listByCatid(item._id, '_id title method path')
|
||||
for (let j = 0; j < list.length; j++) {
|
||||
list[j] = list[j].toObject()
|
||||
}
|
||||
}
|
||||
item.list = list;
|
||||
newResult[i] = item
|
||||
newResult[i] = item
|
||||
}
|
||||
ctx.body = yapi.commons.resReturn(newResult);
|
||||
} catch (err) {
|
||||
@ -264,6 +280,7 @@ class interfaceController extends baseController {
|
||||
desc: 'string',
|
||||
catid: 'number'
|
||||
});
|
||||
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase();
|
||||
|
||||
@ -272,7 +289,12 @@ class interfaceController extends baseController {
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
|
||||
}
|
||||
|
||||
let interfaceData = await this.Model.get(id);
|
||||
let auth = await this.checkAuth(interfaceData.project_id, 'project', 'edit')
|
||||
if (!auth) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
|
||||
if (params.path && !yapi.commons.verifyPath(params.path)) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/');
|
||||
@ -302,7 +324,7 @@ class interfaceController extends baseController {
|
||||
data.method = params.method;
|
||||
}
|
||||
|
||||
if(params.catid){
|
||||
if (params.catid) {
|
||||
data.catid = params.catid;
|
||||
}
|
||||
|
||||
@ -338,12 +360,28 @@ class interfaceController extends baseController {
|
||||
data.res_body = params.res_body;
|
||||
}
|
||||
|
||||
if(params.status){
|
||||
if (params.status) {
|
||||
data.status = params.status;
|
||||
}
|
||||
|
||||
try {
|
||||
let result = await this.Model.up(id, data);
|
||||
let username = this.getUsername();
|
||||
let cate;
|
||||
if (params.catid) {
|
||||
cate = await this.catModel.get(+params.catid);
|
||||
} else {
|
||||
let inter = await this.Model.get(id);
|
||||
cate = interfaceData.catid;
|
||||
}
|
||||
|
||||
yapi.commons.saveLog({
|
||||
content: `用户 "${username}" 更新了分类 "${cate.name}" 下的接口 "${data.title}"`,
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: cate.project_id
|
||||
});
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
@ -373,13 +411,25 @@ class interfaceController extends baseController {
|
||||
let data = await this.Model.get(ctx.request.body.id);
|
||||
|
||||
if (data.uid != this.getUid()) {
|
||||
if (await this.jungeProjectAuth(data.project_id) !== true) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
let auth = await this.checkAuth(data.project_id, 'project', 'danger')
|
||||
if (!auth) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let inter = await this.Model.get(id);
|
||||
let result = await this.Model.del(id);
|
||||
|
||||
let username = this.getUsername();
|
||||
let cate = await this.catModel.get(inter.catid);
|
||||
yapi.commons.saveLog({
|
||||
content: `用户 "${username}" 删除了分类 "${cate.name}" 下的接口 "${inter.title}"`,
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: cate.project_id
|
||||
});
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (err) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, err.message);
|
||||
@ -426,10 +476,16 @@ class interfaceController extends baseController {
|
||||
if (!params.project_id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
|
||||
let auth = await this.checkAuth(params.project_id, 'project', 'edit')
|
||||
if (!auth) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
if (!params.name) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '名称不能为空');
|
||||
}
|
||||
|
||||
|
||||
let result = await this.catModel.save({
|
||||
name: params.name,
|
||||
project_id: params.project_id,
|
||||
@ -438,6 +494,16 @@ class interfaceController extends baseController {
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
})
|
||||
|
||||
let username = this.getUsername();
|
||||
yapi.commons.saveLog({
|
||||
content: `用户 "${username}" 添加了分类 "${params.name}"`,
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: params.project_id
|
||||
});
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
|
||||
} catch (e) {
|
||||
@ -452,7 +518,23 @@ class interfaceController extends baseController {
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
up_time: yapi.commons.time()
|
||||
})
|
||||
});
|
||||
|
||||
let username = this.getUsername();
|
||||
let cate = await this.catModel.get(params.catid);
|
||||
|
||||
let auth = await this.checkAuth(cate.project_id, 'project', 'edit')
|
||||
if (!auth) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
yapi.commons.saveLog({
|
||||
content: `用户 "${username}" 更新了分类 "${cate.name}"`,
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: cate.project_id
|
||||
});
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 400, e.message)
|
||||
@ -474,8 +556,19 @@ class interfaceController extends baseController {
|
||||
}
|
||||
}
|
||||
|
||||
let cate = await this.catModel.get(id);
|
||||
let result = await this.catModel.del(id);
|
||||
let r = await this.Model.delByCatid(id)
|
||||
let r = await this.Model.delByCatid(id);
|
||||
let username = this.getUsername();
|
||||
|
||||
yapi.commons.saveLog({
|
||||
content: `用户 "${username}" 删除了分类 "${cate.name}" 及该分类下的接口`,
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: cate.project_id
|
||||
});
|
||||
|
||||
return ctx.body = yapi.commons.resReturn(r);
|
||||
|
||||
|
||||
|
@ -48,7 +48,7 @@ class interfaceColController extends baseController{
|
||||
* @example
|
||||
*/
|
||||
async list(ctx){
|
||||
try {
|
||||
try {
|
||||
let id = ctx.query.project_id;
|
||||
let result = await this.colModel.list(id);
|
||||
|
||||
@ -91,6 +91,11 @@ class interfaceColController extends baseController{
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '名称不能为空');
|
||||
}
|
||||
|
||||
let auth = await this.checkAuth(params.project_id, 'project', 'edit')
|
||||
if (!auth) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
|
||||
let result = await this.colModel.save({
|
||||
name: params.name,
|
||||
project_id: params.project_id,
|
||||
@ -137,7 +142,6 @@ class interfaceColController extends baseController{
|
||||
* @param {String} casename
|
||||
* @param {Number} col_id
|
||||
* @param {Number} project_id
|
||||
* @param {String} env
|
||||
* @param {String} domain
|
||||
* @param {String} path
|
||||
* @param {String} method
|
||||
@ -157,14 +161,20 @@ class interfaceColController extends baseController{
|
||||
casename: 'string',
|
||||
project_id: 'number',
|
||||
col_id: 'number',
|
||||
env: 'string',
|
||||
domain: 'string',
|
||||
method: 'string'
|
||||
});
|
||||
|
||||
|
||||
if (!params.project_id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
|
||||
let auth = await this.checkAuth(params.project_id, 'project', 'edit')
|
||||
if (!auth) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
|
||||
if (!params.col_id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口集id不能为空');
|
||||
}
|
||||
@ -187,6 +197,61 @@ class interfaceColController extends baseController{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加一个接口用例
|
||||
* @interface /col/up_case
|
||||
* @method POST
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
* @param {number} id
|
||||
* @param {String} casename
|
||||
* @param {String} domain
|
||||
* @param {String} path
|
||||
* @param {String} method
|
||||
* @param {Object} req_query
|
||||
* @param {Object} req_headers
|
||||
* @param {String} req_body_type
|
||||
* @param {Array} req_body_form
|
||||
* @param {String} req_body_other
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
async upCase(ctx){
|
||||
try{
|
||||
let params = ctx.request.body;
|
||||
params = yapi.commons.handleParams(params, {
|
||||
id: 'number',
|
||||
casename: 'string',
|
||||
domain: 'string',
|
||||
method: 'string'
|
||||
});
|
||||
|
||||
if (!params.id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '用例id不能为空');
|
||||
}
|
||||
|
||||
if(!params.casename){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '用例名称不能为空');
|
||||
}
|
||||
|
||||
let caseData = await this.caseModel.get(id);
|
||||
let auth = await this.checkAuth(caseData.project_id, 'project', 'edit')
|
||||
if (!auth) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
|
||||
params.uid = this.getUid();
|
||||
|
||||
let result = await this.caseModel.up(params.id, params);
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个接口用例详情
|
||||
* @interface /col/case
|
||||
@ -223,6 +288,13 @@ class interfaceColController extends baseController{
|
||||
async upCol(ctx){
|
||||
try{
|
||||
let params = ctx.request.body;
|
||||
let id = params.col_id;
|
||||
let colData = await this.colModel.get(id);
|
||||
let auth = await this.checkAuth(colData.project_id, 'project', 'edit')
|
||||
if (!auth) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
|
||||
let result = await this.colModel.up(params.col_id, {
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
|
202
static/doc/static/server/controllers/project.js.html
vendored
202
static/doc/static/server/controllers/project.js.html
vendored
@ -133,21 +133,40 @@ class projectController extends baseController {
|
||||
icon: params.icon,
|
||||
color: params.color,
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
up_time: yapi.commons.time(),
|
||||
env: [{ name: 'local', domain: 'http://127.0.0.1' }]
|
||||
};
|
||||
|
||||
try {
|
||||
let result = await this.Model.save(data);
|
||||
let colInst = yapi.getInst(interfaceColModel);
|
||||
let catInst = yapi.getInst(interfaceCatModel);
|
||||
if (result._id) {
|
||||
await colInst.save({
|
||||
name: '公共测试集',
|
||||
project_id: result._id,
|
||||
desc: '公共测试集',
|
||||
uid: this.getUid(),
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
})
|
||||
await catInst.save({
|
||||
name: '公共分类',
|
||||
project_id: result._id,
|
||||
desc: '公共分类',
|
||||
uid: this.getUid(),
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
})
|
||||
}
|
||||
let username = this.getUsername();
|
||||
yapi.commons.saveLog({
|
||||
content: `用户${username}添加了项目${params.name}`,
|
||||
content: `用户 "${username}" 添加了项目 "${params.name}"`,
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: params.group_id,
|
||||
typename: params.group_name,
|
||||
color: params.color,
|
||||
icon: params.icon
|
||||
typename: params.group_name
|
||||
});
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
@ -187,7 +206,7 @@ class projectController extends baseController {
|
||||
params.role = params.role === 'owner' ? 'owner' : 'dev';
|
||||
|
||||
let userdata = await this.getUserdata(params.member_uid, params.role);
|
||||
if(userdata === null){
|
||||
if (userdata === null) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '成员uid不存在')
|
||||
}
|
||||
|
||||
@ -195,15 +214,12 @@ class projectController extends baseController {
|
||||
try {
|
||||
let result = await this.Model.addMember(params.id, userdata);
|
||||
let username = this.getUsername();
|
||||
let project = await this.Model.get(params.id);
|
||||
yapi.commons.saveLog({
|
||||
content: `用户${username}添加了项目成员${userdata.username}`,
|
||||
content: `用户 "${username}" 添加了项目成员 "${userdata.username}"`,
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: params.id,
|
||||
color: project.color,
|
||||
icon: project.icon
|
||||
typeid: params.id
|
||||
});
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
@ -244,15 +260,13 @@ class projectController extends baseController {
|
||||
let result = await this.Model.delMember(params.id, params.member_uid);
|
||||
let username = this.getUsername();
|
||||
let project = await this.Model.get(params.id);
|
||||
let member = await yapi.getInst(userModel).findById(params.member_uid);
|
||||
let member = await yapi.getInst(userModel).findById(params.member_uid);
|
||||
yapi.commons.saveLog({
|
||||
content: `用户${username}删除了项目${project.name}中的成员${member.username}`,
|
||||
content: `用户 "${username}" 删除了项目 "${project.name}" 中的成员 "${member.username}"`,
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: params.id,
|
||||
color: project.color,
|
||||
icon: project.icon
|
||||
typeid: params.id
|
||||
});
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
@ -261,11 +275,11 @@ class projectController extends baseController {
|
||||
}
|
||||
|
||||
|
||||
async getUserdata(uid, role){
|
||||
async getUserdata(uid, role) {
|
||||
role = role || 'dev';
|
||||
let userInst = yapi.getInst(userModel);
|
||||
let userData = await userInst.findById(uid);
|
||||
if(!userData){
|
||||
if (!userData) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
@ -319,7 +333,7 @@ class projectController extends baseController {
|
||||
}
|
||||
try {
|
||||
let result = await this.Model.getBaseInfo(params.id);
|
||||
if(!result){
|
||||
if (!result) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '不存在的项目');
|
||||
}
|
||||
result = result.toObject();
|
||||
@ -351,19 +365,19 @@ class projectController extends baseController {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
|
||||
}
|
||||
|
||||
let auth =await this.checkAuth(group_id, 'group', 'edit')
|
||||
let auth = await this.checkAuth(group_id, 'group', 'edit')
|
||||
try {
|
||||
let result = await this.Model.list(group_id, auth);
|
||||
let follow = await this.followModel.list(this.getUid());
|
||||
let uids = [];
|
||||
result.forEach((item, index) => {
|
||||
result[index] = item.toObject();
|
||||
let f = _.find(follow, (fol)=>{
|
||||
let f = _.find(follow, (fol) => {
|
||||
return fol.projectid === item._id
|
||||
})
|
||||
if(f){
|
||||
if (f) {
|
||||
result[index].follow = true;
|
||||
}else{
|
||||
} else {
|
||||
result[index].follow = false;
|
||||
}
|
||||
if (uids.indexOf(item.uid) === -1) {
|
||||
@ -431,7 +445,7 @@ class projectController extends baseController {
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
async changeMemberRole(ctx){
|
||||
async changeMemberRole(ctx) {
|
||||
let params = ctx.request.body;
|
||||
let projectInst = yapi.getInst(projectModel);
|
||||
if (!params.member_uid) {
|
||||
@ -455,15 +469,13 @@ class projectController extends baseController {
|
||||
|
||||
let username = this.getUsername();
|
||||
let project = await this.Model.get(params.id);
|
||||
let member = await yapi.getInst(userModel).findByUids(params.member_uid);
|
||||
let member = await yapi.getInst(userModel).findById(params.member_uid);
|
||||
yapi.commons.saveLog({
|
||||
content: `用户${username}修改了项目${project.name}中成员${member.username}的角色为${params.role}`,
|
||||
content: `用户 "${username}" 修改了项目 "${project.name}" 中成员 "${member.username}" 的角色为 "${params.role}"`,
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: params.id,
|
||||
color: project.color,
|
||||
icon: project.icon
|
||||
typeid: params.id
|
||||
});
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
@ -471,6 +483,39 @@ class projectController extends baseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 项目设置
|
||||
* @interface /project/upset
|
||||
* @method POST
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @param {String} icon 项目icon
|
||||
* @param {Array} color 项目color
|
||||
* @returns {Object}
|
||||
* @example ./api/project/upset
|
||||
*/
|
||||
async upSet(ctx) {
|
||||
let id = ctx.request.body.id;
|
||||
let data = {};
|
||||
data.color = ctx.request.body.color;
|
||||
data.icon = ctx.request.body.icon;
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空');
|
||||
}
|
||||
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);
|
||||
}
|
||||
try {
|
||||
this.followModel.updateById(this.getUid(), id, data).then();
|
||||
} catch (e) {
|
||||
yapi.commons.log(e, 'error'); // eslint-disable-line
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑项目
|
||||
* @interface /project/up
|
||||
@ -531,38 +576,20 @@ class projectController extends baseController {
|
||||
|
||||
if (params.name) data.name = params.name;
|
||||
if (params.desc) data.desc = params.desc;
|
||||
if (params.basepath ) {
|
||||
if (params.basepath) {
|
||||
data.basepath = params.basepath;
|
||||
}
|
||||
if (params.env) data.env = params.env;
|
||||
if(params.color) data.color = params.color;
|
||||
if(params.icon) data.icon = params.icon;
|
||||
if (params.color) data.color = params.color;
|
||||
if (params.icon) data.icon = params.icon;
|
||||
let result = await this.Model.up(id, data);
|
||||
// try{
|
||||
// let data = {};
|
||||
// if(params.name){
|
||||
// data.projectname = params.name;
|
||||
// }
|
||||
// if(params.icon){
|
||||
// data.icon = params.icon;
|
||||
// }
|
||||
// if(params.color){
|
||||
// data.color = params.color;
|
||||
// }
|
||||
// this.followModel.updateById(this.getUid(),id,data);
|
||||
// }catch(e){
|
||||
// yapi.commons.log(e, 'error'); // eslint-disable-line
|
||||
// }
|
||||
|
||||
let username = this.getUsername();
|
||||
yapi.commons.saveLog({
|
||||
content: `用户${username}更新了项目${projectData.name}`,
|
||||
content: `用户 "${username}" 更新了项目 "${projectData.name}"`,
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: id,
|
||||
icon: params.icon,
|
||||
color: params.color
|
||||
typeid: id
|
||||
});
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
@ -570,37 +597,42 @@ class projectController extends baseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改项目头像
|
||||
* @interface /project/upset
|
||||
* @method POST
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id
|
||||
* @param {String} color
|
||||
* @param {String} icon
|
||||
* @return {Object}
|
||||
*/
|
||||
async upSet(ctx){
|
||||
let id = ctx.request.body.id;
|
||||
let data = {};
|
||||
data.color = ctx.request.body.color;
|
||||
data.icon = ctx.request.body.icon;
|
||||
if(!id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空');
|
||||
}
|
||||
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);
|
||||
}
|
||||
try{
|
||||
this.followModel.updateById(this.getUid(),id,data).then();
|
||||
}catch(e){
|
||||
yapi.commons.log(e, 'error'); // eslint-disable-line
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 修改项目头像
|
||||
* @interface /project/upset
|
||||
* @method POST
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id
|
||||
* @param {String} color
|
||||
* @param {String} icon
|
||||
* @return {Object}
|
||||
*/
|
||||
async upSet(ctx) {
|
||||
let id = ctx.request.body.id;
|
||||
let data = {};
|
||||
data.color = ctx.request.body.color;
|
||||
data.icon = ctx.request.body.icon;
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空');
|
||||
}
|
||||
|
||||
let auth = await this.checkAuth(id, 'project', 'danger')
|
||||
if (!auth) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
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);
|
||||
}
|
||||
try {
|
||||
this.followModel.updateById(this.getUid(), id, data).then();
|
||||
} catch (e) {
|
||||
yapi.commons.log(e, 'error'); // eslint-disable-line
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 模糊搜索项目名称或者组名称
|
||||
@ -677,7 +709,7 @@ class projectController extends baseController {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '项目id不存在');
|
||||
}
|
||||
|
||||
const arr = JSON.stringify(count.map(function(item) {
|
||||
const arr = JSON.stringify(count.map(function (item) {
|
||||
// 返回的json模板数据: item.res_body
|
||||
const mockData = Mock.mock(
|
||||
yapi.commons.json_parse(item.res_body)
|
||||
@ -718,7 +750,7 @@ class projectController extends baseController {
|
||||
});
|
||||
}
|
||||
module.exports = run;`
|
||||
.trim();
|
||||
.trim();
|
||||
return ctx.body = res;
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ class userController extends baseController {
|
||||
|
||||
if (login === true) {
|
||||
yapi.commons.log('login success');
|
||||
ctx.redirect('/');
|
||||
ctx.redirect('/group');
|
||||
}
|
||||
} catch (e) {
|
||||
yapi.commons.log(e.message, 'error');
|
||||
|
14
ydoc.json
14
ydoc.json
@ -37,24 +37,24 @@
|
||||
"detail": {
|
||||
"type": "thumbnail", // 三列布局的介绍板块
|
||||
"content": [{ // 三列布局的内容,每项的key值非必需,但建议每列的key值一致
|
||||
"name": "项目接口管理", // 板块名称
|
||||
"name": "项目管理", // 板块名称
|
||||
"src": "http://ojk406wln.bkt.clouddn.com/intro_muti.png", // 缩略图
|
||||
"desc": "提供基本的项目分组,项目管理,接口管理功能" // 描述
|
||||
"desc": "无论是大企业还是创业团队,Yapi成熟的团队管理,项目权限和优化的交互都能满足您的需求" // 描述
|
||||
},{
|
||||
"name": "mockServer服务",
|
||||
"name": "接口管理",
|
||||
"src": "http://ojk406wln.bkt.clouddn.com/intro_md.png",
|
||||
"desc": "用户只需在项目配置线上域名和接口基本路径,通过将线上域名指到我们的YApi平台服务器,就可使用mockServer服务"
|
||||
"desc": "友好的接口文档,基于websocket的多人协作接口编辑功能和类postman测试工具,让多人协作成倍提升开发效率"
|
||||
},{
|
||||
"name": "用户管理",
|
||||
"name": "MockServer",
|
||||
"src": "http://ojk406wln.bkt.clouddn.com/intro_theme.png",
|
||||
"desc": "提供基本的用户注册登录管理等功能,集成了去哪儿QSSO登录"
|
||||
"desc": "基于Mockjs,使用简单,功能强大"
|
||||
}]
|
||||
}
|
||||
}]
|
||||
},
|
||||
"banner": { // Banner 配置
|
||||
"title": "YApi",
|
||||
"description": "高效、易用、功能强大、的api管理平台,旨在为开发、产品、测试人员提供更优雅的接口管理服务。"
|
||||
"description": "高效、易用、功能强大的api管理平台,旨在为开发、产品、测试人员提供更优雅的接口管理服务。"
|
||||
},
|
||||
"content": "./doc/home.md" // 内容(这里以markdown文件举例)
|
||||
},{
|
||||
|
Loading…
Reference in New Issue
Block a user