mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-24 13:14:16 +08:00
feat: del prd_host and perfect the interface edit style
This commit is contained in:
parent
9bba7a6ec1
commit
aabc83ac57
@ -58,7 +58,6 @@ class ProjectList extends Component {
|
||||
const { form, addProject } = this.props;
|
||||
e.preventDefault();
|
||||
form.validateFields((err, values) => {
|
||||
console.log(values);
|
||||
if (!err) {
|
||||
values.protocol = this.state.protocol.split(':')[0];
|
||||
|
||||
@ -110,6 +109,7 @@ class ProjectList extends Component {
|
||||
label="所属分组"
|
||||
>
|
||||
{getFieldDecorator('group_id', {
|
||||
initialValue: this.state.groupList.length > 0? this.state.groupList[0]._id.toString() : null ,
|
||||
rules: [{
|
||||
required: true, message: '请选择项目所属的分组!'
|
||||
}]
|
||||
@ -122,37 +122,12 @@ class ProjectList extends Component {
|
||||
|
||||
<hr className="breakline" />
|
||||
|
||||
<FormItem
|
||||
{...formItemLayout}
|
||||
label={(
|
||||
<span>
|
||||
线上域名
|
||||
<Tooltip title="将根据配置的线上域名访问mock数据">
|
||||
<Icon type="question-circle-o" />
|
||||
</Tooltip>
|
||||
</span>
|
||||
)}
|
||||
>
|
||||
{getFieldDecorator('prd_host', {
|
||||
rules: [{
|
||||
required: true,
|
||||
message: '请输入项目线上域名!'
|
||||
}]
|
||||
})(
|
||||
<Input addonBefore={(
|
||||
<Select defaultValue="http://" onChange={this.protocolChange}>
|
||||
<Option value="http://">{'http:\/\/'}</Option>
|
||||
<Option value="https://">{'https:\/\/'}</Option>
|
||||
</Select>)} />
|
||||
)}
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
{...formItemLayout}
|
||||
label={(
|
||||
<span>
|
||||
基本路径
|
||||
<Tooltip title="基本路径为空是根路径">
|
||||
<Tooltip title="接口基本路径,为空是根路径">
|
||||
<Icon type="question-circle-o" />
|
||||
</Tooltip>
|
||||
</span>
|
||||
|
@ -10,7 +10,8 @@ import './Edit.scss'
|
||||
@connect(
|
||||
state => {
|
||||
return {
|
||||
curdata: state.inter.curdata
|
||||
curdata: state.inter.curdata,
|
||||
currProject: state.project.currProject
|
||||
}
|
||||
},{
|
||||
updateInterfaceData
|
||||
@ -20,9 +21,18 @@ import './Edit.scss'
|
||||
class InterfaceEdit extends Component{
|
||||
static propTypes = {
|
||||
curdata: PropTypes.object,
|
||||
currProject:PropTypes.object,
|
||||
updateInterfaceData: PropTypes.func
|
||||
}
|
||||
|
||||
constructor(props){
|
||||
super(props)
|
||||
const {curdata, currProject} = this.props;
|
||||
this.state = {
|
||||
mockUrl: location.protocol + '//' + location.hostname + (location.port !== "" ? ":" + location.port : "") + `/mock/${currProject._id}${currProject.basepath}/${curdata.path}`
|
||||
}
|
||||
}
|
||||
|
||||
onSubmit =async (params)=>{
|
||||
params.id = params._id = this.props.curdata._id;
|
||||
let result =await axios.post('/api/interface/up', params);
|
||||
@ -31,14 +41,12 @@ class InterfaceEdit extends Component{
|
||||
message.success('保存成功');
|
||||
}else{
|
||||
message.success(result.data.errmsg)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
render(){
|
||||
return <div className="interface-edit">
|
||||
<InterfaceEditForm onSubmit={this.onSubmit} curdata={this.props.curdata} />
|
||||
<InterfaceEditForm mockUrl={this.state.mockUrl} basepath={this.props.currProject.basepath} onSubmit={this.onSubmit} curdata={this.props.curdata} />
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
@ -3,4 +3,9 @@
|
||||
.interface-edit-item{
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.interface-edit-del-icon{
|
||||
margin-top: 4px;
|
||||
margin-left: 5px;
|
||||
cursor: pointer
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import {
|
||||
} from 'antd';
|
||||
const FormItem = Form.Item;
|
||||
const Option = Select.Option;
|
||||
const InputGroup = Input.Group;
|
||||
const RadioGroup = Radio.Group;
|
||||
const dataTpl = {
|
||||
req_query: { name: "", required: "1", desc: "" },
|
||||
@ -20,7 +21,9 @@ class InterfaceEditForm extends Component {
|
||||
static propTypes = {
|
||||
form: PropTypes.object,
|
||||
curdata: PropTypes.object,
|
||||
onSubmit: PropTypes.func
|
||||
mockUrl: PropTypes.string,
|
||||
onSubmit: PropTypes.func,
|
||||
basepath: PropTypes.string
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
@ -53,7 +56,8 @@ class InterfaceEditForm extends Component {
|
||||
res_body_type: 'json',
|
||||
res_body: '',
|
||||
desc: '',
|
||||
res_body_mock: ''
|
||||
res_body_mock: '',
|
||||
mockUrl: this.props.mockUrl
|
||||
}, curdata)
|
||||
}
|
||||
|
||||
@ -80,17 +84,23 @@ class InterfaceEditForm extends Component {
|
||||
}
|
||||
})
|
||||
|
||||
mockEditor({
|
||||
let resBodyEditor = mockEditor({
|
||||
container: 'res_body_json',
|
||||
data: that.state.res_body,
|
||||
onChange: function (d) {
|
||||
|
||||
|
||||
that.setState({
|
||||
res_body: d.text,
|
||||
res_body_mock: d.mockText
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
that.setState({
|
||||
res_body_mock: resBodyEditor.curData.mockText
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
addParams = (name) => {
|
||||
@ -116,16 +126,7 @@ class InterfaceEditForm extends Component {
|
||||
labelCol: { span: 4 },
|
||||
wrapperCol: { span: 18 }
|
||||
};
|
||||
const prefixSelector = getFieldDecorator('method', {
|
||||
initialValue: 'GET'
|
||||
})(
|
||||
<Select style={{ width: 75 }}>
|
||||
<Option value="GET">GET</Option>
|
||||
<Option value="POST">POST</Option>
|
||||
<Option value="PUT">PUT</Option>
|
||||
<Option value="DELETE">DELETE</Option>
|
||||
</Select>
|
||||
);
|
||||
|
||||
|
||||
const queryTpl = (data, index) => {
|
||||
return <Row key={index}>
|
||||
@ -154,7 +155,7 @@ class InterfaceEditForm extends Component {
|
||||
)}
|
||||
</Col>
|
||||
<Col span="2" >
|
||||
<Icon type="delete" onClick={() => this.delParams(index, 'req_query')} />
|
||||
<Icon type="delete" className="interface-edit-del-icon" onClick={() => this.delParams(index, 'req_query')} />
|
||||
</Col>
|
||||
|
||||
</Row>
|
||||
@ -184,7 +185,7 @@ class InterfaceEditForm extends Component {
|
||||
)}
|
||||
</Col>
|
||||
<Col span="2" >
|
||||
<Icon type="delete" onClick={() => this.delParams(index, 'req_headers')} />
|
||||
<Icon type="delete" className="interface-edit-del-icon" onClick={() => this.delParams(index, 'req_headers')} />
|
||||
</Col>
|
||||
|
||||
</Row>
|
||||
@ -193,11 +194,11 @@ class InterfaceEditForm extends Component {
|
||||
const requestBodyTpl = (data, index) => {
|
||||
return <Row key={index}>
|
||||
<Col span="8">
|
||||
{getFieldDecorator('req_body_form[' + index + '].name',{
|
||||
{getFieldDecorator('req_body_form[' + index + '].name', {
|
||||
initialValue: data.name
|
||||
})(
|
||||
<Input placeholder="name" />
|
||||
)}
|
||||
)}
|
||||
</Col>
|
||||
<Col span="4" >
|
||||
{getFieldDecorator('req_body_form[' + index + '].type', {
|
||||
@ -210,14 +211,14 @@ class InterfaceEditForm extends Component {
|
||||
)}
|
||||
</Col>
|
||||
<Col span="8">
|
||||
{getFieldDecorator('req_body_form[' + index + '].desc',{
|
||||
{getFieldDecorator('req_body_form[' + index + '].desc', {
|
||||
initialValue: data.desc
|
||||
})(
|
||||
<Input placeholder="备注" />
|
||||
)}
|
||||
)}
|
||||
</Col>
|
||||
<Col span="2" >
|
||||
<Icon type="delete" onClick={() => this.delParams(index, 'req_body_form')} />
|
||||
<Icon type="delete" className="interface-edit-del-icon" onClick={() => this.delParams(index, 'req_body_form')} />
|
||||
</Col>
|
||||
</Row>
|
||||
}
|
||||
@ -262,7 +263,25 @@ class InterfaceEditForm extends Component {
|
||||
required: true, message: '清输入接口路径!'
|
||||
}]
|
||||
})(
|
||||
<Input addonBefore={prefixSelector} placeholder="/path" />
|
||||
<InputGroup compact>
|
||||
{getFieldDecorator('method', {
|
||||
initialValue: 'GET'
|
||||
})(
|
||||
<Select style={{ width: "75px" }}>
|
||||
<Option value="GET">GET</Option>
|
||||
<Option value="POST">POST</Option>
|
||||
<Option value="PUT">PUT</Option>
|
||||
<Option value="DELETE">DELETE</Option>
|
||||
</Select>
|
||||
)}
|
||||
<Input value={this.props.basepath} readOnly onChange={() => { }} style={{ width: '100px', marginRight: "10px", marginLeft: "10px" }} />
|
||||
{getFieldDecorator('path', {
|
||||
initialValue: this.state.path
|
||||
})(
|
||||
<Input placeholder="/path" style={{ width: '350px' }} />
|
||||
)}
|
||||
</InputGroup>
|
||||
|
||||
)}
|
||||
</FormItem>
|
||||
|
||||
@ -358,7 +377,7 @@ class InterfaceEditForm extends Component {
|
||||
|
||||
|
||||
<Row className="interface-edit-item" style={{ display: this.props.form.getFieldValue('req_body_type') === 'json' ? 'block' : 'none' }}>
|
||||
<Col span={18} offset={4} id="req_body_json" style={{ minHeight: "300px"}}>
|
||||
<Col span={18} offset={4} id="req_body_json" style={{ minHeight: "300px" }}>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
@ -403,8 +422,8 @@ class InterfaceEditForm extends Component {
|
||||
|
||||
</FormItem>
|
||||
<Row className="interface-edit-item" style={{ display: this.props.form.getFieldValue('res_body_type') === 'json' ? 'block' : 'none' }}>
|
||||
|
||||
<Col span={18} offset={4} id="res_body_json" style={{ minHeight: "300px" }}>
|
||||
|
||||
<Col span={18} offset={4} id="res_body_json" style={{ minHeight: "300px" }}>
|
||||
|
||||
</Col>
|
||||
</Row>
|
||||
@ -413,13 +432,22 @@ class InterfaceEditForm extends Component {
|
||||
style={{ display: this.props.form.getFieldValue('res_body_type') === 'json' ? 'block' : 'none' }}
|
||||
className="interface-edit-item"
|
||||
{...formItemLayout}
|
||||
label="mock预览"
|
||||
label="mock地址"
|
||||
>
|
||||
<pre style={{backgroundColor: "#eee", lineHeight: "20px"}}>
|
||||
<Input onChange={() => { }} value={this.state.mockUrl} />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
style={{ display: this.props.form.getFieldValue('res_body_type') === 'json' ? 'block' : 'none' }}
|
||||
className="interface-edit-item"
|
||||
{...formItemLayout}
|
||||
label="预览"
|
||||
>
|
||||
<pre style={{ backgroundColor: "#eee", lineHeight: "20px" }}>
|
||||
{this.state.res_body_mock || " "}
|
||||
</pre>
|
||||
</FormItem>
|
||||
|
||||
|
||||
|
||||
<Row className="interface-edit-item" style={{ display: this.props.form.getFieldValue('res_body_type') === 'raw' ? 'block' : 'none' }}>
|
||||
<Col span={18} offset={4} >
|
||||
|
@ -12,7 +12,7 @@ import { Setting } from './Setting/Setting.js'
|
||||
@connect(
|
||||
state => {
|
||||
return {
|
||||
curProject: state.project.curProject
|
||||
curProject: state.project.currProject
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -64,7 +64,8 @@ export default (state = initialState, action) => {
|
||||
case FETCH_INTERFACE_LIST:
|
||||
return {
|
||||
...state,
|
||||
list: action.payload.data
|
||||
list: action.payload.data,
|
||||
curdata: action.payload.data.length > 0 ? action.payload.data[0] : {}
|
||||
}
|
||||
default:
|
||||
return state
|
||||
|
@ -24,15 +24,13 @@ const initialState = {
|
||||
export default (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case GET_LOGIN_STATE: {
|
||||
console.log(action.payload.data);
|
||||
return {
|
||||
...state,
|
||||
isLogin: (action.payload.data.errcode == 0),
|
||||
role: action.payload.data.data ? action.payload.data.data.role:null,
|
||||
loginState: (action.payload.data.errcode == 0)?MEMBER_STATUS:GUEST_STATUS,
|
||||
userName: action.payload.data.data ? action.payload.data.data.username : null,
|
||||
uid: action.payload.data.data ? action.payload.data.data._id : null,
|
||||
server_ip: action.payload.data.data ? action.payload.data.data.server_ip:null
|
||||
uid: action.payload.data.data ? action.payload.data.data._id : null
|
||||
};
|
||||
}
|
||||
case LOGIN: {
|
||||
@ -42,8 +40,7 @@ export default (state = initialState, action) => {
|
||||
isLogin: true,
|
||||
loginState: MEMBER_STATUS,
|
||||
uid: action.payload.data.data.uid,
|
||||
userName: action.payload.data.data.username,
|
||||
server_ip: action.payload.data.data.server_ip
|
||||
userName: action.payload.data.data.username
|
||||
};
|
||||
} else {
|
||||
return state;
|
||||
|
@ -45,8 +45,6 @@ class projectController extends baseController {
|
||||
* @foldnumber 10
|
||||
* @param {String} name 项目名称,不能为空
|
||||
* @param {String} basepath 项目基本路径,不能为空
|
||||
* @param {String} prd_host 项目线上域名,不能为空。可通过配置的域名访问到mock数据
|
||||
* @param {String} protocol 线上域名协议,不能为空
|
||||
* @param {Number} group_id 项目分组id,不能为空
|
||||
* @param {String} project_type private public
|
||||
* @param {String} [desc] 项目描述
|
||||
@ -58,8 +56,6 @@ class projectController extends baseController {
|
||||
params = yapi.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
basepath: 'string',
|
||||
prd_host: 'string',
|
||||
protocol: 'string',
|
||||
group_id: 'number',
|
||||
desc: 'string'
|
||||
});
|
||||
@ -82,35 +78,16 @@ class projectController extends baseController {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名');
|
||||
}
|
||||
|
||||
|
||||
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格式有误');
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
|
||||
let data = {
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
prd_host: params.prd_host,
|
||||
basepath: params.basepath,
|
||||
protocol: params.protocol || 'http',
|
||||
members: [],
|
||||
project_type: params.project_type || 'private',
|
||||
uid: this.getUid(),
|
||||
@ -426,7 +403,6 @@ class projectController extends baseController {
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @param {String} name 项目名称,不能为空
|
||||
* @param {String} basepath 项目基本路径,不能为空
|
||||
* @param {String} prd_host 项目线上域名,不能为空。可通过配置的域名访问到mock数据
|
||||
* @param {String} [desc] 项目描述
|
||||
* @param {Array} [env] 项目环境配置
|
||||
* @param {String} [env[].name] 环境名称
|
||||
@ -443,8 +419,6 @@ class projectController extends baseController {
|
||||
params = yapi.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
basepath: 'string',
|
||||
prd_host: 'string',
|
||||
protocol: 'string',
|
||||
group_id: 'number',
|
||||
desc: 'string'
|
||||
});
|
||||
@ -462,17 +436,9 @@ class projectController extends baseController {
|
||||
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;
|
||||
}
|
||||
if (projectData.basepath === params.basepath && projectData.prd_host === params.prd_host) {
|
||||
delete params.basepath;
|
||||
delete params.prd_host;
|
||||
}
|
||||
|
||||
if (params.name) {
|
||||
let checkRepeat = await this.Model.checkNameRepeat(params.name);
|
||||
@ -481,24 +447,15 @@ class projectController extends baseController {
|
||||
}
|
||||
}
|
||||
|
||||
if (params.basepath && params.prd_host) {
|
||||
let checkRepeatDomain = await this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
||||
if (checkRepeatDomain > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
|
||||
}
|
||||
}
|
||||
|
||||
let data = {
|
||||
up_time: yapi.commons.time()
|
||||
};
|
||||
|
||||
if (params.name) data.name = params.name;
|
||||
if (params.desc) data.desc = params.desc;
|
||||
if (params.prd_host ) {
|
||||
data.prd_host = params.prd_host;
|
||||
if (params.basepath ) {
|
||||
data.basepath = params.basepath;
|
||||
}
|
||||
if (params.protocol) data.protocol = params.protocol;
|
||||
if (params.env) data.env = params.env;
|
||||
|
||||
let result = await this.Model.up(id, data);
|
||||
@ -550,7 +507,6 @@ class projectController extends baseController {
|
||||
'members',
|
||||
{ key: 'group_id', alias: 'groupId' },
|
||||
{ key: 'up_time', alias: 'upTime' },
|
||||
{ key: 'prd_host', alias: 'prdHost' },
|
||||
{ key: 'add_time', alias: 'addTime' }
|
||||
];
|
||||
let groupRules = [
|
||||
|
@ -17,8 +17,6 @@ class projectModel extends baseModel {
|
||||
members: [
|
||||
{uid: Number, role: {type: String, enum:['owner', 'dev']},username: String, email: String}
|
||||
],
|
||||
protocol: { type: String, required: true },
|
||||
prd_host: { type: String, required: true },
|
||||
env: [
|
||||
{ name: String, domain: String }
|
||||
],
|
||||
@ -60,7 +58,7 @@ class projectModel extends baseModel {
|
||||
list(group_id, auth) {
|
||||
let params = {group_id: group_id}
|
||||
if(!auth) params.project_type = 'public';
|
||||
return this.model.find(params).select("_id uid name basepath desc group_id project_type protocol prd_host env add_time up_time").sort({ _id: -1 }).exec();
|
||||
return this.model.find(params).select("_id uid name basepath desc group_id project_type env add_time up_time").sort({ _id: -1 }).exec();
|
||||
}
|
||||
|
||||
listWithPaging(group_id, page, limit) {
|
||||
|
@ -116,8 +116,6 @@ var projectController = function (_baseController) {
|
||||
* @foldnumber 10
|
||||
* @param {String} name 项目名称,不能为空
|
||||
* @param {String} basepath 项目基本路径,不能为空
|
||||
* @param {String} prd_host 项目线上域名,不能为空。可通过配置的域名访问到mock数据
|
||||
* @param {String} protocol 线上域名协议,不能为空
|
||||
* @param {Number} group_id 项目分组id,不能为空
|
||||
* @param {String} project_type private public
|
||||
* @param {String} [desc] 项目描述
|
||||
@ -129,7 +127,7 @@ var projectController = function (_baseController) {
|
||||
key: 'add',
|
||||
value: function () {
|
||||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
|
||||
var params, checkRepeat, checkRepeatDomain, data, result, username;
|
||||
var params, checkRepeat, data, result, username;
|
||||
return _regenerator2.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
@ -139,8 +137,6 @@ var projectController = function (_baseController) {
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
basepath: 'string',
|
||||
prd_host: 'string',
|
||||
protocol: 'string',
|
||||
group_id: 'number',
|
||||
desc: 'string'
|
||||
});
|
||||
@ -189,53 +185,21 @@ var projectController = function (_baseController) {
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
|
||||
|
||||
case 16:
|
||||
if (params.prd_host) {
|
||||
_context.next = 18;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目domain不能为空'));
|
||||
|
||||
case 18:
|
||||
|
||||
params.basepath = params.basepath || '';
|
||||
|
||||
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
|
||||
_context.next = 21;
|
||||
_context.next = 19;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
|
||||
|
||||
case 21:
|
||||
if (this.verifyDomain(params.prd_host)) {
|
||||
_context.next = 23;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误'));
|
||||
|
||||
case 23:
|
||||
_context.next = 25;
|
||||
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
||||
|
||||
case 25:
|
||||
checkRepeatDomain = _context.sent;
|
||||
|
||||
if (!(checkRepeatDomain > 0)) {
|
||||
_context.next = 28;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
|
||||
|
||||
case 28:
|
||||
case 19:
|
||||
data = {
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
prd_host: params.prd_host,
|
||||
basepath: params.basepath,
|
||||
protocol: params.protocol || 'http',
|
||||
members: [],
|
||||
project_type: params.project_type || 'private',
|
||||
uid: this.getUid(),
|
||||
@ -243,14 +207,14 @@ var projectController = function (_baseController) {
|
||||
add_time: _yapi2.default.commons.time(),
|
||||
up_time: _yapi2.default.commons.time()
|
||||
};
|
||||
_context.prev = 29;
|
||||
_context.next = 32;
|
||||
_context.prev = 20;
|
||||
_context.next = 23;
|
||||
return this.Model.save(data);
|
||||
|
||||
case 32:
|
||||
case 23:
|
||||
result = _context.sent;
|
||||
username = this.getUsername();
|
||||
_context.next = 36;
|
||||
_context.next = 27;
|
||||
return this.logModel.save({
|
||||
content: '\u7528\u6237' + username + '\u6DFB\u52A0\u4E86\u9879\u76EE' + params.name,
|
||||
type: 'project',
|
||||
@ -259,23 +223,23 @@ var projectController = function (_baseController) {
|
||||
typeid: params.group_id
|
||||
});
|
||||
|
||||
case 36:
|
||||
case 27:
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context.next = 42;
|
||||
_context.next = 33;
|
||||
break;
|
||||
|
||||
case 39:
|
||||
_context.prev = 39;
|
||||
_context.t1 = _context['catch'](29);
|
||||
case 30:
|
||||
_context.prev = 30;
|
||||
_context.t1 = _context['catch'](20);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t1.message);
|
||||
|
||||
case 42:
|
||||
case 33:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, this, [[29, 39]]);
|
||||
}, _callee, this, [[20, 30]]);
|
||||
}));
|
||||
|
||||
function add(_x) {
|
||||
@ -1022,7 +986,6 @@ var projectController = function (_baseController) {
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @param {String} name 项目名称,不能为空
|
||||
* @param {String} basepath 项目基本路径,不能为空
|
||||
* @param {String} prd_host 项目线上域名,不能为空。可通过配置的域名访问到mock数据
|
||||
* @param {String} [desc] 项目描述
|
||||
* @param {Array} [env] 项目环境配置
|
||||
* @param {String} [env[].name] 环境名称
|
||||
@ -1035,7 +998,7 @@ var projectController = function (_baseController) {
|
||||
key: 'up',
|
||||
value: function () {
|
||||
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
|
||||
var _id2, params, projectData, checkRepeat, checkRepeatDomain, data, result, username;
|
||||
var _id2, params, projectData, checkRepeat, data, result, username;
|
||||
|
||||
return _regenerator2.default.wrap(function _callee10$(_context10) {
|
||||
while (1) {
|
||||
@ -1049,8 +1012,6 @@ var projectController = function (_baseController) {
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
basepath: 'string',
|
||||
prd_host: 'string',
|
||||
protocol: 'string',
|
||||
group_id: 'number',
|
||||
desc: 'string'
|
||||
});
|
||||
@ -1091,61 +1052,30 @@ var projectController = function (_baseController) {
|
||||
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
|
||||
|
||||
case 17:
|
||||
if (this.verifyDomain(params.prd_host)) {
|
||||
_context10.next = 19;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误'));
|
||||
|
||||
case 19:
|
||||
|
||||
if (projectData.name === params.name) {
|
||||
delete params.name;
|
||||
}
|
||||
if (projectData.basepath === params.basepath && projectData.prd_host === params.prd_host) {
|
||||
delete params.basepath;
|
||||
delete params.prd_host;
|
||||
}
|
||||
|
||||
if (!params.name) {
|
||||
_context10.next = 27;
|
||||
_context10.next = 24;
|
||||
break;
|
||||
}
|
||||
|
||||
_context10.next = 24;
|
||||
_context10.next = 21;
|
||||
return this.Model.checkNameRepeat(params.name);
|
||||
|
||||
case 24:
|
||||
case 21:
|
||||
checkRepeat = _context10.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context10.next = 27;
|
||||
_context10.next = 24;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
|
||||
|
||||
case 27:
|
||||
if (!(params.basepath && params.prd_host)) {
|
||||
_context10.next = 33;
|
||||
break;
|
||||
}
|
||||
|
||||
_context10.next = 30;
|
||||
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
||||
|
||||
case 30:
|
||||
checkRepeatDomain = _context10.sent;
|
||||
|
||||
if (!(checkRepeatDomain > 0)) {
|
||||
_context10.next = 33;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
|
||||
|
||||
case 33:
|
||||
case 24:
|
||||
data = {
|
||||
up_time: _yapi2.default.commons.time()
|
||||
};
|
||||
@ -1153,20 +1083,18 @@ var projectController = function (_baseController) {
|
||||
|
||||
if (params.name) data.name = params.name;
|
||||
if (params.desc) data.desc = params.desc;
|
||||
if (params.prd_host) {
|
||||
data.prd_host = params.prd_host;
|
||||
if (params.basepath) {
|
||||
data.basepath = params.basepath;
|
||||
}
|
||||
if (params.protocol) data.protocol = params.protocol;
|
||||
if (params.env) data.env = params.env;
|
||||
|
||||
_context10.next = 41;
|
||||
_context10.next = 31;
|
||||
return this.Model.up(_id2, data);
|
||||
|
||||
case 41:
|
||||
case 31:
|
||||
result = _context10.sent;
|
||||
username = this.getUsername();
|
||||
_context10.next = 45;
|
||||
_context10.next = 35;
|
||||
return this.logModel.save({
|
||||
content: '\u7528\u6237' + username + '\u66F4\u65B0\u4E86\u9879\u76EE' + params.name,
|
||||
type: 'project',
|
||||
@ -1175,24 +1103,24 @@ var projectController = function (_baseController) {
|
||||
typeid: _id2
|
||||
});
|
||||
|
||||
case 45:
|
||||
case 35:
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context10.next = 51;
|
||||
_context10.next = 41;
|
||||
break;
|
||||
|
||||
case 48:
|
||||
_context10.prev = 48;
|
||||
case 38:
|
||||
_context10.prev = 38;
|
||||
_context10.t1 = _context10['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context10.t1.message);
|
||||
|
||||
case 51:
|
||||
case 41:
|
||||
case 'end':
|
||||
return _context10.stop();
|
||||
}
|
||||
}
|
||||
}, _callee10, this, [[0, 48]]);
|
||||
}, _callee10, this, [[0, 38]]);
|
||||
}));
|
||||
|
||||
function up(_x11) {
|
||||
@ -1250,7 +1178,7 @@ var projectController = function (_baseController) {
|
||||
|
||||
case 10:
|
||||
groupList = _context11.sent;
|
||||
projectRules = ['_id', 'name', 'basepath', 'uid', 'env', 'members', { key: 'group_id', alias: 'groupId' }, { key: 'up_time', alias: 'upTime' }, { key: 'prd_host', alias: 'prdHost' }, { key: 'add_time', alias: 'addTime' }];
|
||||
projectRules = ['_id', 'name', 'basepath', 'uid', 'env', 'members', { key: 'group_id', alias: 'groupId' }, { key: 'up_time', alias: 'upTime' }, { key: 'add_time', alias: 'addTime' }];
|
||||
groupRules = ['_id', 'uid', { key: 'group_name', alias: 'groupName' }, { key: 'group_desc', alias: 'groupDesc' }, { key: 'add_time', alias: 'addTime' }, { key: 'up_time', alias: 'upTime' }];
|
||||
|
||||
|
||||
|
@ -54,8 +54,6 @@ var projectModel = function (_baseModel) {
|
||||
group_id: { type: Number, required: true },
|
||||
project_type: { type: String, required: true, enum: ['public', 'private'] },
|
||||
members: [{ uid: Number, role: { type: String, enum: ['owner', 'dev'] }, username: String, email: String }],
|
||||
protocol: { type: String, required: true },
|
||||
prd_host: { type: String, required: true },
|
||||
env: [{ name: String, domain: String }],
|
||||
add_time: Number,
|
||||
up_time: Number
|
||||
@ -101,7 +99,7 @@ var projectModel = function (_baseModel) {
|
||||
value: function list(group_id, auth) {
|
||||
var params = { group_id: group_id };
|
||||
if (!auth) params.project_type = 'public';
|
||||
return this.model.find(params).select("_id uid name basepath desc group_id project_type protocol prd_host env add_time up_time").sort({ _id: -1 }).exec();
|
||||
return this.model.find(params).select("_id uid name basepath desc group_id project_type env add_time up_time").sort({ _id: -1 }).exec();
|
||||
}
|
||||
}, {
|
||||
key: 'listWithPaging',
|
||||
|
Loading…
Reference in New Issue
Block a user