feat: 增加修改项目分组功能

This commit is contained in:
suxiaoxin 2017-10-18 20:57:32 +08:00
parent 271a5633e8
commit ce542615c2
3 changed files with 33 additions and 10 deletions

View File

@ -1,8 +1,9 @@
import React, { Component } from 'react'
import { Form, Input, Icon, Tooltip, Button, Row, Col, message, Card, Radio, Alert, Modal, Popover } from 'antd';
import { Form, Input,Select, Icon, Tooltip, Button, Row, Col, message, Card, Radio, Alert, Modal, Popover } from 'antd';
import PropTypes from 'prop-types';
import { updateProject, delProject, getProjectMsg, upsetProject } from '../../../../reducer/modules/project';
import { fetchGroupMsg } from '../../../../reducer/modules/group';
import { fetchGroupList } from '../../../../reducer/modules/group.js'
import { connect } from 'react-redux';
const { TextArea } = Input;
import { withRouter } from 'react-router';
@ -28,10 +29,13 @@ const formItemLayout = {
className: 'form-item'
};
const Option = Select.Option;
@connect(
state => {
return {
projectList: state.project.projectList,
groupList: state.group.groupList,
projectMsg: state.project.projectMsg
}
},
@ -40,7 +44,8 @@ const formItemLayout = {
delProject,
getProjectMsg,
fetchGroupMsg,
upsetProject
upsetProject,
fetchGroupList
}
)
@withRouter
@ -62,10 +67,14 @@ class ProjectMessage extends Component {
history: PropTypes.object,
fetchGroupMsg: PropTypes.func,
upsetProject: PropTypes.func,
groupList: PropTypes.array,
projectList: PropTypes.array,
projectMsg: PropTypes.object
projectMsg: PropTypes.object,
fetchGroupList: PropTypes.func
}
// 确认修改
handleOk = (e) => {
e.preventDefault();
@ -149,6 +158,7 @@ class ProjectMessage extends Component {
}
async componentWillMount() {
await this.props.fetchGroupList();
await this.props.getProjectMsg(this.props.projectId);
const groupMsg = await this.props.fetchGroupMsg(this.props.projectMsg.group_id);
this.setState({
@ -161,8 +171,8 @@ class ProjectMessage extends Component {
const { projectMsg } = this.props;
const mockUrl = location.protocol + '//' + location.hostname + (location.port !== "" ? ":" + location.port : "") + `/mock/${projectMsg._id}${projectMsg.basepath}+$接口请求路径`
let initFormValues = {};
const { name, basepath, desc, project_type } = projectMsg;
initFormValues = { name, basepath, desc, project_type };
const { name, basepath, desc, project_type, group_id } = projectMsg;
initFormValues = { name, basepath, desc, project_type, group_id };
const colorArr = entries(constants.PROJECT_COLOR);
const colorSelector = (<RadioGroup onChange={this.changeProjectColor} value={projectMsg.color} className="color">
@ -185,7 +195,7 @@ class ProjectMessage extends Component {
</Popover>
</Col>
<Col xs={18} sm={15} lg={19} className="setting-intro">
<h2 className="ui-title">{this.state.currGroup + ' / ' + projectMsg.name}</h2>
<h2 className="ui-title">{(this.state.currGroup || '') + ' / ' + (projectMsg.name || '')}</h2>
{/* <p className="ui-desc">{projectMsg.desc}</p> */}
</Col>
</Row>
@ -209,14 +219,25 @@ class ProjectMessage extends Component {
<Input />
)}
</FormItem>
<FormItem
{...formItemLayout}
label="所属分组"
>
<Input value={this.state.currGroup} disabled={true} />
{getFieldDecorator('group_id', {
initialValue: initFormValues.group_id+'' ,
rules: [{
required: true, message: '请选择项目所属的分组!'
}]
})(
<Select>
{this.props.groupList.map((item, index) => (
<Option value={item._id.toString()} key={index}>{item.group_name}</Option>
))}
</Select>
)}
</FormItem>
<FormItem
{...formItemLayout}
label={(

View File

@ -162,14 +162,15 @@ export function addProject(data) {
// 修改项目
export function updateProject(data) {
const { name, project_type, basepath, desc, _id, env } = data;
const { name, project_type, basepath, desc, _id, env, group_id } = data;
const param = {
name,
project_type,
basepath,
desc,
id: _id,
env
env,
group_id
};
return {
type: PROJECT_UPDATE,

View File

@ -603,6 +603,7 @@ class projectController extends baseController {
if (!_.isUndefined(params.name)) data.name = params.name;
if (!_.isUndefined(params.desc)) data.desc = params.desc;
if (!_.isUndefined(params.group_id)) data.group_id = params.group_id;
data.basepath = params.basepath;
if (!_.isUndefined(params.color)) data.color = params.color;
if (!_.isUndefined(params.icon)) data.icon = params.icon;