Commit 1abc39fe by zhaochengxiang

编辑规则库

parent dab0abfd
import React from 'react' import React from 'react'
import { Input, Space, Modal } from 'antd' import { Input, Space, Modal, Divider, Tooltip, Typography } from 'antd'
import { dispatch } from '../../../../model' import { dispatch } from '../../../../model'
import PermissionButton from '../../../../util/Component/PermissionButton' import PermissionButton from '../../../../util/Component/PermissionButton'
...@@ -35,23 +35,101 @@ const FC = (props) => { ...@@ -35,23 +35,101 @@ const FC = (props) => {
{ {
title: '规则编号', title: '规则编号',
dataIndex: 'number', dataIndex: 'number',
render: (text, record) => (
<Tooltip title={text}>
<Typography.Text ellipsis={true}>
{ text }
</Typography.Text>
</Tooltip>
)
}, },
{ {
title: '规则中文名称', title: '规则中文名称',
dataIndex: 'name', dataIndex: 'name',
render: (text, record) => (
<Tooltip title={text}>
<Typography.Text ellipsis={true}>
<a onClick={() => {
setUpdateParams({
visible: true,
type: 'detail',
item: record
})
}}>
{ text }
</a>
</Typography.Text>
</Tooltip>
)
}, },
{ {
title: '规则描述', title: '规则描述',
dataIndex: 'remark', dataIndex: 'remark',
render: (text, record) => (
<Tooltip title={text}>
<Typography.Text ellipsis={true}>
{ text }
</Typography.Text>
</Tooltip>
)
}, },
{ {
title: '检查类型', title: '检查类型',
dataIndex: 'checkTypeName', dataIndex: 'checkTypeName',
render: (text, record) => (
<Tooltip title={text}>
<Typography.Text ellipsis={true}>
{ text }
</Typography.Text>
</Tooltip>
)
}, },
{ {
title: '引用次数', title: '引用次数',
dataIndex: 'referenceCount', dataIndex: 'referenceCount',
}, },
{
title: '操作',
key: 'action',
width: 120,
render: (text, record) => {
return (
<div style={{ display: 'flex', alignItems: 'center' }}>
<PermissionButton
type='link'
size='small'
onClick={() => {
setUpdateParams({
visible: true,
type: 'edit',
item: record,
})
}}
style={{ padding: 0 }}
// permissionKey='编辑'
// permissions={permissions}
defaultPermission={true}
>
编辑
</PermissionButton>
<div style={{ margin: '0 5px' }}>
<Divider type='vertical' />
</div>
<PermissionButton
type='link'
size='small'
onClick={() => { onDeteteClick(record); }}
style={{ padding: 0 }}
// permissionKey='删除'
// permissions={permissions}
defaultPermission={true}
>
删除
</PermissionButton>
</div>
)
}
}
]) ])
}, []) }, [])
...@@ -157,6 +235,7 @@ const FC = (props) => { ...@@ -157,6 +235,7 @@ const FC = (props) => {
/> />
</div> </div>
<Table <Table
extraColWidth={32}
loading={loading} loading={loading}
columns={cols??[]} columns={cols??[]}
dataSource={_data} dataSource={_data}
......
import React from "react" import React from "react"
import { Modal, Button, Spin, Form, Input, Select, Space, InputNumber } from "antd" import { Modal, Button, Spin, Form, Input, Select, Space, InputNumber, Row, Col } from "antd"
import { dispatch } from '../../../../model' import { dispatch } from '../../../../model'
import { IsArr } from "../../../../util"
const FC = (props) => { const FC = (props) => {
const { visible, type, item, onCancel } = props const { visible, type, item, onCancel } = props
...@@ -11,7 +12,7 @@ const FC = (props) => { ...@@ -11,7 +12,7 @@ const FC = (props) => {
const title = React.useMemo(() => { const title = React.useMemo(() => {
if (type === 'add') return '新增检查规则' if (type === 'add') return '新增检查规则'
if (type === 'update') return '修改检查规则' if (type === 'edit') return '修改检查规则'
if (type === 'detail') return '检查规则详情' if (type === 'detail') return '检查规则详情'
return '' return ''
...@@ -43,7 +44,7 @@ const FC = (props) => { ...@@ -43,7 +44,7 @@ const FC = (props) => {
dispatch({ dispatch({
type: 'datamodel.updateRuleTemplate', type: 'datamodel.updateRuleTemplate',
payload: { payload: {
data: {...item, rows} data: {...item, ...rows}
}, },
callback: data => { callback: data => {
close(true) close(true)
...@@ -81,7 +82,7 @@ const FC = (props) => { ...@@ -81,7 +82,7 @@ const FC = (props) => {
onCancel={() => { close() }} onCancel={() => { close() }}
> >
<Spin spinning={waiting}> <Spin spinning={waiting}>
<Basic ref={basicRef} item={item} /> <Basic ref={basicRef} type={type} item={item} />
</Spin> </Spin>
</Modal> </Modal>
) )
...@@ -89,7 +90,7 @@ const FC = (props) => { ...@@ -89,7 +90,7 @@ const FC = (props) => {
export default FC export default FC
export const Basic = React.forwardRef(function ({ item }, ref) { export const Basic = React.forwardRef(function ({ type, item }, ref) {
const [loadingCheckTypes, setLoadingCheckTypes] = React.useState(false) const [loadingCheckTypes, setLoadingCheckTypes] = React.useState(false)
const [checkTypes, setCheckTypes] = React.useState() const [checkTypes, setCheckTypes] = React.useState()
const [checkTypeValue, setCheckTypeValue] = React.useState() const [checkTypeValue, setCheckTypeValue] = React.useState()
...@@ -98,7 +99,7 @@ export const Basic = React.forwardRef(function ({ item }, ref) { ...@@ -98,7 +99,7 @@ export const Basic = React.forwardRef(function ({ item }, ref) {
React.useImperativeHandle(ref, () => ({ React.useImperativeHandle(ref, () => ({
validate: async () => { validate: async () => {
return await form.validateFields() return await form?.validateFields()
}, },
}), [form]) }), [form])
...@@ -106,6 +107,39 @@ export const Basic = React.forwardRef(function ({ item }, ref) { ...@@ -106,6 +107,39 @@ export const Basic = React.forwardRef(function ({ item }, ref) {
getCheckTypes() getCheckTypes()
}, []) }, [])
React.useEffect(() => {
if (item) {
form?.setFieldsValue(item)
setCheckTypeValue(item.checkType)
}
}, [item])
const [checkPropertyDescription, preCheckPropertyDescription] = React.useMemo(() => {
if (item) {
let newCheckPropertyDescription = `${item?.checkProperty?.propertyCnName??''} ${item?.checkProperty?.expressionTypeCnName??''} ${item?.checkProperty?.verifyExpression?.cnName??''}`
if (IsArr(item?.checkProperty?.verifyExpression?.value)) {
newCheckPropertyDescription = `${newCheckPropertyDescription} ${item?.checkProperty?.verifyExpression?.value.join(';')}`
} else {
newCheckPropertyDescription = `${newCheckPropertyDescription} ${item?.checkProperty?.verifyExpression?.value}`
}
let newPreCheckPropertyDescription = `${item?.preCheckProperty?.propertyCnName??''} ${item?.preCheckProperty?.expressionTypeCnName??''} ${item?.preCheckProperty?.verifyExpression?.cnName??''}`
if (IsArr(item?.preCheckProperty?.verifyExpression?.value)) {
newPreCheckPropertyDescription = `${newPreCheckPropertyDescription} ${item?.preCheckProperty?.verifyExpression?.value.join(';')}`
} else {
newPreCheckPropertyDescription = `${newPreCheckPropertyDescription} ${item?.preCheckProperty?.verifyExpression?.value}`
}
return [newCheckPropertyDescription, newPreCheckPropertyDescription]
}
return ['', '']
}, [item])
const marginBottom = React.useMemo(() => {
return type === 'detail' ? 5 : 15
}, [type])
const getCheckTypes = () => { const getCheckTypes = () => {
setLoadingCheckTypes(true) setLoadingCheckTypes(true)
dispatch({ dispatch({
...@@ -126,6 +160,29 @@ export const Basic = React.forwardRef(function ({ item }, ref) { ...@@ -126,6 +160,29 @@ export const Basic = React.forwardRef(function ({ item }, ref) {
} }
} }
const validatorCheckProperty = (_, value) => {
console.log('value', value)
if (!value?.propertyEnName) {
return Promise.reject(new Error('请选择检查对象!'));
}
if (!value?.expressionTypeEnName) {
return Promise.reject(new Error('请选择检查属性!'));
}
if (!value?.verifyExpression?.enName) {
return Promise.reject(new Error('请选择表达式!'));
}
if (value?.verifyExpression?.valueType !== 'none') {
if (value?.verifyExpression?.valueType === 'List<String>' && (value?.verifyExpression?.value??[]).length === 0) {
return Promise.reject(new Error('请输入表达式的值!'));
} else if (value?.verifyExpression?.value==null||value?.verifyExpression?.value==undefined) {
return Promise.reject(new Error('请输入表达式的值!'));
}
}
return Promise.resolve();
};
return ( return (
<Form <Form
form={form} form={form}
...@@ -134,49 +191,87 @@ export const Basic = React.forwardRef(function ({ item }, ref) { ...@@ -134,49 +191,87 @@ export const Basic = React.forwardRef(function ({ item }, ref) {
autoComplete="off" autoComplete="off"
onValuesChange={onValuesChange} onValuesChange={onValuesChange}
> >
{
type !== 'add' && <Form.Item label='规则编号' style={{ marginBottom }}>
<span>{item?.number}</span>
</Form.Item>
}
<Form.Item name='name' label='规则中文名称' <Form.Item name='name' label='规则中文名称'
style={{ marginBottom }}
rules={[{ required: true, message: '请输入规则中文名称!' }]} rules={[{ required: true, message: '请输入规则中文名称!' }]}
> >
<Input placeholder='请输入规则中文名称' allowClear /> {
type === 'detail' ? <span>{item?.name}</span> : <Input placeholder='请输入规则中文名称' allowClear />
}
</Form.Item> </Form.Item>
<Form.Item name='remark' label='规则描述' <Form.Item name='remark' label='规则描述'
style={{ marginBottom }}
> >
<Input placeholder='请输入规则描述' allowClear /> {
type === 'detail' ? <span>{item?.remark}</span> : <Input placeholder='请输入规则描述' allowClear />
}
</Form.Item> </Form.Item>
<Form.Item name='alertContent' label='规则提示' <Form.Item name='alertContent' label='规则提示'
style={{ marginBottom }}
rules={[{ required: true, message: '请输入规则提示!' }]} rules={[{ required: true, message: '请输入规则提示!' }]}
> >
<Input placeholder='请输入规则提示' allowClear /> {
type === 'detail' ? <span>{item?.alertContent}</span> : <Input placeholder='请输入规则提示' allowClear />
}
</Form.Item> </Form.Item>
<Form.Item name='checkType' label='检查类型' <Form.Item name='checkType' label='检查类型'
style={{ marginBottom }}
rules={[{ required: true, message: '请选择检查类型!' }]} rules={[{ required: true, message: '请选择检查类型!' }]}
> >
<Select allowClear loading={loadingCheckTypes} {
type === 'detail' ? <span>{item?.checkTypeName}</span> : <Select allowClear loading={loadingCheckTypes}
placeholder='请选择检查类型' placeholder='请选择检查类型'
> >
{ (checkTypes??[]).map((item, index) => ( { (checkTypes??[]).map((item, index) => (
<Select.Option key={item.type} value={item.type}>{item.name}</Select.Option> <Select.Option key={item.type} value={item.type}>{item.name}</Select.Option>
)) } )) }
</Select> </Select>
}
</Form.Item> </Form.Item>
{ {
checkTypeValue === 'single' && <Form.Item name='checkProperty' label='检查规则' checkTypeValue === 'single' && <Form.Item name='checkProperty' label='检查规则'
rules={[{ required: true, message: '请选择检查规则!' }]} style={{ marginBottom }}
rules={[
{
validator: validatorCheckProperty,
},
]}
> >
<CheckItem /> {
type === 'detail' ? <span>{checkPropertyDescription}</span> : <CheckItem />
}
</Form.Item> </Form.Item>
} }
{ {
checkTypeValue === 'preCheck' && <Form.Item label='检查规则'> checkTypeValue === 'preCheck' && <Form.Item label='检查规则'>
<Form.Item name='preCheckProperty' label='满足条件' <Form.Item name='preCheckProperty' label='满足条件'
rules={[{ required: true, message: '请选择检查规则!' }]} style={{ marginBottom }}
rules={[
{
validator: validatorCheckProperty,
},
]}
> >
<CheckItem /> {
type === 'detail' ? <span>{preCheckPropertyDescription}</span> : <CheckItem />
}
</Form.Item> </Form.Item>
<Form.Item name='checkProperty' label='检查内容' <Form.Item name='checkProperty' label='检查内容'
rules={[{ required: true, message: '请选择检查规则!' }]} style={{ marginBottom }}
rules={[
{
validator: validatorCheckProperty,
},
]}
> >
<CheckItem /> {
type === 'detail' ? <span>{checkPropertyDescription}</span> : <CheckItem />
}
</Form.Item> </Form.Item>
</Form.Item> </Form.Item>
} }
...@@ -196,6 +291,9 @@ const CheckItem = ({ value, onChange }) => { ...@@ -196,6 +291,9 @@ const CheckItem = ({ value, onChange }) => {
const [currentCheckPropertyType, setCurrentCheckPropertyType] = React.useState() const [currentCheckPropertyType, setCurrentCheckPropertyType] = React.useState()
const [currentExpressionType, setCurrentExpressionType] = React.useState() const [currentExpressionType, setCurrentExpressionType] = React.useState()
const [currentExpression, setCurrentExpression] = React.useState() const [currentExpression, setCurrentExpression] = React.useState()
const [currentExpressionValue, setCurrentExpressionValue] = React.useState()
const mountRef = React.useRef(true)
React.useEffect(() => { React.useEffect(() => {
getCheckPropertyTypes() getCheckPropertyTypes()
...@@ -204,6 +302,21 @@ const CheckItem = ({ value, onChange }) => { ...@@ -204,6 +302,21 @@ const CheckItem = ({ value, onChange }) => {
}, []) }, [])
React.useEffect(() => { React.useEffect(() => {
if (mountRef.current && value) {
setCurrentCheckPropertyType(value)
setCurrentExpressionType(value)
setCurrentExpression(value.verifyExpression)
if (IsArr(value.verifyExpression?.value)) {
setCurrentExpressionValue(value.verifyExpression?.value.join(';'))
} else {
setCurrentExpressionValue(value.verifyExpression?.value)
}
}
mountRef.current = false
}, [])
React.useEffect(() => {
onChange?.({...currentCheckPropertyType||{}, ...currentExpressionType||{}, verifyExpression: currentExpression}) onChange?.({...currentCheckPropertyType||{}, ...currentExpressionType||{}, verifyExpression: currentExpression})
}, [currentCheckPropertyType, currentExpressionType, currentExpression]) }, [currentCheckPropertyType, currentExpressionType, currentExpression])
...@@ -258,7 +371,8 @@ const CheckItem = ({ value, onChange }) => { ...@@ -258,7 +371,8 @@ const CheckItem = ({ value, onChange }) => {
} }
return ( return (
<Space> <Row gutter={10}>
<Col span={6}>
<Select allowClear loading={loadingCheckPropertyTypes} <Select allowClear loading={loadingCheckPropertyTypes}
value={currentCheckPropertyType?.propertyEnName} value={currentCheckPropertyType?.propertyEnName}
onChange={(val) => { onChange={(val) => {
...@@ -277,6 +391,8 @@ const CheckItem = ({ value, onChange }) => { ...@@ -277,6 +391,8 @@ const CheckItem = ({ value, onChange }) => {
<Select.Option key={item.propertyEnName} value={item.propertyEnName}>{item.propertyCnName}</Select.Option> <Select.Option key={item.propertyEnName} value={item.propertyEnName}>{item.propertyCnName}</Select.Option>
)) } )) }
</Select> </Select>
</Col>
<Col span={6}>
<Select allowClear loading={loadingExpressionTypes} <Select allowClear loading={loadingExpressionTypes}
value={currentExpressionType?.expressionTypeEnName} value={currentExpressionType?.expressionTypeEnName}
onChange={(val) => { onChange={(val) => {
...@@ -290,6 +406,7 @@ const CheckItem = ({ value, onChange }) => { ...@@ -290,6 +406,7 @@ const CheckItem = ({ value, onChange }) => {
} }
setCurrentExpression() setCurrentExpression()
setCurrentExpressionValue()
}} }}
placeholder='请选择检查属性' placeholder='请选择检查属性'
> >
...@@ -297,6 +414,8 @@ const CheckItem = ({ value, onChange }) => { ...@@ -297,6 +414,8 @@ const CheckItem = ({ value, onChange }) => {
<Select.Option key={item.expressionTypeEnName} value={item.expressionTypeEnName}>{item.expressionTypeCnName}</Select.Option> <Select.Option key={item.expressionTypeEnName} value={item.expressionTypeEnName}>{item.expressionTypeCnName}</Select.Option>
)) } )) }
</Select> </Select>
</Col>
<Col span={6}>
<Select allowClear loading={loadingExpressionMapping} <Select allowClear loading={loadingExpressionMapping}
value={currentExpression?.enName} value={currentExpression?.enName}
onChange={(val) => { onChange={(val) => {
...@@ -308,6 +427,8 @@ const CheckItem = ({ value, onChange }) => { ...@@ -308,6 +427,8 @@ const CheckItem = ({ value, onChange }) => {
} else { } else {
setCurrentExpression() setCurrentExpression()
} }
setCurrentExpressionValue()
}} }}
placeholder='请选择表达式' placeholder='请选择表达式'
> >
...@@ -315,23 +436,29 @@ const CheckItem = ({ value, onChange }) => { ...@@ -315,23 +436,29 @@ const CheckItem = ({ value, onChange }) => {
<Select.Option key={item.enName} value={item.enName}>{item.cnName}</Select.Option> <Select.Option key={item.enName} value={item.enName}>{item.cnName}</Select.Option>
)) } )) }
</Select> </Select>
{ (currentExpression?.valueType === 'string') && <Input </Col>
<Col span={6}>
{ (currentExpression?.valueType === 'string') && <Input value={currentExpressionValue}
onChange={(e) => { onChange={(e) => {
setCurrentExpressionValue(e.target.value)
setCurrentExpression({ setCurrentExpression({
...currentExpression, value: e.target.value ...currentExpression, value: e.target.value
}) })
}}/> } }}/> }
{ (currentExpression?.valueType === 'int') && <InputNumber { (currentExpression?.valueType === 'int') && <InputNumber value={currentExpressionValue}
onChange={(e) => { onChange={(e) => {
setCurrentExpressionValue(e.target.value)
setCurrentExpression({ setCurrentExpression({
...currentExpression, value: e.target.value ...currentExpression, value: e.target.value
}) })
}}/> } }}/> }
{ (currentExpression?.valueType === 'List<String>') && <Input placeholder='枚举值用;隔开 如高;中;低' onChange={(e) => { { (currentExpression?.valueType === 'List<String>') && <Input placeholder='枚举值用;隔开 如高;中;低' value={currentExpressionValue} onChange={(e) => {
setCurrentExpressionValue(e.target.value)
setCurrentExpression({ setCurrentExpression({
...currentExpression, value: (e.target.value??'').split(';') ...currentExpression, value: e.target.value?e.target.value.split(';'):[]
}) })
}} /> } }} /> }
</Space> </Col>
</Row>
) )
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment