Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄庭坚
jinfa-platform
Commits
042dcec6
Commit
042dcec6
authored
May 09, 2022
by
前端-李俊鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 规则配置字段条件切换调整
parent
354aac69
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
34 deletions
+88
-34
index.tsx
...g/ruleEng/ruleEngConfig/components/ConfigDrawer/index.tsx
+3
-3
index.tsx
...ruleEng/ruleEngConfig/components/MaterialDrawer/index.tsx
+21
-4
index.tsx
...g/ruleEng/ruleEngConfig/components/ProcessRules/index.tsx
+35
-13
index.tsx
...ruleEng/ruleEngConfig/components/SelectCategory/index.tsx
+5
-6
index.tsx
...ruleEng/ruleEngConfig/components/SelectMaterial/index.tsx
+7
-8
index.tsx
src/utils/index.tsx
+17
-0
No files found.
src/pages/systemSetting/ruleEng/ruleEngConfig/components/ConfigDrawer/index.tsx
View file @
042dcec6
...
...
@@ -31,14 +31,13 @@ const ConfigDrawer = (props: PropsType, ref) => {
const
handleOk
=
useCallback
(()
=>
{
form
.
validateFields
().
then
((
values
)
=>
{
const
{
id
,
ruleEngineConfigFieldRelations
}
=
values
const
params
=
{
...
paramsRef
.
current
,
id
,
ruleEngineConfigFieldRelations
:
ruleEngineConfigFieldRelations
?.
map
(
item
=>
{
let
temp
=
item
.
ruleEngineConfigFields
||
[]
// 过滤
掉没有选择'所有物料'(isQueryAll)的情况下且字段值未填写
的字段数据
let
ruleEngineConfigFields
:
any
[]
=
temp
?.
filter
(
i
=>
(
i
.
isQueryAll
!==
1
&&
!
[
''
,
undefined
,
null
].
includes
(
i
.
value
)
))
// 过滤
出字段值不为空的字段数据和选择了'所有物料'(isQueryAll)
的字段数据
let
ruleEngineConfigFields
:
any
[]
=
temp
?.
filter
(
i
=>
(
!
[
''
,
undefined
,
null
].
includes
(
i
.
value
)
||
i
.
isQueryAll
===
1
))
return
{
...
item
,
// 若字段配置列表数据的长度为0,则将其置为undefined
...
...
@@ -46,6 +45,7 @@ const ConfigDrawer = (props: PropsType, ref) => {
}
})
}
console
.
log
(
'params'
,
params
)
setLoading
(
true
)
postRuleEngineConfigBatchSaveOrUpdate
(
params
).
then
(({
code
})
=>
{
if
(
code
===
1000
)
{
...
...
src/pages/systemSetting/ruleEng/ruleEngConfig/components/MaterialDrawer/index.tsx
View file @
042dcec6
...
...
@@ -21,12 +21,13 @@ interface PropsType {
onOk
?:
(
rows
:
any
[],
rowKeys
:
any
[])
=>
void
onQueryAll
?:
(
value
?:
any
)
=>
void
fieldCode
?:
string
fieldLabel
?:
string
selectCache
?:
any
[]
}
const
MaterialDrawer
=
(
props
:
PropsType
,
ref
)
=>
{
const
formActions
=
createFormActions
()
const
{
onOk
,
onQueryAll
,
fieldCode
=
'code'
,
selectCache
}
=
props
const
{
onOk
,
onQueryAll
,
fieldCode
=
'code'
,
fieldLabel
,
selectCache
}
=
props
const
[
selectedRowKeys
,
setSelectedRowKeys
]
=
useState
<
any
>
([])
const
[
selectedRows
,
setSelectedRows
]
=
useState
<
any
>
([])
...
...
@@ -36,10 +37,23 @@ const MaterialDrawer = (props: PropsType, ref) => {
const
drawRef
=
useRef
<
HandleType
>
()
const
isValuesChangeRef
=
useRef
<
boolean
>
(
false
)
const
getRealCodeValue
=
(
data
:
any
)
=>
{
const
codeArr
=
fieldCode
?.
split
(
'.'
)
||
[]
const
len
=
codeArr
.
length
if
(
len
)
{
let
result
=
data
for
(
let
i
=
0
;
i
<
len
;
i
++
)
{
result
=
result
?.[
codeArr
[
i
]]
}
return
result
}
return
data
[
'code'
]
}
const
handleOk
=
useCallback
(()
=>
{
isValuesChangeRef
.
current
=
false
onQueryAll
?.(
isQueryAll
)
onOk
?.(
selectedRows
.
map
(
item
=>
({
id
:
item
.
id
,
value
:
item
[
fieldCode
]
}))
,
selectedRowKeys
)
onOk
?.(
selectedRows
.
map
(
item
=>
({
id
:
item
.
id
,
value
:
item
.
value
}))
,
selectedRowKeys
)
},
[
selectedRows
,
selectedRowKeys
,
isQueryAll
])
const
handleShow
=
useCallback
((
params
:
Object
)
=>
{
...
...
@@ -49,7 +63,10 @@ const MaterialDrawer = (props: PropsType, ref) => {
return
new
Promise
((
resolve
)
=>
{
getProductGoodsGetDoesNotFreezeGoodsList
(
params
).
then
(({
code
,
data
})
=>
{
if
(
code
===
1000
)
{
resolve
(
data
)
resolve
({
total
:
data
.
total
,
data
:
data
.
data
?.
map
(
item
=>
({
...
item
,
value
:
getRealCodeValue
(
item
)
}))
})
}
})
})
...
...
@@ -119,7 +136,7 @@ const MaterialDrawer = (props: PropsType, ref) => {
const
columns
:
ColumnType
<
any
>
[]
=
[
{
title
:
'ID'
,
dataIndex
:
'id'
,
key
:
'id'
,
},
{
title
:
'物料编号'
,
dataIndex
:
fieldCode
,
key
:
fieldCode
}
{
title
:
fieldLabel
,
dataIndex
:
'value'
,
key
:
'value'
}
]
const
columns2
:
ColumnType
<
any
>
[]
=
[
...
...
src/pages/systemSetting/ruleEng/ruleEngConfig/components/ProcessRules/index.tsx
View file @
042dcec6
...
...
@@ -14,6 +14,7 @@ import SelectRoles from '../SelectRoles'
import
{
getMemberRolePage
}
from
'@/services/MemberV2Api'
import
{
conditionOptions
,
interrelationOptions
,
Filed_Type
,
Select_Content_Type
,
CONDITION_VALUE
}
from
'../../constant'
import
StringDatePicker
from
'../StringDatePicker'
import
moment
from
'moment'
type
PropsType
=
{
form
?:
FormInstance
...
...
@@ -130,15 +131,31 @@ const ProcessRules: React.FC<PropsType> = ({ form, filedTypeOptions, onFormField
form=
{
form
}
onFieldsChange=
{
(
_
,
_all
)
=>
{
onFormFieldsChange
?.(
_
,
_all
)
let
ruleEngineConfigFieldRelations
=
form
.
getFieldValue
(
'ruleEngineConfigFieldRelations'
)
// 当字段类型改变的时候,需要重置一下对应的code/value/condition
if
(
_
[
0
]?.
name
?.[
4
]
===
'code'
)
{
let
ruleEngineConfigFieldRelations
=
form
.
getFieldValue
(
'ruleEngineConfigFieldRelations'
)
const
filedTypeItem
=
getFiledTypeItem
(
_
[
0
].
value
)
ruleEngineConfigFieldRelations
[
_
[
0
].
name
[
1
]].
ruleEngineConfigFields
[
_
[
0
].
name
[
3
]].
type
=
filedTypeItem
?.
type
ruleEngineConfigFieldRelations
[
_
[
0
].
name
[
1
]].
ruleEngineConfigFields
[
_
[
0
].
name
[
3
]].
value
=
undefined
// 日期格式给予'今天'的默认值
ruleEngineConfigFieldRelations
[
_
[
0
].
name
[
1
]].
ruleEngineConfigFields
[
_
[
0
].
name
[
3
]].
value
=
filedTypeItem
?.
type
===
Filed_Type
.
DATE
?
moment
().
format
(
'YYYY-MM-DD'
)
:
undefined
ruleEngineConfigFieldRelations
[
_
[
0
].
name
[
1
]].
ruleEngineConfigFields
[
_
[
0
].
name
[
3
]].
condition
=
conditionOptions
[
filedTypeItem
?.
type
][
0
].
value
form
.
setFieldsValue
({
ruleEngineConfigFieldRelations
})
}
// 当字段条件改变的时候,需要重置一下对应的value
if
(
_
[
0
]?.
name
?.[
4
]
===
'condition'
)
{
console
.
log
(
'_'
,
_
)
console
.
log
(
'ruleEngineConfigFieldRelations[_[0].name[1]].ruleEngineConfigFields[_[0].name[3]].type'
,
ruleEngineConfigFieldRelations
[
_
[
0
].
name
[
1
]].
ruleEngineConfigFields
[
_
[
0
].
name
[
3
]].
code
)
const
filedTypeItem
=
getFiledTypeItem
(
ruleEngineConfigFieldRelations
[
_
[
0
].
name
[
1
]].
ruleEngineConfigFields
[
_
[
0
].
name
[
3
]].
code
)
console
.
log
(
'filedTypeItem'
,
filedTypeItem
)
// 字符格式切换条件的时候值的格式可能会变化,所以这里需要重置
if
(
filedTypeItem
?.
type
===
Filed_Type
.
STRING
)
{
ruleEngineConfigFieldRelations
[
_
[
0
].
name
[
1
]].
ruleEngineConfigFields
[
_
[
0
].
name
[
3
]].
isQueryAll
=
0
ruleEngineConfigFieldRelations
[
_
[
0
].
name
[
1
]].
ruleEngineConfigFields
[
_
[
0
].
name
[
3
]].
value
=
undefined
}
form
.
setFieldsValue
({
ruleEngineConfigFieldRelations
})
}
}
}
>
<
Form
.
Item
...
...
@@ -293,6 +310,7 @@ const ProcessRules: React.FC<PropsType> = ({ form, filedTypeOptions, onFormField
<
SelectMaterial
onValueChange=
{
(
value
)
=>
{
onMaterialChange
(
ruleFieldKey
,
fieldFieldKey
,
value
)
}
}
fieldCode=
{
filedTypeItem
?.
codeAlias
}
fieldLabel=
{
filedTypeItem
?.
name
}
selectCache=
{
getSelectCache
(
selectMaterial
?.[
ruleFieldKey
]
||
{},
fieldFieldKey
)
}
isAll=
{
ruleEngineConfigFields
?.
isQueryAll
===
1
}
onQueryAll=
{
(
value
)
=>
{
...
...
@@ -368,17 +386,21 @@ const ProcessRules: React.FC<PropsType> = ({ form, filedTypeOptions, onFormField
</
ConfigFieldCard
>
</
div
>
))
}
<
div
className=
{
styles
[
'add'
]
}
>
<
Form
.
Item
>
<
Button
type=
"primary"
onClick=
{
()
=>
{
ruleAdd
({
relation
:
interrelationOptions
[
0
].
value
})
}
}
>
添加规则
</
Button
>
</
Form
.
Item
>
</
div
>
{
// 限制3个流程规则
ruleFields
.
length
<
3
&&
<
div
className=
{
styles
[
'add'
]
}
>
<
Form
.
Item
>
<
Button
type=
"primary"
onClick=
{
()
=>
{
ruleAdd
({
relation
:
interrelationOptions
[
0
].
value
})
}
}
>
添加规则
</
Button
>
</
Form
.
Item
>
</
div
>
}
</
div
>
)
}
}
...
...
src/pages/systemSetting/ruleEng/ruleEngConfig/components/SelectCategory/index.tsx
View file @
042dcec6
import
{
isJSONString
}
from
'@/utils'
import
React
,
{
useState
,
memo
,
useCallback
,
useRef
,
useEffect
}
from
'react'
import
CategoryDrawer
from
'../CategoryDrawer'
import
WrapSelect
from
'../WrapSelect'
...
...
@@ -34,12 +35,10 @@ const SelectMaterial = (props: PropsType) => {
}
useEffect
(()
=>
{
if
(
value
)
{
// JSON字符串转为原数据
const
keys
=
JSON
.
parse
(
value
)
setSelectData
(
keys
)
onValueChange
?.(
keys
)
}
// JSON字符串转为原数据
const
keys
=
value
&&
isJSONString
(
value
)
?
JSON
.
parse
(
value
)
:
[]
setSelectData
(
keys
)
onValueChange
?.(
keys
)
},
[
value
])
return
(
...
...
src/pages/systemSetting/ruleEng/ruleEngConfig/components/SelectMaterial/index.tsx
View file @
042dcec6
import
{
isJSONString
}
from
'@/utils'
import
React
,
{
useState
,
memo
,
useCallback
,
useRef
,
useEffect
}
from
'react'
import
MaterialDrawer
,
{
RefHandleType
}
from
'../MaterialDrawer'
import
WrapSelect
from
'../WrapSelect'
...
...
@@ -7,13 +8,14 @@ interface PropsType {
onValueChange
?:
(
data
:
any
[])
=>
void
value
?:
any
fieldCode
?:
string
fieldLabel
?:
string
onQueryAll
?:
(
value
?:
any
)
=>
void
selectCache
?:
any
[]
isAll
?:
boolean
}
const
SelectMaterial
=
(
props
:
PropsType
)
=>
{
const
{
onChange
,
value
,
fieldCode
=
'code'
,
onQueryAll
,
onValueChange
,
isAll
,
...
rest
}
=
props
const
{
onChange
,
value
,
onQueryAll
,
onValueChange
,
isAll
,
...
rest
}
=
props
const
[
selectData
,
setSelectData
]
=
useState
<
any
[]
>
([])
const
[
isQueryAll
,
setIsQueryAll
]
=
useState
<
boolean
>
(
false
)
...
...
@@ -42,12 +44,10 @@ const SelectMaterial = (props: PropsType) => {
}
useEffect
(()
=>
{
if
(
value
)
{
// JSON字符串转为原数据
const
rows
=
JSON
.
parse
(
value
)
setSelectData
(
rows
)
onValueChange
?.(
rows
)
}
// JSON字符串转为原数据
const
rows
=
value
&&
isJSONString
(
value
)
?
JSON
.
parse
(
value
)
:
[]
setSelectData
(
rows
)
onValueChange
?.(
rows
)
},
[
value
])
useEffect
(()
=>
{
...
...
@@ -66,7 +66,6 @@ const SelectMaterial = (props: PropsType) => {
<
MaterialDrawer
ref=
{
ref
}
onOk=
{
handleOk
}
fieldCode=
{
fieldCode
}
onQueryAll=
{
_onQueryAll
}
{
...
rest
}
/>
...
...
src/utils/index.tsx
View file @
042dcec6
...
...
@@ -728,6 +728,23 @@ export const downloadFile = (url, fileName) => {
x
.
send
();
}
export
const
isJSONString
=
(
str
)
=>
{
if
(
typeof
str
==
'string'
)
{
try
{
var
obj
=
JSON
.
parse
(
str
);
if
(
typeof
obj
==
'object'
&&
obj
){
return
true
;
}
else
{
return
false
;
}
}
catch
(
e
)
{
return
false
;
}
}
return
false
}
export
default
{
isArray
,
isObject
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment