diff --git a/src/components/detail/common.tsx b/src/components/detail/common.tsx index 57902c18fa9ace6e57473ea7a8066cf43eff1e77..c095ba394799aa3c89acfb87cccd856b709e78a7 100644 --- a/src/components/detail/common.tsx +++ b/src/components/detail/common.tsx @@ -24,7 +24,7 @@ export interface DetailFieldConfig { columns?: ColumnsConfig childColumns?: ColumnsConfig display?: 'none' - defaultValue?: string, + defaultValue?: ParamConfig, condition?: DetailFieldConditionConfig layout?: 'horizontal' | 'vertical' styles?: object @@ -132,7 +132,13 @@ export class DetailField extends Reac config } = this.props - return config.defaultValue + if (typeof config.defaultValue === 'string') { + return config.defaultValue + } + if (config.defaultValue !== undefined) { + return ParamHelper(config.defaultValue, { record: this.props.record, data: this.props.data, step: this.props.step }) + } + return undefined } set: (value: T) => Promise = async (value) => { diff --git a/src/components/detail/detailColor/index.tsx b/src/components/detail/detailColor/index.tsx index d498ce13b2c80f547d5db1aea49e4ab0b6a1c27a..f5b3c3e4ba107de0ecc1b7d8fab534492cafccbf 100644 --- a/src/components/detail/detailColor/index.tsx +++ b/src/components/detail/detailColor/index.tsx @@ -10,13 +10,26 @@ export interface IColorProps { } export default class InfoDetail extends DetailField implements IDetailField { + reset: () => Promise = async () => { + const defaults = await this.defaultValue() + return (defaults === undefined) ? '' : defaults + } + + state = { + value: '' + } + renderComponent = (props: IColorProps) => { return 您当前使用的UI版本没有实现colorDetail组件。 } - getValue = () => { + componentDidMount() { + this.getValue() + } + + getValue = async () => { const { value, config: { @@ -24,14 +37,24 @@ export default class InfoDetail extends DetailField { - const value = this.getValue() + const { value } = this.state return ( diff --git a/src/components/detail/enum/index.tsx b/src/components/detail/enum/index.tsx index c79b2cf054310511baceae49e1cd7c387808179b..658ff32984f57b007968df48e9dcf35233a2d7e9 100644 --- a/src/components/detail/enum/index.tsx +++ b/src/components/detail/enum/index.tsx @@ -35,7 +35,7 @@ export interface IEnumProps { export default class EnumDetail extends DetailField implements IDetailField { reset: () => Promise = async () => { const defaults = await this.defaultValue() - return (defaults === undefined) ? '' : defaults + return (defaults === undefined) ? '/' : defaults } renderComponent = (props: IEnumProps) => { diff --git a/src/components/detail/text/index.tsx b/src/components/detail/text/index.tsx index 6338ad6b8fe582c63102b79bb6db9c182b84e93a..15192b8953a782bc0db58560f3f5d3ccc66868f1 100644 --- a/src/components/detail/text/index.tsx +++ b/src/components/detail/text/index.tsx @@ -1,6 +1,6 @@ import React from 'react' import { getBoolean } from '../../../util/value' -import { DetailField, DetailFieldConfig, DetailFieldError, IDetailField } from '../common' +import { DetailField, DetailFieldProps, DetailFieldConfig, DetailFieldError, IDetailField } from '../common' export interface TextFieldConfig extends DetailFieldConfig { type: 'text' @@ -11,6 +11,19 @@ export interface ITextField { } export default class TextField extends DetailField implements IDetailField { + reset: () => Promise = async () => { + const defaults = await this.defaultValue() + return (defaults === undefined) ? '/' : defaults + } + + state = { + value: '' + } + + constructor(props: DetailFieldProps) { + super(props) + } + renderComponent = (props: ITextField) => { return 您当前使用的UI版本没有实现Text组件。 @@ -19,24 +32,45 @@ export default class TextField extends DetailField } - getValue = () => { + componentDidMount() { + this.getValue() + } + + getValue = async () => { const { value, config: { defaultValue } } = this.props - - if (value === undefined || value === null || value === '') { - return defaultValue !== undefined ? defaultValue : '' + if (value) { + if (typeof value !== 'object') { + return this.setState({ + value: String(value) + }) + } else if (Array.isArray(value)) { + return this.setState({ + value: (value as Array).join(',') + }) + } else { + return this.setState({ + value: '/' + }) + } + } + if (typeof defaultValue === 'string') { + this.setState({ + value: defaultValue + }) + } else { + this.setState({ + value: await this.reset() + }) } - return value } render = () => { - const value = this.getValue() - console.log(value, 'text value ') - + const { value } = this.state return ( {this.renderComponent({