Commit 02e825d8 authored by cuiwenlong7's avatar cuiwenlong7
Browse files

Merge branch 'v1.2.4' of gitee.com:jd-platform-opensource/ccms into dev_isv

parents e193be34 55319af7
Showing with 73 additions and 28 deletions
+73 -28
......@@ -85,4 +85,4 @@
"react": "^16.13.1",
"react-dom": "^16.13.1"
}
}
}
\ No newline at end of file
......@@ -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) => ({
......
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 (values.includes(v)) {
return true
} else {
console.warn(`选择框的当前值中${v}不在选项中。`)
......
......@@ -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 | DefaultOptionsConfig
titleColumn?: string,
treeData?: ManualOptionsConfig | InterfaceOptionsConfig | AutomaticOptionsConfig
}
interface TreeSelectMultipleArrayConfig {
......@@ -20,11 +21,12 @@ interface TreeSelectMultipleArrayConfig {
interface TreeSelectMultipleSplitConfig {
type: 'split',
split?: string
split?: string,
valueType?: string
}
export interface DefaultOptionsConfig {
export interface AutomaticOptionsConfig {
from: 'automatic'
defaultValue?: OptionsConfigDefaultValue,
sourceConfig?: OptionsConfigDefaultValue,
format?: InterfaceOptionsListConfig
}
......@@ -91,9 +93,9 @@ export default class TreeSelectField extends Field<TreeSelectFieldConfig, ITreeS
}
}
optionsAutomaticValue = (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 | DefaultOptionsConfig | undefined,
config: ManualOptionsConfig | InterfaceOptionsConfig | AutomaticOptionsConfig | 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.optionsAutomaticValue(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>
)
}
}
}
......@@ -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
}
}
Supports Markdown
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