fix: merge

This commit is contained in:
yhui.yang 2017-07-21 12:29:53 +08:00
commit 5449517f4c
26 changed files with 651 additions and 159 deletions

View File

@ -1,4 +1,3 @@
import LoginRedux from './reducer/Login/Login_redux.js'
import login from './reducer/Login/login.js'
import group from './reducer/group/group.js'
import project from './reducer/group/project.js'
@ -11,7 +10,6 @@ import menu from './reducer/menu/menu.js'
export default {
group,
login,
LoginRedux,
Interface,
user,
project,

View File

@ -37,10 +37,11 @@ const changeTableLoading = (data) => {
};
const addProject = (data) => {
const { name, prd_host, basepath, desc, group_id } = data;
const { name, prd_host, basepath, desc, group_id, protocol } = data;
const param = {
name,
prd_host,
protocol,
basepath,
desc,
group_id
@ -53,13 +54,14 @@ const addProject = (data) => {
};
const updateProject = (data) => {
const { name, prd_host, basepath, desc, group_id } = data;
const { name, prd_host, basepath, desc, _id, protocol } = data;
const param = {
name,
prd_host,
protocol,
basepath,
desc,
group_id
id: _id
};
return {
type: PROJECT_UPDATE,

View File

@ -1,5 +1,5 @@
import moment from 'moment'
exports.formatTime = (timestamp) => {
return moment.unix(timestamp).format("YYYY-MM-DD:HH:mm:ss")
}
return moment.unix(timestamp).format("YYYY-MM-DD HH:mm:ss")
}

View File

@ -63,8 +63,9 @@ class Login extends Component {
<FormItem>
<Button type="primary" htmlType="submit" className="login-form-button">登录</Button>
</FormItem>
<Button id="qsso-login" type="primary" className="login-form-button" onClick={() => window.QSSO.attach('qsso-login','/user/login_by_token')}>QSSO登录</Button>
</Form>
)
}
}

View File

@ -4,7 +4,9 @@ import { connect } from 'react-redux';
import { Table, Button, Modal, Form, Input, Icon, Tooltip, Select, Popconfirm, message } from 'antd';
import { addProject, fetchProjectList, delProject, changeUpdateModal, changeTableLoading } from '../../../actions/project';
import UpDateModal from './UpDateModal';
import { Link } from 'react-router-dom'
import variable from '../../../constants/variable';
import common from '../../../common';
import { autobind } from 'core-decorators';
const { TextArea } = Input;
const FormItem = Form.Item;
@ -12,33 +14,49 @@ const Option = Select.Option;
import './ProjectList.scss'
const deleteConfirm = (id, handleDelete, currGroupId, handleFetchList) => {
const test = () => {
handleDelete(id).then((res) => {
// 确认删除项目 handleDelete, currGroup._id, fetchProjectList
const deleteConfirm = (id, props) => {
const { delProject, currGroup, fetchProjectList } = props;
const handle = () => {
delProject(id).then((res) => {
console.log(res);
console.log(handleFetchList, currGroupId);
handleFetchList(currGroupId).then((res) => {
console.log(res);
});
console.log(fetchProjectList, currGroup._id);
if (res.payload.data.errcode == 0) {
message.success('删除成功!')
fetchProjectList(currGroup._id).then((res) => {
console.log(res);
});
} else {
message.error(res.payload.data.errmsg);
}
});
}
return test;
return handle;
};
const getColumns = (data, handleDelete, currGroupId, handleFetchList, handleUpdateModal) => {
const getColumns = (data, props) => {
const { changeUpdateModal, userInfo } = props;
return [{
title: '项目名称',
dataIndex: 'name',
key: 'name',
render: text => <a href="#">{text}</a>
render: (text, record) => {
return <Link to={`Interface/${record._id}`}>{text}</Link>
}
}, {
title: '创建人',
dataIndex: 'owner',
key: 'owner'
key: 'owner',
render: (text, record, index) => {
// data是projectList的列表值
// 根据序号找到对应项的uid根据uid获取对应项目的创建人
return <span>{userInfo[data[index].uid] ? userInfo[data[index].uid].username : ''}</span>;
}
}, {
title: '创建时间',
dataIndex: 'add_time',
key: 'add_time'
key: 'add_time',
render: time => <span>{common.formatTime(time)}</span>
}, {
title: '操作',
key: 'action',
@ -46,9 +64,9 @@ const getColumns = (data, handleDelete, currGroupId, handleFetchList, handleUpda
const id = record._id;
return (
<span>
<a onClick={() => handleUpdateModal(true, index)}>修改</a>
<a onClick={() => changeUpdateModal(true, index)}>修改</a>
<span className="ant-divider" />
<Popconfirm title="你确定要删除项目吗?" onConfirm={deleteConfirm(id, handleDelete, currGroupId, handleFetchList)} okText="删除" cancelText="取消">
<Popconfirm title="你确定要删除项目吗?" onConfirm={deleteConfirm(id, props)} okText="删除" cancelText="取消">
<a href="#">删除</a>
</Popconfirm>
</span>
@ -71,6 +89,7 @@ const formItemLayout = {
state => {
return {
projectList: state.project.projectList,
userInfo: state.project.userInfo,
tableLoading: state.project.tableLoading,
currGroup: state.group.currGroup,
total: state.project.total,
@ -102,6 +121,7 @@ class ProjectList extends Component {
changeUpdateModal: PropTypes.func,
changeTableLoading: PropTypes.func,
projectList: PropTypes.array,
userInfo: PropTypes.object,
tableLoading: PropTypes.bool,
currGroup: PropTypes.object,
total: PropTypes.number,
@ -116,7 +136,7 @@ class ProjectList extends Component {
});
}
// 确认修改
// 确认添加项目
@autobind
handleOk(e) {
const { form, currGroup, changeTableLoading, addProject, fetchProjectList } = this.props;
@ -124,7 +144,7 @@ class ProjectList extends Component {
e.preventDefault();
form.validateFields((err, values) => {
if (!err) {
values.prd_host = this.state.protocol + values.prd_host;
values.protocol = this.state.protocol.split(':')[0];
// 获取当前分组id传入values
values.group_id = currGroup._id;
@ -246,7 +266,8 @@ class ProjectList extends Component {
>
{getFieldDecorator('prd_host', {
rules: [{
required: true, message: '请输入项目线上域名!'
required: true,
message: '请输入项目线上域名!'
}]
})(
<Input addonBefore={(
@ -263,7 +284,7 @@ class ProjectList extends Component {
>
{getFieldDecorator('basepath', {
rules: [{
required: true, message: '请输入项目基本路径!'
required: true, message: '请输入项目基本路径'
}]
})(
<Input />
@ -285,16 +306,18 @@ class ProjectList extends Component {
</Form>
</Modal>
<UpDateModal/>
<Button className="m-btn" icon="plus" type="primary" onClick={this.showAddProjectModal}>创建项目</Button>
<Table
className="m-table"
bordered={true}
loading={this.props.tableLoading}
columns={getColumns(this.state.projectData, this.props.delProject, this.props.currGroup._id, this.props.fetchProjectList, this.props.changeUpdateModal)}
columns={getColumns(this.state.projectData, this.props)}
dataSource={this.state.projectData}
pagination={{
total: this.props.total * variable.PAGE_LIMIT,
defaultPageSize: variable.PAGE_LIMIT,
onChange: this.paginationChange
}}
title={() => <Button type="primary" onClick={this.showAddProjectModal}>创建项目</Button>}
/>
</div>

View File

@ -3,6 +3,12 @@
padding: 16px 24px;
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20);
border-radius: 4px;
text-align: right;
}
.m-table {
text-align: left;
margin-top: .16rem;
}
.ant-input-group-wrapper {

View File

@ -1,7 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Modal, Form, Input, Icon, Tooltip, Select, message, Button } from 'antd';
import { Modal, Form, Input, Icon, Tooltip, Select, message, Button, Row, Col } from 'antd';
import { updateProject, fetchProjectList, delProject, changeUpdateModal, changeTableLoading } from '../../../actions/project';
const { TextArea } = Input;
const FormItem = Form.Item;
@ -23,7 +23,7 @@ const formItemLayout = {
const formItemLayoutWithOutLabel = {
wrapperCol: {
xs: { span: 24, offset: 0 },
sm: { span: 20, offset: 4 }
sm: { span: 20, offset: 6 }
}
};
let uuid = 0;
@ -78,22 +78,19 @@ class UpDateModal extends Component {
this.props.changeUpdateModal(false, -1);
}
// 确认修改
handleOk = (e) => {
e.preventDefault();
const { form, updateProject, changeUpdateModal, currGroup, projectList, handleUpdateIndex, fetchProjectList, changeTableLoading } = this.props;
form.validateFields((err, values) => {
if (!err) {
console.log(values);
console.log(projectList[handleUpdateIndex]);
let assignValue = Object.assign(projectList[handleUpdateIndex], values);
assignValue.prd_host = this.state.protocol + assignValue.prd_host;
assignValue.env = assignValue.envs.map((item) => {
console.log(assignValue);
const arr = assignValue['envs-'+item].split(',');
if (arr.length === 2) {
return {
host: arr[0],
name: arr[1]
}
values.protocol = this.state.protocol.split(':')[0];
assignValue.env = assignValue.envs.map((item, index) => {
return {
name: values['envs-name-'+index],
host: values['envs-host-'+index]
}
});
console.log(assignValue);
@ -166,52 +163,74 @@ class UpDateModal extends Component {
// 如果列表存在且用户点击修改按钮时,设置表单默认值
if (projectList.length !== 0 && handleUpdateIndex !== -1 ) {
// console.log(projectList[handleUpdateIndex]);
const { name, basepath, desc, env } = projectList[handleUpdateIndex];
const { name, basepath, desc , env} = projectList[handleUpdateIndex];
initFormValues = { name, basepath, desc, env };
if (env) {
envMessage = env.map((item) => {
return item.host + ',' + item.name;
})
if (env.length !== 0) {
envMessage = env;
}
initFormValues.prd_host = projectList[handleUpdateIndex].prd_host.split('\/\/')[1];
initFormValues.prd_protocol = projectList[handleUpdateIndex].prd_host.split('\/\/')[0] + '\/\/';
initFormValues.prd_host = projectList[handleUpdateIndex].prd_host;
initFormValues.prd_protocol = projectList[handleUpdateIndex].protocol + '\/\/';
}
getFieldDecorator('envs', { initialValue: envMessage });
const envs = getFieldValue('envs');
const formItems = envs.map((k, index) => {
// console.log(k);
const secondIndex = 'next' + index; // 为保证key的唯一性
return (
<FormItem
{...(index === 0 ? formItemLayout : formItemLayoutWithOutLabel)}
label={index === 0 ? (
<span>环境配置&nbsp;
<Tooltip title="依次输入环境域名(host)与环境名称,以英文逗号分隔">
<Icon type="question-circle-o" />
</Tooltip>
</span>) : ''}
required={false}
key={k}
>
{getFieldDecorator(`envs-${k}`, {
validateTrigger: ['onChange', 'onBlur'],
initialValue: envMessage.length !== 0 ? k : '',
rules: [{
required: false,
whitespace: true,
message: "请输入环境配置,放弃配置请清空输入框"
}]
})(
<Input placeholder="请输入环境配置" style={{ width: '60%', marginRight: 8 }} />
)}
{envs.length > 1 ? (
<Icon
className="dynamic-delete-button"
type="minus-circle-o"
disabled={envs.length === 1}
onClick={() => this.remove(k)}
/>
) : null}
</FormItem>
<Row key={index} type="flex" justify="space-between" align={index === 0 ? 'middle' : 'top'}>
<Col span={10} offset={2}>
<FormItem
label={index === 0 ? (
<span>环境名称</span>) : ''}
required={false}
key={index}
>
{getFieldDecorator(`envs-name-${index}`, {
validateTrigger: ['onChange', 'onBlur'],
initialValue: envMessage.length !== 0 ? k.name : '',
rules: [{
required: false,
whitespace: true,
message: "请输入环境名称"
}]
})(
<Input placeholder="请输入环境名称" style={{ width: '90%', marginRight: 8 }} />
)}
</FormItem>
</Col>
<Col span={10}>
<FormItem
label={index === 0 ? (
<span>环境域名</span>) : ''}
required={false}
key={secondIndex}
>
{getFieldDecorator(`envs-host-${index}`, {
validateTrigger: ['onChange', 'onBlur'],
initialValue: envMessage.length !== 0 ? k.host : '',
rules: [{
required: false,
whitespace: true,
message: "请输入环境域名"
}]
})(
<Input placeholder="请输入环境域名" style={{ width: '90%', marginRight: 8 }} />
)}
</FormItem>
</Col>
<Col span={2}>
{envs.length > 1 ? (
<Icon
className="dynamic-delete-button"
type="minus-circle-o"
disabled={envs.length === 1}
onClick={() => this.remove(k)}
/>
) : null}
</Col>
</Row>
);
});
return (
@ -269,7 +288,7 @@ class UpDateModal extends Component {
{getFieldDecorator('basepath', {
initialValue: initFormValues.basepath,
rules: [{
required: true, message: '请输入项目基本路径!'
required: true, message: '请输入项目基本路径! '
}]
})(
<Input />

View File

@ -1,9 +0,0 @@
export default function (state = 3, action) {
const count = state
switch (action.type) {
case 'increasec':
return count + 1
default:
return state
}
}

View File

@ -10,6 +10,7 @@ const initialState = {
isUpdateModalShow: false,
handleUpdateIndex: -1,
projectList: [],
userInfo: {},
tableLoading: true,
total: 0,
currPage: 1
@ -34,7 +35,8 @@ export default (state = initialState, action) => {
return {
...state,
projectList: action.payload.data.data.list,
total: action.payload.data.data.total
total: action.payload.data.data.total,
userInfo: action.payload.data.data.userinfo
};
}
case PROJECT_ADD: {

View File

@ -1,9 +0,0 @@
export default function (state = 3, action) {
const count = state
switch (action.type) {
case 'increasec':
return count + 1
default:
return state
}
}

346
doc/build/api.html vendored
View File

@ -207,6 +207,20 @@
<li >
<a href="#-interface-del">/interface/del</a>
</li>
</ul>
<!-- <li > -->
<li >
<a href="#node">node</a>
</li>
<ul class="nav docs-sidenav-extend" >
<li >
<a href="#-node-list">/node/list</a>
</li>
</ul>
@ -1235,7 +1249,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#16" target="_blank">./server/controllers/project.js:16</a>
<a href="./static/server/controllers/project.js.html#42" target="_blank">./server/controllers/project.js:42</a>
</p>
@ -1376,7 +1390,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#80" target="_blank">./server/controllers/project.js:80</a>
<a href="./static/server/controllers/project.js.html#114" target="_blank">./server/controllers/project.js:114</a>
</p>
@ -1460,7 +1474,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#112" target="_blank">./server/controllers/project.js:112</a>
<a href="./static/server/controllers/project.js.html#146" target="_blank">./server/controllers/project.js:146</a>
</p>
@ -1544,7 +1558,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#145" target="_blank">./server/controllers/project.js:145</a>
<a href="./static/server/controllers/project.js.html#179" target="_blank">./server/controllers/project.js:179</a>
</p>
@ -1622,7 +1636,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#173" target="_blank">./server/controllers/project.js:173</a>
<a href="./static/server/controllers/project.js.html#207" target="_blank">./server/controllers/project.js:207</a>
</p>
@ -1705,7 +1719,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#197" target="_blank">./server/controllers/project.js:197</a>
<a href="./static/server/controllers/project.js.html#231" target="_blank">./server/controllers/project.js:231</a>
</p>
@ -1952,7 +1966,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#244" target="_blank">./server/controllers/project.js:244</a>
<a href="./static/server/controllers/project.js.html#278" target="_blank">./server/controllers/project.js:278</a>
</p>
@ -2024,7 +2038,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#277" target="_blank">./server/controllers/project.js:277</a>
<a href="./static/server/controllers/project.js.html#311" target="_blank">./server/controllers/project.js:311</a>
</p>
@ -2128,7 +2142,7 @@
</tr>
<tr>
<td>env[].host</td>
<td>env[].domain</td>
<td>String</td>
<td>环境域名</td>
<td>
@ -2184,7 +2198,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#351" target="_blank">./server/controllers/project.js:351</a>
<a href="./static/server/controllers/project.js.html#394" target="_blank">./server/controllers/project.js:394</a>
</p>
@ -2319,6 +2333,18 @@
<td></td>
</tr>
<tr>
<td>title</td>
<td>String</td>
<td>接口标题,不能为空</td>
<td>
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
</td>
<td></td>
</tr>
<tr>
<td>path</td>
<td>String</td>
@ -2404,7 +2430,7 @@
</tr>
<tr>
<td>req_params</td>
<td>req_params_form</td>
<td>Mixed</td>
<td>请求参数,如果请求方式是form参数是Array数组其他格式请求参数是字符串</td>
<td>
@ -2414,7 +2440,7 @@
</tr>
<tr>
<td>req_params[].name</td>
<td>req_params_form[].name</td>
<td>String</td>
<td>请求参数名</td>
<td>
@ -2424,7 +2450,7 @@
</tr>
<tr>
<td>req_params[].value</td>
<td>req_params_form[].value</td>
<td>String</td>
<td>请求参数值可填写生成规则mock。如@email随机生成一条email</td>
<td>
@ -2434,7 +2460,7 @@
</tr>
<tr>
<td>req_params[].type</td>
<td>req_params_form[].type</td>
<td>String</td>
<td>请求参数类型,有["text", "file"]两种</td>
<td>
@ -2443,6 +2469,16 @@
<td></td>
</tr>
<tr>
<td>req_params_other</td>
<td>String</td>
<td>非form类型的请求参数可保存到此字段</td>
<td>
</td>
<td></td>
</tr>
<tr>
<td>res_body_type</td>
<td>String</td>
@ -2483,6 +2519,7 @@
<span class="token comment" spellcheck="true">//header Content-Type:application/json</span>
<span class="token punctuation">{</span>
<span class="token string">"title"</span><span class="token punctuation">:</span> <span class="token string">"testapi"</span><span class="token punctuation">,</span>
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"api"</span><span class="token punctuation">,</span>
<span class="token string">"method"</span><span class="token punctuation">:</span> <span class="token string">"post"</span><span class="token punctuation">,</span>
<span class="token string">"path"</span><span class="token punctuation">:</span> <span class="token string">"/testapi"</span><span class="token punctuation">,</span>
@ -2517,6 +2554,7 @@
<span class="token string">"data"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">422</span><span class="token punctuation">,</span>
<span class="token string">"title"</span><span class="token punctuation">:</span> <span class="token string">"testapi"</span><span class="token punctuation">,</span>
<span class="token string">"project_id"</span><span class="token punctuation">:</span> <span class="token number">8</span><span class="token punctuation">,</span>
<span class="token string">"path"</span><span class="token punctuation">:</span> <span class="token string">"/testapi"</span><span class="token punctuation">,</span>
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"api"</span><span class="token punctuation">,</span>
@ -2569,7 +2607,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/interface.js.html#77" target="_blank">./server/controllers/interface.js:77</a>
<a href="./static/server/controllers/interface.js.html#81" target="_blank">./server/controllers/interface.js:81</a>
</p>
@ -2629,12 +2667,12 @@
</blockquote>
<p>
<small class="text-muted">描述:</small>
添加项目分组
接口列表
</p>
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/interface.js.html#100" target="_blank">./server/controllers/interface.js:100</a>
<a href="./static/server/controllers/interface.js.html#104" target="_blank">./server/controllers/interface.js:104</a>
</p>
@ -2694,12 +2732,12 @@
</blockquote>
<p>
<small class="text-muted">描述:</small>
添加项目分组
编辑接口
</p>
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/interface.js.html#124" target="_blank">./server/controllers/interface.js:124</a>
<a href="./static/server/controllers/interface.js.html#128" target="_blank">./server/controllers/interface.js:128</a>
</p>
@ -2817,7 +2855,7 @@
</tr>
<tr>
<td>req_params</td>
<td>req_params_form</td>
<td>Mixed</td>
<td>请求参数,如果请求方式是form参数是Array数组其他格式请求参数是字符串</td>
<td>
@ -2827,7 +2865,7 @@
</tr>
<tr>
<td>req_params[].name</td>
<td>req_params_form[].name</td>
<td>String</td>
<td>请求参数名</td>
<td>
@ -2837,7 +2875,7 @@
</tr>
<tr>
<td>req_params[].value</td>
<td>req_params_form[].value</td>
<td>String</td>
<td>请求参数值可填写生成规则mock。如@email随机生成一条email</td>
<td>
@ -2847,7 +2885,7 @@
</tr>
<tr>
<td>req_params[].type</td>
<td>req_params_form[].type</td>
<td>String</td>
<td>请求参数类型,有["text", "file"]两种</td>
<td>
@ -2856,6 +2894,16 @@
<td></td>
</tr>
<tr>
<td>req_params_other</td>
<td>String</td>
<td>非form类型的请求参数可保存到此字段</td>
<td>
</td>
<td></td>
</tr>
<tr>
<td>res_body_type</td>
<td>String</td>
@ -2922,7 +2970,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/interface.js.html#189" target="_blank">./server/controllers/interface.js:189</a>
<a href="./static/server/controllers/interface.js.html#197" target="_blank">./server/controllers/interface.js:197</a>
</p>
@ -2977,6 +3025,256 @@
</div>
<h2 id="node" class="page-header subject">node<a class="hashlink" href="#node">#</a></h2>
<div class="con-list-item">
<blockquote class="api">
<h3 id="-node-list" class="page-header subject">
/node/list
<span class="ui-badge">GET</span>
<a class="hashlink" href="#-node-list">#</a>
</h3>
</blockquote>
<p>
<small class="text-muted">描述:</small>
获取节点列表
</p>
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/log.js.html#12" target="_blank">./server/controllers/log.js:12</a>
</p>
<p>
<small class="text-muted">参数:</small>
</p>
<div class="docs-table">
<table class="yo-table yo-table-border">
<colgroup>
<col class="c1">
<col class="c2">
<col class="c3">
<col class="c4">
</colgroup>
<thead>
<tr class="active">
<th>参数名</th>
<th>类型</th>
<th>描述</th>
<th>必选</th>
<th>支持版本</th>
</tr>
</thead>
<tr>
<td>uid</td>
<td>Number</td>
<td>用户id 不能为空</td>
<td>
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
</td>
<td></td>
</tr>
<tr>
<td>page</td>
<td>Number</td>
<td>分页页码</td>
<td>
</td>
<td></td>
</tr>
<tr>
<td>limit</td>
<td>Number</td>
<td>分页大小</td>
<td>
</td>
<td></td>
</tr>
</table>
</div>
<div>示例:</div>
<pre class="ydoc-example" data-foldnumber=10><code><span class="token punctuation">{</span>
<span class="token string">"errcode"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">"success"</span><span class="token punctuation">,</span>
<span class="token string">"data"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
<span class="token string">"total"</span><span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">,</span>
<span class="token string">"list"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">529</span><span class="token punctuation">,</span>
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"yapi"</span><span class="token punctuation">,</span>
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"aaa"</span><span class="token punctuation">,</span>
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"http://www.yapi.com"</span><span class="token punctuation">,</span>
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"/a/"</span><span class="token punctuation">,</span>
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500465369</span><span class="token punctuation">,</span>
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500522419</span><span class="token punctuation">,</span>
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token string">"107"</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">558</span><span class="token punctuation">,</span>
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"12"</span><span class="token punctuation">,</span>
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"21\n"</span><span class="token punctuation">,</span>
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"http://11/"</span><span class="token punctuation">,</span>
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"12/"</span><span class="token punctuation">,</span>
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500466250</span><span class="token punctuation">,</span>
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500466250</span><span class="token punctuation">,</span>
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token string">"107"</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">626</span><span class="token punctuation">,</span>
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"1233"</span><span class="token punctuation">,</span>
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"123"</span><span class="token punctuation">,</span>
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"http://1234/"</span><span class="token punctuation">,</span>
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"1234/"</span><span class="token punctuation">,</span>
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500471230</span><span class="token punctuation">,</span>
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500471230</span><span class="token punctuation">,</span>
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token string">"107"</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">665</span><span class="token punctuation">,</span>
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"222"</span><span class="token punctuation">,</span>
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"222"</span><span class="token punctuation">,</span>
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"http://222/"</span><span class="token punctuation">,</span>
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"222/"</span><span class="token punctuation">,</span>
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500471668</span><span class="token punctuation">,</span>
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500471668</span><span class="token punctuation">,</span>
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token string">"107"</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">704</span><span class="token punctuation">,</span>
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"333"</span><span class="token punctuation">,</span>
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"222333"</span><span class="token punctuation">,</span>
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"http://333/"</span><span class="token punctuation">,</span>
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"333/"</span><span class="token punctuation">,</span>
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500471674</span><span class="token punctuation">,</span>
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500471674</span><span class="token punctuation">,</span>
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token string">"107"</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">743</span><span class="token punctuation">,</span>
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"444"</span><span class="token punctuation">,</span>
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"444"</span><span class="token punctuation">,</span>
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"https://444/"</span><span class="token punctuation">,</span>
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"444/"</span><span class="token punctuation">,</span>
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500471695</span><span class="token punctuation">,</span>
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500471695</span><span class="token punctuation">,</span>
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token string">"107"</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">763</span><span class="token punctuation">,</span>
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"122333"</span><span class="token punctuation">,</span>
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"3/"</span><span class="token punctuation">,</span>
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"http://33/"</span><span class="token punctuation">,</span>
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"33/"</span><span class="token punctuation">,</span>
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500481743</span><span class="token punctuation">,</span>
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500481743</span><span class="token punctuation">,</span>
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token string">"107"</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">778</span><span class="token punctuation">,</span>
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"555"</span><span class="token punctuation">,</span>
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"555"</span><span class="token punctuation">,</span>
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"https://555/"</span><span class="token punctuation">,</span>
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"555/"</span><span class="token punctuation">,</span>
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500519203</span><span class="token punctuation">,</span>
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500519203</span><span class="token punctuation">,</span>
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token string">"107"</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">823</span><span class="token punctuation">,</span>
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"5"</span><span class="token punctuation">,</span>
<span class="token string">"desc"</span><span class="token punctuation">:</span> <span class="token string">"5"</span><span class="token punctuation">,</span>
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"http://5/"</span><span class="token punctuation">,</span>
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"5/"</span><span class="token punctuation">,</span>
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500519769</span><span class="token punctuation">,</span>
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500519769</span><span class="token punctuation">,</span>
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token string">"107"</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span>
<span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token string">"userinfo"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
<span class="token string">"107"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">107</span><span class="token punctuation">,</span>
<span class="token string">"username"</span><span class="token punctuation">:</span> <span class="token string">"admin"</span><span class="token punctuation">,</span>
<span class="token string">"email"</span><span class="token punctuation">:</span> <span class="token string">"admin@admin.com"</span><span class="token punctuation">,</span>
<span class="token string">"role"</span><span class="token punctuation">:</span> <span class="token string">"admin"</span><span class="token punctuation">,</span>
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500280333</span><span class="token punctuation">,</span>
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500373530</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre>
</div>
</div>
</div>

View File

@ -42,6 +42,7 @@ class interfaceController extends baseController{
* @category interface
* @foldnumber 10
* @param {Number} project_id 项目id不能为空
* @param {String} title 接口标题,不能为空
* @param {String} path 接口请求路径,不能为空
* @param {String} method 请求方式
* @param {Array} [req_headers] 请求的header信息
@ -50,10 +51,11 @@ class interfaceController extends baseController{
* @param {Boolean} [req_headers[].required] 是否是必须,默认为否
* @param {String} [req_headers[].desc] header描述
* @param {String} [req_params_type] 请求参数方式,有["form", "json", "text", "xml"]四种
* @param {Mixed} [req_params] 请求参数,如果请求方式是form参数是Array数组其他格式请求参数是字符串
* @param {String} [req_params[].name] 请求参数名
* @param {String} [req_params[].value] 请求参数值可填写生成规则mock。如@email随机生成一条email
* @param {String} [req_params[].type] 请求参数类型,有["text", "file"]两种
* @param {Mixed} [req_params_form] 请求参数,如果请求方式是form参数是Array数组其他格式请求参数是字符串
* @param {String} [req_params_form[].name] 请求参数名
* @param {String} [req_params_form[].value] 请求参数值可填写生成规则mock。如@email随机生成一条email
* @param {String} [req_params_form[].type] 请求参数类型,有["text", "file"]两种
* @param {String} [req_params_other] 非form类型的请求参数可保存到此字段
* @param {String} [res_body_type] 相应信息的数据格式,有["json", "text", "xml"]三种
* @param {String} [res_body] 响应信息可填写任意字符串如果res_body_type是json,则会调用mock功能
* @param {String} [desc] 接口描述
@ -63,6 +65,7 @@ class interfaceController extends baseController{
async add(ctx){
let params = ctx.request.body;
params.method = params.method || 'GET';
params.method = params.method.toUpperCase()
params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json';
if(!params.project_id){
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
@ -80,6 +83,7 @@ class interfaceController extends baseController{
try{
let data = {
project_id: params.project_id,
title: params.title,
path: params.path,
desc: params.desc,
method: params.method,
@ -92,8 +96,8 @@ class interfaceController extends baseController{
up_time: yapi.commons.time()
}
if(data.req_params_type === 'form') data.req_params_form = params.req_params;
else data.req_params_other = params.req_params;
if(params.req_params_form) data.req_params_form = params.req_params_form;
if(params.req_params_other) data.req_params_other = params.req_params_other;
let result = await this.Model.save(data);
ctx.body = yapi.commons.resReturn(result);
@ -126,7 +130,7 @@ class interfaceController extends baseController{
}
/**
* 添加项目分组
* 接口列表
* @interface /interface/list
* @method GET
* @category interface
@ -150,7 +154,7 @@ class interfaceController extends baseController{
}
/**
* 添加项目分组
* 编辑接口
* @interface /interface/up
* @method POST
* @category interface
@ -164,10 +168,11 @@ class interfaceController extends baseController{
* @param {Boolean} [req_headers[].required] 是否是必须,默认为否
* @param {String} [req_headers[].desc] header描述
* @param {String} [req_params_type] 请求参数方式,有["form", "json", "text", "xml"]四种
* @param {Mixed} [req_params] 请求参数,如果请求方式是form参数是Array数组其他格式请求参数是字符串
* @param {String} [req_params[].name] 请求参数名
* @param {String} [req_params[].value] 请求参数值可填写生成规则mock。如@email随机生成一条email
* @param {String} [req_params[].type] 请求参数类型,有["text", "file"]两种
* @param {Mixed} [req_params_form] 请求参数,如果请求方式是form参数是Array数组其他格式请求参数是字符串
* @param {String} [req_params_form[].name] 请求参数名
* @param {String} [req_params_form[].value] 请求参数值可填写生成规则mock。如@email随机生成一条email
* @param {String} [req_params_form[].type] 请求参数类型,有["text", "file"]两种
* @param {String} [req_params_other] 非form类型的请求参数可保存到此字段
* @param {String} [res_body_type] 相应信息的数据格式,有["json", "text", "xml"]三种
* @param {String} [res_body] 响应信息可填写任意字符串如果res_body_type是json,则会调用mock功能
* @param {String} [desc] 接口描述
@ -178,11 +183,13 @@ class interfaceController extends baseController{
async up(ctx){
let params = ctx.request.body;
params.method = params.method || 'GET';
params.method = params.method.toUpperCase()
let id = ctx.request.body.id;
if(!id){
return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
}
if(params.path){
let interfaceData = await this.Model.get(id);
if(params.path && params.path !== interfaceData.path && params.method !== interfaceData.method){
let checkRepeat = await this.Model.checkRepeat(params.path, params.method);
if(checkRepeat > 0){
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
@ -194,13 +201,14 @@ class interfaceController extends baseController{
}
if(params.path) data.path = params.path;
if(params.title) data.title = params.title;
if(params.desc) data.desc = params.desc;
if(params.method) data.method = params.method;
if(params.req_headers) data.req_headers = params.req_headers;
if(params.req_params_type === 'form') data.req_params_form = params.req_params;
else data.req_params_other = params.req_params;
if(params.req_params_form) data.req_params_form = params.req_params_form;
if(params.req_params_other) data.req_params_other = params.req_params_other;
if(params.res_body_type) data.res_body_type = params.res_body_type;
if(params.res_body) data.res_body = params.res_body;

View File

@ -0,0 +1,114 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<title>yapi : ./server/controllers/log.js</title>
<link type="text/css" rel="stylesheet" href="../../../source/code.css"/>
<script type="text/javascript" src="../../../source/shCore.js"></script>
<script type="text/javascript" src="../../../source/shBrush-js.js"></script>
<style>
.syntaxhighlighter .number1 .spaces,.syntaxhighlighter .toolbar{ display: none;}
.syntaxhighlighter table td.gutter .line.highlight { background-color: #6ce26c !important; color: white; }
</style>
</head>
<body>
<div class="ydoc">
<div class="ydoc-banner-bg">
<div class="ydoc-banner" id="content" tabindex="-1">
<div class="ydoc-banner-area">
<h1>yapi : ./server/controllers/log.js</h1>
<p>源代码</p>
</div>
</div>
<div class="ydoc-container">
<div class="ydoc-container-content">
<div class="static-code-content" role="main">
<pre class="brush: js;">
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;
</pre>
</div>
</div>
</div>
</div>
<!-- <div class="docs-header" id="content" tabindex="-1">
<div class="container">
<h1>yapi : ./server/controllers/log.js</h1>
<p>源代码</p>
</div>
</div> -->
<footer class="docs-footer" role="contentinfo">
<div class="container">
<p></p>
</div>
</footer>
</div>
<script type="text/javascript">
SyntaxHighlighter.all();
function getTop(node){
return node.offsetTop + (node.offsetParent ? getTop(node.offsetParent) : 0);
}
document.addEventListener('DOMContentLoaded', function() {
setTimeout(function() {
try {
var lineNum = (parseInt(location.hash.replace(/#/g, '')) - 1) || 0,
node = document.querySelectorAll('div.line')[lineNum];
document.body.scrollTop = getTop(node);
node.className += ' highlight';
} catch(e) {}
}, 500);
}, false);
</script>
</body>
</html>

View File

@ -41,6 +41,32 @@ class projectController extends baseController {
this.groupModel = yapi.getInst(groupModel);
}
handleBasepath(basepath){
if(!basepath) return false;
if(basepath[0] !== '/') basepath = '/' + basepath;
if(basepath[basepath.length -1] === '/') basepath = basepath.substr(0, basepath.length -1)
if(!this.verifyPath(basepath)){
return false;
}
return basepath;
}
verifyPath(path){
if(/^[a-zA-Z0-9\-\/_:]+$/.test(path)){
return true;
}else{
return false;
}
}
verifyDomain(domain){
if(!domain) return false;
if(/^[a-zA-Z0-9\-_\.]+[a-zA-Z]{2,6}$/.test(domain)){
return true;
}
return false;
}
/**
* 添加项目分组
* @interface /project/add
@ -79,6 +105,14 @@ class projectController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 400, '项目domain不能为空');
}
if((params.basepath = this.handleBasepath(params.basepath)) === false){
return ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误')
}
if(!this.verifyDomain(params.prd_host)){
return ctx.body = yapi.commons.resReturn(null, 401, '线上域名格式有误')
}
let checkRepeatDomain = await this.Model.checkDomainRepeat(params.prd_host, params.basepath);
if(checkRepeatDomain > 0){
return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
@ -315,7 +349,7 @@ class projectController extends baseController {
* @param {String} [desc] 项目描述
* @param {Array} [env] 项目环境配置
* @param {String} [env[].name] 环境名称
* @param {String} [env[].host] 环境域名
* @param {String} [env[].domain] 环境域名
* @returns {Object}
* @example ./api/project/up.json
*/
@ -333,6 +367,15 @@ class projectController extends baseController {
}
let projectData = await this.Model.get(id);
if(params.basepath = (this.handleBasepath(params.basepath)) === false){
return ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误')
}
if(!this.verifyDomain(params.prd_host)){
return ctx.body = yapi.commons.resReturn(null, 401, '线上域名格式有误')
}
if(projectData.name === params.name){
delete params.name;
}

View File

@ -10,4 +10,4 @@
<div id="yapi" style="height: 100%;"></div>
<script src="prd/index@dev.js"></script>
</body>
</html>
</html>

View File

@ -10,7 +10,6 @@ import bodyParser from 'koa-bodyparser'
import router from './router.js'
yapi.connect = dbModule.connect()
const app = new Koa()
app.use(mockServer)
app.use(bodyParser())

View File

@ -25,7 +25,7 @@ class projectController extends baseController {
}
verifyPath(path){
if(/^[a-zA-Z0-9\-\/_:]+$/.test(basepath)){
if(/^[a-zA-Z0-9\-\/_:]+$/.test(path)){
return true;
}else{
return false;
@ -78,7 +78,7 @@ class projectController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 400, '项目domain不能为空');
}
if(params.basepath = (this.handleBasepath(params.basepath)) === false){
if((params.basepath = this.handleBasepath(params.basepath)) === false){
return ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误')
}
@ -90,7 +90,6 @@ class projectController extends baseController {
if(checkRepeatDomain > 0){
return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
}
let data = {
name: params.name,
@ -323,7 +322,7 @@ class projectController extends baseController {
* @param {String} [desc] 项目描述
* @param {Array} [env] 项目环境配置
* @param {String} [env[].name] 环境名称
* @param {String} [env[].host] 环境域名
* @param {String} [env[].domain] 环境域名
* @returns {Object}
* @example ./api/project/up.json
*/

View File

@ -70,7 +70,7 @@ class interfaceModel extends baseModel{
list (project_id){
return this.model.find({
project_id: project_id
}).exec()
}).sort({_id: -1}).exec()
}
del(id){

View File

@ -12,6 +12,7 @@ class projectModel extends baseModel{
name: {type: String, required: true},
basepath: {type: String, required: true, validate: {
validator: (v) => {
console.log('basepath: ', v)
return v && v[0] === '/'
},
message: 'basepath必须是/开头'
@ -64,7 +65,7 @@ class projectModel extends baseModel{
list (group_id){
return this.model.find({
group_id: group_id
}).exec()
}).sort({_id: -1}).exec()
}
listWithPaging(group_id, page, limit) {
@ -72,7 +73,7 @@ class projectModel extends baseModel{
limit = parseInt(limit);
return this.model.find({
group_id: group_id
}).skip((page - 1) * limit).limit(limit).exec();
}).sort({_id: -1}).skip((page - 1) * limit).limit(limit).exec();
}
listCount(group_id) {

View File

@ -47,7 +47,7 @@ class userModel extends baseModel{
listWithPaging(page, limit) {
page = parseInt(page);
limit = parseInt(limit);
return this.model.find().skip((page - 1) * limit).limit(limit).select("_id username email role add_time up_time").exec();
return this.model.find().sort({_id: -1}).skip((page - 1) * limit).limit(limit).select("_id username email role add_time up_time").exec();
}
listCount() {
return this.model.count();

View File

@ -42,7 +42,6 @@ _yapi2.default.commons = _commons2.default;
_yapi2.default.connect = _db2.default.connect();
var app = new _koa2.default();
app.use(_mockServer2.default);
app.use((0, _koaBodyparser2.default)());

View File

@ -85,7 +85,7 @@ var projectController = function (_baseController) {
}, {
key: 'verifyPath',
value: function verifyPath(path) {
if (/^[a-zA-Z0-9\-\/_:]+$/.test(basepath)) {
if (/^[a-zA-Z0-9\-\/_:]+$/.test(path)) {
return true;
} else {
return false;
@ -174,7 +174,7 @@ var projectController = function (_baseController) {
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目domain不能为空'));
case 14:
if (!(params.basepath = this.handleBasepath(params.basepath) === false)) {
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
_context.next = 16;
break;
}

View File

@ -114,7 +114,7 @@ var interfaceModel = function (_baseModel) {
value: function list(project_id) {
return this.model.find({
project_id: project_id
}).exec();
}).sort({ _id: -1 }).exec();
}
}, {
key: 'del',

View File

@ -51,6 +51,7 @@ var projectModel = function (_baseModel) {
name: { type: String, required: true },
basepath: { type: String, required: true, validate: {
validator: function validator(v) {
console.log('basepath: ', v);
return v && v[0] === '/';
},
message: 'basepath必须是/开头'
@ -105,7 +106,7 @@ var projectModel = function (_baseModel) {
value: function list(group_id) {
return this.model.find({
group_id: group_id
}).exec();
}).sort({ _id: -1 }).exec();
}
}, {
key: 'listWithPaging',
@ -114,7 +115,7 @@ var projectModel = function (_baseModel) {
limit = parseInt(limit);
return this.model.find({
group_id: group_id
}).skip((page - 1) * limit).limit(limit).exec();
}).sort({ _id: -1 }).skip((page - 1) * limit).limit(limit).exec();
}
}, {
key: 'listCount',

View File

@ -99,7 +99,7 @@ var userModel = function (_baseModel) {
value: function listWithPaging(page, limit) {
page = parseInt(page);
limit = parseInt(limit);
return this.model.find().skip((page - 1) * limit).limit(limit).select("_id username email role add_time up_time").exec();
return this.model.find().sort({ _id: -1 }).skip((page - 1) * limit).limit(limit).select("_id username email role add_time up_time").exec();
}
}, {
key: 'listCount',

View File

@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>my yApi</title>
<link rel="stylesheet" href="http://127.0.0.1:4000/yapi/prd/index@dev.css">
<script src="https://qsso.corp.qunar.com/lib/qsso-auth.js"></script>
</head>
<body>
<div id="yapi" style="height: 100%;"></div>
@ -33,7 +34,3 @@ xhr.send()
-->
</body>
</html>