import React, { PureComponent as Component } from 'react'; import { Form, Input, Switch, Select, Icon, Tooltip, Button, Row, Col, message, Card, Radio, Alert, Modal, Popover } from 'antd'; import PropTypes from 'prop-types'; import { updateProject, delProject, getProject, upsetProject } from '../../../../reducer/modules/project'; import { fetchGroupMsg } from '../../../../reducer/modules/group'; import { fetchGroupList } from '../../../../reducer/modules/group.js'; import { setBreadcrumb } from '../../../../reducer/modules/user'; import { connect } from 'react-redux'; const { TextArea } = Input; import { withRouter } from 'react-router'; const FormItem = Form.Item; const RadioGroup = Radio.Group; const RadioButton = Radio.Button; import constants from '../../../../constants/variable.js'; const confirm = Modal.confirm; import { nameLengthLimit, entries, trim, htmlFilter } from '../../../../common'; import '../Setting.scss'; import _ from 'underscore'; import ProjectTag from './ProjectTag.js'; // layout const formItemLayout = { labelCol: { lg: { offset: 1, span: 3 }, xs: { span: 24 }, sm: { span: 6 } }, wrapperCol: { lg: { span: 19 }, xs: { span: 24 }, sm: { span: 14 } }, className: 'form-item' }; const Option = Select.Option; @connect( state => { return { projectList: state.project.projectList, groupList: state.group.groupList, projectMsg: state.project.currProject, currGroup: state.group.currGroup }; }, { updateProject, delProject, getProject, fetchGroupMsg, upsetProject, fetchGroupList, setBreadcrumb } ) @withRouter class ProjectMessage extends Component { constructor(props) { super(props); this.state = { protocol: 'http://', projectMsg: {}, showDangerOptions: false }; } static propTypes = { projectId: PropTypes.number, form: PropTypes.object, updateProject: PropTypes.func, delProject: PropTypes.func, getProject: PropTypes.func, history: PropTypes.object, fetchGroupMsg: PropTypes.func, upsetProject: PropTypes.func, groupList: PropTypes.array, projectList: PropTypes.array, projectMsg: PropTypes.object, fetchGroupList: PropTypes.func, currGroup: PropTypes.object, setBreadcrumb: PropTypes.func }; // 确认修改 handleOk = e => { e.preventDefault(); const { form, updateProject, projectMsg, groupList } = this.props; form.validateFields((err, values) => { if (!err) { let { tag } = this.tag.state; // let tag = this.refs.tag; tag = tag.filter(val => { return val.name !== ''; }); let assignValue = Object.assign(projectMsg, values, { tag }); values.protocol = this.state.protocol.split(':')[0]; const group_id = assignValue.group_id; const selectGroup = _.find(groupList, item => { return item._id == group_id; }); updateProject(assignValue) .then(res => { if (res.payload.data.errcode == 0) { this.props.getProject(this.props.projectId); message.success('修改成功! '); // 如果如果项目所在的分组位置发生改变 this.props.fetchGroupMsg(group_id); // this.props.history.push('/group'); let projectName = htmlFilter(assignValue.name); this.props.setBreadcrumb([ { name: selectGroup.group_name, href: '/group/' + group_id }, { name: projectName } ]); } }) .catch(() => {}); form.resetFields(); } }); }; tagSubmit = tag => { this.tag = tag; }; showConfirm = () => { let that = this; confirm({ title: '确认删除 ' + that.props.projectMsg.name + ' 项目吗?', content: (

请输入项目名称确认此操作:

), onOk() { let groupName = trim(document.getElementById('project_name').value); if (that.props.projectMsg.name !== groupName) { message.error('项目名称有误'); return new Promise((resolve, reject) => { reject('error'); }); } else { that.props.delProject(that.props.projectId).then(res => { if (res.payload.data.errcode == 0) { message.success('删除成功!'); that.props.history.push('/group/' + that.props.projectMsg.group_id); } }); } }, iconType: 'delete', onCancel() {} }); }; // 修改项目头像的背景颜色 changeProjectColor = e => { const { _id, color, icon } = this.props.projectMsg; this.props.upsetProject({ id: _id, color: e.target.value || color, icon }).then(res => { if (res.payload.data.errcode === 0) { this.props.getProject(this.props.projectId); } }); }; // 修改项目头像的图标 changeProjectIcon = e => { const { _id, color, icon } = this.props.projectMsg; this.props.upsetProject({ id: _id, color, icon: e.target.value || icon }).then(res => { if (res.payload.data.errcode === 0) { this.props.getProject(this.props.projectId); } }); }; // 点击“查看危险操作”按钮 toggleDangerOptions = () => { // console.log(this.state.showDangerOptions); this.setState({ showDangerOptions: !this.state.showDangerOptions }); }; async UNSAFE_componentWillMount() { await this.props.fetchGroupList(); await this.props.fetchGroupMsg(this.props.projectMsg.group_id); } render() { const { getFieldDecorator } = this.props.form; const { projectMsg, currGroup } = 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, group_id, switch_notice, strice, is_json5, tag } = projectMsg; initFormValues = { name, basepath, desc, project_type, group_id, switch_notice, strice, is_json5, tag }; const colorArr = entries(constants.PROJECT_COLOR); const colorSelector = ( {colorArr.map((item, index) => { return ( {item[0] === projectMsg.color ? : null} ); })} ); const iconSelector = ( {constants.PROJECT_ICON.map(item => { return ( ); })} ); const selectDisbaled = projectMsg.role === 'owner' || projectMsg.role === 'admin'; return (

{(currGroup.group_name || '') + ' / ' + (projectMsg.name || '')}

{/*

{projectMsg.desc}

*/}

{this.props.projectMsg._id} {getFieldDecorator('name', { initialValue: initFormValues.name, rules: nameLengthLimit('项目') })()} {getFieldDecorator('group_id', { initialValue: initFormValues.group_id + '', rules: [ { required: true, message: '请选择项目所属的分组!' } ] })( )} 接口基本路径  } > {getFieldDecorator('basepath', { initialValue: initFormValues.basepath, rules: [ { required: false, message: '请输入基本路径! ' } ] })()} MOCK地址  } > {}} /> {getFieldDecorator('desc', { initialValue: initFormValues.desc, rules: [ { required: false } ] })(