Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
xiaojuan huang
Ccms
Commits
02e825d8
Commit
02e825d8
authored
3 years ago
by
cuiwenlong7
Browse files
Options
Download
Plain Diff
Merge branch 'v1.2.4' of gitee.com:jd-platform-opensource/ccms into dev_isv
parents
e193be34
55319af7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
package.json
+1
-1
package.json
src/components/formFields/select/common.tsx
+6
-6
src/components/formFields/select/common.tsx
src/components/formFields/select/multiple/index.tsx
+7
-5
src/components/formFields/select/multiple/index.tsx
src/components/formFields/treeSelect/index.tsx
+35
-14
src/components/formFields/treeSelect/index.tsx
src/util/value.ts
+24
-2
src/util/value.ts
with
73 additions
and
28 deletions
+73
-28
package.json
+
1
-
1
View file @
02e825d8
...
...
@@ -85,4 +85,4 @@
"react"
:
"^16.13.1"
,
"react-dom"
:
"^16.13.1"
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/components/formFields/select/common.tsx
+
6
-
6
View file @
02e825d8
...
...
@@ -19,7 +19,7 @@ type OptionsConfigDefaultValue =
interface
AutomaticEnumerationOptionsConfig
{
from
:
'
automatic
'
;
defaultValue
?:
OptionsConfigDefaultValue
;
sourceConfig
?:
OptionsConfigDefaultValue
;
format
?:
|
InterfaceEnumerationOptionsKVConfig
|
InterfaceEnumerationOptionsListConfig
;
...
...
@@ -55,9 +55,9 @@ export default class SelectField<C extends SelectFieldConfig, E, T> extends Fiel
}
}
optionsAutomaticValue
=
(
defaultValue
:
OptionsConfigDefaultValue
)
=>
{
if
(
defaultValue
!==
undefined
)
{
return
ParamHelper
(
defaultValue
,
{
record
:
this
.
props
.
record
,
data
:
this
.
props
.
data
,
step
:
this
.
props
.
step
})
optionsAutomaticValue
=
(
sourceConfig
:
OptionsConfigDefaultValue
)
=>
{
if
(
sourceConfig
!==
undefined
)
{
return
ParamHelper
(
sourceConfig
,
{
record
:
this
.
props
.
record
,
data
:
this
.
props
.
data
,
step
:
this
.
props
.
step
})
}
return
undefined
}
...
...
@@ -67,8 +67,8 @@ export default class SelectField<C extends SelectFieldConfig, E, T> extends Fiel
)
=>
{
if
(
config
)
{
if
(
config
.
from
===
'
automatic
'
)
{
if
(
config
.
defaultValue
&&
config
.
defaultValue
.
source
&&
config
.
defaultValue
.
field
)
{
const
data
=
this
.
optionsAutomaticValue
(
config
.
defaultValue
)
if
(
config
.
sourceConfig
&&
config
.
sourceConfig
.
source
&&
config
.
sourceConfig
.
field
)
{
const
data
=
this
.
optionsAutomaticValue
(
config
.
sourceConfig
)
if
(
config
.
format
)
{
if
(
config
.
format
.
type
===
'
kv
'
)
{
return
Object
.
keys
(
data
).
map
((
key
)
=>
({
...
...
This diff is collapsed.
Click to expand it.
src/components/formFields/select/multiple/index.tsx
+
7
-
5
View file @
02e825d8
import
React
from
'
react
'
import
{
getBoolean
}
from
'
../../../../util/value
'
import
{
getBoolean
,
transformValueType
}
from
'
../../../../util/value
'
import
{
FieldError
}
from
'
../../common
'
import
SelectField
,
{
ISelectFieldOption
,
SelectFieldConfig
}
from
'
../common
'
...
...
@@ -17,7 +17,8 @@ interface SelectMultipleArrayConfig {
interface
SelectMultipleSplitConfig
{
type
:
'
split
'
,
split
?:
string
split
?:
string
,
valueType
?:
string
}
export
interface
ISelectMultipleField
{
...
...
@@ -135,8 +136,8 @@ export default class SelectMultipleField extends SelectField<SelectMultipleField
console
.
warn
(
'
数组类型的多项选择框的值需要是字符串或数值的数组。
'
)
}
}
else
if
(
multiple
?.
type
===
'
split
'
)
{
if
(
typeof
value
===
'
string
'
)
{
props
.
value
=
String
(
value
).
split
(
multiple
.
split
||
'
,
'
)
if
(
typeof
value
===
'
string
'
&&
value
!==
''
)
{
props
.
value
=
transformValueType
(
String
(
value
).
split
(
multiple
.
split
||
'
,
'
)
,
multiple
?.
valueType
)
}
else
if
(
value
!==
undefined
)
{
props
.
value
=
undefined
console
.
warn
(
'
字符串分隔类型的多项选择框的值需要是字符串。
'
)
...
...
@@ -146,8 +147,9 @@ export default class SelectMultipleField extends SelectField<SelectMultipleField
}
if
(
props
.
value
!==
undefined
)
{
const
values
=
props
.
options
.
map
((
option
)
=>
option
.
value
)
props
.
value
.
filter
((
v
)
=>
{
if
(
props
.
options
.
map
((
option
)
=>
option
.
value
)
.
includes
(
v
.
toString
()
))
{
if
(
value
s
.
includes
(
v
))
{
return
true
}
else
{
console
.
warn
(
`选择框的当前值中
${
v
}
不在选项中。`
)
...
...
This diff is collapsed.
Click to expand it.
src/components/formFields/treeSelect/index.tsx
+
35
-
14
View file @
02e825d8
...
...
@@ -4,14 +4,15 @@ import { Field, FieldConfig, IField, FieldError, FieldProps } from '../common'
import
InterfaceHelper
,
{
InterfaceConfig
}
from
'
../../../util/interface
'
import
ParamHelper
from
'
../../../util/param
'
import
{
RecordParamConfig
,
DataParamConfig
,
StepParamConfig
,
SourceParamConfig
}
from
'
../../../interface
'
import
{
transformValueType
}
from
'
../../../util/value
'
type
OptionsConfigDefaultValue
=
RecordParamConfig
|
DataParamConfig
|
StepParamConfig
|
SourceParamConfig
export
interface
TreeSelectFieldConfig
extends
FieldConfig
{
type
:
'
tree_select
'
mode
?:
'
tree
'
|
'
table
'
multiple
?:
true
|
TreeSelectMultipleArrayConfig
|
TreeSelectMultipleSplitConfig
,
titleColumn
:
string
,
treeData
?:
ManualOptionsConfig
|
InterfaceOptionsConfig
|
Default
OptionsConfig
titleColumn
?
:
string
,
treeData
?:
ManualOptionsConfig
|
InterfaceOptionsConfig
|
Automatic
OptionsConfig
}
interface
TreeSelectMultipleArrayConfig
{
...
...
@@ -20,11 +21,12 @@ interface TreeSelectMultipleArrayConfig {
interface
TreeSelectMultipleSplitConfig
{
type
:
'
split
'
,
split
?:
string
split
?:
string
,
valueType
?:
string
}
export
interface
Default
OptionsConfig
{
export
interface
Automatic
OptionsConfig
{
from
:
'
automatic
'
defaultValue
?:
OptionsConfigDefaultValue
,
sourceConfig
?:
OptionsConfigDefaultValue
,
format
?:
InterfaceOptionsListConfig
}
...
...
@@ -91,9 +93,9 @@ export default class TreeSelectField extends Field<TreeSelectFieldConfig, ITreeS
}
}
optionsAutomatic
Value
=
(
defaultValue
:
OptionsConfigDefaultValue
)
=>
{
if
(
defaultValue
!==
undefined
)
{
return
ParamHelper
(
defaultValue
,
{
record
:
this
.
props
.
record
,
data
:
this
.
props
.
data
,
step
:
this
.
props
.
step
})
optionsAutomatic
=
(
sourceConfig
:
OptionsConfigDefaultValue
)
=>
{
if
(
sourceConfig
!==
undefined
)
{
return
ParamHelper
(
sourceConfig
,
{
record
:
this
.
props
.
record
,
data
:
this
.
props
.
data
,
step
:
this
.
props
.
step
})
}
return
undefined
}
...
...
@@ -122,7 +124,7 @@ export default class TreeSelectField extends Field<TreeSelectFieldConfig, ITreeS
}
options
=
(
config
:
ManualOptionsConfig
|
InterfaceOptionsConfig
|
Default
OptionsConfig
|
undefined
,
config
:
ManualOptionsConfig
|
InterfaceOptionsConfig
|
Automatic
OptionsConfig
|
undefined
,
datas
:
{
record
?:
object
data
:
object
[]
...
...
@@ -131,8 +133,8 @@ export default class TreeSelectField extends Field<TreeSelectFieldConfig, ITreeS
)
=>
{
if
(
config
)
{
if
(
config
.
from
===
'
automatic
'
)
{
if
(
config
.
defaultValue
&&
config
.
defaultValue
.
source
&&
config
.
defaultValue
.
field
)
{
const
data
=
this
.
optionsAutomatic
Value
(
config
.
defaultValue
)
if
(
config
.
sourceConfig
&&
config
.
sourceConfig
.
source
&&
config
.
sourceConfig
.
field
)
{
const
data
=
this
.
optionsAutomatic
(
config
.
sourceConfig
)
if
(
Array
.
isArray
(
data
))
{
return
this
.
formatTree
(
data
,
...
...
@@ -208,6 +210,15 @@ export default class TreeSelectField extends Field<TreeSelectFieldConfig, ITreeS
return
errors
.
length
?
errors
:
true
}
renderComponent
=
(
props
:
ITreeSelectField
)
=>
{
return
<
React
.
Fragment
>
您当前使用的UI版本没有实现TreeSelectSingleField组件的SelectSingle模式。
<
div
style
=
{
{
display
:
'
none
'
}
}
>
<
button
onClick
=
{
()
=>
props
.
onChange
(
''
)
}
>
onChange
</
button
>
</
div
>
</
React
.
Fragment
>
}
renderTreeComponent
=
(
props
:
ITreeSelectField
)
=>
{
return
<
React
.
Fragment
>
您当前使用的UI版本没有实现TreeSelectField组件的tree模式。
...
...
@@ -263,8 +274,8 @@ export default class TreeSelectField extends Field<TreeSelectFieldConfig, ITreeS
console
.
warn
(
'
数组类型的树形选框的值需要是字符串或数值的数组。
'
)
}
}
else
if
(
multiple
?.
type
===
'
split
'
)
{
if
(
typeof
value
===
'
string
'
)
{
props
.
value
=
String
(
value
).
split
(
multiple
.
split
||
'
,
'
)
if
(
typeof
value
===
'
string
'
&&
value
!==
''
)
{
props
.
value
=
transformValueType
(
String
(
value
).
split
(
multiple
.
split
||
'
,
'
)
,
multiple
?.
valueType
)
}
else
if
(
value
!==
undefined
)
{
props
.
value
=
undefined
console
.
warn
(
'
字符串分隔类型的树形选框的值需要是字符串。
'
)
...
...
@@ -276,8 +287,18 @@ export default class TreeSelectField extends Field<TreeSelectFieldConfig, ITreeS
if
(
mode
===
'
table
'
)
{
props
.
titleColumn
=
titleColumn
return
this
.
renderTableComponent
(
props
)
}
else
{
}
else
if
(
mode
===
'
tree
'
)
{
return
this
.
renderTreeComponent
(
props
)
}
else
{
return
(
<
React
.
Fragment
>
{
this
.
renderComponent
({
value
,
treeData
:
this
.
state
.
interfaceOptionsData
,
onChange
:
async
(
value
:
string
)
=>
await
this
.
props
.
onValueSet
(
''
,
value
,
await
this
.
validate
(
value
))
})
}
</
React
.
Fragment
>
)
}
}
}
This diff is collapsed.
Click to expand it.
src/util/value.ts
+
24
-
2
View file @
02e825d8
...
...
@@ -114,10 +114,32 @@ export const listItemMove = (list: any[], currentIndex: number, sortType: 'up' |
switch
(
sortType
)
{
case
'
up
'
:
currentIndex
!==
0
&&
(
list
[
currentIndex
]
=
list
.
splice
(
currentIndex
-
1
,
1
,
list
[
currentIndex
])[
0
])
break
;
break
case
'
down
'
:
currentIndex
<
list
.
length
-
1
&&
(
list
[
currentIndex
]
=
list
.
splice
(
currentIndex
+
1
,
1
,
list
[
currentIndex
])[
0
])
break
;
break
}
return
list
}
/**
* 转化value数组中的值类型
* @param list value数组
* @param type 值类型
* @returns value数组
*/
export
const
transformValueType
=
(
list
:
any
[],
type
:
string
|
undefined
)
=>
{
switch
(
type
)
{
case
'
string
'
:
return
list
.
map
(
v
=>
String
(
v
))
case
'
number
'
:
return
list
.
map
(
v
=>
+
v
)
case
'
boolean
'
:
return
list
.
map
(
v
=>
Boolean
(
v
))
default
:
return
list
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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