index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import React from 'react'
  2. import { Form, Input, Row, Col, Button, Modal, message } from 'antd'
  3. import AceEditor from 'react-ace'
  4. import { create, test } from '../service'
  5. import 'ace-builds/src-noconflict/mode-java'
  6. import 'ace-builds/src-noconflict/theme-monokai'
  7. import { connect } from 'dva'
  8. import router from 'umi/router'
  9. const formItemLayout = {
  10. layout: 'vertical'
  11. }
  12. @connect(({ user }) => ({
  13. currentUser: user.currentUser
  14. }))
  15. @Form.create()
  16. class Add extends React.PureComponent {
  17. state = {
  18. content: '',
  19. showTest: false, // 是否展示测试内容
  20. testContent: '', // 测试数据
  21. testResult: '' // 测试结果
  22. }
  23. create = () => {
  24. this.props.form.validateFields((err, values) => {
  25. if (!err) {
  26. create({
  27. ...values,
  28. createUser: this.props.currentUser.name, // 创建人
  29. updateUser: this.props.currentUser.name // 最后修改人
  30. }).then(res => {
  31. if (res.code === 0) {
  32. this.setState({ ...values })
  33. Modal.success({
  34. title: '提交成功',
  35. content: '策略代码编译正常,点击“测试按钮”可以继续测试策略逻辑'
  36. })
  37. // 跳转到列表页
  38. router.push('/fengkong/features/group')
  39. }
  40. })
  41. }
  42. })
  43. }
  44. test =() => {
  45. if (!this.state.name) {
  46. message.warn('请先提交分组内容!')
  47. return false
  48. }
  49. test({
  50. name: this.state.name,
  51. input: this.state.testContent
  52. }).then(res => {
  53. if (res.code === 0) {
  54. this.setState({ testResult: res.data })
  55. }
  56. })
  57. }
  58. render () {
  59. const { getFieldDecorator } = this.props.form
  60. return (
  61. <div>
  62. <h1>新增分组</h1>
  63. <Row>
  64. <Col span={12}>
  65. <Form {...formItemLayout}>
  66. <Form.Item label="分组名称">
  67. {getFieldDecorator('name')(<Input placeholder="全英文或英文带下划线" />)}
  68. </Form.Item>
  69. <Form.Item label="特征列表">
  70. {getFieldDecorator('features')(<Input placeholder=",号分割" />)}
  71. </Form.Item>
  72. <Form.Item label="分组描述">
  73. {getFieldDecorator('description')(<Input.TextArea placeholder="多行输入" />)}
  74. </Form.Item>
  75. <Form.Item label="前置函数">
  76. {getFieldDecorator('preScript')(<Input placeholder="预处理分组函数" />)}
  77. </Form.Item>
  78. <Form.Item label="后置函数">
  79. {getFieldDecorator('postScript')(<Input placeholder="后处理分组函数" />)}
  80. </Form.Item>
  81. <Form.Item>
  82. <Button type="primary" onClick={this.create}>提交</Button>&emsp;
  83. <Button onClick={() => this.setState({ showTest: true })}>测试</Button>
  84. </Form.Item>
  85. </Form>
  86. </Col>
  87. <Col span={12}>
  88. <div style={{ paddingLeft: '20px', display: this.state.showTest ? 'block' : 'none' }}>
  89. <Form.Item label="输入数据">
  90. <AceEditor
  91. mode="json"
  92. theme="monokai"
  93. onChange={(value) => this.setState({ testContent: value })}
  94. fontSize={14}
  95. showPrintMargin={true}
  96. showGutter={true}
  97. highlightActiveLine={true}
  98. value={this.state.testContent}
  99. height="300px"
  100. setOptions={{
  101. enableBasicAutocompletion: true,
  102. enableLiveAutocompletion: true,
  103. enableSnippets: true,
  104. showLineNumbers: true,
  105. tabSize: 2
  106. }}
  107. />
  108. </Form.Item>
  109. <Button type="primary" onClick={this.test}>执行测试</Button>&emsp;
  110. <Form.Item label="输出结果">
  111. <AceEditor
  112. mode="json"
  113. theme="monokai"
  114. fontSize={14}
  115. showPrintMargin={true}
  116. showGutter={true}
  117. highlightActiveLine={true}
  118. value={this.state.testResult}
  119. setOptions={{
  120. enableBasicAutocompletion: true,
  121. enableLiveAutocompletion: true,
  122. enableSnippets: true,
  123. showLineNumbers: true,
  124. tabSize: 2
  125. }}
  126. />
  127. </Form.Item>
  128. </div>
  129. </Col>
  130. </Row>
  131. </div>
  132. )
  133. }
  134. }
  135. export default Add