|
@@ -1,9 +1,10 @@
|
|
|
import React from 'react'
|
|
|
-import { Form, Input, Row, Col, Button, Modal, message } from 'antd'
|
|
|
+import { Form, Input, Row, Col, Button, Modal, message, Select, Spin } from 'antd'
|
|
|
import { connect } from 'dva'
|
|
|
import AceEditor from 'react-ace'
|
|
|
import { isJSON } from '@/utils/utils'
|
|
|
import { detail, update, test } from '../service'
|
|
|
+import { featureList } from './service.js'
|
|
|
|
|
|
import 'ace-builds/src-noconflict/mode-java'
|
|
|
import 'ace-builds/src-noconflict/theme-monokai'
|
|
@@ -11,6 +12,7 @@ import 'ace-builds/src-noconflict/theme-monokai'
|
|
|
const formItemLayout = {
|
|
|
layout: 'vertical'
|
|
|
}
|
|
|
+const { Option } = Select;
|
|
|
@connect(({ user }) => ({
|
|
|
currentUser: user.currentUser
|
|
|
}))
|
|
@@ -20,24 +22,59 @@ class Add extends React.PureComponent {
|
|
|
content: '',
|
|
|
showTest: false, // 是否展示测试内容
|
|
|
testContent: '', // 测试数据
|
|
|
- testResult: '' // 测试结果
|
|
|
+ testResult: '', // 测试结果
|
|
|
+ data: [],
|
|
|
+ value: [],
|
|
|
+ fetching: false,
|
|
|
}
|
|
|
|
|
|
- componentDidMount () {
|
|
|
+ fetchFeature = value => {
|
|
|
+ this.lastFetchId += 1
|
|
|
+ if (value != "") {
|
|
|
+ featureList({ queryName: value, page: 1, pageNum: 200 }).then(res => {
|
|
|
+ if (res.code === 0 && res.data.list != null) {
|
|
|
+ const data = res.data.list.map((item, idx) => ({
|
|
|
+ text: item.name,
|
|
|
+ value: item.name
|
|
|
+ })
|
|
|
+ )
|
|
|
+ this.setState({ data, fetching: false })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ handleChange = value => {
|
|
|
+ this.props.form.setFieldsValue({ features: value })
|
|
|
+ this.setState({
|
|
|
+ fetching: false,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ componentDidMount() {
|
|
|
detail({
|
|
|
name: this.props.match.params.name
|
|
|
}).then(res => {
|
|
|
if (res.code === 0) {
|
|
|
this.setState({ ...res.data })
|
|
|
+ let features = res.data.features.split(',').map(feature => ({
|
|
|
+ key: feature,
|
|
|
+ label: feature
|
|
|
+ }))
|
|
|
+ this.props.form.setFieldsValue({ features: features })
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
create = () => {
|
|
|
this.props.form.validateFields((err, values) => {
|
|
|
+ let features = values.features.map(feature => {
|
|
|
+ return feature.key
|
|
|
+ }).join(',')
|
|
|
if (!err) {
|
|
|
update({
|
|
|
...values,
|
|
|
+ features: features,
|
|
|
content: this.state.content,
|
|
|
createUser: this.state.createUser || this.props.currentUser.name, // 创建人
|
|
|
updateUser: this.props.currentUser.name // 最后修改人
|
|
@@ -54,7 +91,7 @@ class Add extends React.PureComponent {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- test =() => {
|
|
|
+ test = () => {
|
|
|
if (!this.state.name) {
|
|
|
message.warn('请先提交策略内容!')
|
|
|
return false
|
|
@@ -73,8 +110,9 @@ class Add extends React.PureComponent {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- render () {
|
|
|
+ render() {
|
|
|
const { getFieldDecorator } = this.props.form
|
|
|
+ const { fetching, data} = this.state
|
|
|
const { name, features, description, preScript, postScript } = this.state
|
|
|
return (
|
|
|
<div>
|
|
@@ -85,12 +123,30 @@ class Add extends React.PureComponent {
|
|
|
<Form.Item label="分组名称">
|
|
|
{getFieldDecorator('name', {
|
|
|
initialValue: name
|
|
|
- })(<Input placeholder="全英文或英文带下划线" />)}
|
|
|
+ })(<Input placeholder="全英文或英文带下划线" disabled={true} />)}
|
|
|
</Form.Item>
|
|
|
<Form.Item label="特征列表">
|
|
|
{getFieldDecorator('features', {
|
|
|
- initialValue: features
|
|
|
- })(<Input placeholder=",号分割" />)}
|
|
|
+ rules: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: '不能为空'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ })(<Select
|
|
|
+ mode="multiple"
|
|
|
+ labelInValue
|
|
|
+ placeholder="选择特征列表 (模糊搜索最多显示200个,可以输入更详细特征名)"
|
|
|
+ notFoundContent={fetching ? <Spin size="small" /> : null}
|
|
|
+ filterOption={false}
|
|
|
+ onSearch={this.fetchFeature}
|
|
|
+ onChange={this.handleChange}
|
|
|
+ style={{ width: '100%' }}
|
|
|
+ >
|
|
|
+ {data.map(d => (
|
|
|
+ <Option key={d.value}>{d.text}</Option>
|
|
|
+ ))}
|
|
|
+ </Select>)}
|
|
|
</Form.Item>
|
|
|
<Form.Item label="分组描述">
|
|
|
{getFieldDecorator('description', {
|