mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-09 05:00:30 +08:00
Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev
This commit is contained in:
commit
86be98c721
@ -286,11 +286,18 @@ class ProjectList extends Component {
|
||||
|
||||
<FormItem
|
||||
{...formItemLayout}
|
||||
label="基本路径"
|
||||
label={(
|
||||
<span>
|
||||
基本路径
|
||||
<Tooltip title="基本路径为空是根路径">
|
||||
<Icon type="question-circle-o" />
|
||||
</Tooltip>
|
||||
</span>
|
||||
)}
|
||||
>
|
||||
{getFieldDecorator('basepath', {
|
||||
rules: [{
|
||||
required: true, message: '请输入项目基本路径'
|
||||
required: false, message: '请输入项目基本路径'
|
||||
}]
|
||||
})(
|
||||
<Input />
|
||||
@ -303,7 +310,7 @@ class ProjectList extends Component {
|
||||
>
|
||||
{getFieldDecorator('desc', {
|
||||
rules: [{
|
||||
required: true, message: '请输入描述!'
|
||||
required: false, message: '请输入描述!'
|
||||
}]
|
||||
})(
|
||||
<TextArea rows={4} />
|
||||
|
@ -52,7 +52,7 @@ class LeftMenu extends Component {
|
||||
} else {
|
||||
this._searchSign = this.searchSign;
|
||||
}
|
||||
}, 600)
|
||||
}, 60)
|
||||
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@ class LeftMenu extends Component {
|
||||
style={{ width: '100%' }}
|
||||
dataSource={dataSource.map(this.renderOption)}
|
||||
onSearch={this.handleSearch}
|
||||
placeholder="input here"
|
||||
placeholder="搜索用户"
|
||||
optionLabelProp="text"
|
||||
>
|
||||
<Input suffix={<Icon type="search" className="certain-category-icon" />} />
|
||||
|
@ -15,8 +15,8 @@ class projectController extends baseController {
|
||||
}
|
||||
|
||||
handleBasepath(basepath) {
|
||||
if (!basepath) return false;
|
||||
if (basepath === '/') return basepath;
|
||||
if (!basepath) return "";
|
||||
if (basepath === '/') return "";
|
||||
if (basepath[0] !== '/') basepath = '/' + basepath;
|
||||
if (basepath[basepath.length - 1] === '/') basepath = basepath.substr(0, basepath.length - 1);
|
||||
if (!yapi.commons.verifyPath(basepath)) {
|
||||
@ -72,13 +72,13 @@ class projectController extends baseController {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名');
|
||||
}
|
||||
|
||||
if (!params.basepath) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目basepath不能为空');
|
||||
}
|
||||
|
||||
if (!params.prd_host) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目domain不能为空');
|
||||
}
|
||||
|
||||
params.basepath = params.basepath || '';
|
||||
|
||||
if ((params.basepath = this.handleBasepath(params.basepath)) === false) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误');
|
||||
}
|
||||
@ -332,6 +332,7 @@ class projectController extends baseController {
|
||||
try {
|
||||
let id = ctx.request.body.id;
|
||||
let params = ctx.request.body;
|
||||
params.basepath = params.basepath || '';
|
||||
params = yapi.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
basepath: 'string',
|
||||
|
@ -26,10 +26,10 @@ module.exports = async (ctx, next) => {
|
||||
|
||||
for (let i = 0, l = projects.length; i < l; i++) {
|
||||
let project = projects[i];
|
||||
|
||||
if (ctx.path && ctx.path.indexOf(project.basepath) === 0) {
|
||||
matchProject.push(project);
|
||||
|
||||
if(ctx.path && project.basepath == ""){
|
||||
matchProject = project;
|
||||
}
|
||||
else if (ctx.path && ctx.path.indexOf(project.basepath) === 0) {
|
||||
if (project.basepath.length > maxBasepath) {
|
||||
maxBasepath = project.basepath.length;
|
||||
matchProject = project;
|
||||
@ -64,9 +64,17 @@ module.exports = async (ctx, next) => {
|
||||
interfaceData = interfaceData[0];
|
||||
ctx.set("Access-Control-Allow-Origin", "*")
|
||||
if (interfaceData.res_body_type === 'json') {
|
||||
return ctx.body = Mock.mock(
|
||||
yapi.commons.json_parse(interfaceData.res_body)
|
||||
);
|
||||
try{
|
||||
return ctx.body = Mock.mock(
|
||||
yapi.commons.json_parse(interfaceData.res_body)
|
||||
);
|
||||
}catch(e){
|
||||
return ctx.body = {
|
||||
errcode: 400,
|
||||
errmsg: 'mock json数据格式有误',
|
||||
data: interfaceData.res_body
|
||||
}
|
||||
}
|
||||
}
|
||||
return ctx.body = interfaceData.res_body;
|
||||
} catch (e) {
|
||||
|
@ -10,14 +10,7 @@ class projectModel extends baseModel {
|
||||
return {
|
||||
uid: { type: Number, required: true },
|
||||
name: { type: String, required: true },
|
||||
basepath: {
|
||||
type: String, required: true, validate: {
|
||||
validator: (v) => {
|
||||
return v && v[0] === '/';
|
||||
},
|
||||
message: 'basepath必须是/开头'
|
||||
}
|
||||
},
|
||||
basepath: {type: String },
|
||||
desc: String,
|
||||
group_id: { type: Number, required: true },
|
||||
members: Array,
|
||||
|
@ -74,8 +74,8 @@ var projectController = function (_baseController) {
|
||||
(0, _createClass3.default)(projectController, [{
|
||||
key: 'handleBasepath',
|
||||
value: function handleBasepath(basepath) {
|
||||
if (!basepath) return false;
|
||||
if (basepath === '/') return basepath;
|
||||
if (!basepath) return "";
|
||||
if (basepath === '/') return "";
|
||||
if (basepath[0] !== '/') basepath = '/' + basepath;
|
||||
if (basepath[basepath.length - 1] === '/') basepath = basepath.substr(0, basepath.length - 1);
|
||||
if (!_yapi2.default.commons.verifyPath(basepath)) {
|
||||
@ -159,52 +159,47 @@ var projectController = function (_baseController) {
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
|
||||
|
||||
case 11:
|
||||
if (params.basepath) {
|
||||
_context.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目basepath不能为空'));
|
||||
|
||||
case 13:
|
||||
if (params.prd_host) {
|
||||
_context.next = 15;
|
||||
_context.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目domain不能为空'));
|
||||
|
||||
case 15:
|
||||
case 13:
|
||||
|
||||
params.basepath = params.basepath || '';
|
||||
|
||||
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
|
||||
_context.next = 17;
|
||||
_context.next = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
|
||||
|
||||
case 17:
|
||||
case 16:
|
||||
if (this.verifyDomain(params.prd_host)) {
|
||||
_context.next = 19;
|
||||
_context.next = 18;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误'));
|
||||
|
||||
case 19:
|
||||
_context.next = 21;
|
||||
case 18:
|
||||
_context.next = 20;
|
||||
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
||||
|
||||
case 21:
|
||||
case 20:
|
||||
checkRepeatDomain = _context.sent;
|
||||
|
||||
if (!(checkRepeatDomain > 0)) {
|
||||
_context.next = 24;
|
||||
_context.next = 23;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
|
||||
|
||||
case 24:
|
||||
case 23:
|
||||
data = {
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
@ -217,29 +212,29 @@ var projectController = function (_baseController) {
|
||||
add_time: _yapi2.default.commons.time(),
|
||||
up_time: _yapi2.default.commons.time()
|
||||
};
|
||||
_context.prev = 25;
|
||||
_context.next = 28;
|
||||
_context.prev = 24;
|
||||
_context.next = 27;
|
||||
return this.Model.save(data);
|
||||
|
||||
case 28:
|
||||
case 27:
|
||||
result = _context.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context.next = 35;
|
||||
_context.next = 34;
|
||||
break;
|
||||
|
||||
case 32:
|
||||
_context.prev = 32;
|
||||
_context.t0 = _context['catch'](25);
|
||||
case 31:
|
||||
_context.prev = 31;
|
||||
_context.t0 = _context['catch'](24);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
|
||||
|
||||
case 35:
|
||||
case 34:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, this, [[25, 32]]);
|
||||
}, _callee, this, [[24, 31]]);
|
||||
}));
|
||||
|
||||
function add(_x) {
|
||||
@ -760,6 +755,7 @@ var projectController = function (_baseController) {
|
||||
id = ctx.request.body.id;
|
||||
params = ctx.request.body;
|
||||
|
||||
params.basepath = params.basepath || '';
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
basepath: 'string',
|
||||
@ -770,49 +766,49 @@ var projectController = function (_baseController) {
|
||||
});
|
||||
|
||||
if (id) {
|
||||
_context8.next = 6;
|
||||
_context8.next = 7;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
|
||||
|
||||
case 6:
|
||||
_context8.next = 8;
|
||||
case 7:
|
||||
_context8.next = 9;
|
||||
return this.jungeMemberAuth(id, this.getUid());
|
||||
|
||||
case 8:
|
||||
case 9:
|
||||
_context8.t0 = _context8.sent;
|
||||
|
||||
if (!(_context8.t0 !== true)) {
|
||||
_context8.next = 11;
|
||||
_context8.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
||||
|
||||
case 11:
|
||||
_context8.next = 13;
|
||||
case 12:
|
||||
_context8.next = 14;
|
||||
return this.Model.get(id);
|
||||
|
||||
case 13:
|
||||
case 14:
|
||||
projectData = _context8.sent;
|
||||
|
||||
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
|
||||
_context8.next = 16;
|
||||
_context8.next = 17;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
|
||||
|
||||
case 16:
|
||||
case 17:
|
||||
if (this.verifyDomain(params.prd_host)) {
|
||||
_context8.next = 18;
|
||||
_context8.next = 19;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误'));
|
||||
|
||||
case 18:
|
||||
case 19:
|
||||
|
||||
if (projectData.name === params.name) {
|
||||
delete params.name;
|
||||
@ -823,43 +819,43 @@ var projectController = function (_baseController) {
|
||||
}
|
||||
|
||||
if (!params.name) {
|
||||
_context8.next = 26;
|
||||
_context8.next = 27;
|
||||
break;
|
||||
}
|
||||
|
||||
_context8.next = 23;
|
||||
_context8.next = 24;
|
||||
return this.Model.checkNameRepeat(params.name);
|
||||
|
||||
case 23:
|
||||
case 24:
|
||||
checkRepeat = _context8.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context8.next = 26;
|
||||
_context8.next = 27;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
|
||||
|
||||
case 26:
|
||||
case 27:
|
||||
if (!(params.basepath && params.prd_host)) {
|
||||
_context8.next = 32;
|
||||
_context8.next = 33;
|
||||
break;
|
||||
}
|
||||
|
||||
_context8.next = 29;
|
||||
_context8.next = 30;
|
||||
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
||||
|
||||
case 29:
|
||||
case 30:
|
||||
checkRepeatDomain = _context8.sent;
|
||||
|
||||
if (!(checkRepeatDomain > 0)) {
|
||||
_context8.next = 32;
|
||||
_context8.next = 33;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
|
||||
|
||||
case 32:
|
||||
case 33:
|
||||
data = {
|
||||
uid: this.getUid(),
|
||||
up_time: _yapi2.default.commons.time()
|
||||
@ -875,28 +871,28 @@ var projectController = function (_baseController) {
|
||||
if (params.protocol) data.protocol = params.protocol;
|
||||
if (params.env) data.env = params.env;
|
||||
|
||||
_context8.next = 40;
|
||||
_context8.next = 41;
|
||||
return this.Model.up(id, data);
|
||||
|
||||
case 40:
|
||||
case 41:
|
||||
result = _context8.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context8.next = 47;
|
||||
_context8.next = 48;
|
||||
break;
|
||||
|
||||
case 44:
|
||||
_context8.prev = 44;
|
||||
case 45:
|
||||
_context8.prev = 45;
|
||||
_context8.t1 = _context8['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context8.t1.message);
|
||||
|
||||
case 47:
|
||||
case 48:
|
||||
case 'end':
|
||||
return _context8.stop();
|
||||
}
|
||||
}
|
||||
}, _callee8, this, [[0, 44]]);
|
||||
}, _callee8, this, [[0, 45]]);
|
||||
}));
|
||||
|
||||
function up(_x8) {
|
||||
|
@ -80,10 +80,9 @@ module.exports = function () {
|
||||
for (i = 0, l = projects.length; i < l; i++) {
|
||||
_project = projects[i];
|
||||
|
||||
|
||||
if (ctx.path && ctx.path.indexOf(_project.basepath) === 0) {
|
||||
matchProject.push(_project);
|
||||
|
||||
if (ctx.path && _project.basepath == "") {
|
||||
matchProject = _project;
|
||||
} else if (ctx.path && ctx.path.indexOf(_project.basepath) === 0) {
|
||||
if (_project.basepath.length > maxBasepath) {
|
||||
maxBasepath = _project.basepath.length;
|
||||
matchProject = _project;
|
||||
@ -139,26 +138,36 @@ module.exports = function () {
|
||||
ctx.set("Access-Control-Allow-Origin", "*");
|
||||
|
||||
if (!(interfaceData.res_body_type === 'json')) {
|
||||
_context.next = 41;
|
||||
_context.next = 47;
|
||||
break;
|
||||
}
|
||||
|
||||
_context.prev = 40;
|
||||
return _context.abrupt('return', ctx.body = _mockjs2.default.mock(_yapi2.default.commons.json_parse(interfaceData.res_body)));
|
||||
|
||||
case 41:
|
||||
return _context.abrupt('return', ctx.body = interfaceData.res_body);
|
||||
|
||||
case 44:
|
||||
_context.prev = 44;
|
||||
_context.t1 = _context['catch'](25);
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 409, _context.t1.message));
|
||||
_context.t1 = _context['catch'](40);
|
||||
return _context.abrupt('return', ctx.body = {
|
||||
errcode: 400,
|
||||
errmsg: 'mock json数据格式有误',
|
||||
data: interfaceData.res_body
|
||||
});
|
||||
|
||||
case 47:
|
||||
return _context.abrupt('return', ctx.body = interfaceData.res_body);
|
||||
|
||||
case 50:
|
||||
_context.prev = 50;
|
||||
_context.t2 = _context['catch'](25);
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 409, _context.t2.message));
|
||||
|
||||
case 53:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, undefined, [[10, 16], [25, 44]]);
|
||||
}, _callee, undefined, [[10, 16], [25, 50], [40, 44]]);
|
||||
}));
|
||||
|
||||
return function (_x, _x2) {
|
||||
|
@ -49,14 +49,7 @@ var projectModel = function (_baseModel) {
|
||||
return {
|
||||
uid: { type: Number, required: true },
|
||||
name: { type: String, required: true },
|
||||
basepath: {
|
||||
type: String, required: true, validate: {
|
||||
validator: function validator(v) {
|
||||
return v && v[0] === '/';
|
||||
},
|
||||
message: 'basepath必须是/开头'
|
||||
}
|
||||
},
|
||||
basepath: { type: String },
|
||||
desc: String,
|
||||
group_id: { type: Number, required: true },
|
||||
members: Array,
|
||||
|
Loading…
Reference in New Issue
Block a user