Commit 9094696b authored by wangailin's avatar wangailin
Browse files

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

parents 34873287 f597cd1d
Showing with 37 additions and 17 deletions
+37 -17
......@@ -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) => ({
......
......@@ -10,8 +10,8 @@ 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 {
......@@ -22,9 +22,9 @@ interface TreeSelectMultipleSplitConfig {
type: 'split',
split?: string
}
export interface DefaultOptionsConfig {
export interface AutomaticOptionsConfig {
from: 'automatic'
defaultValue?: OptionsConfigDefaultValue,
sourceConfig?: OptionsConfigDefaultValue,
format?: InterfaceOptionsListConfig
}
......@@ -91,9 +91,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 +122,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 +131,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 +208,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模式。
......@@ -255,6 +264,7 @@ export default class TreeSelectField extends Field<TreeSelectFieldConfig, ITreeS
if (optionsConfig && (optionsConfig.from === 'manual' || optionsConfig.from === 'automatic')) {
props.treeData = temp
}
debugger
if (multiple === true || multiple?.type === 'array') {
if (Array.isArray(value)) {
props.value = (value as Array<string | number>)
......@@ -276,8 +286,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>
)
}
}
}
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