|
@@ -1,8 +1,8 @@
|
|
|
import React from 'react'
|
|
|
-import { Form, Input, Row, Col, Switch, Button, Modal, message } from 'antd'
|
|
|
+import { Form, Input, Row, Col, Switch, Button, Modal, message, Select, Icon } from 'antd'
|
|
|
import { connect } from 'dva'
|
|
|
import AceEditor from 'react-ace'
|
|
|
-import { detail, test, update } from '../service'
|
|
|
+import { detail, test, update, groupList } from '../service'
|
|
|
import { isJSON } from '@/utils/utils'
|
|
|
|
|
|
import 'ace-builds/src-noconflict/mode-java'
|
|
@@ -21,15 +21,33 @@ class Add extends React.PureComponent {
|
|
|
content: '',
|
|
|
showTest: false, // 是否展示测试内容
|
|
|
testContent: '', // 测试数据
|
|
|
- testResult: '' // 测试结果
|
|
|
+ testResult: '', // 测试结果
|
|
|
+ timeTaskEnabled: false,
|
|
|
+ dos: [],
|
|
|
+ groupList: [],
|
|
|
+ group: '',
|
|
|
+ features: ''
|
|
|
}
|
|
|
|
|
|
- componentDidMount () {
|
|
|
+ async componentDidMount () {
|
|
|
+ await groupList({ pageNum: 999 }).then(res => this.setState({ groupList: res.data.list }))
|
|
|
+
|
|
|
detail({
|
|
|
name: this.props.match.params.name
|
|
|
}).then(res => {
|
|
|
if (res.code === 0) {
|
|
|
- this.setState({ ...res.data })
|
|
|
+ if (res.data.type === 4) {
|
|
|
+ const content = JSON.parse(res.data.content)
|
|
|
+ const fts = (this.state.groupList.filter(item => item.name === content.group)[0] || { features: '' }).features
|
|
|
+ const obj = Object.create(null)
|
|
|
+ fts.split(',').forEach((k, index) => {
|
|
|
+ obj[k.trim()] = 0
|
|
|
+ })
|
|
|
+ this.state.testContent = JSON.stringify(obj)
|
|
|
+ this.setState({ ...res.data, dos: content.dos, group: content.group, features: fts })
|
|
|
+ } else {
|
|
|
+ this.setState({ ...res.data })
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -37,9 +55,13 @@ class Add extends React.PureComponent {
|
|
|
create = () => {
|
|
|
this.props.form.validateFields((err, values) => {
|
|
|
if (!err) {
|
|
|
+ if (this.state.type === 4) {
|
|
|
+ values.content = JSON.stringify({ group: this.state.group, dos: this.state.dos })
|
|
|
+ } else {
|
|
|
+ values.content = this.state.content
|
|
|
+ }
|
|
|
update({
|
|
|
...values,
|
|
|
- content: this.state.content,
|
|
|
createUser: this.state.createUser || this.props.currentUser.name, // 创建人
|
|
|
updateUser: this.props.currentUser.name // 最后修改人
|
|
|
}).then(res => {
|
|
@@ -47,7 +69,7 @@ class Add extends React.PureComponent {
|
|
|
this.setState({ ...values })
|
|
|
Modal.success({
|
|
|
title: '提交成功',
|
|
|
- content: '策略代码编译正常,点击“测试按钮”可以继续测试策略逻辑'
|
|
|
+ content: '决策代码编译正常,点击“测试按钮”可以继续测试决策逻辑'
|
|
|
})
|
|
|
}
|
|
|
})
|
|
@@ -57,7 +79,11 @@ class Add extends React.PureComponent {
|
|
|
|
|
|
test =(id) => {
|
|
|
if (!this.state.name) {
|
|
|
- message.warn('请先提交策略内容!')
|
|
|
+ message.warn('请先提交决策内容!')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (this.state.timeTaskEnabled) {
|
|
|
+ message.warn('定时启用不能测试,请先关闭!')
|
|
|
return false
|
|
|
}
|
|
|
if (!isJSON(this.state.testContent)) {
|
|
@@ -66,61 +92,168 @@ class Add extends React.PureComponent {
|
|
|
}
|
|
|
test({
|
|
|
name: this.state.name,
|
|
|
+ type: this.state.type,
|
|
|
input: JSON.parse(this.state.testContent)
|
|
|
}).then(res => {
|
|
|
if (res.code === 0) {
|
|
|
- console.log(res)
|
|
|
this.setState({ testResult: JSON.stringify(res) })
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ addDos = () => {
|
|
|
+ const dos = this.state.dos.slice()
|
|
|
+ dos.push({
|
|
|
+ r: { ep: '', f: '', v: '' }, ep: '', v: ''
|
|
|
+ })
|
|
|
+ this.setState({ dos: dos })
|
|
|
+ }
|
|
|
+
|
|
|
+ changeDos = (index, key, value) => {
|
|
|
+ const dos = this.state.dos.slice()
|
|
|
+ const keyList = key.split('.')
|
|
|
+
|
|
|
+ if (keyList.length > 1) {
|
|
|
+ dos[index][keyList[0]][keyList[1]] = value
|
|
|
+ } else {
|
|
|
+ dos[index][keyList[0]] = value
|
|
|
+ }
|
|
|
+ this.setState({ dos: dos })
|
|
|
+ }
|
|
|
+
|
|
|
+ removeDos = (index) => {
|
|
|
+ const dos = this.state.dos.slice()
|
|
|
+ dos.splice(index, 1)
|
|
|
+ this.setState({ dos: dos })
|
|
|
+ }
|
|
|
+
|
|
|
render () {
|
|
|
const { getFieldDecorator } = this.props.form
|
|
|
const { name, description, enabled, content } = this.state
|
|
|
return (
|
|
|
<div>
|
|
|
- <h1>编辑策略</h1>
|
|
|
+ <h1>编辑决策</h1>
|
|
|
<Row>
|
|
|
<Col span={12}>
|
|
|
<Form {...formItemLayout}>
|
|
|
- <Form.Item label="策略名称">
|
|
|
+ <Form.Item label="决策名称">
|
|
|
{getFieldDecorator('name', {
|
|
|
initialValue: name
|
|
|
})(<Input placeholder="全英文或英文带下划线" />)}
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="策略描述">
|
|
|
+ <Form.Item label="决策描述">
|
|
|
{getFieldDecorator('description', {
|
|
|
initialValue: description
|
|
|
})(<Input.TextArea placeholder="多行输入" />)}
|
|
|
</Form.Item>
|
|
|
+ <Form.Item label="决策类型">
|
|
|
+ {getFieldDecorator('type', { initialValue: this.state.type })(
|
|
|
+ <Select placeholder={'请选择类型'} onChange={value => this.setState({ type: value })}>
|
|
|
+ <Select.Option value= {0}>策略</Select.Option>
|
|
|
+ <Select.Option value= {1}>流程</Select.Option>
|
|
|
+ <Select.Option value= {2}>模型</Select.Option>
|
|
|
+ <Select.Option value= {3}>调度</Select.Option>
|
|
|
+ <Select.Option value= {4}>规则</Select.Option>
|
|
|
+ </Select>)
|
|
|
+ }
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ {
|
|
|
+ this.state.type === 4 && (
|
|
|
+ <Form.Item label="特征分组">
|
|
|
+ {getFieldDecorator('group', { initialValue: this.state.group })(
|
|
|
+ <Select placeholder={'请选择分组'} onChange={value => this.setState({ group: value }, () => this.setState({ dos: [], features: this.state.groupList.filter(item => item.name === value)[0].features }))}>
|
|
|
+ {
|
|
|
+ this.state.groupList.map(item => <Select.Option value={item.name}>{item.name}</Select.Option>)
|
|
|
+ }
|
|
|
+ </Select>)
|
|
|
+ }
|
|
|
+ </Form.Item>
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
<Form.Item label="是否启用">
|
|
|
{getFieldDecorator('enabled', {
|
|
|
initialValue: enabled
|
|
|
})(<Switch checked={enabled} onChange={checked => this.setState({ enabled: checked })} />)}
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="策略逻辑开发">
|
|
|
+ {
|
|
|
+ // (this.state.type !== 3 && this.setState({ timeTaskEnabled: false })) ||
|
|
|
+ (this.state.type === 3 && (
|
|
|
+ <Form.Item label="定时是否启用">
|
|
|
+ {getFieldDecorator('timeTaskEnabled', {
|
|
|
+ initialValue: this.state.timeTaskEnabled
|
|
|
+ })(<Switch checked={this.state.timeTaskEnabled} onChange={checked => this.setState({ timeTaskEnabled: checked })} />)}
|
|
|
+ </Form.Item>
|
|
|
+ ))
|
|
|
+ }
|
|
|
|
|
|
- <AceEditor
|
|
|
- style={{ width: this.state.showTest ? '100%' : '200%' }}
|
|
|
- mode="java"
|
|
|
- theme="monokai"
|
|
|
- name="content"
|
|
|
- onChange={(value) => this.setState({ content: value })}
|
|
|
- fontSize={14}
|
|
|
- showPrintMargin={true}
|
|
|
- showGutter={true}
|
|
|
- highlightActiveLine={true}
|
|
|
- value={content}
|
|
|
- setOptions={{
|
|
|
- enableBasicAutocompletion: true,
|
|
|
- enableLiveAutocompletion: true,
|
|
|
- enableSnippets: true,
|
|
|
- showLineNumbers: true,
|
|
|
- tabSize: 2
|
|
|
- }}
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
+ {
|
|
|
+ this.state.type === 4 && (
|
|
|
+ <Form.Item label="决策规则开发">
|
|
|
+ <Button onClick={this.addDos}>点击创建规则</Button>
|
|
|
+ {
|
|
|
+ this.state.dos.map((item, index) => (
|
|
|
+ <div style={{ margin: '10px 0' }}>
|
|
|
+ <Select value={item.r.f} style={{ width: '150px' }} onChange={(value) => this.changeDos(index, 'r.f', value)}>
|
|
|
+ {
|
|
|
+ this.state.features.split(',').map(item => (<Select.Option value={item}>{item}</Select.Option>))
|
|
|
+ }
|
|
|
+ </Select> 
|
|
|
+ <Select value={item.r.ep} style={{ width: '60px' }} onChange={(value) => this.changeDos(index, 'r.ep', value)}>
|
|
|
+ <Select.Option value=">">{'>'}</Select.Option>
|
|
|
+ <Select.Option value=">=">{'>='}</Select.Option>
|
|
|
+ <Select.Option value="<">{'<'}</Select.Option>
|
|
|
+ <Select.Option value="<=">{'<='}</Select.Option>
|
|
|
+ <Select.Option value="!=">{'!='}</Select.Option>
|
|
|
+ <Select.Option value="==">{'='}</Select.Option>
|
|
|
+ </Select> 
|
|
|
+ <Input defaultValue={item.r.v} style={{ width: '50px' }} onChange={(e) => this.changeDos(index, 'r.v', e.target.value)} /> 
|
|
|
+ <Select value={item.ep} style={{ width: '50px' }} onChange={(value) => this.changeDos(index, 'ep', value)}>
|
|
|
+ <Select.Option value="+">{'+'}</Select.Option>
|
|
|
+ <Select.Option value="-">{'-'}</Select.Option>
|
|
|
+ <Select.Option value="*">{'*'}</Select.Option>
|
|
|
+ <Select.Option value="/">{'/'}</Select.Option>
|
|
|
+ </Select> 
|
|
|
+ <Input defaultValue={item.v} style={{ width: '50px' }} onChange={(e) => this.changeDos(index, 'v', e.target.value)} /> 
|
|
|
+ <Icon
|
|
|
+ type="minus-circle-o"
|
|
|
+ theme="twoTone"
|
|
|
+ twoToneColor="#eb2f96"
|
|
|
+ onClick={() => this.removeDos(index)}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ ))
|
|
|
+ }
|
|
|
+ </Form.Item>
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ this.state.type !== 4 && (
|
|
|
+ <Form.Item label="决策逻辑开发">
|
|
|
+ <AceEditor
|
|
|
+ style={{ width: this.state.showTest ? '100%' : '200%' }}
|
|
|
+ mode="java"
|
|
|
+ theme="monokai"
|
|
|
+ name="content"
|
|
|
+ onChange={(value) => this.setState({ content: value })}
|
|
|
+ fontSize={14}
|
|
|
+ showPrintMargin={true}
|
|
|
+ showGutter={true}
|
|
|
+ highlightActiveLine={true}
|
|
|
+ value={content}
|
|
|
+ setOptions={{
|
|
|
+ enableBasicAutocompletion: true,
|
|
|
+ enableLiveAutocompletion: true,
|
|
|
+ enableSnippets: true,
|
|
|
+ showLineNumbers: true,
|
|
|
+ tabSize: 2
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ )
|
|
|
+ }
|
|
|
<Form.Item>
|
|
|
<Button type="primary" onClick={this.create}>提交</Button> 
|
|
|
<Button onClick={() => this.setState({ showTest: true })}>测试</Button>
|