diff --git a/package/components/LocalProvider/index.js b/package/components/LocalProvider/index.js index 72e7beb..e00f509 100644 --- a/package/components/LocalProvider/index.js +++ b/package/components/LocalProvider/index.js @@ -35,7 +35,9 @@ const langs = { 'enum_desc_msg': 'enum description', 'required': 'required', 'mock': 'mock', - 'mockLink': 'Help' + 'mockLink': 'Help', + 'integerFormat': 'integer format', + 'className': 'class name' }, zh_CN: { 'title': '标题', @@ -70,7 +72,9 @@ const langs = { 'enum_desc_msg': '备注描述信息', 'required': '是否必须', 'mock': 'mock', - 'mockLink': '查看文档' + 'mockLink': '查看文档', + 'integerFormat': '整数类型', + 'className': '对象类名' } } diff --git a/package/components/SchemaComponents/SchemaJson.js b/package/components/SchemaComponents/SchemaJson.js index cbfcea1..e48e80f 100644 --- a/package/components/SchemaComponents/SchemaJson.js +++ b/package/components/SchemaComponents/SchemaJson.js @@ -179,7 +179,7 @@ class SchemaArray extends PureComponent { this.handleShowEdit('title')} />} placeholder={LocaleProvider('title')} - value={value.title} + value={items.title} onChange={this.handleChangeTitle} /> diff --git a/package/components/SchemaComponents/SchemaOther.js b/package/components/SchemaComponents/SchemaOther.js index 04a61cc..fa3cf0e 100644 --- a/package/components/SchemaComponents/SchemaOther.js +++ b/package/components/SchemaComponents/SchemaOther.js @@ -31,6 +31,52 @@ const changeOtherValue = (value, name, data, change) => { change(data); }; +class SchemaObject extends PureComponent { + constructor(props) { + super(props); + this.state = { + checked: _.isUndefined(props.data.enum) ? false : true + }; + } + + componentWillReceiveProps(nextprops) { + if (this.props.data.enum !== nextprops.data.enum) { + this.setState({ + checked: _.isUndefined(nextprops.data.enum) ? false : true + }); + } + } + + changeClassNameValue = (value, data) => { + data["$$ref"] = "#/definitions/" + value; + this.context.changeCustomValue(data); + }; + + render() { + const { data } = this.props; + return ( +
+
{LocalProvider('base_setting')}
+ + + {LocalProvider('className')}: + + + this.changeClassNameValue(e.target.value, data)} + /> + + +
+ ); + } +} +SchemaObject.contextTypes = { + changeCustomValue: PropTypes.func +}; + class SchemaString extends PureComponent { constructor(props, context) { super(props); @@ -424,6 +470,242 @@ SchemaNumber.contextTypes = { changeCustomValue: PropTypes.func }; +class SchemaInteger extends PureComponent { + + constructor(props, context) { + super(props); + this.state = { + checked: _.isUndefined(props.data.enum) ? false : true, + enum: _.isUndefined(props.data.enum) ? '' : props.data.enum.join('\n') + }; + this.format = context.Model.__jsonIntegerFormat; + } + + componentWillReceiveProps(nextprops) { + const enumStr = _.isUndefined(this.props.data.enum) ? '' : this.props.data.enum.join('\n'); + const nextEnumStr = _.isUndefined(nextprops.data.enum) ? '' : nextprops.data.enum.join('\n'); + if (enumStr !== nextEnumStr) { + this.setState({ enum: nextEnumStr }); + } + } + + changeOtherValue = (value, name, data) => { + data[name] = value; + this.context.changeCustomValue(data); + }; + + onChangeCheckBox = (checked, data) => { + this.setState({ + checked + }); + + if (!checked) { + delete data.enum; + this.setState({ enum: '' }); + this.context.changeCustomValue(data); + } + }; + + changeEnumOtherValue = (value, data) => { + this.setState({ enum: value }); + var arr = value.split('\n'); + if (arr.length === 0 || (arr.length == 1 && !arr[0])) { + delete data.enum; + this.context.changeCustomValue(data); + } else { + data.enum = arr.map(item => +item); + this.context.changeCustomValue(data); + } + }; + + onEnterEnumOtherValue = (value, data) => { + let arr = value.split('\n').map(item => +item); + data.enum = arr; + this.context.changeCustomValue(data); + }; + + changeEnumDescOtherValue = (value, data) => { + data.enumDesc = value; + this.context.changeCustomValue(data); + }; + + render() { + const { data } = this.props; + return ( +
+
{LocalProvider('base_setting')}
+ + + {LocalProvider('integerFormat')}: + + + + + + {LocalProvider('default')}: + + + + changeOtherValue(e.target.value, 'default', data, this.context.changeCustomValue) + } + /> + + + + + + + + exclusiveMinimum  + + + +   : + + + + + changeOtherValue(e, 'exclusiveMinimum', data, this.context.changeCustomValue) + } + /> + + + + + + + + exclusiveMaximum  + + + +   : + + + + + changeOtherValue(e, 'exclusiveMaximum', data, this.context.changeCustomValue) + } + /> + + + + + + + + + {LocalProvider('minimum')}: + + + + changeOtherValue(e, 'minimum', data, this.context.changeCustomValue) + } + /> + + + + + + + {LocalProvider('maximum')}: + + + + changeOtherValue(e, 'maximum', data, this.context.changeCustomValue) + } + /> + + + + + + + + {LocalProvider('enum')} + this.onChangeCheckBox(e.target.checked, data)} + />{' '} + : + + + +