mirror of
https://github.com/YMFE/yapi.git
synced 2025-04-18 15:20:25 +08:00
Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev
This commit is contained in:
commit
b7ac596de5
@ -1,7 +1,7 @@
|
||||
## YApi
|
||||
|
||||
### 一、平台介绍
|
||||

|
||||

|
||||
|
||||
<p style='text-indent:2em;line-height:1.8em'>YApi是<strong>高效</strong>、<strong>易用</strong>、<strong>功能强大</strong>的api管理平台,旨在为开发、产品、测试人员提供更优雅的接口管理服务。可以帮助开发者轻松创建、发布、维护 API,YApi还为用户提供了优秀的交互体验,开发人员只需利用平台提供的接口数据写入工具以及简单的点击操作就可以实现接口的管理。</p>
|
||||
|
||||
|
@ -37,3 +37,11 @@ exports.logoSVG = (length) => (<svg className="svg" width={length} height={lengt
|
||||
</g>
|
||||
</g>
|
||||
</svg>);
|
||||
|
||||
exports.debounce = (func, wait) => {
|
||||
let timeout;
|
||||
return function() {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(func, wait);
|
||||
};
|
||||
};
|
||||
|
@ -1,65 +1,81 @@
|
||||
import './ProjectCard.scss';
|
||||
import React, { Component } from 'react';
|
||||
import { Card, Icon, Tooltip, message } from 'antd';
|
||||
import { Card, Icon, Tooltip } from 'antd';
|
||||
import { connect } from 'react-redux'
|
||||
import { delFollow } from '../../reducer/modules/follow';
|
||||
import { delFollow, addFollow } from '../../reducer/modules/follow';
|
||||
// import { Link } from 'react-router-dom';
|
||||
import PropTypes from 'prop-types';
|
||||
import { withRouter } from 'react-router';
|
||||
import { debounce } from '../../common';
|
||||
|
||||
@connect(
|
||||
() => {
|
||||
return {}
|
||||
state => {
|
||||
return {
|
||||
uid: state.user.uid
|
||||
}
|
||||
},
|
||||
{
|
||||
delFollow
|
||||
delFollow,
|
||||
addFollow
|
||||
}
|
||||
)
|
||||
@withRouter
|
||||
class ProjectCard extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.add = debounce(this.add, 400);
|
||||
this.del = debounce(this.del, 400);
|
||||
}
|
||||
|
||||
static propTypes = {
|
||||
projectData: PropTypes.object,
|
||||
isFollowed: PropTypes.bool,
|
||||
uid: PropTypes.number,
|
||||
inFollowPage: PropTypes.bool,
|
||||
callbackResult: PropTypes.func,
|
||||
history: PropTypes.object,
|
||||
delFollow: PropTypes.func
|
||||
delFollow: PropTypes.func,
|
||||
addFollow: PropTypes.func
|
||||
}
|
||||
|
||||
del = () => {
|
||||
console.log('del');
|
||||
const id = this.props.projectData.projectid;
|
||||
const id = this.props.projectData.projectid || this.props.projectData._id;
|
||||
this.props.delFollow(id).then((res) => {
|
||||
if (res.payload.data.errcode === 0) {
|
||||
this.props.callbackResult();
|
||||
message.success('已取消关注!');
|
||||
// message.success('已取消关注!'); // 星号已做出反馈 无需重复提醒用户
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
add = () => {
|
||||
const { uid, projectData } = this.props;
|
||||
const param = {
|
||||
uid,
|
||||
projectid: projectData._id,
|
||||
projectname: projectData.name,
|
||||
icon: projectData.icon,
|
||||
color: projectData.color
|
||||
}
|
||||
this.props.addFollow(param).then((res) => {
|
||||
console.log(res);
|
||||
if (res.payload.data.errcode === 0) {
|
||||
this.props.callbackResult();
|
||||
// message.success('已添加关注!'); // 星号已做出反馈 无需重复提醒用户
|
||||
}
|
||||
});
|
||||
}
|
||||
add() {
|
||||
console.log('add');
|
||||
}
|
||||
// <Link to={`/project/${projectData._id}`} className="card-link">
|
||||
//
|
||||
// </Link>
|
||||
|
||||
// <Popconfirm placement="leftBottom" title={<Icon type="up" />} onConfirm={confirm} okText="确认" cancelText="取消">
|
||||
// <Icon type="star-o" className="icon" onClick={this.clickHandle}/>
|
||||
// </Popconfirm>
|
||||
render() {
|
||||
const { projectData, isFollowed } = this.props;
|
||||
const { projectData, inFollowPage } = this.props;
|
||||
return (
|
||||
<div className="card-container">
|
||||
<Card bordered={false} className="m-card" onClick={() => this.props.history.push('/project/' + projectData._id)}>
|
||||
<Icon type="area-chart" className="ui-logo" />
|
||||
<Icon type={projectData.icon || 'star-o'} className="ui-logo" style={{backgroundColor: projectData.color || '#2395f1'}} />
|
||||
<h4 className="ui-title">{projectData.name || projectData.projectname}</h4>
|
||||
</Card>
|
||||
<div className="card-btns">
|
||||
<Tooltip placement="rightTop" title={isFollowed ? '取消关注' : '添加关注'}>
|
||||
<Icon type={isFollowed ? 'star' : 'star-o'} className="icon" onClick={isFollowed ? this.del : this.add}/>
|
||||
<div className="card-btns" onClick={projectData.follow || inFollowPage ? this.del : this.add}>
|
||||
<Tooltip placement="rightTop" title={projectData.follow || inFollowPage ? '取消关注' : '添加关注'}>
|
||||
<Icon type={projectData.follow || inFollowPage ? 'star' : 'star-o'} className="icon"/>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -66,15 +66,9 @@
|
||||
font-size: .19rem;
|
||||
margin-bottom: .08rem;
|
||||
font-weight: normal;
|
||||
}
|
||||
.ui-desc {
|
||||
font-size: .16rem;
|
||||
height: .24rem;
|
||||
line-height: .24rem;
|
||||
overflow: hidden;
|
||||
text-overflow:ellipsis;
|
||||
white-space: nowrap;
|
||||
color: rgba(39, 56, 72, 0.43);
|
||||
}
|
||||
.m-card-body {
|
||||
.icon {
|
||||
|
@ -9,7 +9,8 @@ const { TextArea } = Input;
|
||||
const FormItem = Form.Item;
|
||||
const Option = Select.Option;
|
||||
const RadioGroup = Radio.Group;
|
||||
import './Addproject.scss'
|
||||
import { withRouter } from 'react-router';
|
||||
import './Addproject.scss';
|
||||
|
||||
const formItemLayout = {
|
||||
labelCol: {
|
||||
@ -36,7 +37,7 @@ const formItemLayout = {
|
||||
addProject
|
||||
}
|
||||
)
|
||||
|
||||
@withRouter
|
||||
class ProjectList extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@ -48,6 +49,7 @@ class ProjectList extends Component {
|
||||
groupList: PropTypes.array,
|
||||
form: PropTypes.object,
|
||||
addProject: PropTypes.func,
|
||||
history: PropTypes.object,
|
||||
fetchGroupList: PropTypes.func
|
||||
}
|
||||
|
||||
@ -65,6 +67,7 @@ class ProjectList extends Component {
|
||||
if (res.payload.data.errcode == 0) {
|
||||
form.resetFields();
|
||||
message.success('创建成功! ');
|
||||
this.props.history.push('/project/' + res.payload.data.data._id + '/interface/api');
|
||||
}
|
||||
}).catch(() => {
|
||||
});
|
||||
|
@ -33,7 +33,7 @@ class Follows extends Component {
|
||||
}
|
||||
|
||||
receiveRes = () => {
|
||||
console.log('receive!');
|
||||
console.log('receive res!');
|
||||
this.props.getFollowList(this.props.uid).then((res) => {
|
||||
console.log(res);
|
||||
if (res.payload.data.errcode === 0) {
|
||||
@ -74,7 +74,7 @@ class Follows extends Component {
|
||||
{data.length ? data.map((item, index) => {
|
||||
return (
|
||||
<Col span={8} key={index}>
|
||||
<ProjectCard projectData={item} isFollowed={true} callbackResult={this.receiveRes} />
|
||||
<ProjectCard projectData={item} inFollowPage={true} callbackResult={this.receiveRes} />
|
||||
</Col>);
|
||||
}): <ErrMsg type="noFollow"/>}
|
||||
</Row>
|
||||
|
@ -16,7 +16,6 @@ import './ProjectList.scss'
|
||||
userInfo: state.project.userInfo,
|
||||
tableLoading: state.project.tableLoading,
|
||||
currGroup: state.group.currGroup,
|
||||
total: state.project.total,
|
||||
currPage: state.project.currPage
|
||||
}
|
||||
},
|
||||
@ -46,7 +45,6 @@ class ProjectList extends Component {
|
||||
userInfo: PropTypes.object,
|
||||
tableLoading: PropTypes.bool,
|
||||
currGroup: PropTypes.object,
|
||||
total: PropTypes.number,
|
||||
currPage: PropTypes.number
|
||||
}
|
||||
|
||||
@ -67,6 +65,11 @@ class ProjectList extends Component {
|
||||
})
|
||||
}
|
||||
|
||||
// 获取 ProjectCard 组件的关注事件回调,收到后更新数据
|
||||
@autobind
|
||||
receiveRes() {
|
||||
this.props.fetchProjectList(this.props.currGroup._id, this.props.currPage);
|
||||
}
|
||||
// // 分页逻辑 取消分页
|
||||
// @autobind
|
||||
// paginationChange(pageNum) {
|
||||
@ -106,10 +109,9 @@ class ProjectList extends Component {
|
||||
<div className="m-panel card-panel card-panel-s">
|
||||
<Row gutter={16}>
|
||||
{projectData.length ? projectData.map((item, index) => {
|
||||
console.log(item);
|
||||
return (
|
||||
<Col span={8} key={index}>
|
||||
<ProjectCard projectData={item} />
|
||||
<ProjectCard projectData={item} callbackResult={this.receiveRes} />
|
||||
</Col>);
|
||||
}) : <ErrMsg type="noProject"/>}
|
||||
</Row>
|
||||
|
@ -44,7 +44,7 @@ class Login extends Component {
|
||||
if (!err) {
|
||||
this.props.loginActions(values).then((res) => {
|
||||
if (res.payload.data.errcode == 0) {
|
||||
this.props.history.push('/');
|
||||
this.props.history.push('/group');
|
||||
message.success('登录成功! ');
|
||||
} else {
|
||||
message.error(res.payload.data.errmsg);
|
||||
|
@ -51,22 +51,28 @@ class InterfaceEditForm extends Component {
|
||||
path: '',
|
||||
status: 'undone',
|
||||
method: 'get',
|
||||
|
||||
req_params: [],
|
||||
|
||||
req_query: [{
|
||||
name: '',
|
||||
desc: '',
|
||||
required: "1"
|
||||
}],
|
||||
req_body_type: 'form',
|
||||
|
||||
req_headers: [{
|
||||
name: '',
|
||||
value: '', required: "1"
|
||||
}],
|
||||
|
||||
req_body_type: 'form',
|
||||
req_body_form: [{
|
||||
name: '',
|
||||
type: 'text',
|
||||
required: '1'
|
||||
}],
|
||||
req_body_other: '',
|
||||
|
||||
res_body_type: 'json',
|
||||
res_body: '',
|
||||
desc: '',
|
||||
@ -83,7 +89,7 @@ class InterfaceEditForm extends Component {
|
||||
if (!err) {
|
||||
if (values.res_body_type === 'json') values.res_body = this.state.res_body;
|
||||
values.req_params = this.state.req_params;
|
||||
values.req_body_json = this.state.res_body;
|
||||
values.req_body_other = this.state.req_body_other;
|
||||
values.method = this.state.method;
|
||||
let isfile = false, isHavaContentType = false;
|
||||
if (values.req_body_type === 'form') {
|
||||
@ -105,6 +111,19 @@ class InterfaceEditForm extends Component {
|
||||
value: isfile ? 'multipart/form-data' : 'application/x-www-form-urlencoded'
|
||||
})
|
||||
}
|
||||
}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){
|
||||
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 !== ''): []
|
||||
@ -123,11 +142,11 @@ class InterfaceEditForm extends Component {
|
||||
let that = this, mockPreview, resBodyEditor;
|
||||
mockEditor({
|
||||
container: 'req_body_json',
|
||||
data: that.state.req_body_json,
|
||||
data: that.state.req_body_other,
|
||||
onChange: function (d) {
|
||||
if (d.format !== true) return false;
|
||||
that.setState({
|
||||
req_body_json: d.text
|
||||
req_body_other: d.text
|
||||
})
|
||||
}
|
||||
})
|
||||
@ -374,7 +393,7 @@ class InterfaceEditForm extends Component {
|
||||
})}
|
||||
</Select>
|
||||
|
||||
<Tooltip title="接口基本路径,可在项目配置里修改">
|
||||
<Tooltip title="接口基本路径,可在项目配置里修改" style={{display: this.props.basepath == '' ? 'block': 'none'}}>
|
||||
<Input disabled value={this.props.basepath} readOnly onChange={() => { }} style={{ width: '25%' }} />
|
||||
</Tooltip>
|
||||
{getFieldDecorator('path', {
|
||||
@ -577,9 +596,9 @@ class InterfaceEditForm extends Component {
|
||||
|
||||
<FormItem
|
||||
className="interface-edit-item"
|
||||
wrapperCol={{ span: 12, offset: 6 }}
|
||||
wrapperCol={{ span: 14, offset: 10 }}
|
||||
>
|
||||
<Button type="primary" htmlType="submit">Submit</Button>
|
||||
<Button type="primary" htmlType="submit">保存</Button>
|
||||
</FormItem>
|
||||
</Form>
|
||||
);
|
||||
|
@ -1,10 +1,11 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Form, Input, Icon, Tooltip, Select, Button, Row, Col, message, Card, Radio, Alert, Modal } from 'antd';
|
||||
import { Form, Input, Icon, Tooltip, Select, Button, Row, Col, message, Card, Radio, Alert, Modal, Popover } from 'antd';
|
||||
import PropTypes from 'prop-types';
|
||||
import { updateProject, delProject, getProjectMsg } from '../../../../reducer/modules/project';
|
||||
import { fetchGroupMsg } from '../../../../reducer/modules/group';
|
||||
import { connect } from 'react-redux';
|
||||
const { TextArea } = Input;
|
||||
import { withRouter } from 'react-router';
|
||||
const FormItem = Form.Item;
|
||||
const Option = Select.Option;
|
||||
const RadioGroup = Radio.Group;
|
||||
@ -41,6 +42,7 @@ let uuid = 0; // 环境配置的计数
|
||||
fetchGroupMsg
|
||||
}
|
||||
)
|
||||
@withRouter
|
||||
class ProjectMessage extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@ -56,6 +58,7 @@ class ProjectMessage extends Component {
|
||||
updateProject: PropTypes.func,
|
||||
delProject: PropTypes.func,
|
||||
getProjectMsg: PropTypes.func,
|
||||
history: PropTypes.object,
|
||||
fetchGroupMsg: PropTypes.func,
|
||||
projectList: PropTypes.array,
|
||||
projectMsg: PropTypes.object
|
||||
@ -130,15 +133,6 @@ class ProjectMessage extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
handleDelete = () => {
|
||||
console.log(this.props); // 出问题了
|
||||
this.props.delProject(this.props.projectId).then((res) => {
|
||||
if (res.payload.data.errcode == 0) {
|
||||
message.success('删除成功!');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
showConfirm = () => {
|
||||
let that = this;
|
||||
confirm({
|
||||
@ -161,6 +155,7 @@ class ProjectMessage extends Component {
|
||||
that.props.delProject(that.props.projectId).then((res) => {
|
||||
if (res.payload.data.errcode == 0) {
|
||||
message.success('删除成功!');
|
||||
that.props.history.push('/group');
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -176,12 +171,13 @@ class ProjectMessage extends Component {
|
||||
const groupMsg = await this.props.fetchGroupMsg(this.props.projectMsg.group_id);
|
||||
this.setState({
|
||||
currGroup: groupMsg.payload.data.data.group_name
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
render () {
|
||||
const { getFieldDecorator, getFieldValue } = this.props.form;
|
||||
const { projectMsg } = this.props;
|
||||
console.log(projectMsg);
|
||||
let initFormValues = {};
|
||||
let envMessage = [];
|
||||
const { name, basepath, desc, env, project_type } = projectMsg;
|
||||
@ -289,8 +285,27 @@ class ProjectMessage extends Component {
|
||||
</Row>
|
||||
);
|
||||
});
|
||||
|
||||
const colorSelector = (<RadioGroup onChange={this.onChange} value={1}>
|
||||
<Radio value={1} style={{color: 'red'}}></Radio>
|
||||
<Radio value={2}></Radio>
|
||||
<Radio value={3}></Radio>
|
||||
<Radio value={4}></Radio>
|
||||
</RadioGroup>);
|
||||
return (
|
||||
<div className="m-panel">
|
||||
<Row className="project-setting">
|
||||
<Col sm={6} lg={3} className="setting-logo">
|
||||
<Popover placement="bottom" title={colorSelector} content={'content'} trigger="click">
|
||||
<Icon type={projectMsg.icon || 'star-o'} className="ui-logo" style={{backgroundColor: projectMsg.color || '#2395f1'}} />
|
||||
</Popover>
|
||||
</Col>
|
||||
<Col sm={18} lg={21} className="setting-intro">
|
||||
<h2 className="ui-title">{projectMsg.group_name + ' / ' + projectMsg.name}</h2>
|
||||
<p className="ui-desc">{projectMsg.desc}</p>
|
||||
</Col>
|
||||
</Row>
|
||||
<hr className="breakline" />
|
||||
<Form>
|
||||
<FormItem
|
||||
{...formItemLayout}
|
||||
@ -350,7 +365,7 @@ class ProjectMessage extends Component {
|
||||
|
||||
<FormItem
|
||||
{...formItemLayout}
|
||||
label="所属分组"
|
||||
label="环境配置"
|
||||
>
|
||||
{envSettingItems}
|
||||
</FormItem>
|
||||
|
@ -57,3 +57,36 @@
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
}
|
||||
|
||||
.project-setting {
|
||||
.setting-logo {
|
||||
text-align: right;
|
||||
padding: .24rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.setting-intro {
|
||||
padding: .24rem;
|
||||
height: 1.48rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
.ui-title {
|
||||
font-size: .32rem;
|
||||
font-weight: normal;
|
||||
width: 100%;
|
||||
}
|
||||
.ui-desc {
|
||||
font-size: .16rem;
|
||||
}
|
||||
}
|
||||
.ui-logo {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
border-radius: 50%;
|
||||
font-size: .6rem;
|
||||
color: #fff;
|
||||
background-color: #2395f1;
|
||||
line-height: 1rem;
|
||||
box-shadow: 0 4px 6px rgba(50,50,93,.11), 0 1px 3px rgba(0,0,0,.08);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import axios from 'axios';
|
||||
// Actions
|
||||
const GET_FOLLOW_LIST = 'yapi/follow/GET_FOLLOW_LIST';
|
||||
const DEL_FOLLOW = 'yapi/follow/DEL_FOLLOW';
|
||||
const ADD_FOLLOW = 'yapi/follow/ADD_FOLLOW';
|
||||
|
||||
// Reducer
|
||||
const initialState = {
|
||||
@ -32,10 +33,18 @@ export function getFollowList(uid) {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 添加关注
|
||||
export function addFollow(param) {
|
||||
return {
|
||||
type: ADD_FOLLOW,
|
||||
payload: axios.post('/api/follow/add', param)
|
||||
}
|
||||
}
|
||||
|
||||
// 删除关注
|
||||
export function delFollow(id) {
|
||||
return {
|
||||
type: DEL_FOLLOW,
|
||||
payload: axios.post('/api/follow/del', { id })
|
||||
payload: axios.post('/api/follow/del', { projectid: id })
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 254 KiB |
@ -3,12 +3,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,6 +109,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);
|
||||
@ -317,6 +329,22 @@ class interfaceController extends baseController {
|
||||
|
||||
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 = await this.catModel.get(inter.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);
|
||||
@ -351,8 +379,19 @@ class interfaceController extends baseController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
@ -411,6 +450,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) {
|
||||
@ -425,7 +474,18 @@ 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);
|
||||
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)
|
||||
@ -447,8 +507,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);
|
||||
|
||||
|
||||
|
@ -428,15 +428,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}`,
|
||||
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) {
|
||||
@ -444,6 +442,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
|
||||
@ -511,31 +542,13 @@ class projectController extends baseController {
|
||||
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}`,
|
||||
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) {
|
||||
|
@ -62,7 +62,7 @@ class logModel extends baseModel {
|
||||
return this.model.find({
|
||||
type: type,
|
||||
typeid: typeid
|
||||
}).skip((page - 1) * limit).limit(limit).exec();
|
||||
}).sort({add_time:-1}).skip((page - 1) * limit).limit(limit).exec();
|
||||
}
|
||||
|
||||
listCount(typeid,type) {
|
||||
|
@ -52,6 +52,10 @@ var _user = require('../models/user.js');
|
||||
|
||||
var _user2 = _interopRequireDefault(_user);
|
||||
|
||||
var _project = require('../models/project.js');
|
||||
|
||||
var _project2 = _interopRequireDefault(_project);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var interfaceController = function (_baseController) {
|
||||
@ -64,6 +68,7 @@ var interfaceController = function (_baseController) {
|
||||
|
||||
_this.Model = _yapi2.default.getInst(_interface2.default);
|
||||
_this.catModel = _yapi2.default.getInst(_interfaceCat2.default);
|
||||
_this.projectModel = _yapi2.default.getInst(_project2.default);
|
||||
return _this;
|
||||
}
|
||||
|
||||
@ -101,7 +106,7 @@ var interfaceController = function (_baseController) {
|
||||
key: 'add',
|
||||
value: function () {
|
||||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
|
||||
var params, checkRepeat, data, result;
|
||||
var params, checkRepeat, data, result, username, cate;
|
||||
return _regenerator2.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
@ -199,23 +204,38 @@ var interfaceController = function (_baseController) {
|
||||
|
||||
case 24:
|
||||
result = _context.sent;
|
||||
username = this.getUsername();
|
||||
// let project = await this.projectModel.get(params.project_id);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context.next = 31;
|
||||
break;
|
||||
_context.next = 28;
|
||||
return this.catModel.get(params.catid);
|
||||
|
||||
case 28:
|
||||
_context.prev = 28;
|
||||
cate = _context.sent;
|
||||
|
||||
_yapi2.default.commons.saveLog({
|
||||
content: '\u7528\u6237 "' + username + '" \u4E3A\u5206\u7C7B "' + cate.name + '" \u6DFB\u52A0\u4E86\u63A5\u53E3 "' + data.title + '"',
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: params.project_id
|
||||
});
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context.next = 36;
|
||||
break;
|
||||
|
||||
case 33:
|
||||
_context.prev = 33;
|
||||
_context.t0 = _context['catch'](16);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
|
||||
|
||||
case 31:
|
||||
case 36:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, this, [[16, 28]]);
|
||||
}, _callee, this, [[16, 33]]);
|
||||
}));
|
||||
|
||||
function add(_x) {
|
||||
@ -507,7 +527,7 @@ var interfaceController = function (_baseController) {
|
||||
key: 'up',
|
||||
value: function () {
|
||||
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
|
||||
var params, id, interfaceData, checkRepeat, data, result;
|
||||
var params, id, interfaceData, checkRepeat, data, result, username, cate, inter;
|
||||
return _regenerator2.default.wrap(function _callee6$(_context6) {
|
||||
while (1) {
|
||||
switch (_context6.prev = _context6.next) {
|
||||
@ -632,23 +652,59 @@ var interfaceController = function (_baseController) {
|
||||
|
||||
case 36:
|
||||
result = _context6.sent;
|
||||
username = this.getUsername();
|
||||
cate = void 0;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context6.next = 43;
|
||||
if (!params.catid) {
|
||||
_context6.next = 45;
|
||||
break;
|
||||
}
|
||||
|
||||
_context6.next = 42;
|
||||
return this.catModel.get(+params.catid);
|
||||
|
||||
case 42:
|
||||
cate = _context6.sent;
|
||||
_context6.next = 51;
|
||||
break;
|
||||
|
||||
case 40:
|
||||
_context6.prev = 40;
|
||||
case 45:
|
||||
_context6.next = 47;
|
||||
return this.Model.get(id);
|
||||
|
||||
case 47:
|
||||
inter = _context6.sent;
|
||||
_context6.next = 50;
|
||||
return this.catModel.get(inter.catid);
|
||||
|
||||
case 50:
|
||||
cate = _context6.sent;
|
||||
|
||||
case 51:
|
||||
|
||||
_yapi2.default.commons.saveLog({
|
||||
content: '\u7528\u6237 "' + username + '" \u66F4\u65B0\u4E86\u5206\u7C7B "' + cate.name + '" \u4E0B\u7684\u63A5\u53E3 "' + data.title + '"',
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: cate.project_id
|
||||
});
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context6.next = 58;
|
||||
break;
|
||||
|
||||
case 55:
|
||||
_context6.prev = 55;
|
||||
_context6.t0 = _context6['catch'](33);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context6.t0.message);
|
||||
|
||||
case 43:
|
||||
case 58:
|
||||
case 'end':
|
||||
return _context6.stop();
|
||||
}
|
||||
}
|
||||
}, _callee6, this, [[33, 40]]);
|
||||
}, _callee6, this, [[33, 55]]);
|
||||
}));
|
||||
|
||||
function up(_x6) {
|
||||
@ -673,7 +729,7 @@ var interfaceController = function (_baseController) {
|
||||
key: 'del',
|
||||
value: function () {
|
||||
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
|
||||
var id, data, result;
|
||||
var id, data, inter, result, username, cate;
|
||||
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
||||
while (1) {
|
||||
switch (_context7.prev = _context7.next) {
|
||||
@ -715,27 +771,46 @@ var interfaceController = function (_baseController) {
|
||||
|
||||
case 13:
|
||||
_context7.next = 15;
|
||||
return this.Model.del(id);
|
||||
return this.Model.get(id);
|
||||
|
||||
case 15:
|
||||
inter = _context7.sent;
|
||||
_context7.next = 18;
|
||||
return this.Model.del(id);
|
||||
|
||||
case 18:
|
||||
result = _context7.sent;
|
||||
username = this.getUsername();
|
||||
_context7.next = 22;
|
||||
return this.catModel.get(inter.catid);
|
||||
|
||||
case 22:
|
||||
cate = _context7.sent;
|
||||
|
||||
_yapi2.default.commons.saveLog({
|
||||
content: '\u7528\u6237 "' + username + '" \u5220\u9664\u4E86\u5206\u7C7B "' + cate.name + '" \u4E0B\u7684\u63A5\u53E3 "' + inter.title + '"',
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: cate.project_id
|
||||
});
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context7.next = 22;
|
||||
_context7.next = 30;
|
||||
break;
|
||||
|
||||
case 19:
|
||||
_context7.prev = 19;
|
||||
case 27:
|
||||
_context7.prev = 27;
|
||||
_context7.t1 = _context7['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context7.t1.message);
|
||||
|
||||
case 22:
|
||||
case 30:
|
||||
case 'end':
|
||||
return _context7.stop();
|
||||
}
|
||||
}
|
||||
}, _callee7, this, [[0, 19]]);
|
||||
}, _callee7, this, [[0, 27]]);
|
||||
}));
|
||||
|
||||
function del(_x7) {
|
||||
@ -831,7 +906,7 @@ var interfaceController = function (_baseController) {
|
||||
key: 'addCat',
|
||||
value: function () {
|
||||
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
|
||||
var params, result;
|
||||
var params, result, username;
|
||||
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
||||
while (1) {
|
||||
switch (_context9.prev = _context9.next) {
|
||||
@ -873,24 +948,33 @@ var interfaceController = function (_baseController) {
|
||||
|
||||
case 9:
|
||||
result = _context9.sent;
|
||||
username = this.getUsername();
|
||||
|
||||
_yapi2.default.commons.saveLog({
|
||||
content: '\u7528\u6237 "' + username + '" \u6DFB\u52A0\u4E86\u5206\u7C7B "' + params.name + '"',
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: params.project_id
|
||||
});
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
|
||||
_context9.next = 16;
|
||||
_context9.next = 18;
|
||||
break;
|
||||
|
||||
case 13:
|
||||
_context9.prev = 13;
|
||||
case 15:
|
||||
_context9.prev = 15;
|
||||
_context9.t0 = _context9['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context9.t0.message);
|
||||
|
||||
case 16:
|
||||
case 18:
|
||||
case 'end':
|
||||
return _context9.stop();
|
||||
}
|
||||
}
|
||||
}, _callee9, this, [[0, 13]]);
|
||||
}, _callee9, this, [[0, 15]]);
|
||||
}));
|
||||
|
||||
function addCat(_x9) {
|
||||
@ -903,7 +987,7 @@ var interfaceController = function (_baseController) {
|
||||
key: 'upCat',
|
||||
value: function () {
|
||||
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
|
||||
var params, result;
|
||||
var params, result, username, cate;
|
||||
return _regenerator2.default.wrap(function _callee10$(_context10) {
|
||||
while (1) {
|
||||
switch (_context10.prev = _context10.next) {
|
||||
@ -919,23 +1003,37 @@ var interfaceController = function (_baseController) {
|
||||
|
||||
case 4:
|
||||
result = _context10.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context10.next = 11;
|
||||
break;
|
||||
username = this.getUsername();
|
||||
_context10.next = 8;
|
||||
return this.catModel.get(params.catid);
|
||||
|
||||
case 8:
|
||||
_context10.prev = 8;
|
||||
cate = _context10.sent;
|
||||
|
||||
_yapi2.default.commons.saveLog({
|
||||
content: '\u7528\u6237 "' + username + '" \u66F4\u65B0\u4E86\u5206\u7C7B "' + cate.name + '"',
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: cate.project_id
|
||||
});
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context10.next = 16;
|
||||
break;
|
||||
|
||||
case 13:
|
||||
_context10.prev = 13;
|
||||
_context10.t0 = _context10['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, _context10.t0.message);
|
||||
|
||||
case 11:
|
||||
case 16:
|
||||
case 'end':
|
||||
return _context10.stop();
|
||||
}
|
||||
}
|
||||
}, _callee10, this, [[0, 8]]);
|
||||
}, _callee10, this, [[0, 13]]);
|
||||
}));
|
||||
|
||||
function upCat(_x10) {
|
||||
@ -948,7 +1046,7 @@ var interfaceController = function (_baseController) {
|
||||
key: 'delCat',
|
||||
value: function () {
|
||||
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee11(ctx) {
|
||||
var id, catData, auth, result, r;
|
||||
var id, catData, auth, cate, result, r, username;
|
||||
return _regenerator2.default.wrap(function _callee11$(_context11) {
|
||||
while (1) {
|
||||
switch (_context11.prev = _context11.next) {
|
||||
@ -985,29 +1083,45 @@ var interfaceController = function (_baseController) {
|
||||
|
||||
case 12:
|
||||
_context11.next = 14;
|
||||
return this.catModel.del(id);
|
||||
return this.catModel.get(id);
|
||||
|
||||
case 14:
|
||||
result = _context11.sent;
|
||||
cate = _context11.sent;
|
||||
_context11.next = 17;
|
||||
return this.Model.delByCatid(id);
|
||||
return this.catModel.del(id);
|
||||
|
||||
case 17:
|
||||
result = _context11.sent;
|
||||
_context11.next = 20;
|
||||
return this.Model.delByCatid(id);
|
||||
|
||||
case 20:
|
||||
r = _context11.sent;
|
||||
username = this.getUsername();
|
||||
|
||||
|
||||
_yapi2.default.commons.saveLog({
|
||||
content: '\u7528\u6237 "' + username + '" \u5220\u9664\u4E86\u5206\u7C7B "' + cate.name + '" \u53CA\u8BE5\u5206\u7C7B\u4E0B\u7684\u63A5\u53E3',
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: cate.project_id
|
||||
});
|
||||
|
||||
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(r));
|
||||
|
||||
case 21:
|
||||
_context11.prev = 21;
|
||||
case 26:
|
||||
_context11.prev = 26;
|
||||
_context11.t0 = _context11['catch'](0);
|
||||
|
||||
_yapi2.default.commons.resReturn(null, 400, _context11.t0.message);
|
||||
|
||||
case 24:
|
||||
case 29:
|
||||
case 'end':
|
||||
return _context11.stop();
|
||||
}
|
||||
}
|
||||
}, _callee11, this, [[0, 21]]);
|
||||
}, _callee11, this, [[0, 26]]);
|
||||
}));
|
||||
|
||||
function delCat(_x11) {
|
||||
|
@ -995,7 +995,7 @@ var projectController = function (_baseController) {
|
||||
case 24:
|
||||
project = _context9.sent;
|
||||
_context9.next = 27;
|
||||
return _yapi2.default.getInst(_user2.default).findByUids(params.member_uid);
|
||||
return _yapi2.default.getInst(_user2.default).findById(params.member_uid);
|
||||
|
||||
case 27:
|
||||
member = _context9.sent;
|
||||
@ -1005,9 +1005,7 @@ var projectController = function (_baseController) {
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: params.id,
|
||||
color: project.color,
|
||||
icon: project.icon
|
||||
typeid: params.id
|
||||
});
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context9.next = 35;
|
||||
@ -1034,6 +1032,81 @@ var projectController = function (_baseController) {
|
||||
return changeMemberRole;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 项目设置
|
||||
* @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
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'upSet',
|
||||
value: function () {
|
||||
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
|
||||
var id, data, result;
|
||||
return _regenerator2.default.wrap(function _callee10$(_context10) {
|
||||
while (1) {
|
||||
switch (_context10.prev = _context10.next) {
|
||||
case 0:
|
||||
id = ctx.request.body.id;
|
||||
data = {};
|
||||
|
||||
data.color = ctx.request.body.color;
|
||||
data.icon = ctx.request.body.icon;
|
||||
|
||||
if (id) {
|
||||
_context10.next = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
|
||||
|
||||
case 6:
|
||||
_context10.prev = 6;
|
||||
_context10.next = 9;
|
||||
return this.Model.up(id, data);
|
||||
|
||||
case 9:
|
||||
result = _context10.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context10.next = 16;
|
||||
break;
|
||||
|
||||
case 13:
|
||||
_context10.prev = 13;
|
||||
_context10.t0 = _context10['catch'](6);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context10.t0.message);
|
||||
|
||||
case 16:
|
||||
try {
|
||||
this.followModel.updateById(this.getUid(), id, data).then();
|
||||
} catch (e) {
|
||||
_yapi2.default.commons.log(e, 'error'); // eslint-disable-line
|
||||
}
|
||||
|
||||
case 17:
|
||||
case 'end':
|
||||
return _context10.stop();
|
||||
}
|
||||
}
|
||||
}, _callee10, this, [[6, 13]]);
|
||||
}));
|
||||
|
||||
function upSet(_x11) {
|
||||
return _ref10.apply(this, arguments);
|
||||
}
|
||||
|
||||
return upSet;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 编辑项目
|
||||
* @interface /project/up
|
||||
@ -1054,13 +1127,13 @@ var projectController = function (_baseController) {
|
||||
}, {
|
||||
key: 'up',
|
||||
value: function () {
|
||||
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
|
||||
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee11(ctx) {
|
||||
var id, params, projectData, checkRepeat, data, result, username;
|
||||
return _regenerator2.default.wrap(function _callee10$(_context10) {
|
||||
return _regenerator2.default.wrap(function _callee11$(_context11) {
|
||||
while (1) {
|
||||
switch (_context10.prev = _context10.next) {
|
||||
switch (_context11.prev = _context11.next) {
|
||||
case 0:
|
||||
_context10.prev = 0;
|
||||
_context11.prev = 0;
|
||||
id = ctx.request.body.id;
|
||||
params = ctx.request.body;
|
||||
|
||||
@ -1075,39 +1148,39 @@ var projectController = function (_baseController) {
|
||||
});
|
||||
|
||||
if (id) {
|
||||
_context10.next = 7;
|
||||
_context11.next = 7;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
|
||||
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
|
||||
|
||||
case 7:
|
||||
_context10.next = 9;
|
||||
_context11.next = 9;
|
||||
return this.checkAuth(id, 'project', 'edit');
|
||||
|
||||
case 9:
|
||||
_context10.t0 = _context10.sent;
|
||||
_context11.t0 = _context11.sent;
|
||||
|
||||
if (!(_context10.t0 !== true)) {
|
||||
_context10.next = 12;
|
||||
if (!(_context11.t0 !== true)) {
|
||||
_context11.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
||||
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
||||
|
||||
case 12:
|
||||
_context10.next = 14;
|
||||
_context11.next = 14;
|
||||
return this.Model.get(id);
|
||||
|
||||
case 14:
|
||||
projectData = _context10.sent;
|
||||
projectData = _context11.sent;
|
||||
|
||||
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
|
||||
_context10.next = 17;
|
||||
_context11.next = 17;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
|
||||
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
|
||||
|
||||
case 17:
|
||||
|
||||
@ -1116,22 +1189,22 @@ var projectController = function (_baseController) {
|
||||
}
|
||||
|
||||
if (!params.name) {
|
||||
_context10.next = 24;
|
||||
_context11.next = 24;
|
||||
break;
|
||||
}
|
||||
|
||||
_context10.next = 21;
|
||||
_context11.next = 21;
|
||||
return this.Model.checkNameRepeat(params.name);
|
||||
|
||||
case 21:
|
||||
checkRepeat = _context10.sent;
|
||||
checkRepeat = _context11.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context10.next = 24;
|
||||
_context11.next = 24;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
|
||||
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
|
||||
|
||||
case 24:
|
||||
data = {
|
||||
@ -1147,28 +1220,11 @@ var projectController = function (_baseController) {
|
||||
if (params.env) data.env = params.env;
|
||||
if (params.color) data.color = params.color;
|
||||
if (params.icon) data.icon = params.icon;
|
||||
_context10.next = 33;
|
||||
_context11.next = 33;
|
||||
return this.Model.up(id, data);
|
||||
|
||||
case 33:
|
||||
result = _context10.sent;
|
||||
|
||||
// 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
|
||||
// }
|
||||
|
||||
result = _context11.sent;
|
||||
username = this.getUsername();
|
||||
|
||||
_yapi2.default.commons.saveLog({
|
||||
@ -1176,30 +1232,28 @@ var projectController = function (_baseController) {
|
||||
type: 'project',
|
||||
uid: this.getUid(),
|
||||
username: username,
|
||||
typeid: id,
|
||||
icon: params.icon,
|
||||
color: params.color
|
||||
typeid: id
|
||||
});
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context10.next = 42;
|
||||
_context11.next = 42;
|
||||
break;
|
||||
|
||||
case 39:
|
||||
_context10.prev = 39;
|
||||
_context10.t1 = _context10['catch'](0);
|
||||
_context11.prev = 39;
|
||||
_context11.t1 = _context11['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context10.t1.message);
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context11.t1.message);
|
||||
|
||||
case 42:
|
||||
case 'end':
|
||||
return _context10.stop();
|
||||
return _context11.stop();
|
||||
}
|
||||
}
|
||||
}, _callee10, this, [[0, 39]]);
|
||||
}, _callee11, this, [[0, 39]]);
|
||||
}));
|
||||
|
||||
function up(_x11) {
|
||||
return _ref10.apply(this, arguments);
|
||||
function up(_x12) {
|
||||
return _ref11.apply(this, arguments);
|
||||
}
|
||||
|
||||
return up;
|
||||
@ -1220,11 +1274,11 @@ var projectController = function (_baseController) {
|
||||
}, {
|
||||
key: 'upSet',
|
||||
value: function () {
|
||||
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee11(ctx) {
|
||||
var _ref12 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee12(ctx) {
|
||||
var id, data, result;
|
||||
return _regenerator2.default.wrap(function _callee11$(_context11) {
|
||||
return _regenerator2.default.wrap(function _callee12$(_context12) {
|
||||
while (1) {
|
||||
switch (_context11.prev = _context11.next) {
|
||||
switch (_context12.prev = _context12.next) {
|
||||
case 0:
|
||||
id = ctx.request.body.id;
|
||||
data = {};
|
||||
@ -1233,29 +1287,29 @@ var projectController = function (_baseController) {
|
||||
data.icon = ctx.request.body.icon;
|
||||
|
||||
if (id) {
|
||||
_context11.next = 6;
|
||||
_context12.next = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
|
||||
return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
|
||||
|
||||
case 6:
|
||||
_context11.prev = 6;
|
||||
_context11.next = 9;
|
||||
_context12.prev = 6;
|
||||
_context12.next = 9;
|
||||
return this.Model.up(id, data);
|
||||
|
||||
case 9:
|
||||
result = _context11.sent;
|
||||
result = _context12.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context11.next = 16;
|
||||
_context12.next = 16;
|
||||
break;
|
||||
|
||||
case 13:
|
||||
_context11.prev = 13;
|
||||
_context11.t0 = _context11['catch'](6);
|
||||
_context12.prev = 13;
|
||||
_context12.t0 = _context12['catch'](6);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context11.t0.message);
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context12.t0.message);
|
||||
|
||||
case 16:
|
||||
try {
|
||||
@ -1266,14 +1320,14 @@ var projectController = function (_baseController) {
|
||||
|
||||
case 17:
|
||||
case 'end':
|
||||
return _context11.stop();
|
||||
return _context12.stop();
|
||||
}
|
||||
}
|
||||
}, _callee11, this, [[6, 13]]);
|
||||
}, _callee12, this, [[6, 13]]);
|
||||
}));
|
||||
|
||||
function upSet(_x12) {
|
||||
return _ref11.apply(this, arguments);
|
||||
function upSet(_x13) {
|
||||
return _ref12.apply(this, arguments);
|
||||
}
|
||||
|
||||
return upSet;
|
||||
@ -1293,40 +1347,40 @@ var projectController = function (_baseController) {
|
||||
}, {
|
||||
key: 'search',
|
||||
value: function () {
|
||||
var _ref12 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee12(ctx) {
|
||||
var _ref13 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee13(ctx) {
|
||||
var q, projectList, groupList, projectRules, groupRules, queryList;
|
||||
return _regenerator2.default.wrap(function _callee12$(_context12) {
|
||||
return _regenerator2.default.wrap(function _callee13$(_context13) {
|
||||
while (1) {
|
||||
switch (_context12.prev = _context12.next) {
|
||||
switch (_context13.prev = _context13.next) {
|
||||
case 0:
|
||||
q = ctx.request.query.q;
|
||||
|
||||
if (q) {
|
||||
_context12.next = 3;
|
||||
_context13.next = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'No keyword.'));
|
||||
return _context13.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'No keyword.'));
|
||||
|
||||
case 3:
|
||||
if (_yapi2.default.commons.validateSearchKeyword(q)) {
|
||||
_context12.next = 5;
|
||||
_context13.next = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'Bad query.'));
|
||||
return _context13.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'Bad query.'));
|
||||
|
||||
case 5:
|
||||
_context12.next = 7;
|
||||
_context13.next = 7;
|
||||
return this.Model.search(q);
|
||||
|
||||
case 7:
|
||||
projectList = _context12.sent;
|
||||
_context12.next = 10;
|
||||
projectList = _context13.sent;
|
||||
_context13.next = 10;
|
||||
return this.groupModel.search(q);
|
||||
|
||||
case 10:
|
||||
groupList = _context12.sent;
|
||||
groupList = _context13.sent;
|
||||
projectRules = ['_id', 'name', 'basepath', 'uid', 'env', 'members', { key: 'group_id', alias: 'groupId' }, { key: 'up_time', alias: 'upTime' }, { key: 'add_time', alias: 'addTime' }];
|
||||
groupRules = ['_id', 'uid', { key: 'group_name', alias: 'groupName' }, { key: 'group_desc', alias: 'groupDesc' }, { key: 'add_time', alias: 'addTime' }, { key: 'up_time', alias: 'upTime' }];
|
||||
|
||||
@ -1338,18 +1392,18 @@ var projectController = function (_baseController) {
|
||||
project: projectList,
|
||||
group: groupList
|
||||
};
|
||||
return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(queryList, 0, 'ok'));
|
||||
return _context13.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(queryList, 0, 'ok'));
|
||||
|
||||
case 17:
|
||||
case 'end':
|
||||
return _context12.stop();
|
||||
return _context13.stop();
|
||||
}
|
||||
}
|
||||
}, _callee12, this);
|
||||
}, _callee13, this);
|
||||
}));
|
||||
|
||||
function search(_x13) {
|
||||
return _ref12.apply(this, arguments);
|
||||
function search(_x14) {
|
||||
return _ref13.apply(this, arguments);
|
||||
}
|
||||
|
||||
return search;
|
||||
@ -1368,36 +1422,36 @@ var projectController = function (_baseController) {
|
||||
}, {
|
||||
key: 'download',
|
||||
value: function () {
|
||||
var _ref13 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee13(ctx) {
|
||||
var _ref14 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee14(ctx) {
|
||||
var project_id, interfaceInst, count, arr, fileName, res;
|
||||
return _regenerator2.default.wrap(function _callee13$(_context13) {
|
||||
return _regenerator2.default.wrap(function _callee14$(_context14) {
|
||||
while (1) {
|
||||
switch (_context13.prev = _context13.next) {
|
||||
switch (_context14.prev = _context14.next) {
|
||||
case 0:
|
||||
project_id = ctx.request.query.project_id;
|
||||
interfaceInst = _yapi2.default.getInst(_interface2.default);
|
||||
// 根据 project_id 获取接口数据
|
||||
|
||||
_context13.next = 4;
|
||||
_context14.next = 4;
|
||||
return interfaceInst.list(project_id);
|
||||
|
||||
case 4:
|
||||
count = _context13.sent;
|
||||
count = _context14.sent;
|
||||
|
||||
if (project_id) {
|
||||
_context13.next = 9;
|
||||
_context14.next = 9;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context13.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
|
||||
return _context14.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
|
||||
|
||||
case 9:
|
||||
if (count) {
|
||||
_context13.next = 11;
|
||||
_context14.next = 11;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context13.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '项目id不存在'));
|
||||
return _context14.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '项目id不存在'));
|
||||
|
||||
case 11:
|
||||
arr = (0, _stringify2.default)(count.map(function (item) {
|
||||
@ -1411,23 +1465,23 @@ var projectController = function (_baseController) {
|
||||
fileName = 'mock.js';
|
||||
|
||||
ctx.attachment(fileName);
|
||||
_context13.next = 16;
|
||||
_context14.next = 16;
|
||||
return send(ctx, fileName, { root: __dirname + '/public' });
|
||||
|
||||
case 16:
|
||||
res = ('\n var Mock = require(\'mockjs\');\n var xhook = require(\'xhook\');\n var data = ' + arr + ';\n function run() {\n xhook.before(function(request, callback) {\n setTimeout(function() {\n var res;\n data.forEach((item) => {\n // \u8BF7\u6C42\u7684\u63A5\u53E3\u5728 data \u4E2D\u5B58\u5728\n if(request.url === item.path) {\n res = {\n status: 200,\n text: Mock.mock(item.mock)\n }\n }\n });\n if (res) {\n callback(res);\n }else {\n callback({ status: 405, text: \'\u63A5\u53E3\u4E0D\u5B58\u5728\' });\n }\n }, 500);\n });\n }\n module.exports = run;').trim();
|
||||
return _context13.abrupt('return', ctx.body = res);
|
||||
return _context14.abrupt('return', ctx.body = res);
|
||||
|
||||
case 18:
|
||||
case 'end':
|
||||
return _context13.stop();
|
||||
return _context14.stop();
|
||||
}
|
||||
}
|
||||
}, _callee13, this);
|
||||
}, _callee14, this);
|
||||
}));
|
||||
|
||||
function download(_x14) {
|
||||
return _ref13.apply(this, arguments);
|
||||
function download(_x15) {
|
||||
return _ref14.apply(this, arguments);
|
||||
}
|
||||
|
||||
return download;
|
||||
|
@ -106,7 +106,7 @@ var logModel = function (_baseModel) {
|
||||
return this.model.find({
|
||||
type: type,
|
||||
typeid: typeid
|
||||
}).skip((page - 1) * limit).limit(limit).exec();
|
||||
}).sort({ add_time: -1 }).skip((page - 1) * limit).limit(limit).exec();
|
||||
}
|
||||
}, {
|
||||
key: 'listCount',
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 254 KiB |
@ -71,7 +71,7 @@
|
||||
<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> </p>
|
||||
<img src="./images/mock.jpg" /></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>
|
||||
<pre><code class="lang-javascript"><span class="token keyword">let</span> prefix <span class="token operator">=</span> <span class="token string">'http://yapi.local.qunar.com:3000/mock/2817'</span>
|
||||
$<span class="token punctuation">.</span><span class="token function">post</span><span class="token punctuation">(</span>prefix<span class="token operator">+</span><span class="token string">'/baseapi/path'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>username<span class="token punctuation">:</span> <span class="token string">'xxx'</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token keyword">function</span><span class="token punctuation">(</span>res<span class="token punctuation">)</span><span class="token punctuation">{</span>
|
||||
|
BIN
yapi-base-flow.jpg
Normal file
BIN
yapi-base-flow.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
Loading…
x
Reference in New Issue
Block a user