Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev

This commit is contained in:
wenbo.dong 2017-07-20 21:37:00 +08:00
commit b6524a6ced
27 changed files with 681 additions and 865 deletions

View File

@ -1,22 +1,28 @@
import React, { Component } from 'react'
import axios from 'axios';
import { Route, HashRouter, Redirect } from 'react-router-dom'
import { Header, Home, ProjectGroups, Interface, News, AddInterface } from './containers/index'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'
import { Route, HashRouter, Redirect, Switch } from 'react-router-dom'
import { Home, ProjectGroups, Interface, News, AddInterface } from './containers/index'
import User from './containers/User/User.js'
import Header from './components/Header/Header'
import { checkLoginState } from './actions/login'
const LOADING_STATUS = 0;
const GUEST_STATUS = 1;
const MEMBER_STATUS = 2;
class App extends Component {
constructor(props) {
super(props)
super(props);
this.state = {
login: LOADING_STATUS
}
}
static propTypes = {
checkLoginState:PropTypes.func
}
route = (status) => {
let r;
if (status === LOADING_STATUS) {
@ -24,14 +30,15 @@ class App extends Component {
} else if (status === GUEST_STATUS) {
r = (
<HashRouter>
<div className="router-main">
<Header />
<Route path="/" component={Home} exact />
<Redirect to="/" />
<Switch>
<Route
path="/"
component={Home}/>
<Redirect from="(/:str)" to="/" />
</Switch>
</div>
</HashRouter>
)
} else {
@ -39,14 +46,13 @@ class App extends Component {
<HashRouter>
<div className="router-main">
<Header />
<Route path="/" component={ProjectGroups} exact />
<Route path="/" component={Home} exact />
<Route path="/ProjectGroups" component={ProjectGroups} />
<Route path="/Interface" component={Interface} />
<Route path="/user" component={User} />
<Route path="/News" component={News} />
<Route path="/AddInterface" component={ AddInterface } />
</div>
</HashRouter>
)
}
@ -55,9 +61,9 @@ class App extends Component {
}
componentDidMount() {
console.log('app.js init')
axios.get('/user/status').then((res) => {
if (res.data.errcode === 0 && res.data.data._id > 0) {
this.props.checkLoginState().then((res) => {
console.log(res);
if (res.payload.data.errcode === 0 && res.payload.data.data._id > 0) {
this.setState({
login: MEMBER_STATUS
})
@ -66,22 +72,26 @@ class App extends Component {
login: GUEST_STATUS
})
}
}, (err) => {
}).catch((err) => {
this.setState({
login: GUEST_STATUS
})
console.log(err.message)
})
});
console.log(err)
});
}
render() {
console.log(MEMBER_STATUS)
console.log(this.route(this.state.login))
return this.route(this.state.login)
}
}
export default App
export default connect(
state => {
return{
login:state.login.isLogin
}
},
{
checkLoginState
}
)(App)

View File

@ -5,6 +5,7 @@ import Interface from './reducer/Interface/InterfaceReducer.js'
import news from './reducer/news/news.js'
import addInterface from './reducer/addInterface/addInterface.js'
import user from './reducer/user/user.js'
import menu from './reducer/menu/menu.js'
export default {
group,
@ -13,5 +14,6 @@ export default {
user,
project,
news,
addInterface
addInterface,
menu
}

View File

@ -24,6 +24,7 @@ const loginActions = (data) => {
data: res
}
});
location.reload();
} else {
console.log('登录失败,errcode不为0');
}
@ -57,6 +58,7 @@ const logoutActions = () => {
dispatch({
type: LOGIN_OUT
})
location.reload();
}
}).catch((err) => {
console.log(err);

10
client/actions/menu.js Normal file
View File

@ -0,0 +1,10 @@
import {
CHANGE_MENU_ITEM
} from '../constants/action-types.js'
export function changeMenuItem(curKey) {
return {
type: CHANGE_MENU_ITEM,
data: curKey
}
}

View File

@ -1,22 +1,28 @@
import React, { Component } from 'react'
import axios from 'axios';
import { Route, HashRouter, Redirect } from 'react-router-dom'
import { Header, Home, ProjectGroups, Interface, News, AddInterface } from './containers/index'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'
import { Route, HashRouter, Redirect, Switch } from 'react-router-dom'
import { Home, ProjectGroups, Interface, News, AddInterface } from './containers/index'
import User from './containers/User/User.js'
import Header from './components/Header/Header'
import { checkLoginState } from './actions/login'
const LOADING_STATUS = 0;
const GUEST_STATUS = 1;
const MEMBER_STATUS = 2;
class App extends Component {
constructor(props) {
super(props)
super(props);
this.state = {
login: LOADING_STATUS
}
}
static propTypes = {
checkLoginState:PropTypes.func
}
route = (status) => {
let r;
if (status === LOADING_STATUS) {
@ -24,14 +30,15 @@ class App extends Component {
} else if (status === GUEST_STATUS) {
r = (
<HashRouter>
<div className="router-main">
<Header />
<Route path="/" component={Home} exact />
<Redirect to="/" />
<Switch>
<Route
path="/"
component={Home}/>
<Redirect from="(/:str)" to="/" />
</Switch>
</div>
</HashRouter>
)
} else {
@ -39,14 +46,13 @@ class App extends Component {
<HashRouter>
<div className="router-main">
<Header />
<Route path="/" component={ProjectGroups} exact />
<Route path="/" component={Home} exact />
<Route path="/ProjectGroups" component={ProjectGroups} />
<Route path="/Interface" component={Interface} />
<Route path="/user" component={User} />
<Route path="/News" component={News} />
<Route path="/AddInterface" component={ AddInterface } />
</div>
</HashRouter>
)
}
@ -55,9 +61,9 @@ class App extends Component {
}
componentDidMount() {
console.log('app.js init')
axios.get('/user/status').then((res) => {
if (res.data.errcode === 0 && res.data.data._id > 0) {
this.props.checkLoginState().then((res) => {
console.log(res);
if (res.payload.data.errcode === 0 && res.payload.data.data._id > 0) {
this.setState({
login: MEMBER_STATUS
})
@ -66,22 +72,26 @@ class App extends Component {
login: GUEST_STATUS
})
}
}, (err) => {
}).catch((err) => {
this.setState({
login: GUEST_STATUS
})
console.log(err.message)
})
});
console.log(err)
});
}
render() {
console.log(MEMBER_STATUS)
console.log(this.route(this.state.login))
return this.route(this.state.login)
}
}
export default App
export default connect(
state => {
return{
login:state.login.isLogin
}
},
{
checkLoginState
}
)(App)

View File

@ -11,7 +11,6 @@ class Footer extends Component {
footList: PropTypes.array
}
render () {
console.log(this.props);
return (
<div className = 'footer'>
<div className = 'footContent'>

View File

@ -3,62 +3,107 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { Link } from 'react-router-dom'
import { Icon, Layout, Menu} from 'antd'
import { Icon, Layout, Menu, Dropdown } from 'antd'
import { checkLoginState, logoutActions, loginTypeAction} from '../../actions/login'
import { changeMenuItem } from '../../actions/menu'
import { withRouter } from 'react-router';
import Srch from './Search/Search'
const { Header } = Layout;
const MenuUser = (props) => (
<Menu>
<Menu.Item key="0">
<Link to={`/profile/${props.uid}`} onClick={props.relieveLink}><Icon type="user" />{ props.user }</Link>
</Menu.Item>
<Menu.Item key="1">
<Link to="/news" onClick={props.relieveLink}><Icon type="mail" />{ props.msg }</Link>
</Menu.Item>
<Menu.Item key="2">
<a onClick={props.logout}>退出</a>
</Menu.Item>
</Menu>
);
MenuUser.propTypes={
user:PropTypes.string,
msg:PropTypes.string,
uid: PropTypes.number,
relieveLink:PropTypes.func,
logout:PropTypes.func
}
const ToolUser = (props)=> (
<ul>
<li><Link to="/user" onClick={props.relieveLink}><Icon type="user" />{ props.user }</Link></li>
<li><Link to="/News" onClick={props.relieveLink}><Icon type="mail" />{ props.msg }</Link></li>
<li onClick={props.logout}>退出</li>
<li className="toolbar-li">
<Srch groupList={props.groupList}/>
</li>
<li className="toolbar-li">
<Dropdown overlay={
<MenuUser
user={props.user}
msg={props.msg}
uid={props.uid}
relieveLink={props.relieveLink}
logout={props.logout}
/>
}>
<a className="dropdown-link">
<Icon type="user"/>
</a>
</Dropdown>
</li>
</ul>
);
ToolUser.propTypes={
user:PropTypes.string,
msg:PropTypes.string,
uid: PropTypes.number,
relieveLink:PropTypes.func,
logout:PropTypes.func
logout:PropTypes.func,
groupList: PropTypes.array
};
@withRouter
class HeaderCom extends Component {
constructor(props) {
super(props);
this.state = {
current : window.location.hash.split("#")[1]
}
}
static propTypes ={
router: PropTypes.object,
user: PropTypes.string,
msg: PropTypes.string,
uid: PropTypes.number,
login:PropTypes.bool,
curKey:PropTypes.string,
relieveLink:PropTypes.func,
logoutActions:PropTypes.func,
checkLoginState:PropTypes.func,
loginTypeAction:PropTypes.func,
changeMenuItem:PropTypes.func,
history: PropTypes.object,
location: PropTypes.object
}
componentDidMount() {
const { router } = this.props;
console.log(router);
}
linkTo = (e) =>{
this.setState({
current : e.key
})
this.props.changeMenuItem(e.key);
// this.props.curKey = e.key;
// this.setState({
// current : e.key
// })
}
relieveLink = () => {
this.setState({
current : ""
})
this.props.changeMenuItem("");
// this.setState({
// current : ""
// })
}
logout = (e) => {
e.preventDefault();
this.props.logoutActions();
this.props.history.push('/');
this.props.changeMenuItem("/");
// this.setState({
// current : "/"
// })
}
handleLogin = (e) => {
e.preventDefault();
@ -78,8 +123,8 @@ class HeaderCom extends Component {
})
}
render () {
this.checkLoginState();
const { login, user, msg } = this.props;
const { login, user, msg, uid, curKey } = this.props;
console.log(curKey);
return (
<acticle className="header-box">
<Layout className="'layout">
@ -94,7 +139,7 @@ class HeaderCom extends Component {
theme="dark"
style={{ lineHeight : '.64rem'}}
onClick={this.linkTo}
selectedKeys={[this.state.current]}
selectedKeys={[curKey]}
>
<Menu.Item key="/">
<Link to="/">首页</Link>
@ -110,7 +155,15 @@ class HeaderCom extends Component {
</Menu.Item>
</Menu>
<div className="user-toolbar">
{login?<ToolUser user={user} msg={msg} relieveLink={this.relieveLink} logout={this.logout}/>:""}
{login?
<ToolUser
user = { user }
msg = { msg }
uid = { uid }
relieveLink = { this.relieveLink }
logout = { this.logout }
/>
:""}
</div>
</div>
</Header>
@ -124,13 +177,16 @@ export default connect(
(state) => {
return{
user: state.login.userName,
uid: state.login.uid,
msg: null,
login:state.login.isLogin
login:state.login.isLogin,
curKey: state.menu.curKey
}
},
{
loginTypeAction,
logoutActions,
checkLoginState
checkLoginState,
changeMenuItem
}
)(HeaderCom)

View File

@ -42,17 +42,20 @@ $color-black-light : #404040;
.user-toolbar{
float: right;
line-height: .14rem;
li{
height: .64rem;
display: flex;
align-items: center;
.toolbar-li{
&:first-child{
width: 2rem;
}
float: left;
margin: .26rem 0;
padding: 0 0 0 .12rem;
margin: 0 0 0 .12rem;
font-size: .14rem;
cursor: pointer;
color: $color-white;
&:not(:last-child){
border-right: .01rem solid $color-white;
padding: 0 .12rem;
margin: 0 .12rem;
}
&:hover{
color: $color-blue;
@ -72,6 +75,11 @@ $color-black-light : #404040;
i{
margin-right: .03rem;
}
.dropdown-link{
i{
font-size: .2rem;
}
}
}
}
}

View File

@ -0,0 +1,95 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { Icon, Input, AutoComplete } from 'antd'
import './Search.scss'
import { withRouter } from 'react-router';
import axios from 'axios';
@connect(
state => ({
groupList: state.group.groupList,
projectList: state.project.projectList
})
)
@withRouter
export default class Srch extends Component{
constructor(props){
super(props);
this.state = {
dataSource:[]
};
}
static propTypes = {
groupList : PropTypes.array,
projectList: PropTypes.array,
router: PropTypes.object,
history: PropTypes.object,
location: PropTypes.object
}
onSelect = (value) => {
if( value.split(":")[0] == "group" ){
this.props.history.push('/group/'+value.split(":")[1].trim());
} else {
this.props.history.push('/project/'+value.split("(")[1].slice(0,-1));
}
}
handleSearch = (value) => {
axios.get('/project/search?q='+value)
.then((res) => {
if(res.data && res.data.errcode === 0){
const dataSource = [];
for(let title in res.data.data){
res.data.data[title].map(item => {
title == "group" ? dataSource.push( title+": "+item.groupName ): dataSource.push( title+": "+item.name+"("+item._id+")" );
})
}
this.setState({
dataSource: dataSource
});
}else{
console.log("查询项目或分组失败");
}
})
.catch((err) => {
console.log(err);
})
}
getDataSource(groupList){
const groupArr =[];
groupList.forEach(item =>{
groupArr.push("group: "+ item["group_name"]);
})
return groupArr;
}
render(){
const { dataSource } = this.state;
return(
<div className="search-wrapper">
<AutoComplete
className="search-dropdown"
dataSource={dataSource}
size="large"
style={{ width: '100%' }}
defaultActiveFirstOption= {false}
onSelect={this.onSelect}
onSearch={this.handleSearch}
filterOption={(inputValue, option) => option.props.children.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1}
>
<Input
prefix={<Icon type="search" className="srch-icon" />}
size="large" style={{ width: 200 }}
placeholder="search group/project"
className="search-input"
/>
</AutoComplete>
</div>
)
}
}

View File

@ -0,0 +1,11 @@
$color-grey:#979DA7;
.search-wrapper{
.search-input{
border:1px solid #AAA;
background-color: rgba(255,255,255,0.5);
}
.srch-icon{
color: $color-grey;
}
}

View File

@ -36,6 +36,7 @@ export const REGISTER = 'REGISTER'; // 注册
//header
export const LOGIN_TYPE = 'LOGIN_TYPE';
export const LOGIN_OUT = 'LOGIN_OUT';
export const CHANGE_MENU_ITEM = 'CHANGE_MENU_ITEM';
// News
export const FETCH_NEWS_DATA = 'FETCH_NEWS_DATA';

View File

@ -7,6 +7,7 @@ import PropTypes from "prop-types"
import Login from '../Login/LoginWrap'
import Intro from '../../components/Intro/Intro'
import Footer from "../../components/Footer/Footer";
import { changeMenuItem } from '../../actions/menu'
const HomeGuest = (props) => (
<div>
@ -50,7 +51,10 @@ HomeGuest.propTypes ={
@connect(
state => ({
login: state.login.isLogin
})
}),
{
changeMenuItem
}
)
class Home extends Component {
@ -59,7 +63,11 @@ class Home extends Component {
}
static propTypes = {
introList: PropTypes.array,
login : PropTypes.bool
login : PropTypes.bool,
changeMenuItem : PropTypes.func
}
toStart = () =>{
this.props.changeMenuItem('/ProjectGroups');
}
render () {
const { login } = this.props;

View File

@ -8,12 +8,11 @@ $color-black-lighter: #404040;
.home-main {
height:calc(100% - .64rem);
display: -webkit-box;
margin-top: .64rem;
-webkit-box-orient: vertical;
background: $color-grey-lighter;
.main-one{
height:calc(100% - .64rem);
padding: .5rem .5rem 0 .5rem;
//background: radial-gradient(ellipse at center,#45484d 0%,#000 100%);
.home-des{
@ -44,8 +43,11 @@ $color-black-lighter: #404040;
}
}
.user-home{
height:calc(100% - .64rem);
padding: .5rem .5rem 0 .5rem;
display: flex;
align-items: center;
height:calc(100% - 2rem);
max-width: 11rem;
margin: 0 auto;
.user-des{
max-width: 11rem;
margin: 0 auto .5rem;

View File

@ -1,4 +1,4 @@
.g-doc {
max-width: 11rem;
margin: .88rem auto .24rem;
margin: .24rem auto;
}

View File

@ -3,7 +3,7 @@ import 'babel-polyfill'
import thunkMiddleware from 'redux-thunk'
import promiseMiddleware from 'redux-promise';
import ReactDOM from 'react-dom'
import App from './app'
import App from './App'
import { createStore, combineReducers, applyMiddleware } from 'redux'
import { Provider } from 'react-redux'
import ReduxContainer from './ReduxContainer.js'

View File

@ -25,6 +25,7 @@ export default (state = initialState, action) => {
return {
...state,
isLogin: true,
uid: action.payload.data.uid,
userName: action.payload.data.userName
};
}

View File

@ -25,6 +25,7 @@ export default (state = initialState, action) => {
return {
...state,
isLogin: true,
uid: action.payload.data.uid,
userName: action.payload.data.userName
};
}

View File

@ -0,0 +1,21 @@
import {
CHANGE_MENU_ITEM
} from '../../constants/action-types.js'
const initialState = {
curKey: window.location.hash.split("#")[1]
}
export default (state = initialState, action) => {
switch (action.type) {
case CHANGE_MENU_ITEM: {
return {
...state,
curKey: action.data
};
}
default:
return state;
}
}

49
server/controllers/log.js Normal file
View File

@ -0,0 +1,49 @@
import logModel from '../models/log.js';
import yapi from '../yapi.js';
import baseController from './base.js';
import groupModel from '../models/group';
class logController extends baseController {
constructor(ctx) {
super(ctx);
this.Model = yapi.getInst(logModel);
this.groupModel = yapi.getInst(groupModel);
}
/**
* 获取节点列表
* @interface /node/list
* @method GET
* @category node
* @foldnumber 10
* @param {Number} uid 用户id 不能为空
* @param {Number} [page] 分页页码
* @param {Number} [limit] 分页大小
* @returns {Object}
* @example ./api/project/list.json
*/
async list(ctx) {
let uid = ctx.request.query.uid,
page = ctx.request.query.page || 1,
limit = ctx.request.query.limit || 10;
if(!uid){
return ctx.body = yapi.commons.resReturn(null, 400, '用户id不能为空');
}
try {
let result = await this.Model.listWithPaging(uid, page, limit);
let count = await this.Model.listCount(uid);
ctx.body = yapi.commons.resReturn({
total: Math.ceil(count / limit),
list: result
})
} catch(err) {
ctx.body = yapi.commons.resReturn(null, 402, e.message)
}
}
}
module.exports = logController;

View File

@ -1,181 +0,0 @@
import nodeModel from '../models/node.js'
import yapi from '../yapi.js'
import baseController from './base.js'
import interfaceModel from '../models/interface.js'
import groupModel from '../models/group'
import commons from '../utils/commons.js'
class nodeController extends baseController {
constructor(ctx) {
super(ctx);
this.Model = yapi.getInst(nodeModel);
this.groupModel = yapi.getInst(groupModel);
}
/**
* 添加记录节点
* @interface /node/add
* @method POST
* @category node
* @foldnumber 10
* @param {String} title 节点名称不能为空
* @param {String} content 节点内容不能为空
* @returns {Object}
* @example ./api/node/add.json
*/
async add(ctx) {
let params = ctx.request.body;
if(!params.title) {
return ctx.body = yapi.commons.resReturn(null, 400, 'title不能为空');
}
if(!params.content) {
return ctx.body = yapi.commons.resReturn(null, 400, 'content不能为空');
}
let data = {
title: params.title,
content: params.content,
is_read: false,
uid: this.getUid(),
add_time: yapi.commons.time()
};
try {
let result = await this.Model.save(data);
ctx.body = yapi.commons.resReturn(result);
} catch(e) {
ctx.body = yapi.commons.resReturn(null, 402, e.message)
}
}
/**
* 获取节点
* @interface /node/get
* @method GET
* @category node
* @foldnumber 10
* @param {Number} id 节点id不能为空
* @returns {Object}
* @example ./api/node/get.json
*/
async get(ctx){
let params = ctx.request.query;
if(!params.id){
return ctx.body = yapi.commons.resReturn(null, 400, '节点id不能为空');
}
try {
let result = await this.Model.get(params.id);
ctx.body = yapi.commons.resReturn(result);
} catch(e){
ctx.body = yapi.commons.resReturn(null, 402, e.message)
}
}
/**
* 获取节点列表
* @interface /node/list
* @method GET
* @category node
* @foldnumber 10
* @param {Number} uid 用户id 不能为空
* @param {Number} [page] 分页页码
* @param {Number} [limit] 分页大小
* @returns {Object}
* @example ./api/project/list.json
*/
async list(ctx) {
let uid = ctx.request.query.uid,
page = ctx.request.query.page || 1,
limit = ctx.request.query.limit || 10;
if(!uid){
return ctx.body = yapi.commons.resReturn(null, 400, '用户id不能为空');
}
try {
let result = await this.Model.listWithPaging(uid, page, limit);
let count = await this.Model.listCount(uid);
ctx.body = yapi.commons.resReturn({
total: Math.ceil(count / limit),
list: result
})
} catch(err) {
ctx.body = yapi.commons.resReturn(null, 402, e.message)
}
}
/**
* 删除节点
* @interface /node/del
* @method POST
* @category node
* @foldnumber 10
* @param {Number} id 节点id不能为空
* @returns {Object}
* @example ./api/project/del.json
*/
async del(ctx){
try{
let id = ctx.request.body.id;
if(!id){
return ctx.body = yapi.commons.resReturn(null, 400, '节点id不能为空');
}
let result = await this.Model.del(id);
ctx.body = yapi.commons.resReturn(result);
}catch(err){
ctx.body = yapi.commons.resReturn(null, 402, e.message)
}
}
/**
* 编辑节点
* @interface /node/up
* @method POST
* @category node
* @foldnumber 10
* @param {Number} id 节点id不能为空
* @param {String} [title]
* @param {String} [content] 节点描述
* @param {Boolean} [is_read] 是否阅读
* @returns {Object}
* @example ./api/node/up.json
*/
async up(ctx){
try{
let id = ctx.request.body.id;
let params = ctx.request.body;
if(await this.jungeMemberAuth(id, this.getUid()) !== true){
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
if(!id){
return ctx.body = yapi.commons.resReturn(null, 402, '节点id不能为空');
}
let data= {
uid: this.getUid(),
up_time: yapi.commons.time()
};
if(params.title) data.title = params.title;
if(params.content) data.content = params.content;
if(params.is_read) data.is_read = params.is_read;
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)
}
}
}
module.exports = nodeController;

View File

@ -1,30 +1,36 @@
import yapi from '../yapi.js';
import baseModel from './base.js';
import userModel from '../models/user.js';
class nodeModel extends baseModel {
class logModel extends baseModel {
getName() {
return 'node';
return 'log';
}
getSchema() {
return {
uid: {type: Number, required: true},
title: {type: String, required: true},
type: {type: String, enum:['user', 'group', 'interface', 'project', 'other'], required: true},
content: {type: String, required: true},
is_read: {type: Boolean, required: true},
username: {type: String, required: true},
add_time: Number
}
}
save(data) {
let node = new this.model(data);
return node.save();
}
get(id){
return this.model.findOne({
_id: id
}).exec()
async save(data) {
let userInst = yapi.getInst(userModel);
let username = await userInst.findById(data.uid);
let saveData = {
title: data.title,
content: data.content,
type: data.type,
uid: data.uid,
username: username,
add_time: yapi.commons.time()
};
let log = new this.model(saveData);
return log.save();
}
list (uid){
@ -46,18 +52,6 @@ class nodeModel extends baseModel {
uid: uid
});
}
del(id){
return this.model.deleteOne({
_id: id
})
}
up(id, data){
data.up_time = yapi.commons.time();
return this.model.update({
_id: id,
}, data, { runValidators: true })
}
}
module.exports = nodeModel;
module.exports = logModel;

View File

@ -5,7 +5,7 @@ import userController from './controllers/user.js'
import yapi from './yapi.js'
import projectController from './controllers/project.js'
import nodeController from './controllers/node.js'
import logController from './controllers/log.js'
const router = koaRouter();
@ -27,9 +27,9 @@ const INTERFACE_CONFIG = {
prefix: '/project/',
controller: projectController
},
node: {
prefix: '/node/',
controller: nodeController
log: {
prefix: '/log/',
controller: logController
}
};
@ -72,11 +72,7 @@ createAction('interface', 'up', 'post', 'up')
createAction('interface', 'del', 'post', 'del')
//node
createAction('node', 'add', 'post', 'add');
createAction('node', 'get', 'get', 'get');
createAction('node', 'list', 'get', 'list');
createAction('node', 'del', 'post', 'del');
createAction('node', 'up', 'post', 'up');
createAction('log', 'list', 'get', 'list');
/**

View File

@ -0,0 +1,137 @@
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
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 _log = require('../models/log.js');
var _log2 = _interopRequireDefault(_log);
var _yapi = require('../yapi.js');
var _yapi2 = _interopRequireDefault(_yapi);
var _base = require('./base.js');
var _base2 = _interopRequireDefault(_base);
var _group = require('../models/group');
var _group2 = _interopRequireDefault(_group);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var logController = function (_baseController) {
(0, _inherits3.default)(logController, _baseController);
function logController(ctx) {
(0, _classCallCheck3.default)(this, logController);
var _this = (0, _possibleConstructorReturn3.default)(this, (logController.__proto__ || (0, _getPrototypeOf2.default)(logController)).call(this, ctx));
_this.Model = _yapi2.default.getInst(_log2.default);
_this.groupModel = _yapi2.default.getInst(_group2.default);
return _this;
}
/**
* 获取节点列表
* @interface /node/list
* @method GET
* @category node
* @foldnumber 10
* @param {Number} uid 用户id 不能为空
* @param {Number} [page] 分页页码
* @param {Number} [limit] 分页大小
* @returns {Object}
* @example ./api/project/list.json
*/
(0, _createClass3.default)(logController, [{
key: 'list',
value: function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
var uid, page, limit, result, count;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
uid = ctx.request.query.uid, page = ctx.request.query.page || 1, limit = ctx.request.query.limit || 10;
if (uid) {
_context.next = 3;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '用户id不能为空'));
case 3:
_context.prev = 3;
_context.next = 6;
return this.Model.listWithPaging(uid, page, limit);
case 6:
result = _context.sent;
_context.next = 9;
return this.Model.listCount(uid);
case 9:
count = _context.sent;
ctx.body = _yapi2.default.commons.resReturn({
total: Math.ceil(count / limit),
list: result
});
_context.next = 16;
break;
case 13:
_context.prev = 13;
_context.t0 = _context['catch'](3);
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
case 16:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[3, 13]]);
}));
function list(_x) {
return _ref.apply(this, arguments);
}
return list;
}()
}]);
return logController;
}(_base2.default);
module.exports = logController;

View File

@ -1,437 +0,0 @@
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
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 _node = require('../models/node.js');
var _node2 = _interopRequireDefault(_node);
var _yapi = require('../yapi.js');
var _yapi2 = _interopRequireDefault(_yapi);
var _base = require('./base.js');
var _base2 = _interopRequireDefault(_base);
var _interface = require('../models/interface.js');
var _interface2 = _interopRequireDefault(_interface);
var _group = require('../models/group');
var _group2 = _interopRequireDefault(_group);
var _commons = require('../utils/commons.js');
var _commons2 = _interopRequireDefault(_commons);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var nodeController = function (_baseController) {
(0, _inherits3.default)(nodeController, _baseController);
function nodeController(ctx) {
(0, _classCallCheck3.default)(this, nodeController);
var _this = (0, _possibleConstructorReturn3.default)(this, (nodeController.__proto__ || (0, _getPrototypeOf2.default)(nodeController)).call(this, ctx));
_this.Model = _yapi2.default.getInst(_node2.default);
_this.groupModel = _yapi2.default.getInst(_group2.default);
return _this;
}
/**
* 添加记录节点
* @interface /node/add
* @method POST
* @category node
* @foldnumber 10
* @param {String} title 节点名称不能为空
* @param {String} content 节点内容不能为空
* @returns {Object}
* @example ./api/node/add.json
*/
(0, _createClass3.default)(nodeController, [{
key: 'add',
value: function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
var params, data, result;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
params = ctx.request.body;
if (params.title) {
_context.next = 3;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, 'title不能为空'));
case 3:
if (params.content) {
_context.next = 5;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, 'content不能为空'));
case 5:
data = {
title: params.title,
content: params.content,
is_read: false,
uid: this.getUid(),
add_time: _yapi2.default.commons.time()
};
_context.prev = 6;
_context.next = 9;
return this.Model.save(data);
case 9:
result = _context.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context.next = 16;
break;
case 13:
_context.prev = 13;
_context.t0 = _context['catch'](6);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
case 16:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[6, 13]]);
}));
function add(_x) {
return _ref.apply(this, arguments);
}
return add;
}()
/**
* 获取节点
* @interface /node/get
* @method GET
* @category node
* @foldnumber 10
* @param {Number} id 节点id不能为空
* @returns {Object}
* @example ./api/node/get.json
*/
}, {
key: 'get',
value: function () {
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(ctx) {
var params, result;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
params = ctx.request.query;
if (params.id) {
_context2.next = 3;
break;
}
return _context2.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '节点id不能为空'));
case 3:
_context2.prev = 3;
_context2.next = 6;
return this.Model.get(params.id);
case 6:
result = _context2.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context2.next = 13;
break;
case 10:
_context2.prev = 10;
_context2.t0 = _context2['catch'](3);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context2.t0.message);
case 13:
case 'end':
return _context2.stop();
}
}
}, _callee2, this, [[3, 10]]);
}));
function get(_x2) {
return _ref2.apply(this, arguments);
}
return get;
}()
/**
* 获取节点列表
* @interface /node/list
* @method GET
* @category node
* @foldnumber 10
* @param {Number} uid 用户id 不能为空
* @param {Number} [page] 分页页码
* @param {Number} [limit] 分页大小
* @returns {Object}
* @example ./api/project/list.json
*/
}, {
key: 'list',
value: function () {
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(ctx) {
var uid, page, limit, result, count;
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
uid = ctx.request.query.uid, page = ctx.request.query.page || 1, limit = ctx.request.query.limit || 10;
if (uid) {
_context3.next = 3;
break;
}
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '用户id不能为空'));
case 3:
_context3.prev = 3;
_context3.next = 6;
return this.Model.listWithPaging(uid, page, limit);
case 6:
result = _context3.sent;
_context3.next = 9;
return this.Model.listCount(uid);
case 9:
count = _context3.sent;
ctx.body = _yapi2.default.commons.resReturn({
total: Math.ceil(count / limit),
list: result
});
_context3.next = 16;
break;
case 13:
_context3.prev = 13;
_context3.t0 = _context3['catch'](3);
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
case 16:
case 'end':
return _context3.stop();
}
}
}, _callee3, this, [[3, 13]]);
}));
function list(_x3) {
return _ref3.apply(this, arguments);
}
return list;
}()
/**
* 删除节点
* @interface /node/del
* @method POST
* @category node
* @foldnumber 10
* @param {Number} id 节点id不能为空
* @returns {Object}
* @example ./api/project/del.json
*/
}, {
key: 'del',
value: function () {
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) {
var id, result;
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.prev = 0;
id = ctx.request.body.id;
if (id) {
_context4.next = 4;
break;
}
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '节点id不能为空'));
case 4:
_context4.next = 6;
return this.Model.del(id);
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'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
case 13:
case 'end':
return _context4.stop();
}
}
}, _callee4, this, [[0, 10]]);
}));
function del(_x4) {
return _ref4.apply(this, arguments);
}
return del;
}()
/**
* 编辑节点
* @interface /node/up
* @method POST
* @category node
* @foldnumber 10
* @param {Number} id 节点id不能为空
* @param {String} [title]
* @param {String} [content] 节点描述
* @param {Boolean} [is_read] 是否阅读
* @returns {Object}
* @example ./api/node/up.json
*/
}, {
key: 'up',
value: function () {
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
var id, params, data, result;
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.prev = 0;
id = ctx.request.body.id;
params = ctx.request.body;
_context5.next = 5;
return this.jungeMemberAuth(id, this.getUid());
case 5:
_context5.t0 = _context5.sent;
if (!(_context5.t0 !== true)) {
_context5.next = 8;
break;
}
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 8:
if (id) {
_context5.next = 10;
break;
}
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, '节点id不能为空'));
case 10:
data = {
uid: this.getUid(),
up_time: _yapi2.default.commons.time()
};
if (params.title) data.title = params.title;
if (params.content) data.content = params.content;
if (params.is_read) data.is_read = params.is_read;
_context5.next = 16;
return this.Model.up(id, data);
case 16:
result = _context5.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context5.next = 23;
break;
case 20:
_context5.prev = 20;
_context5.t1 = _context5['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context5.t1.message);
case 23:
case 'end':
return _context5.stop();
}
}
}, _callee5, this, [[0, 20]]);
}));
function up(_x5) {
return _ref5.apply(this, arguments);
}
return up;
}()
}]);
return nodeController;
}(_base2.default);
module.exports = nodeController;

137
server_dist/models/log.js Normal file
View File

@ -0,0 +1,137 @@
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
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);
var _user = require('../models/user.js');
var _user2 = _interopRequireDefault(_user);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var logModel = function (_baseModel) {
(0, _inherits3.default)(logModel, _baseModel);
function logModel() {
(0, _classCallCheck3.default)(this, logModel);
return (0, _possibleConstructorReturn3.default)(this, (logModel.__proto__ || (0, _getPrototypeOf2.default)(logModel)).apply(this, arguments));
}
(0, _createClass3.default)(logModel, [{
key: 'getName',
value: function getName() {
return 'log';
}
}, {
key: 'getSchema',
value: function getSchema() {
return {
uid: { type: Number, required: true },
title: { type: String, required: true },
type: { type: String, enum: ['user', 'group', 'interface', 'project', 'other'], required: true },
content: { type: String, required: true },
username: { type: String, required: true },
add_time: Number
};
}
}, {
key: 'save',
value: function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(data) {
var userInst, username, saveData, log;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
userInst = _yapi2.default.getInst(_user2.default);
_context.next = 3;
return userInst.findById(data.uid);
case 3:
username = _context.sent;
saveData = {
title: data.title,
content: data.content,
type: data.type,
uid: data.uid,
username: username,
add_time: _yapi2.default.commons.time()
};
log = new this.model(saveData);
return _context.abrupt('return', log.save());
case 7:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
function save(_x) {
return _ref.apply(this, arguments);
}
return save;
}()
}, {
key: 'list',
value: function list(uid) {
return this.model.find({
uid: uid
}).exec();
}
}, {
key: 'listWithPaging',
value: function listWithPaging(uid, page, limit) {
page = parseInt(page);
limit = parseInt(limit);
return this.model.find({
uid: uid
}).skip((page - 1) * limit).limit(limit).exec();
}
}, {
key: 'listCount',
value: function listCount(uid) {
return this.model.count({
uid: uid
});
}
}]);
return logModel;
}(_base2.default);
module.exports = logModel;

View File

@ -1,112 +0,0 @@
'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 nodeModel = function (_baseModel) {
(0, _inherits3.default)(nodeModel, _baseModel);
function nodeModel() {
(0, _classCallCheck3.default)(this, nodeModel);
return (0, _possibleConstructorReturn3.default)(this, (nodeModel.__proto__ || (0, _getPrototypeOf2.default)(nodeModel)).apply(this, arguments));
}
(0, _createClass3.default)(nodeModel, [{
key: 'getName',
value: function getName() {
return 'node';
}
}, {
key: 'getSchema',
value: function getSchema() {
return {
uid: { type: Number, required: true },
title: { type: String, required: true },
content: { type: String, required: true },
is_read: { type: Boolean, required: true },
add_time: Number
};
}
}, {
key: 'save',
value: function save(data) {
var node = new this.model(data);
return node.save();
}
}, {
key: 'get',
value: function get(id) {
return this.model.findOne({
_id: id
}).exec();
}
}, {
key: 'list',
value: function list(uid) {
return this.model.find({
uid: uid
}).exec();
}
}, {
key: 'listWithPaging',
value: function listWithPaging(uid, page, limit) {
page = parseInt(page);
limit = parseInt(limit);
return this.model.find({
uid: uid
}).skip((page - 1) * limit).limit(limit).exec();
}
}, {
key: 'listCount',
value: function listCount(uid) {
return this.model.count({
uid: uid
});
}
}, {
key: 'del',
value: function del(id) {
return this.model.deleteOne({
_id: id
});
}
}, {
key: 'up',
value: function up(id, data) {
data.up_time = _yapi2.default.commons.time();
return this.model.update({
_id: id
}, data, { runValidators: true });
}
}]);
return nodeModel;
}(_base2.default);
module.exports = nodeModel;

View File

@ -32,9 +32,9 @@ var _project = require('./controllers/project.js');
var _project2 = _interopRequireDefault(_project);
var _node = require('./controllers/node.js');
var _log = require('./controllers/log.js');
var _node2 = _interopRequireDefault(_node);
var _log2 = _interopRequireDefault(_log);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@ -57,9 +57,9 @@ var INTERFACE_CONFIG = {
prefix: '/project/',
controller: _project2.default
},
node: {
prefix: '/node/',
controller: _node2.default
log: {
prefix: '/log/',
controller: _log2.default
}
};
@ -101,11 +101,7 @@ createAction('interface', 'up', 'post', 'up');
createAction('interface', 'del', 'post', 'del');
//node
createAction('node', 'add', 'post', 'add');
createAction('node', 'get', 'get', 'get');
createAction('node', 'list', 'get', 'list');
createAction('node', 'del', 'post', 'del');
createAction('node', 'up', 'post', 'up');
createAction('log', 'list', 'get', 'list');
/**
*