-
+
+
+
+
+
+
+
+
+
+
- )
+ )
}
}
-export default User
\ No newline at end of file
+export default User
diff --git a/client/containers/User/index.scss b/client/containers/User/index.scss
index 75cbbb3b..d25fb2b3 100644
--- a/client/containers/User/index.scss
+++ b/client/containers/User/index.scss
@@ -1,5 +1,9 @@
@import '../../styles/mixin.scss';
+.g-doc {
+ margin: .24rem auto;
+}
+
/* .user-box.css */
.user-box {
@include row-width-limit;
@@ -15,7 +19,6 @@
.user-list {
- width: 216px;
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20);
background: #FFF;
border-radius:5px;
@@ -30,15 +33,15 @@
}
}
.user-name{
- padding: 24px 0px;
- text-align: center;
+ padding: 24px 10px;
+ // text-align: center;
background-color: #34495e;
color: white;
font-size: 16px;
border-top-left-radius:5px;
border-top-right-radius: 5px;
span{
- margin-right: 10px;
+ margin-right: 5px;
}
}
.router-content{
@@ -70,9 +73,6 @@
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20);
background: #FFF;
border-radius:5px;
- .ant-btn-group{
- margin-top: 12px;
- }
.user-item {
min-height:35px;
line-height:35px;
@@ -87,8 +87,14 @@
#old_password{
margin-top: 0px;
}
+ .ant-col-12{
+ .ant-input{
+ width: 70%;
+ margin-right: 24px;
+ }
+ }
.ant-col-4{
- color: black;
+ color: rgba(0,0,0,0.85);
padding: 0px 10px;
text-indent: .7em;
// background-color: #f1f3f6;
diff --git a/config.json b/config.json
new file mode 100644
index 00000000..be5bd2aa
--- /dev/null
+++ b/config.json
@@ -0,0 +1,20 @@
+{
+"port": "3000",
+"webhost": "yapi.local.qunar.com",
+"adminAccount": "admin@admin.com",
+"db": {
+"servername": "10.86.40.194",
+"DATABASE": "yapi",
+"port": 27017,
+"user": "test1",
+"pass": "test1"
+},
+"mail": {
+"host": "smtp.163.com",
+"port": 465,
+"auth": {
+"user": "hellosean1025@163.com",
+"pass": "helloqunar123"
+}
+}
+}
\ No newline at end of file
diff --git a/package.json b/package.json
index 25eee71b..a881dd70 100644
--- a/package.json
+++ b/package.json
@@ -62,9 +62,7 @@
"url": "^0.11.0",
"wangeditor": "^3.0.4",
"ykit-config-antd": "^0.1.3",
- "ykit-config-react": "^0.4.4"
- },
- "devDependencies": {
+ "ykit-config-react": "^0.4.4",
"axios": "^0.16.2",
"babel": "^6.5.2",
"babel-cli": "^6.24.1",
@@ -89,12 +87,11 @@
"extract-text-webpack-plugin": "^1.0.1",
"fast-sass-loader": "^1.2.5",
"fs-extra": "^3.0.1",
- "ghooks": "^2.0.0",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-watch": "^4.3.11",
"node-sass": "^4.5.3",
- "nodemon": "^1.11.0",
+
"ora": "^1.3.0",
"prop-types": "^15.5.10",
"react": "^15.6.1",
@@ -106,9 +103,13 @@
"sass-loader": "^6.0.6",
"scss-loader": "0.0.1",
"style-loader": "^0.18.2",
- "validate-commit-msg": "^2.12.2",
+ "validate-commit-msg": "^2.12.2"
+ },
+ "devDependencies": {
+ "nodemon": "^1.11.0",
"webpack": "^2.0.0",
- "webpack-node-externals": "^1.6.0"
+ "webpack-node-externals": "^1.6.0",
+ "ghooks": "^2.0.0"
},
"config": {
"ghooks": {
diff --git a/server/controllers/interface.js b/server/controllers/interface.js
index a01f3bb1..642b0cb1 100644
--- a/server/controllers/interface.js
+++ b/server/controllers/interface.js
@@ -1,10 +1,10 @@
-import interfaceModel from '../models/interface.js'
-import baseController from './base.js'
-import yapi from '../yapi.js'
+import interfaceModel from '../models/interface.js';
+import baseController from './base.js';
+import yapi from '../yapi.js';
-class interfaceController extends baseController{
- constructor(ctx){
- super(ctx)
+class interfaceController extends baseController {
+ constructor(ctx) {
+ super(ctx);
this.Model = yapi.getInst(interfaceModel);
}
@@ -35,37 +35,39 @@ class interfaceController extends baseController{
* @returns {Object}
* @example ./api/interface/add.json
*/
- async add(ctx){
+ async add(ctx) {
let params = ctx.request.body;
+
params = yapi.commons.handleParams(params, {
project_id: 'number',
title: 'string',
path: 'string',
method: 'string',
desc: 'string'
- })
+ });
params.method = params.method || 'GET';
- params.method = params.method.toUpperCase()
+ params.method = params.method.toUpperCase();
params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json';
- if(!params.project_id){
+
+ if (!params.project_id) {
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
}
- if(!params.path){
+ if (!params.path) {
return ctx.body = yapi.commons.resReturn(null, 400, '接口请求路径不能为空');
}
- if(!yapi.commons.verifyPath(params.path)){
- return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/')
+ if (!yapi.commons.verifyPath(params.path)) {
+ return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/');
}
-
+
let checkRepeat = await this.Model.checkRepeat(params.project_id, params.path, params.method);
- if(checkRepeat > 0){
- return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
- }
+ if (checkRepeat > 0) {
+ return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
+ }
- try{
+ try {
let data = {
project_id: params.project_id,
title: params.title,
@@ -74,20 +76,24 @@ class interfaceController extends baseController{
method: params.method,
req_headers: params.req_headers,
req_params_type: params.req_params_type,
- res_body: params.res_body,
+ res_body: params.res_body,
res_body_type: params.res_body_type,
uid: this.getUid(),
add_time: yapi.commons.time(),
up_time: yapi.commons.time()
+ };
+
+ 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.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);
- }catch(e){
- ctx.body = yapi.commons.resReturn(null, 402, e.message)
+ } catch (e) {
+ ctx.body = yapi.commons.resReturn(null, 402, e.message);
}
}
@@ -101,16 +107,18 @@ class interfaceController extends baseController{
* @returns {Object}
* @example ./api/interface/get.json
*/
- async get(ctx){
+ async get(ctx) {
let params = ctx.request.query;
- if(!params.id){
+
+ if (!params.id) {
return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
}
- try{
+
+ 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)
+ } catch (e) {
+ ctx.body = yapi.commons.resReturn(null, 402, e.message);
}
}
@@ -124,17 +132,18 @@ class interfaceController extends baseController{
* @returns {Object}
* @example ./api/interface/list.json
*/
-
- async list(ctx){
+ async list(ctx) {
let project_id = ctx.request.query.project_id;
- if(!project_id){
+
+ if (!project_id) {
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
}
- try{
+
+ try {
let result = await this.Model.list(project_id);
- ctx.body = yapi.commons.resReturn(result)
- }catch(err){
- ctx.body = yapi.commons.resReturn(null, 402, e.message)
+ ctx.body = yapi.commons.resReturn(result);
+ } catch (err) {
+ ctx.body = yapi.commons.resReturn(null, 402, err.message);
}
}
@@ -165,55 +174,76 @@ class interfaceController extends baseController{
* @example ./api/interface/up.json
*/
- async up(ctx){
+ async up(ctx) {
let params = ctx.request.body;
+
params = yapi.commons.handleParams(params, {
title: 'string',
path: 'string',
method: 'string',
desc: 'string'
- })
+ });
params.method = params.method || 'GET';
- params.method = params.method.toUpperCase()
+ params.method = params.method.toUpperCase();
+
let id = ctx.request.body.id;
- if(!id){
+
+ if (!id) {
return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
}
let interfaceData = await this.Model.get(id);
- if(params.path && !yapi.commons.verifyPath(params.path)){
- return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/')
+ if (params.path && !yapi.commons.verifyPath(params.path)) {
+ return ctx.body = yapi.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/');
}
-
- if(params.path && params.path !== interfaceData.path && params.method !== interfaceData.method){
- let checkRepeat = await this.Model.checkRepeat(interfaceData.project_id,params.path, params.method);
- if(checkRepeat > 0){
- return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
+
+ if (params.path && params.path !== interfaceData.path && params.method !== interfaceData.method) {
+ let checkRepeat = await this.Model.checkRepeat(interfaceData.project_id, params.path, params.method);
+ if (checkRepeat > 0) {
+ return ctx.body = yapi.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']');
}
- }
+ }
let data = {
up_time: yapi.commons.time()
+ };
+
+ 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.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_headers) data.req_headers = params.req_headers;
+ 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.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;
+ if (params.res_body_type) {
+ data.res_body_type = params.res_body_type;
+ }
+ if (params.res_body) {
+ data.res_body = params.res_body;
+ }
- try{
+ try {
let result = await this.Model.up(id, data);
- ctx.body = yapi.commons.resReturn(result)
- }catch(e){
- ctx.body = yapi.commons.resReturn(null, 402, e.message)
+ ctx.body = yapi.commons.resReturn(result);
+ } catch (e) {
+ ctx.body = yapi.commons.resReturn(null, 402, e.message);
}
}
@@ -229,27 +259,27 @@ class interfaceController extends baseController{
* @example ./api/interface/del.json
*/
- async del(ctx){
- try{
- let id = ctx.request.body.id;
-
- if(!id){
+ async del(ctx) {
+ try {
+ let id = ctx.request.body.id;
+
+ if (!id) {
return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
}
let data = await this.Model.get(ctx.request.body.id);
- if(data.uid != this.getUid()){
- if(await this.jungeProjectAuth(data.project_id) !== true){
+ if (data.uid != this.getUid()) {
+ if (await this.jungeProjectAuth(data.project_id) !== true) {
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
}
-
+
let result = await this.Model.del(id);
- ctx.body = yapi.commons.resReturn(result)
- }catch(err){
- ctx.body = yapi.commons.resReturn(null, 402, err.message)
+ ctx.body = yapi.commons.resReturn(result);
+ } catch (err) {
+ ctx.body = yapi.commons.resReturn(null, 402, err.message);
}
}
}
diff --git a/server/models/interface.js b/server/models/interface.js
index 0f760aa0..f5c4e1c9 100644
--- a/server/models/interface.js
+++ b/server/models/interface.js
@@ -82,10 +82,11 @@ class interfaceModel extends baseModel {
_id: id
});
}
+
up(id, data) {
data.up_time = yapi.commons.time();
return this.model.update({
- _id: id,
+ _id: id
}, data, { runValidators: true });
}
}
diff --git a/server/utils/commons.js b/server/utils/commons.js
index c1a719b1..360d380a 100644
--- a/server/utils/commons.js
+++ b/server/utils/commons.js
@@ -23,10 +23,18 @@ exports.log = (msg, type) => {
let f;
switch (type) {
- case 'log': f = console.log; break;
- case 'warn': f = console.warn; break;
- case 'error': f = console.error; break;
- default: f = console.log; break;
+ case 'log':
+ f = console.log;
+ break;
+ case 'warn':
+ f = console.warn;
+ break;
+ case 'error':
+ f = console.error;
+ break;
+ default:
+ f = console.log;
+ break;
}
f(type + ':', msg);
@@ -204,8 +212,10 @@ exports.handleParams = (params, keys) => {
var filter = keys[key];
if (params[key]) {
switch (filter) {
- case 'string': params[key] = trim(params[key] + ''); break;
- case 'number': params[key] = parseInt(params[key], 10); break;
+ case 'string': params[key] = trim(params[key] + '');
+ break;
+ case 'number': params[key] = parseInt(params[key], 10);
+ break;
default: params[key] = trim(params + '');
}
}
diff --git a/server/utils/db.js b/server/utils/db.js
index 1a705e77..a427a0cf 100644
--- a/server/utils/db.js
+++ b/server/utils/db.js
@@ -2,8 +2,8 @@ import mongoose from 'mongoose';
import yapi from '../yapi.js';
import autoIncrement from 'mongoose-auto-increment';
-function model(model, schema){
- if(schema instanceof mongoose.Schema === false){
+function model(model, schema) {
+ if (schema instanceof mongoose.Schema === false) {
schema = new mongoose.Schema(schema);
}
@@ -12,20 +12,20 @@ function model(model, schema){
return yapi.connect.model(model, schema, model);
}
-function connect(){
+function connect() {
mongoose.Promise = global.Promise;
let config = yapi.WEBCONFIG;
let options = {};
- if(config.user){
- options.user = config.db.user,
+ if (config.user) {
+ options.user = config.db.user;
options.pass = config.db.pass;
}
-
+
let db = mongoose.connect(`mongodb://${config.db.servername}:${config.db.port}/${config.db.DATABASE}`, options);
- db.then(function (res) {
+ db.then(function () {
yapi.commons.log('mongodb load success...');
}, function (err) {
yapi.commons.log(err, 'Mongo connect error');
@@ -37,7 +37,7 @@ function connect(){
yapi.db = model;
-module.exports = {
+module.exports = {
model: model,
connect: connect
};
\ No newline at end of file
diff --git a/server_dist/controllers/base.js b/server_dist/controllers/base.js
index 16423ac4..9b0c96bc 100644
--- a/server_dist/controllers/base.js
+++ b/server_dist/controllers/base.js
@@ -85,7 +85,7 @@ var baseController = function () {
}()
}, {
key: 'getUid',
- value: function getUid(ctx) {
+ value: function getUid() {
return parseInt(this.$uid, 10);
}
}, {
diff --git a/server_dist/controllers/group.js b/server_dist/controllers/group.js
index 1b1f3e79..39c95071 100644
--- a/server_dist/controllers/group.js
+++ b/server_dist/controllers/group.js
@@ -50,7 +50,6 @@ var _project2 = _interopRequireDefault(_project);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-//
var groupController = function (_baseController) {
(0, _inherits3.default)(groupController, _baseController);
@@ -83,6 +82,7 @@ var groupController = function (_baseController) {
case 0:
params = ctx.request.body;
+
params = _yapi2.default.commons.handleParams(params, {
group_name: 'string',
group_desc: 'string'
@@ -133,6 +133,7 @@ var groupController = function (_baseController) {
case 16:
result = _context.sent;
+
result = _yapi2.default.commons.fieldSelect(result, ['_id', 'group_name', 'group_desc', 'uid']);
ctx.body = _yapi2.default.commons.resReturn(result);
_context.next = 24;
@@ -280,7 +281,7 @@ var groupController = function (_baseController) {
_context3.prev = 19;
_context3.t0 = _context3['catch'](2);
- ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
+ ctx.body = _yapi2.default.commons.resReturn(null, 402, _context3.t0.message);
case 22:
case 'end':
@@ -358,7 +359,7 @@ var groupController = function (_baseController) {
_context4.prev = 16;
_context4.t0 = _context4['catch'](2);
- ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
+ ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
case 19:
case 'end':
diff --git a/server_dist/controllers/interface.js b/server_dist/controllers/interface.js
index 039bd5ad..1a6941c4 100644
--- a/server_dist/controllers/interface.js
+++ b/server_dist/controllers/interface.js
@@ -94,6 +94,7 @@ var interfaceController = function (_baseController) {
case 0:
params = ctx.request.body;
+
params = _yapi2.default.commons.handleParams(params, {
project_id: 'number',
title: 'string',
@@ -160,8 +161,12 @@ var interfaceController = function (_baseController) {
};
- 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.req_params_form) {
+ data.req_params_form = params.req_params_form;
+ }
+ if (params.req_params_other) {
+ data.req_params_other = params.req_params_other;
+ }
_context.next = 22;
return this.Model.save(data);
@@ -301,7 +306,7 @@ var interfaceController = function (_baseController) {
_context3.prev = 10;
_context3.t0 = _context3['catch'](3);
- ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
+ ctx.body = _yapi2.default.commons.resReturn(null, 402, _context3.t0.message);
case 13:
case 'end':
@@ -356,6 +361,7 @@ var interfaceController = function (_baseController) {
case 0:
params = ctx.request.body;
+
params = _yapi2.default.commons.handleParams(params, {
title: 'string',
path: 'string',
@@ -364,6 +370,7 @@ var interfaceController = function (_baseController) {
});
params.method = params.method || 'GET';
params.method = params.method.toUpperCase();
+
id = ctx.request.body.id;
if (id) {
@@ -412,18 +419,36 @@ var interfaceController = function (_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.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_headers) {
+ data.req_headers = params.req_headers;
+ }
- 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.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;
+ if (params.res_body_type) {
+ data.res_body_type = params.res_body_type;
+ }
+ if (params.res_body) {
+ data.res_body = params.res_body;
+ }
_context4.prev = 28;
_context4.next = 31;
diff --git a/server_dist/utils/commons.js b/server_dist/utils/commons.js
index c43f49ee..792f05ab 100644
--- a/server_dist/utils/commons.js
+++ b/server_dist/utils/commons.js
@@ -47,13 +47,17 @@ exports.log = function (msg, type) {
switch (type) {
case 'log':
- f = console.log;break;
+ f = console.log;
+ break;
case 'warn':
- f = console.warn;break;
+ f = console.warn;
+ break;
case 'error':
- f = console.error;break;
+ f = console.error;
+ break;
default:
- f = console.log;break;
+ f = console.log;
+ break;
}
f(type + ':', msg);
@@ -231,9 +235,11 @@ exports.handleParams = function (params, keys) {
if (params[key]) {
switch (filter) {
case 'string':
- params[key] = trim(params[key] + '');break;
+ params[key] = trim(params[key] + '');
+ break;
case 'number':
- params[key] = parseInt(params[key], 10);break;
+ params[key] = parseInt(params[key], 10);
+ break;
default:
params[key] = trim(params + '');
}
diff --git a/server_dist/utils/db.js b/server_dist/utils/db.js
index cb66a49a..21aae9bd 100644
--- a/server_dist/utils/db.js
+++ b/server_dist/utils/db.js
@@ -31,12 +31,13 @@ function connect() {
var options = {};
if (config.user) {
- options.user = config.db.user, options.pass = config.db.pass;
+ options.user = config.db.user;
+ options.pass = config.db.pass;
}
var db = _mongoose2.default.connect('mongodb://' + config.db.servername + ':' + config.db.port + '/' + config.db.DATABASE, options);
- db.then(function (res) {
+ db.then(function () {
_yapi2.default.commons.log('mongodb load success...');
}, function (err) {
_yapi2.default.commons.log(err, 'Mongo connect error');