黄嗣楠 4 gadi atpakaļ
vecāks
revīzija
9bc97d33f9

+ 1 - 0
package.json

@@ -17,6 +17,7 @@
     "rc-color-picker": "^1.2.6",
     "react": "^16.9.0",
     "react-copy-to-clipboard": "^5.0.2",
+    "react-diff-viewer": "^3.1.1",
     "react-dom": "^16.9.0",
     "react-rnd": "^10.1.8",
     "wptpc-design": "^2.0.85"

+ 1 - 1
src/pages/fengkong/biz/index.js

@@ -22,7 +22,7 @@ class BizList extends React.PureComponent {
     isClearSearch: true,
     formFields: [
       {
-        label: '描述:',
+        label: '名称:',
         type: 'input',
         key: 'queryName',
         placeholder: '分类名称'

+ 1 - 1
src/pages/fengkong/features/feature.js

@@ -14,7 +14,7 @@ class FeaturesList extends React.PureComponent {
     isClearSearch: true,
     formFields: [
       {
-        label: '描述:',
+        label: '名称:',
         type: 'input',
         key: 'queryName',
         placeholder: '特征名称'

+ 67 - 8
src/pages/fengkong/features/group/add/index.js

@@ -1,5 +1,5 @@
 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 AceEditor from 'react-ace'
 import { create, test } from '../service'
 
@@ -7,27 +7,66 @@ import 'ace-builds/src-noconflict/mode-java'
 import 'ace-builds/src-noconflict/theme-monokai'
 import { connect } from 'dva'
 import router from 'umi/router'
+import debounce from 'lodash/debounce'
+import { featureList } from './service.js'
 
 const formItemLayout = {
   layout: 'vertical'
 }
+const { Option } = Select;
 @connect(({ user }) => ({
   currentUser: user.currentUser
 }))
 @Form.create()
 class Add extends React.PureComponent {
+  constructor(props) {
+    super(props)
+    this.lastFetchId = 0
+    this.fetchFeature = debounce(this.fetchFeature, 600)
+  }
   state = {
     content: '',
     showTest: false, // 是否展示测试内容
     testContent: '', // 测试数据
-    testResult: '' // 测试结果
+    testResult: '', // 测试结果
+    data: [],
+    value: [],
+    fetching: false,
+  }
+
+  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,
+    })
+  }
+
+
   create = () => {
     this.props.form.validateFields((err, values) => {
+      let features = values.features.map(feature => {
+        return feature.key
+      }).join(',')
       if (!err) {
         create({
           ...values,
+          features:features,
           createUser: this.props.currentUser.name, // 创建人
           updateUser: this.props.currentUser.name // 最后修改人
         }).then(res => {
@@ -45,7 +84,7 @@ class Add extends React.PureComponent {
     })
   }
 
-  test =() => {
+  test = () => {
     if (!this.state.name) {
       message.warn('请先提交分组内容!')
       return false
@@ -60,9 +99,9 @@ class Add extends React.PureComponent {
     })
   }
 
-  render () {
+  render() {
     const { getFieldDecorator } = this.props.form
-
+    const { fetching, data} = this.state
     return (
       <div>
         <h1>新增分组</h1>
@@ -84,7 +123,28 @@ class Add extends React.PureComponent {
                 })(<Input placeholder="全英文或英文带下划线" />)}
               </Form.Item>
               <Form.Item label="特征列表">
-                {getFieldDecorator('features')(<Input placeholder=",号分割" />)}
+                {/* {getFieldDecorator('features')(<Input placeholder=",号分割" />)} */}
+                {getFieldDecorator('features', {
+                  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')(<Input.TextArea placeholder="多行输入" />)}
@@ -96,8 +156,7 @@ class Add extends React.PureComponent {
                 {getFieldDecorator('postScript')(<Input placeholder="后处理分组函数" />)}
               </Form.Item>
               <Form.Item>
-                <Button type="primary" onClick={this.create}>提交</Button>&emsp;
-                <Button onClick={() => this.setState({ showTest: true })}>测试</Button>
+                <Button type="primary" onClick={this.create}>提交</Button>
               </Form.Item>
             </Form>
           </Col>

+ 8 - 0
src/pages/fengkong/features/group/add/service.js

@@ -0,0 +1,8 @@
+import { fetchApi, fetchApi_get as fetchApiGet } from '@/apis/'
+import { thanos } from '@/conf/config'
+
+// 新增策略
+export async function featureList (params) {
+    const url = `${thanos}/thanos-admin/api/v1/feature/list`
+    return fetchApi(url, params)
+  }

+ 64 - 8
src/pages/fengkong/features/group/edit/$name.js

@@ -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', {

+ 8 - 0
src/pages/fengkong/features/group/edit/service.js

@@ -0,0 +1,8 @@
+import { fetchApi, fetchApi_get as fetchApiGet } from '@/apis/'
+import { thanos } from '@/conf/config'
+
+// 新增策略
+export async function featureList (params) {
+    const url = `${thanos}/thanos-admin/api/v1/feature/list`
+    return fetchApi(url, params)
+  }

+ 1 - 1
src/pages/fengkong/features/group/index.js

@@ -22,7 +22,7 @@ class GroupList extends React.PureComponent {
     isClearSearch: true,
     formFields: [
       {
-        label: '描述:',
+        label: '名称:',
         type: 'input',
         key: 'queryName',
         placeholder: '分组名称'

+ 1 - 1
src/pages/fengkong/model/index.js

@@ -26,7 +26,7 @@ class ModelList extends React.PureComponent {
     isClearSearch: true,
     formFields: [
       {
-        label: '描述:',
+        label: '名称:',
         type: 'input',
         key: 'queryName',
         placeholder: '模型名称'

+ 1 - 1
src/pages/fengkong/risk/sale/sale.js

@@ -49,7 +49,7 @@ class SaleRiskQuery extends React.PureComponent {
     isClearSearch: true,
     formFields: [
       {
-        label: '描述:',
+        label: '订单ID:',
         type: 'input',
         key: 'saleId',
         placeholder: '订单ID'

+ 1 - 1
src/pages/fengkong/risk/user/user.js

@@ -49,7 +49,7 @@ class UserRiskQuery extends React.PureComponent {
     isClearSearch: true,
     formFields: [
       {
-        label: '描述:',
+        label: '用户ID:',
         type: 'input',
         key: 'userId',
         placeholder: '用户ID'

+ 12 - 1
src/pages/fengkong/strategies/add/index.js

@@ -131,7 +131,18 @@ class Add extends React.PureComponent {
                 })(<Input placeholder="全英文或英文带下划线" />)}
               </Form.Item>
               <Form.Item label="决策描述">
-                {getFieldDecorator('description')(<Input.TextArea placeholder="多行输入" />)}
+                {getFieldDecorator('description',{
+                  rules:[
+                    {
+                      required:true,
+                      message:'不能为空'
+                    },
+                    {
+                      max: 64,
+                      message: '长度不能超过64'
+                    }
+                  ]
+                })(<Input.TextArea placeholder="多行输入" />)}
               </Form.Item>
               <Form.Item label="决策类型">
                 {getFieldDecorator('type', { initialValue: this.state.type })(

+ 14 - 1
src/pages/fengkong/strategies/edit/$name.js

@@ -120,6 +120,9 @@ class Add extends React.PureComponent {
     }).then(res => {
       if (res.code === 0) {
         this.setState({ testResult: JSON.stringify(res) })
+      } if (res.code === 1) {
+        // alert(JSON.stringify(res))
+        this.setState({ testResult: res.data })
       }
     })
   }
@@ -166,7 +169,17 @@ class Add extends React.PureComponent {
               </Form.Item>
               <Form.Item label="决策描述">
                 {getFieldDecorator('description', {
-                  initialValue: description
+                  initialValue: description,
+                  rules:[
+                    {
+                      required:true,
+                      message:'不能为空'
+                    },
+                    {
+                      max: 64,
+                      message: '长度不能超过64'
+                    }
+                  ]
                 })(<Input.TextArea placeholder="多行输入" />)}
               </Form.Item>
               <Form.Item label="决策类型">

+ 1 - 1
src/pages/fengkong/strategies/strategies.js

@@ -24,7 +24,7 @@ class GroupList extends React.PureComponent {
     isClearSearch: true,
     formFields: [
       {
-        label: '描述:',
+        label: '名称:',
         type: 'input',
         key: 'queryName',
         placeholder: '分组名称'

+ 1 - 1
src/pages/fengkong/view/history/history.js

@@ -19,7 +19,7 @@ class LogList extends React.PureComponent {
     isClearSearch: true,
     formFields: [
       {
-        label: '描述:',
+        label: '名称:',
         type: 'input',
         key: 'queryName',
         placeholder: '名称'

+ 6 - 2
src/pages/fengkong/view/other/other.js

@@ -2,7 +2,7 @@ import React from 'react'
 import { FilterTable } from 'wptpc-design'
 import { thanos } from '@/conf/config'
 import { message, Divider } from 'antd'
-import { update, writeLog, queryLog, reviewOk } from '../service'
+import { update, writeLog, queryLog, detail, reviewOk } from '../service.js'
 import Rv from '@/pages/fengkong/view/other/review'
 import VCM from '@/pages/fengkong/view/other/viewCodeModal'
 import { connect } from 'dva'
@@ -156,7 +156,11 @@ class OtherList extends React.PureComponent {
   }
 
   viewCode = (record) => {
-    this.setState({ showVCModal: true, vParams:record})
+    detail({ name: record.name.substr(5) }).then(res => {
+      if (res.code === 0) {
+        this.setState({ showVCModal: true, vParams:{'newCode':record?.content,'oldCode':res?.data?.content }})
+      }
+    })
   }
 
   onRvOk = () => {

+ 7 - 21
src/pages/fengkong/view/other/viewCodeModal.js

@@ -3,39 +3,25 @@ import { Modal, Form } from 'antd'
 import AceEditor from 'react-ace'
 import 'ace-builds/src-noconflict/mode-java'
 import 'ace-builds/src-noconflict/theme-monokai'
+import ReactDiffViewer from 'react-diff-viewer';
 
 export default class ViewCodeModal extends Component {
+  
   render () {
     const { showModal, params, onChange, onOk, onCancel, fetching } = this.props
+    
     return (
       <Modal
-        width={800}
+        width={1200}
         title={'待审核代码'}
         visible={showModal}
         onOk={onOk}
         onCancel={onCancel}
         okButtonProps={{ disabled: fetching }}
       >
-        <Form.Item label="代码">
-            <AceEditor
-              style={{ width: '100%' }}
-              mode="java"
-              theme="monokai"
-              name="content"
-              fontSize={14}
-              showPrintMargin={true}
-              showGutter={true}
-              highlightActiveLine={true}
-              value={params.content}
-              setOptions={{
-                enableBasicAutocompletion: true,
-                enableLiveAutocompletion: true,
-                enableSnippets: true,
-                showLineNumbers: true,
-                tabSize: 2
-              }}
-            />
-          </Form.Item>
+      <ReactDiffViewer oldValue={params.oldCode} newValue={params.newCode} splitView={true} 
+        leftTitle ='原代码' rightTitle ='待审核代码'
+        />  
       </Modal>
     )
   }

+ 1 - 1
src/pages/fengkong/view/self/self.js

@@ -23,7 +23,7 @@ class SlefList extends React.PureComponent {
     isClearSearch: true,
     formFields: [
       {
-        label: '描述:',
+        label: '名称:',
         type: 'input',
         key: 'queryName',
         placeholder: '名称'