mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-30 13:20:24 +08:00
feat: add interface cat
This commit is contained in:
parent
e8f5808d06
commit
649bedf1e9
@ -6,6 +6,7 @@ import { Route, Switch } from 'react-router-dom';
|
||||
import './interface.scss'
|
||||
|
||||
import InterfaceMenu from './InterfaceList/InterfaceMenu.js'
|
||||
import InterfaceList from './InterfaceList/InterfaceList.js'
|
||||
import InterfaceContent from './InterfaceList/InterfaceContent.js'
|
||||
|
||||
import InterfaceColMenu from './InterfaceCol/InterfaceColMenu.js'
|
||||
@ -15,13 +16,19 @@ import InterfaceCaseContent from './InterfaceCol/InterfaceCaseContent.js'
|
||||
const InterfaceRoute = (props) => {
|
||||
let C;
|
||||
if (props.match.params.action === 'api') {
|
||||
C = InterfaceContent;
|
||||
if(!props.match.params.actionId){
|
||||
C = InterfaceList
|
||||
}else if(!isNaN(props.match.params.actionId)){
|
||||
C = InterfaceContent;
|
||||
}else if(props.match.params.actionId.indexOf('cat_')===0){
|
||||
C = InterfaceList
|
||||
}
|
||||
} else if (props.match.params.action === 'col') {
|
||||
C = InterfaceColContent;
|
||||
} else if (props.match.params.action === 'case') {
|
||||
C = InterfaceCaseContent;
|
||||
}
|
||||
return <C />
|
||||
return <C {...props} />
|
||||
}
|
||||
|
||||
InterfaceRoute.propTypes = {
|
||||
@ -45,7 +52,6 @@ class Interface extends Component {
|
||||
|
||||
onChange = (action) => {
|
||||
let params = this.props.match.params;
|
||||
|
||||
this.props.history.push('/project/'+params.id + '/interface/' + action)
|
||||
}
|
||||
|
||||
@ -71,7 +77,7 @@ class Interface extends Component {
|
||||
<div className="right-content">
|
||||
<Switch>
|
||||
<Route exact path="/project/:id/interface/:action" component={InterfaceRoute} />
|
||||
<Route exact path="/project/:id/interface/:action/:actionId" component={InterfaceRoute} />
|
||||
<Route exact path="/project/:id/interface/:action/:actionId" component={InterfaceRoute} />
|
||||
</Switch>
|
||||
</div>
|
||||
</Col>
|
||||
|
@ -42,16 +42,8 @@ class Content extends Component {
|
||||
this.handleRequest(this.props)
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
this.handleRequest(nextProps)
|
||||
}
|
||||
|
||||
handleRequest(nextProps) {
|
||||
let matchParams = nextProps.match.params;
|
||||
|
||||
if (!matchParams.actionId && (nextProps.list.length > 0)) {
|
||||
return this.props.history.replace('/project/' + matchParams.id + '/interface/api/' + nextProps.list[0]._id)
|
||||
}
|
||||
if (matchParams.actionId && this._actionId !== matchParams.actionId) {
|
||||
this._actionId = matchParams.actionId;
|
||||
this.props.fetchInterfaceData(matchParams.actionId)
|
||||
|
@ -0,0 +1,95 @@
|
||||
import React,{Component} from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import axios from 'axios'
|
||||
import {
|
||||
Table
|
||||
} from 'antd';
|
||||
class InterfaceList extends Component{
|
||||
constructor(props){
|
||||
super(props)
|
||||
this.state = {
|
||||
data : [],
|
||||
sortedInfo: {
|
||||
order: 'descend',
|
||||
columnKey: 'title'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static propTypes = {
|
||||
match: PropTypes.object
|
||||
}
|
||||
|
||||
handleRequest = async (props)=>{
|
||||
const {params} = props.match;
|
||||
if(!params.actionId){
|
||||
let projectId = params.id;
|
||||
let r = await axios.get('/api/interface/list?project_id=' + projectId);
|
||||
this.setState({
|
||||
data: r.data.data
|
||||
})
|
||||
}else if(isNaN(params.actionId)){
|
||||
let catid = params.actionId.substr(4)
|
||||
let r = await axios.get('/api/interface/list_cat?catid=' + catid);
|
||||
this.setState({
|
||||
data: r.data.data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
handleChange = (pagination, filters, sorter) => {
|
||||
this.setState({
|
||||
sortedInfo: sorter
|
||||
});
|
||||
}
|
||||
|
||||
componentWillMount(){
|
||||
this.actionId = this.props.match.params.actionId;
|
||||
this.handleRequest(this.props)
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps){
|
||||
let _actionId = nextProps.match.params.actionId;
|
||||
if(this.actionId !== _actionId){
|
||||
this.actionId = _actionId;
|
||||
this.handleRequest(nextProps)
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
let { sortedInfo } = this.state;
|
||||
sortedInfo = sortedInfo || {};
|
||||
const columns = [{
|
||||
title: '接口名称',
|
||||
dataIndex: 'title',
|
||||
key: 'title',
|
||||
sorter: (a, b) => b.title.length - a.title.length,
|
||||
sortOrder: sortedInfo.columnKey === 'title' && sortedInfo.order
|
||||
},{
|
||||
title: '接口URL',
|
||||
dataIndex: 'path',
|
||||
key: 'path'
|
||||
},{
|
||||
title: '请求方式',
|
||||
dataIndex: 'method',
|
||||
key: 'method'
|
||||
},{
|
||||
title: '更新日期',
|
||||
dataIndex: 'add_time',
|
||||
key: 'add_time'
|
||||
}]
|
||||
|
||||
const data = this.state.data.map(item=>{
|
||||
item.key = item._id;
|
||||
return item;
|
||||
});
|
||||
|
||||
return (
|
||||
<section className="interface-table">
|
||||
<Table size="small" pagination={false} bordered={true} columns={columns} onChange={this.handleChange} dataSource={data} />
|
||||
</section>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default InterfaceList
|
@ -2,13 +2,13 @@ import React, { Component } from 'react'
|
||||
import { connect } from 'react-redux';
|
||||
import PropTypes from 'prop-types'
|
||||
import { fetchInterfaceList, fetchInterfaceData, addInterfaceData, deleteInterfaceData } from '../../../../reducer/modules/interface.js';
|
||||
import { Menu, Input, Icon, Tag, Modal, message } from 'antd';
|
||||
import { Menu, Input, Icon, Tag, Modal, message, Tree, Dropdown } from 'antd';
|
||||
import AddInterfaceForm from './AddInterfaceForm';
|
||||
import axios from 'axios'
|
||||
import { Link, withRouter } from 'react-router-dom';
|
||||
|
||||
const confirm = Modal.confirm;
|
||||
const SubMenu = Menu.SubMenu;
|
||||
const TreeNode = Tree.TreeNode;
|
||||
|
||||
|
||||
@connect(
|
||||
@ -79,6 +79,10 @@ class InterfaceMenu extends Component {
|
||||
// this.handleRequest()
|
||||
// }
|
||||
|
||||
onSelect = (selectedKeys, info) => {
|
||||
console.log('selected', selectedKeys, info);
|
||||
}
|
||||
|
||||
handleAddInterface = (data) => {
|
||||
data.project_id = this.props.projectId;
|
||||
axios.post('/api/interface/add', data).then((res) => {
|
||||
@ -111,8 +115,8 @@ class InterfaceMenu extends Component {
|
||||
this.props.deleteInterfaceData(id)
|
||||
}
|
||||
|
||||
enterItem = (e) => {
|
||||
this.setState({ delIcon: e.key })
|
||||
enterItem = (id) => {
|
||||
this.setState({ delIcon: id })
|
||||
}
|
||||
|
||||
leaveItem = () => {
|
||||
@ -125,16 +129,15 @@ class InterfaceMenu extends Component {
|
||||
})
|
||||
}
|
||||
|
||||
handleGroup = (e) =>{
|
||||
console.log(e, '33')
|
||||
handleGroup = (e) => {
|
||||
e.stopPropagation();
|
||||
return false;
|
||||
}
|
||||
|
||||
render() {
|
||||
const items = [];
|
||||
const matchParams = this.props.match.params;
|
||||
this.props.list.forEach((item) => {
|
||||
|
||||
const item_interface_create = (item) => {
|
||||
let color, filter = this.state.filter;
|
||||
if (filter && item.title.indexOf(filter) === -1 && item.path.indexOf(filter) === -1) {
|
||||
return null;
|
||||
@ -146,21 +149,33 @@ class InterfaceMenu extends Component {
|
||||
case 'DELETE': color = 'red'; break;
|
||||
default: color = "green";
|
||||
}
|
||||
return <TreeNode
|
||||
title={<div onMouseEnter={() => this.enterItem(item._id)} onMouseLeave={this.leaveItem} >
|
||||
<Link className="interface-item" to={"/project/" + matchParams.id + "/interface/api/" + item._id} ><Tag color={color} className="btn-http" >{item.method}</Tag>{item.title}</Link>
|
||||
<Icon type='delete' className="interface-delete-icon" onClick={() => { this.showConfirm(item._id) }} style={{ display: this.state.delIcon == item._id ? 'block' : 'none' }} />
|
||||
</div>}
|
||||
key={'' + item._id} />
|
||||
|
||||
items.push(
|
||||
}
|
||||
|
||||
<Menu.Item onMouseEnter={this.enterItem} onMouseLeave={this.leaveItem} key={"" + item._id}>
|
||||
<Tag className="btn-http" color={color}>{item.method} </Tag>
|
||||
<Link className="interface-item" to={"/project/" + matchParams.id + "/interface/api/" + item._id} >{item.title}</Link>
|
||||
<Icon type="delete" onClick={() => { this.showConfirm(item._id) }} style={{ display: this.state.delIcon == item._id ? 'block' : 'none' }} className="interface-delete-icon" />
|
||||
const menu = (
|
||||
<Menu>
|
||||
<Menu.Item>
|
||||
<span onClick={this.showModal}>添加接口</span>
|
||||
</Menu.Item>
|
||||
)
|
||||
})
|
||||
<Menu.Item>
|
||||
<span >修改分类</span>
|
||||
</Menu.Item>
|
||||
<Menu.Item>
|
||||
<span onClick={this.showModal}>删除分类</span>
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
);
|
||||
|
||||
return <div>
|
||||
<div className="interface-filter">
|
||||
<Input onChange={this.onFilter} value={this.state.filter} placeholder="Filter by name" style={{ width: "70%" }} />
|
||||
<Tag onClick={this.showModal} color="#108ee9" style={{ marginLeft: "15px" }} ><Icon type="plus" /></Tag>
|
||||
<Tag color="#108ee9" style={{ marginLeft: "15px" }} ><Icon type="plus" /></Tag>
|
||||
<Modal
|
||||
title="添加接口"
|
||||
visible={this.state.visible}
|
||||
@ -171,11 +186,29 @@ class InterfaceMenu extends Component {
|
||||
<AddInterfaceForm onCancel={this.handleCancel} onSubmit={this.handleAddInterface} />
|
||||
</Modal>
|
||||
</div>
|
||||
<Menu className="interface-list" defaultSelectedKeys={['aaa']} mode="inline" defaultOpenKeys={['aaa']}>
|
||||
<SubMenu key={"aaa"} title={<span onClick={this.handleGroup}><Icon type="appstore" /><span>Navigation Two</span></span>}>
|
||||
{items}
|
||||
</SubMenu>
|
||||
</Menu>
|
||||
{this.props.list.length > 0 ?
|
||||
<Tree
|
||||
className="interface-list"
|
||||
defaultExpandedKeys={['group-' + this.props.list[0]._id]}
|
||||
onSelect={this.onSelect}
|
||||
>
|
||||
<TreeNode title={<Link style={{fontSize: '14px'}} to={"/project/" + matchParams.id + "/interface/api"}><Icon type="folder-open" style={{marginRight: 5}} />全部接口</Link>} key="root" />
|
||||
{this.props.list.map((item) => {
|
||||
return <TreeNode title={<div>
|
||||
<Link className="interface-item" to={"/project/" + matchParams.id + "/interface/api/cat_" + item._id} ><Icon type="folder-open" style={{marginRight: 5}} />{item.name}</Link>
|
||||
<Dropdown overlay={menu}>
|
||||
<Icon type='bars' className="interface-delete-icon" />
|
||||
</Dropdown>
|
||||
</div>} key={'group-' + item._id} >
|
||||
{item.list.map(item_interface_create)}
|
||||
|
||||
</TreeNode>
|
||||
})}
|
||||
|
||||
|
||||
|
||||
</Tree>
|
||||
: null}
|
||||
</div>
|
||||
|
||||
}
|
||||
|
@ -37,6 +37,9 @@
|
||||
background-color: #efefef
|
||||
}
|
||||
.interface-list{
|
||||
a{
|
||||
color: #333
|
||||
}
|
||||
|
||||
.btn-http{
|
||||
height: 23px;
|
||||
@ -49,10 +52,15 @@
|
||||
display: inline
|
||||
}
|
||||
|
||||
.ant-tree-node-content-wrapper{
|
||||
width: 100%
|
||||
}
|
||||
|
||||
.interface-delete-icon{
|
||||
position: absolute;
|
||||
right: 5px;
|
||||
top: 14px;
|
||||
position: relative;
|
||||
right: 31px;
|
||||
top: 6px;
|
||||
float: right
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ export async function fetchInterfaceData(interfaceId) {
|
||||
}
|
||||
|
||||
export async function fetchInterfaceList(projectId) {
|
||||
let result = await axios.get('/api/interface/list?project_id=' + projectId);
|
||||
let result = await axios.get('/api/interface/list_menu?project_id=' + projectId);
|
||||
return {
|
||||
type: FETCH_INTERFACE_LIST,
|
||||
payload: result.data
|
||||
|
@ -24,7 +24,7 @@ app.use(router.allowedMethods());
|
||||
websocket(app);
|
||||
|
||||
app.use( async (ctx, next) => {
|
||||
if( /^\/(?!api)[a-zA-Z0-9\/\-]*$/.test(ctx.path) ){
|
||||
if( /^\/(?!api)[a-zA-Z0-9\/\-_]*$/.test(ctx.path) ){
|
||||
ctx.path = "/"
|
||||
await next()
|
||||
}else{
|
||||
|
@ -1,4 +1,5 @@
|
||||
import interfaceModel from '../models/interface.js';
|
||||
import interfaceCatModel from '../models/interfaceCat.js';
|
||||
import baseController from './base.js';
|
||||
import yapi from '../yapi.js';
|
||||
import userModel from '../models/user.js';
|
||||
@ -7,6 +8,7 @@ class interfaceController extends baseController {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
this.Model = yapi.getInst(interfaceModel);
|
||||
this.catModel = yapi.getInst(interfaceCatModel)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,7 +47,8 @@ class interfaceController extends baseController {
|
||||
title: 'string',
|
||||
path: 'string',
|
||||
method: 'string',
|
||||
desc: 'string'
|
||||
desc: 'string',
|
||||
catid: 'number'
|
||||
});
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase();
|
||||
@ -72,6 +75,7 @@ class interfaceController extends baseController {
|
||||
try {
|
||||
let data = {
|
||||
project_id: params.project_id,
|
||||
catid: params.catid,
|
||||
title: params.title,
|
||||
path: params.path,
|
||||
desc: params.desc,
|
||||
@ -159,6 +163,43 @@ class interfaceController extends baseController {
|
||||
}
|
||||
}
|
||||
|
||||
async listByCat(ctx) {
|
||||
let catid = ctx.request.query.catid;
|
||||
if (!catid) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, 'catid不能为空');
|
||||
}
|
||||
try {
|
||||
let result = await this.Model.listByCatid(catid)
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (err) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, err.message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async listByMenu(ctx) {
|
||||
let project_id = ctx.request.query.project_id;
|
||||
if (!project_id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
try {
|
||||
let result = await this.catModel.list(project_id), newResult = [];
|
||||
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[j] = list[j].toObject()
|
||||
}
|
||||
item.list = list;
|
||||
newResult[i] = item
|
||||
}
|
||||
ctx.body = yapi.commons.resReturn(newResult);
|
||||
} catch (err) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, err.message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑接口
|
||||
* @interface /interface/up
|
||||
@ -193,7 +234,8 @@ class interfaceController extends baseController {
|
||||
title: 'string',
|
||||
path: 'string',
|
||||
method: 'string',
|
||||
desc: 'string'
|
||||
desc: 'string',
|
||||
catid: 'number'
|
||||
});
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase();
|
||||
@ -233,6 +275,10 @@ class interfaceController extends baseController {
|
||||
data.method = params.method;
|
||||
}
|
||||
|
||||
if(params.catid){
|
||||
data.catid = params.catid;
|
||||
}
|
||||
|
||||
if (params.req_headers) {
|
||||
data.req_headers = params.req_headers;
|
||||
}
|
||||
@ -313,29 +359,101 @@ class interfaceController extends baseController {
|
||||
try {
|
||||
let id = parseInt(ctx.query.id, 10), result, userInst, userinfo, data;
|
||||
if (!id) return ctx.websocket.send("id 参数有误");
|
||||
result = await this.Model.get(id), userinfo;
|
||||
if(result.edit_uid !== 0 && result.edit_uid !== this.getUid()){
|
||||
result = await this.Model.get(id), userinfo;
|
||||
if (result.edit_uid !== 0 && result.edit_uid !== this.getUid()) {
|
||||
userInst = yapi.getInst(userModel);
|
||||
userinfo = await userInst.findById(result.edit_uid);
|
||||
data = {
|
||||
errno: result.edit_uid,
|
||||
data: {uid: result.edit_uid, username: userinfo.username}
|
||||
data: { uid: result.edit_uid, username: userinfo.username }
|
||||
}
|
||||
}else{
|
||||
this.Model.upEditUid(id, this.getUid() ).then()
|
||||
} else {
|
||||
this.Model.upEditUid(id, this.getUid()).then()
|
||||
data = {
|
||||
errno: 0,
|
||||
data: result
|
||||
}
|
||||
}
|
||||
ctx.websocket.send(JSON.stringify(data));
|
||||
ctx.websocket.on('close', ()=> {
|
||||
ctx.websocket.send(JSON.stringify(data));
|
||||
ctx.websocket.on('close', () => {
|
||||
this.Model.upEditUid(id, 0).then()
|
||||
})
|
||||
} catch (err) {
|
||||
yapi.commons.log(err, 'error')
|
||||
}
|
||||
}
|
||||
|
||||
async addCat(ctx) {
|
||||
try {
|
||||
let params = ctx.request.body;
|
||||
params = yapi.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
project_id: 'number',
|
||||
desc: 'string'
|
||||
});
|
||||
|
||||
if (!params.project_id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
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,
|
||||
desc: params.desc,
|
||||
uid: this.getUid(),
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
})
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
async upCat(ctx) {
|
||||
try {
|
||||
let params = ctx.request.body;
|
||||
let result = await this.catModel.up(params.catid, {
|
||||
name: params.cat_name,
|
||||
desc: params.cat_desc,
|
||||
up_time: yapi.commons.time()
|
||||
})
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 400, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
async delCat(ctx) {
|
||||
try {
|
||||
let id = ctx.request.body.catid;
|
||||
let catData = await this.catModel.get(id);
|
||||
if (!catData) {
|
||||
ctx.body = yapi.commons.resReturn(null, 400, "不存在的分类")
|
||||
}
|
||||
|
||||
if (catData.uid !== this.getUid()) {
|
||||
let auth = await this.checkAuth(catData.project_id, 'project', 'danger')
|
||||
if (!auth) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
}
|
||||
|
||||
let result = await this.catModel.del(id);
|
||||
await this.Model.delByCatid(id)
|
||||
return ctx.body = yapi.commons.resReturn(result);
|
||||
|
||||
|
||||
} catch (e) {
|
||||
yapi.commons.resReturn(null, 400, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = interfaceController;
|
@ -266,6 +266,7 @@ class interfaceColController extends baseController{
|
||||
}
|
||||
|
||||
let result = await this.colModel.del(caseid);
|
||||
await this.caseModel.delByCol(id)
|
||||
return ctx.body = yapi.commons.resReturn(result);
|
||||
|
||||
|
||||
|
@ -284,6 +284,7 @@ class projectController extends baseController {
|
||||
}
|
||||
try {
|
||||
let result = await this.Model.get(params.id);
|
||||
console.log(result)
|
||||
result = result.toObject();
|
||||
delete result.members;
|
||||
result.role = await this.getProjectRole(params.id, 'project');
|
||||
|
@ -13,6 +13,7 @@ class interfaceModel extends baseModel {
|
||||
path: { type: String, required: true },
|
||||
method: { type: String, required: true },
|
||||
project_id: { type: Number, required: true },
|
||||
catid: {type: Number, required: true},
|
||||
edit_uid: {type: Number, default: 0},
|
||||
status: {type: String, enum: ['undone', 'done'], default: 'undone'},
|
||||
desc: String,
|
||||
@ -99,20 +100,35 @@ class interfaceModel extends baseModel {
|
||||
});
|
||||
}
|
||||
|
||||
list(project_id) {
|
||||
list(project_id, select) {
|
||||
select = select || '_id title uid path method project_id catid edit_uid status desc add_time up_time'
|
||||
return this.model.find({
|
||||
project_id: project_id
|
||||
})
|
||||
.select(select)
|
||||
.sort({ _id: -1 })
|
||||
.exec();
|
||||
}
|
||||
|
||||
listByCatid(catid, select){
|
||||
select = select || '_id title uid path method project_id catid edit_uid status desc add_time up_time'
|
||||
return this.model.find({
|
||||
catid: catid
|
||||
}).select(select).exec();
|
||||
}
|
||||
|
||||
del(id) {
|
||||
return this.model.deleteOne({
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
|
||||
delByCatid(id){
|
||||
return this.model.deleteMany({
|
||||
catid: id
|
||||
})
|
||||
}
|
||||
|
||||
delByProjectId(id){
|
||||
return this.model.deleteMany({
|
||||
project_id: id
|
||||
|
@ -69,6 +69,12 @@ class interfaceCase extends baseModel {
|
||||
})
|
||||
}
|
||||
|
||||
delByCol(id){
|
||||
return this.model.deleteMany({
|
||||
col_id: id
|
||||
})
|
||||
}
|
||||
|
||||
up(id, data) {
|
||||
data.up_time = yapi.commons.time()
|
||||
return this.model.update(
|
||||
|
69
server/models/interfaceCat.js
Normal file
69
server/models/interfaceCat.js
Normal file
@ -0,0 +1,69 @@
|
||||
import yapi from '../yapi.js';
|
||||
import baseModel from './base.js';
|
||||
|
||||
/**
|
||||
* 接口分类
|
||||
*/
|
||||
class interfaceCat extends baseModel {
|
||||
getName() {
|
||||
return 'interface_cat';
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
return {
|
||||
name: { type: String, required: true },
|
||||
uid: { type: Number, required: true },
|
||||
project_id: { type: Number, required: true },
|
||||
desc: String,
|
||||
add_time: Number,
|
||||
up_time: Number
|
||||
};
|
||||
}
|
||||
|
||||
save(data) {
|
||||
let m = new this.model(data);
|
||||
return m.save();
|
||||
}
|
||||
|
||||
get(id) {
|
||||
return this.model.findOne({
|
||||
_id: id
|
||||
}).exec();
|
||||
}
|
||||
|
||||
checkRepeat(name) {
|
||||
return this.model.count({
|
||||
name: name
|
||||
});
|
||||
}
|
||||
|
||||
list(project_id) {
|
||||
return this.model.find({
|
||||
project_id: project_id
|
||||
}).exec();
|
||||
}
|
||||
|
||||
del(id) {
|
||||
return this.model.deleteOne({
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
|
||||
delByProjectId(id){
|
||||
return this.model.deleteMany({
|
||||
project_id: id
|
||||
})
|
||||
}
|
||||
|
||||
up(id, data) {
|
||||
data.up_time = yapi.commons.time()
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
data
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = interfaceCat;
|
@ -244,6 +244,27 @@ const routerConfig = {
|
||||
"action": "del",
|
||||
"path": "del",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
action: 'listByCat',
|
||||
path: 'list_cat',
|
||||
method: 'get'
|
||||
},{
|
||||
action: 'listByMenu',
|
||||
path: 'list_menu',
|
||||
method: 'get'
|
||||
},{
|
||||
action: 'addCat',
|
||||
path: 'add_cat',
|
||||
method: 'post'
|
||||
},{
|
||||
action: 'upCat',
|
||||
path: 'up_cat',
|
||||
method: 'post'
|
||||
},{
|
||||
action: 'delCat',
|
||||
path: 'del_cat',
|
||||
method: 'post'
|
||||
}
|
||||
],
|
||||
"log": [
|
||||
|
@ -70,7 +70,7 @@ app.use(function () {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
if (!/^\/(?!api)[a-zA-Z0-9\/\-]*$/.test(ctx.path)) {
|
||||
if (!/^\/(?!api)[a-zA-Z0-9\/\-_]*$/.test(ctx.path)) {
|
||||
_context.next = 6;
|
||||
break;
|
||||
}
|
||||
|
@ -36,6 +36,10 @@ var _interface = require('../models/interface.js');
|
||||
|
||||
var _interface2 = _interopRequireDefault(_interface);
|
||||
|
||||
var _interfaceCat = require('../models/interfaceCat.js');
|
||||
|
||||
var _interfaceCat2 = _interopRequireDefault(_interfaceCat);
|
||||
|
||||
var _base = require('./base.js');
|
||||
|
||||
var _base2 = _interopRequireDefault(_base);
|
||||
@ -59,6 +63,7 @@ var interfaceController = function (_baseController) {
|
||||
var _this = (0, _possibleConstructorReturn3.default)(this, (interfaceController.__proto__ || (0, _getPrototypeOf2.default)(interfaceController)).call(this, ctx));
|
||||
|
||||
_this.Model = _yapi2.default.getInst(_interface2.default);
|
||||
_this.catModel = _yapi2.default.getInst(_interfaceCat2.default);
|
||||
return _this;
|
||||
}
|
||||
|
||||
@ -109,7 +114,8 @@ var interfaceController = function (_baseController) {
|
||||
title: 'string',
|
||||
path: 'string',
|
||||
method: 'string',
|
||||
desc: 'string'
|
||||
desc: 'string',
|
||||
catid: 'number'
|
||||
});
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase();
|
||||
@ -156,6 +162,7 @@ var interfaceController = function (_baseController) {
|
||||
_context.prev = 16;
|
||||
data = {
|
||||
project_id: params.project_id,
|
||||
catid: params.catid,
|
||||
title: params.title,
|
||||
path: params.path,
|
||||
desc: params.desc,
|
||||
@ -341,6 +348,133 @@ var interfaceController = function (_baseController) {
|
||||
|
||||
return list;
|
||||
}()
|
||||
}, {
|
||||
key: 'listByCat',
|
||||
value: function () {
|
||||
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) {
|
||||
var catid, result;
|
||||
return _regenerator2.default.wrap(function _callee4$(_context4) {
|
||||
while (1) {
|
||||
switch (_context4.prev = _context4.next) {
|
||||
case 0:
|
||||
catid = ctx.request.query.catid;
|
||||
|
||||
if (catid) {
|
||||
_context4.next = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, 'catid不能为空'));
|
||||
|
||||
case 3:
|
||||
_context4.prev = 3;
|
||||
_context4.next = 6;
|
||||
return this.Model.listByCatid(catid);
|
||||
|
||||
case 6:
|
||||
result = _context4.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context4.next = 13;
|
||||
break;
|
||||
|
||||
case 10:
|
||||
_context4.prev = 10;
|
||||
_context4.t0 = _context4['catch'](3);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
|
||||
|
||||
case 13:
|
||||
case 'end':
|
||||
return _context4.stop();
|
||||
}
|
||||
}
|
||||
}, _callee4, this, [[3, 10]]);
|
||||
}));
|
||||
|
||||
function listByCat(_x4) {
|
||||
return _ref4.apply(this, arguments);
|
||||
}
|
||||
|
||||
return listByCat;
|
||||
}()
|
||||
}, {
|
||||
key: 'listByMenu',
|
||||
value: function () {
|
||||
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
|
||||
var project_id, result, newResult, i, item, list, j;
|
||||
return _regenerator2.default.wrap(function _callee5$(_context5) {
|
||||
while (1) {
|
||||
switch (_context5.prev = _context5.next) {
|
||||
case 0:
|
||||
project_id = ctx.request.query.project_id;
|
||||
|
||||
if (project_id) {
|
||||
_context5.next = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
||||
|
||||
case 3:
|
||||
_context5.prev = 3;
|
||||
_context5.next = 6;
|
||||
return this.catModel.list(project_id);
|
||||
|
||||
case 6:
|
||||
result = _context5.sent;
|
||||
newResult = [];
|
||||
i = 0;
|
||||
|
||||
case 9:
|
||||
if (!(i < result.length)) {
|
||||
_context5.next = 20;
|
||||
break;
|
||||
}
|
||||
|
||||
item = result[i].toObject();
|
||||
_context5.next = 13;
|
||||
return this.Model.listByCatid(item._id, '_id title method');
|
||||
|
||||
case 13:
|
||||
list = _context5.sent;
|
||||
|
||||
for (j = 0; j < list.length; j++) {
|
||||
list[j] = list[j].toObject();
|
||||
}
|
||||
item.list = list;
|
||||
newResult[i] = item;
|
||||
|
||||
case 17:
|
||||
i++;
|
||||
_context5.next = 9;
|
||||
break;
|
||||
|
||||
case 20:
|
||||
ctx.body = _yapi2.default.commons.resReturn(newResult);
|
||||
_context5.next = 26;
|
||||
break;
|
||||
|
||||
case 23:
|
||||
_context5.prev = 23;
|
||||
_context5.t0 = _context5['catch'](3);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context5.t0.message);
|
||||
|
||||
case 26:
|
||||
case 'end':
|
||||
return _context5.stop();
|
||||
}
|
||||
}
|
||||
}, _callee5, this, [[3, 23]]);
|
||||
}));
|
||||
|
||||
function listByMenu(_x5) {
|
||||
return _ref5.apply(this, arguments);
|
||||
}
|
||||
|
||||
return listByMenu;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 编辑接口
|
||||
@ -372,11 +506,11 @@ var interfaceController = function (_baseController) {
|
||||
}, {
|
||||
key: 'up',
|
||||
value: function () {
|
||||
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) {
|
||||
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
|
||||
var params, id, interfaceData, checkRepeat, data, result;
|
||||
return _regenerator2.default.wrap(function _callee4$(_context4) {
|
||||
return _regenerator2.default.wrap(function _callee6$(_context6) {
|
||||
while (1) {
|
||||
switch (_context4.prev = _context4.next) {
|
||||
switch (_context6.prev = _context6.next) {
|
||||
case 0:
|
||||
params = ctx.request.body;
|
||||
|
||||
@ -385,7 +519,8 @@ var interfaceController = function (_baseController) {
|
||||
title: 'string',
|
||||
path: 'string',
|
||||
method: 'string',
|
||||
desc: 'string'
|
||||
desc: 'string',
|
||||
catid: 'number'
|
||||
});
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase();
|
||||
@ -393,44 +528,44 @@ var interfaceController = function (_baseController) {
|
||||
id = ctx.request.body.id;
|
||||
|
||||
if (id) {
|
||||
_context4.next = 7;
|
||||
_context6.next = 7;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口id不能为空'));
|
||||
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口id不能为空'));
|
||||
|
||||
case 7:
|
||||
_context4.next = 9;
|
||||
_context6.next = 9;
|
||||
return this.Model.get(id);
|
||||
|
||||
case 9:
|
||||
interfaceData = _context4.sent;
|
||||
interfaceData = _context6.sent;
|
||||
|
||||
if (!(params.path && !_yapi2.default.commons.verifyPath(params.path))) {
|
||||
_context4.next = 12;
|
||||
_context6.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/'));
|
||||
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/'));
|
||||
|
||||
case 12:
|
||||
if (!(params.path && params.path !== interfaceData.path && params.method !== interfaceData.method)) {
|
||||
_context4.next = 18;
|
||||
_context6.next = 18;
|
||||
break;
|
||||
}
|
||||
|
||||
_context4.next = 15;
|
||||
_context6.next = 15;
|
||||
return this.Model.checkRepeat(interfaceData.project_id, params.path, params.method);
|
||||
|
||||
case 15:
|
||||
checkRepeat = _context4.sent;
|
||||
checkRepeat = _context6.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context4.next = 18;
|
||||
_context6.next = 18;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']'));
|
||||
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']'));
|
||||
|
||||
case 18:
|
||||
data = {
|
||||
@ -451,6 +586,10 @@ var interfaceController = function (_baseController) {
|
||||
data.method = params.method;
|
||||
}
|
||||
|
||||
if (params.catid) {
|
||||
data.catid = params.catid;
|
||||
}
|
||||
|
||||
if (params.req_headers) {
|
||||
data.req_headers = params.req_headers;
|
||||
}
|
||||
@ -483,33 +622,33 @@ var interfaceController = function (_baseController) {
|
||||
data.res_body = params.res_body;
|
||||
}
|
||||
|
||||
_context4.prev = 31;
|
||||
_context4.next = 34;
|
||||
_context6.prev = 32;
|
||||
_context6.next = 35;
|
||||
return this.Model.up(id, data);
|
||||
|
||||
case 34:
|
||||
result = _context4.sent;
|
||||
case 35:
|
||||
result = _context6.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context4.next = 41;
|
||||
_context6.next = 42;
|
||||
break;
|
||||
|
||||
case 38:
|
||||
_context4.prev = 38;
|
||||
_context4.t0 = _context4['catch'](31);
|
||||
case 39:
|
||||
_context6.prev = 39;
|
||||
_context6.t0 = _context6['catch'](32);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context6.t0.message);
|
||||
|
||||
case 41:
|
||||
case 42:
|
||||
case 'end':
|
||||
return _context4.stop();
|
||||
return _context6.stop();
|
||||
}
|
||||
}
|
||||
}, _callee4, this, [[31, 38]]);
|
||||
}, _callee6, this, [[32, 39]]);
|
||||
}));
|
||||
|
||||
function up(_x4) {
|
||||
return _ref4.apply(this, arguments);
|
||||
function up(_x6) {
|
||||
return _ref6.apply(this, arguments);
|
||||
}
|
||||
|
||||
return up;
|
||||
@ -529,74 +668,74 @@ var interfaceController = function (_baseController) {
|
||||
}, {
|
||||
key: 'del',
|
||||
value: function () {
|
||||
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
|
||||
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
|
||||
var id, data, result;
|
||||
return _regenerator2.default.wrap(function _callee5$(_context5) {
|
||||
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
||||
while (1) {
|
||||
switch (_context5.prev = _context5.next) {
|
||||
switch (_context7.prev = _context7.next) {
|
||||
case 0:
|
||||
_context5.prev = 0;
|
||||
_context7.prev = 0;
|
||||
id = ctx.request.body.id;
|
||||
|
||||
if (id) {
|
||||
_context5.next = 4;
|
||||
_context7.next = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口id不能为空'));
|
||||
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口id不能为空'));
|
||||
|
||||
case 4:
|
||||
_context5.next = 6;
|
||||
_context7.next = 6;
|
||||
return this.Model.get(ctx.request.body.id);
|
||||
|
||||
case 6:
|
||||
data = _context5.sent;
|
||||
data = _context7.sent;
|
||||
|
||||
if (!(data.uid != this.getUid())) {
|
||||
_context5.next = 13;
|
||||
_context7.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
_context5.next = 10;
|
||||
_context7.next = 10;
|
||||
return this.jungeProjectAuth(data.project_id);
|
||||
|
||||
case 10:
|
||||
_context5.t0 = _context5.sent;
|
||||
_context7.t0 = _context7.sent;
|
||||
|
||||
if (!(_context5.t0 !== true)) {
|
||||
_context5.next = 13;
|
||||
if (!(_context7.t0 !== true)) {
|
||||
_context7.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
||||
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
||||
|
||||
case 13:
|
||||
_context5.next = 15;
|
||||
_context7.next = 15;
|
||||
return this.Model.del(id);
|
||||
|
||||
case 15:
|
||||
result = _context5.sent;
|
||||
result = _context7.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context5.next = 22;
|
||||
_context7.next = 22;
|
||||
break;
|
||||
|
||||
case 19:
|
||||
_context5.prev = 19;
|
||||
_context5.t1 = _context5['catch'](0);
|
||||
_context7.prev = 19;
|
||||
_context7.t1 = _context7['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context5.t1.message);
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context7.t1.message);
|
||||
|
||||
case 22:
|
||||
case 'end':
|
||||
return _context5.stop();
|
||||
return _context7.stop();
|
||||
}
|
||||
}
|
||||
}, _callee5, this, [[0, 19]]);
|
||||
}, _callee7, this, [[0, 19]]);
|
||||
}));
|
||||
|
||||
function del(_x5) {
|
||||
return _ref5.apply(this, arguments);
|
||||
function del(_x7) {
|
||||
return _ref7.apply(this, arguments);
|
||||
}
|
||||
|
||||
return del;
|
||||
@ -604,49 +743,49 @@ var interfaceController = function (_baseController) {
|
||||
}, {
|
||||
key: 'solveConflict',
|
||||
value: function () {
|
||||
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
|
||||
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
|
||||
var _this2 = this;
|
||||
|
||||
var id, result, userInst, userinfo, data;
|
||||
return _regenerator2.default.wrap(function _callee6$(_context6) {
|
||||
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
||||
while (1) {
|
||||
switch (_context6.prev = _context6.next) {
|
||||
switch (_context8.prev = _context8.next) {
|
||||
case 0:
|
||||
_context6.prev = 0;
|
||||
_context8.prev = 0;
|
||||
id = parseInt(ctx.query.id, 10), result = void 0, userInst = void 0, userinfo = void 0, data = void 0;
|
||||
|
||||
if (id) {
|
||||
_context6.next = 4;
|
||||
_context8.next = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context6.abrupt('return', ctx.websocket.send("id 参数有误"));
|
||||
return _context8.abrupt('return', ctx.websocket.send("id 参数有误"));
|
||||
|
||||
case 4:
|
||||
_context6.next = 6;
|
||||
_context8.next = 6;
|
||||
return this.Model.get(id);
|
||||
|
||||
case 6:
|
||||
result = _context6.sent;
|
||||
result = _context8.sent;
|
||||
userinfo;
|
||||
|
||||
if (!(result.edit_uid !== 0 && result.edit_uid !== this.getUid())) {
|
||||
_context6.next = 16;
|
||||
_context8.next = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
userInst = _yapi2.default.getInst(_user2.default);
|
||||
_context6.next = 12;
|
||||
_context8.next = 12;
|
||||
return userInst.findById(result.edit_uid);
|
||||
|
||||
case 12:
|
||||
userinfo = _context6.sent;
|
||||
userinfo = _context8.sent;
|
||||
|
||||
data = {
|
||||
errno: result.edit_uid,
|
||||
data: { uid: result.edit_uid, username: userinfo.username }
|
||||
};
|
||||
_context6.next = 18;
|
||||
_context8.next = 18;
|
||||
break;
|
||||
|
||||
case 16:
|
||||
@ -661,29 +800,217 @@ var interfaceController = function (_baseController) {
|
||||
ctx.websocket.on('close', function () {
|
||||
_this2.Model.upEditUid(id, 0).then();
|
||||
});
|
||||
_context6.next = 25;
|
||||
_context8.next = 25;
|
||||
break;
|
||||
|
||||
case 22:
|
||||
_context6.prev = 22;
|
||||
_context6.t0 = _context6['catch'](0);
|
||||
_context8.prev = 22;
|
||||
_context8.t0 = _context8['catch'](0);
|
||||
|
||||
_yapi2.default.commons.log(_context6.t0, 'error');
|
||||
_yapi2.default.commons.log(_context8.t0, 'error');
|
||||
|
||||
case 25:
|
||||
case 'end':
|
||||
return _context6.stop();
|
||||
return _context8.stop();
|
||||
}
|
||||
}
|
||||
}, _callee6, this, [[0, 22]]);
|
||||
}, _callee8, this, [[0, 22]]);
|
||||
}));
|
||||
|
||||
function solveConflict(_x6) {
|
||||
return _ref6.apply(this, arguments);
|
||||
function solveConflict(_x8) {
|
||||
return _ref8.apply(this, arguments);
|
||||
}
|
||||
|
||||
return solveConflict;
|
||||
}()
|
||||
}, {
|
||||
key: 'addCat',
|
||||
value: function () {
|
||||
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
|
||||
var params, result;
|
||||
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
||||
while (1) {
|
||||
switch (_context9.prev = _context9.next) {
|
||||
case 0:
|
||||
_context9.prev = 0;
|
||||
params = ctx.request.body;
|
||||
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
project_id: 'number',
|
||||
desc: 'string'
|
||||
});
|
||||
|
||||
if (params.project_id) {
|
||||
_context9.next = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
||||
|
||||
case 5:
|
||||
if (params.name) {
|
||||
_context9.next = 7;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '名称不能为空'));
|
||||
|
||||
case 7:
|
||||
_context9.next = 9;
|
||||
return this.catModel.save({
|
||||
name: params.name,
|
||||
project_id: params.project_id,
|
||||
desc: params.desc,
|
||||
uid: this.getUid(),
|
||||
add_time: _yapi2.default.commons.time(),
|
||||
up_time: _yapi2.default.commons.time()
|
||||
});
|
||||
|
||||
case 9:
|
||||
result = _context9.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
|
||||
_context9.next = 16;
|
||||
break;
|
||||
|
||||
case 13:
|
||||
_context9.prev = 13;
|
||||
_context9.t0 = _context9['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context9.t0.message);
|
||||
|
||||
case 16:
|
||||
case 'end':
|
||||
return _context9.stop();
|
||||
}
|
||||
}
|
||||
}, _callee9, this, [[0, 13]]);
|
||||
}));
|
||||
|
||||
function addCat(_x9) {
|
||||
return _ref9.apply(this, arguments);
|
||||
}
|
||||
|
||||
return addCat;
|
||||
}()
|
||||
}, {
|
||||
key: 'upCat',
|
||||
value: function () {
|
||||
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
|
||||
var params, result;
|
||||
return _regenerator2.default.wrap(function _callee10$(_context10) {
|
||||
while (1) {
|
||||
switch (_context10.prev = _context10.next) {
|
||||
case 0:
|
||||
_context10.prev = 0;
|
||||
params = ctx.request.body;
|
||||
_context10.next = 4;
|
||||
return this.catModel.up(params.catid, {
|
||||
name: params.cat_name,
|
||||
desc: params.cat_desc,
|
||||
up_time: _yapi2.default.commons.time()
|
||||
});
|
||||
|
||||
case 4:
|
||||
result = _context10.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context10.next = 11;
|
||||
break;
|
||||
|
||||
case 8:
|
||||
_context10.prev = 8;
|
||||
_context10.t0 = _context10['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, _context10.t0.message);
|
||||
|
||||
case 11:
|
||||
case 'end':
|
||||
return _context10.stop();
|
||||
}
|
||||
}
|
||||
}, _callee10, this, [[0, 8]]);
|
||||
}));
|
||||
|
||||
function upCat(_x10) {
|
||||
return _ref10.apply(this, arguments);
|
||||
}
|
||||
|
||||
return upCat;
|
||||
}()
|
||||
}, {
|
||||
key: 'delCat',
|
||||
value: function () {
|
||||
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee11(ctx) {
|
||||
var id, catData, auth, result;
|
||||
return _regenerator2.default.wrap(function _callee11$(_context11) {
|
||||
while (1) {
|
||||
switch (_context11.prev = _context11.next) {
|
||||
case 0:
|
||||
_context11.prev = 0;
|
||||
id = ctx.request.body.catid;
|
||||
_context11.next = 4;
|
||||
return this.catModel.get(id);
|
||||
|
||||
case 4:
|
||||
catData = _context11.sent;
|
||||
|
||||
if (!catData) {
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, "不存在的分类");
|
||||
}
|
||||
|
||||
if (!(catData.uid !== this.getUid())) {
|
||||
_context11.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
_context11.next = 9;
|
||||
return this.checkAuth(catData.project_id, 'project', 'danger');
|
||||
|
||||
case 9:
|
||||
auth = _context11.sent;
|
||||
|
||||
if (auth) {
|
||||
_context11.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '没有权限'));
|
||||
|
||||
case 12:
|
||||
_context11.next = 14;
|
||||
return this.catModel.del(id);
|
||||
|
||||
case 14:
|
||||
result = _context11.sent;
|
||||
_context11.next = 17;
|
||||
return this.Model.delByCatid(id);
|
||||
|
||||
case 17:
|
||||
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result));
|
||||
|
||||
case 20:
|
||||
_context11.prev = 20;
|
||||
_context11.t0 = _context11['catch'](0);
|
||||
|
||||
_yapi2.default.commons.resReturn(null, 400, _context11.t0.message);
|
||||
|
||||
case 23:
|
||||
case 'end':
|
||||
return _context11.stop();
|
||||
}
|
||||
}
|
||||
}, _callee11, this, [[0, 20]]);
|
||||
}));
|
||||
|
||||
function delCat(_x11) {
|
||||
return _ref11.apply(this, arguments);
|
||||
}
|
||||
|
||||
return delCat;
|
||||
}()
|
||||
}]);
|
||||
return interfaceController;
|
||||
}(_base2.default);
|
||||
|
@ -604,20 +604,24 @@ var interfaceColController = function (_baseController) {
|
||||
|
||||
case 14:
|
||||
result = _context8.sent;
|
||||
_context8.next = 17;
|
||||
return this.caseModel.delByCol(id);
|
||||
|
||||
case 17:
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result));
|
||||
|
||||
case 18:
|
||||
_context8.prev = 18;
|
||||
case 20:
|
||||
_context8.prev = 20;
|
||||
_context8.t0 = _context8['catch'](0);
|
||||
|
||||
_yapi2.default.commons.resReturn(null, 400, _context8.t0.message);
|
||||
|
||||
case 21:
|
||||
case 23:
|
||||
case 'end':
|
||||
return _context8.stop();
|
||||
}
|
||||
}
|
||||
}, _callee8, this, [[0, 18]]);
|
||||
}, _callee8, this, [[0, 20]]);
|
||||
}));
|
||||
|
||||
function delCol(_x8) {
|
||||
|
@ -654,30 +654,31 @@ var projectController = function (_baseController) {
|
||||
case 6:
|
||||
result = _context6.sent;
|
||||
|
||||
console.log(result);
|
||||
result = result.toObject();
|
||||
delete result.members;
|
||||
_context6.next = 11;
|
||||
_context6.next = 12;
|
||||
return this.getProjectRole(params.id, 'project');
|
||||
|
||||
case 11:
|
||||
case 12:
|
||||
result.role = _context6.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context6.next = 18;
|
||||
_context6.next = 19;
|
||||
break;
|
||||
|
||||
case 15:
|
||||
_context6.prev = 15;
|
||||
case 16:
|
||||
_context6.prev = 16;
|
||||
_context6.t0 = _context6['catch'](3);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context6.t0.message);
|
||||
|
||||
case 18:
|
||||
case 19:
|
||||
case 'end':
|
||||
return _context6.stop();
|
||||
}
|
||||
}
|
||||
}, _callee6, this, [[3, 15]]);
|
||||
}, _callee6, this, [[3, 16]]);
|
||||
}));
|
||||
|
||||
function get(_x7) {
|
||||
|
@ -52,6 +52,7 @@ var interfaceModel = function (_baseModel) {
|
||||
path: { type: String, required: true },
|
||||
method: { type: String, required: true },
|
||||
project_id: { type: Number, required: true },
|
||||
catid: { type: Number, required: true },
|
||||
edit_uid: { type: Number, default: 0 },
|
||||
status: { type: String, enum: ['undone', 'done'], default: 'undone' },
|
||||
desc: String,
|
||||
@ -143,10 +144,19 @@ var interfaceModel = function (_baseModel) {
|
||||
}
|
||||
}, {
|
||||
key: 'list',
|
||||
value: function list(project_id) {
|
||||
value: function list(project_id, select) {
|
||||
select = select || '_id title uid path method project_id catid edit_uid status desc add_time up_time';
|
||||
return this.model.find({
|
||||
project_id: project_id
|
||||
}).sort({ _id: -1 }).exec();
|
||||
}).select(select).sort({ _id: -1 }).exec();
|
||||
}
|
||||
}, {
|
||||
key: 'listByCatid',
|
||||
value: function listByCatid(catid, select) {
|
||||
select = select || '_id title uid path method project_id catid edit_uid status desc add_time up_time';
|
||||
return this.model.find({
|
||||
catid: catid
|
||||
}).select(select).exec();
|
||||
}
|
||||
}, {
|
||||
key: 'del',
|
||||
@ -155,6 +165,13 @@ var interfaceModel = function (_baseModel) {
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'delByCatid',
|
||||
value: function delByCatid(id) {
|
||||
return this.model.deleteMany({
|
||||
catid: id
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'delByProjectId',
|
||||
value: function delByProjectId(id) {
|
||||
|
@ -112,6 +112,13 @@ var interfaceCase = function (_baseModel) {
|
||||
project_id: id
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'delByCol',
|
||||
value: function delByCol(id) {
|
||||
return this.model.deleteMany({
|
||||
col_id: id
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'up',
|
||||
value: function up(id, data) {
|
||||
|
114
server_dist/models/interfaceCat.js
Normal file
114
server_dist/models/interfaceCat.js
Normal file
@ -0,0 +1,114 @@
|
||||
'use strict';
|
||||
|
||||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
|
||||
|
||||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
|
||||
|
||||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
||||
|
||||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
||||
|
||||
var _createClass2 = require('babel-runtime/helpers/createClass');
|
||||
|
||||
var _createClass3 = _interopRequireDefault(_createClass2);
|
||||
|
||||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
||||
|
||||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
||||
|
||||
var _inherits2 = require('babel-runtime/helpers/inherits');
|
||||
|
||||
var _inherits3 = _interopRequireDefault(_inherits2);
|
||||
|
||||
var _yapi = require('../yapi.js');
|
||||
|
||||
var _yapi2 = _interopRequireDefault(_yapi);
|
||||
|
||||
var _base = require('./base.js');
|
||||
|
||||
var _base2 = _interopRequireDefault(_base);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* 接口分类
|
||||
*/
|
||||
var interfaceCat = function (_baseModel) {
|
||||
(0, _inherits3.default)(interfaceCat, _baseModel);
|
||||
|
||||
function interfaceCat() {
|
||||
(0, _classCallCheck3.default)(this, interfaceCat);
|
||||
return (0, _possibleConstructorReturn3.default)(this, (interfaceCat.__proto__ || (0, _getPrototypeOf2.default)(interfaceCat)).apply(this, arguments));
|
||||
}
|
||||
|
||||
(0, _createClass3.default)(interfaceCat, [{
|
||||
key: 'getName',
|
||||
value: function getName() {
|
||||
return 'interface_cat';
|
||||
}
|
||||
}, {
|
||||
key: 'getSchema',
|
||||
value: function getSchema() {
|
||||
return {
|
||||
name: { type: String, required: true },
|
||||
uid: { type: Number, required: true },
|
||||
project_id: { type: Number, required: true },
|
||||
desc: String,
|
||||
add_time: Number,
|
||||
up_time: Number
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: 'save',
|
||||
value: function save(data) {
|
||||
var m = new this.model(data);
|
||||
return m.save();
|
||||
}
|
||||
}, {
|
||||
key: 'get',
|
||||
value: function get(id) {
|
||||
return this.model.findOne({
|
||||
_id: id
|
||||
}).exec();
|
||||
}
|
||||
}, {
|
||||
key: 'checkRepeat',
|
||||
value: function checkRepeat(name) {
|
||||
return this.model.count({
|
||||
name: name
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'list',
|
||||
value: function list(project_id) {
|
||||
return this.model.find({
|
||||
project_id: project_id
|
||||
}).exec();
|
||||
}
|
||||
}, {
|
||||
key: 'del',
|
||||
value: function del(id) {
|
||||
return this.model.deleteOne({
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'delByProjectId',
|
||||
value: function delByProjectId(id) {
|
||||
return this.model.deleteMany({
|
||||
project_id: id
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'up',
|
||||
value: function up(id, data) {
|
||||
data.up_time = _yapi2.default.commons.time();
|
||||
return this.model.update({
|
||||
_id: id
|
||||
}, data);
|
||||
}
|
||||
}]);
|
||||
return interfaceCat;
|
||||
}(_base2.default);
|
||||
|
||||
module.exports = interfaceCat;
|
111
server_dist/models/interfaceCol.1.js
Normal file
111
server_dist/models/interfaceCol.1.js
Normal file
@ -0,0 +1,111 @@
|
||||
'use strict';
|
||||
|
||||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
|
||||
|
||||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
|
||||
|
||||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
||||
|
||||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
||||
|
||||
var _createClass2 = require('babel-runtime/helpers/createClass');
|
||||
|
||||
var _createClass3 = _interopRequireDefault(_createClass2);
|
||||
|
||||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
||||
|
||||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
||||
|
||||
var _inherits2 = require('babel-runtime/helpers/inherits');
|
||||
|
||||
var _inherits3 = _interopRequireDefault(_inherits2);
|
||||
|
||||
var _yapi = require('../yapi.js');
|
||||
|
||||
var _yapi2 = _interopRequireDefault(_yapi);
|
||||
|
||||
var _base = require('./base.js');
|
||||
|
||||
var _base2 = _interopRequireDefault(_base);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var interfaceCol = function (_baseModel) {
|
||||
(0, _inherits3.default)(interfaceCol, _baseModel);
|
||||
|
||||
function interfaceCol() {
|
||||
(0, _classCallCheck3.default)(this, interfaceCol);
|
||||
return (0, _possibleConstructorReturn3.default)(this, (interfaceCol.__proto__ || (0, _getPrototypeOf2.default)(interfaceCol)).apply(this, arguments));
|
||||
}
|
||||
|
||||
(0, _createClass3.default)(interfaceCol, [{
|
||||
key: 'getName',
|
||||
value: function getName() {
|
||||
return 'interface_col';
|
||||
}
|
||||
}, {
|
||||
key: 'getSchema',
|
||||
value: function getSchema() {
|
||||
return {
|
||||
name: { type: String, required: true },
|
||||
uid: { type: Number, required: true },
|
||||
project_id: { type: Number, required: true },
|
||||
desc: String,
|
||||
add_time: Number,
|
||||
up_time: Number
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: 'save',
|
||||
value: function save(data) {
|
||||
var m = new this.model(data);
|
||||
return m.save();
|
||||
}
|
||||
}, {
|
||||
key: 'get',
|
||||
value: function get(id) {
|
||||
return this.model.findOne({
|
||||
_id: id
|
||||
}).exec();
|
||||
}
|
||||
}, {
|
||||
key: 'checkRepeat',
|
||||
value: function checkRepeat(name) {
|
||||
return this.model.count({
|
||||
name: name
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'list',
|
||||
value: function list(project_id) {
|
||||
return this.model.find({
|
||||
project_id: project_id
|
||||
}).exec();
|
||||
}
|
||||
}, {
|
||||
key: 'del',
|
||||
value: function del(id) {
|
||||
return this.model.deleteOne({
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'delByProjectId',
|
||||
value: function delByProjectId(id) {
|
||||
return this.model.deleteMany({
|
||||
project_id: id
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'up',
|
||||
value: function up(id, data) {
|
||||
data.up_time = _yapi2.default.commons.time();
|
||||
return this.model.update({
|
||||
_id: id
|
||||
}, data);
|
||||
}
|
||||
}]);
|
||||
return interfaceCol;
|
||||
}(_base2.default);
|
||||
|
||||
module.exports = interfaceCol;
|
@ -243,6 +243,26 @@ var routerConfig = {
|
||||
"action": "del",
|
||||
"path": "del",
|
||||
"method": "post"
|
||||
}, {
|
||||
action: 'listByCat',
|
||||
path: 'list_cat',
|
||||
method: 'get'
|
||||
}, {
|
||||
action: 'listByMenu',
|
||||
path: 'list_menu',
|
||||
method: 'get'
|
||||
}, {
|
||||
action: 'addCat',
|
||||
path: 'add_cat',
|
||||
method: 'post'
|
||||
}, {
|
||||
action: 'upCat',
|
||||
path: 'up_cat',
|
||||
method: 'post'
|
||||
}, {
|
||||
action: 'delCat',
|
||||
path: 'del_cat',
|
||||
method: 'post'
|
||||
}],
|
||||
"log": [{
|
||||
"action": "list",
|
||||
|
Loading…
Reference in New Issue
Block a user