import React, { Component } from 'react' import { Form, Input, Icon, Tooltip, Select, Button, Row, Col, message, Card, Radio, Alert, Modal, Popover } from 'antd'; import PropTypes from 'prop-types'; import { updateProject, delProject, getProjectMsg } from '../../../../reducer/modules/project'; import { fetchGroupMsg } from '../../../../reducer/modules/group'; import { connect } from 'react-redux'; const { TextArea } = Input; import { withRouter } from 'react-router'; const FormItem = Form.Item; const Option = Select.Option; const RadioGroup = Radio.Group; const confirm = Modal.confirm; import '../Setting.scss'; // layout const formItemLayout = { labelCol: { lg: { span: 3 }, xs: { span: 24 }, sm: { span: 6 } }, wrapperCol: { lg: { span: 21 }, xs: { span: 24 }, sm: { span: 14 } }, className: 'form-item' }; let uuid = 0; // 环境配置的计数 @connect( state => { return { projectList: state.project.projectList, projectMsg: state.project.projectMsg } }, { updateProject, delProject, getProjectMsg, fetchGroupMsg } ) @withRouter class ProjectMessage extends Component { constructor(props) { super(props); this.state = { protocol: 'http:\/\/', envProtocolChange: 'http:\/\/', projectMsg: {} } } static propTypes = { projectId: PropTypes.number, form: PropTypes.object, updateProject: PropTypes.func, delProject: PropTypes.func, getProjectMsg: PropTypes.func, history: PropTypes.object, fetchGroupMsg: PropTypes.func, projectList: PropTypes.array, projectMsg: PropTypes.object } // 修改线上域名的协议类型 (http/https) protocolChange = (value) => { this.setState({ protocol: value, currGroup: '' }) } // 确认修改 handleOk = (e) => { e.preventDefault(); const { form, updateProject, projectMsg } = this.props; form.validateFields((err, values) => { if (!err) { let assignValue = Object.assign(projectMsg, values); values.protocol = this.state.protocol.split(':')[0]; assignValue.env = assignValue.envs.map((item, index) => { return { name: values['envs-name-' + index], domain: values['envs-protocol-' + index] + values['envs-domain-' + index] } }); updateProject(assignValue).then((res) => { if (res.payload.data.errcode == 0) { message.success('修改成功! '); } else { message.error(res.payload.data.errmsg); } }).catch(() => { }); form.resetFields(); } }); } // 项目的修改操作 - 删除一项环境配置 remove = (id) => { const { form } = this.props; // can use data-binding to get const envs = form.getFieldValue('envs'); // We need at least one passenger if (envs.length === 0) { return; } // can use data-binding to set form.setFieldsValue({ envs: envs.filter(key => { const realKey = key._id ? key._id : key return realKey !== id; }) }); } // 项目的修改操作 - 添加一项环境配置 add = () => { uuid++; const { form } = this.props; // can use data-binding to get const envs = form.getFieldValue('envs'); const nextKeys = envs.concat(uuid); // can use data-binding to set // important! notify form to detect changes form.setFieldsValue({ envs: nextKeys }); } showConfirm = () => { let that = this; confirm({ title: "确认删除 "+that.props.projectMsg.name+" 分组吗?", content:
请输入项目名称确认此操作:
{projectMsg.desc}
项目一旦删除,将无法恢复数据,请慎重操作!