diff --git a/packages/json-schema-editor/main.vue b/packages/json-schema-editor/main.vue index cc50ed3..4af6a65 100644 --- a/packages/json-schema-editor/main.vue +++ b/packages/json-schema-editor/main.vue @@ -62,11 +62,11 @@ {{ local[key] }} - - + + @@ -128,7 +127,7 @@ export default { AButton: Button, // eslint-disable-next-line vue/no-unused-components AIcon: Icon, - AInput: Input,AInputNumber:InputNumber, + AInput: Input,AInputNumber:InputNumber,ATextarea: Input.TextArea, ACheckbox: Checkbox, ASelect: Select, ASelectOption:Select.Option, @@ -254,10 +253,19 @@ export default { } }, onChangeType() { + this.parseCustomProps() + // 删除自定义属性 + this.customProps.forEach(item => { + this.$delete(this.pickValue, item.key) + }); + this.customProps = []; + this.$delete(this.pickValue,'properties') this.$delete(this.pickValue,'items') this.$delete(this.pickValue,'required') this.$delete(this.pickValue,'format') + this.$delete(this.pickValue,'enum') + if(this.isArray){ this.$set(this.pickValue,'items',{type:'string'}) } @@ -268,6 +276,16 @@ export default { onRootCheck(e){ this._deepCheck( e.target.checked,this.pickValue) }, + changeEnumValue (e) { + const pickType = this.pickValue.type + const value = e.target.value + var arr = value.split('\n') + if (arr.length === 0 || (arr.length == 1 && !arr[0])) { + this.$delete(this.advancedValue, 'enum') + } else { + this.advancedValue.enum = arr.map(item => pickType === 'string' ? item : +item) + } + }, _deepCheck(checked,node){ if(node.type === 'object' && node.properties){ checked ? this.$set(node,'required',Object.keys(node.properties)) : this.$delete(node,'required') @@ -323,7 +341,8 @@ export default { }, onSetting(){ this.modalVisible = true - this.advancedValue = this.advanced.value + console.info('t7', this.advanced.value, this.pickValue) + this.advancedValue = { ...this.advanced.value } for(const k in this.advancedValue) { if(this.pickValue[k]) this.advancedValue[k] = this.pickValue[k] } diff --git a/packages/json-schema-editor/type/integer.js b/packages/json-schema-editor/type/integer.js index 76c42ea..3399f68 100644 --- a/packages/json-schema-editor/type/integer.js +++ b/packages/json-schema-editor/type/integer.js @@ -3,7 +3,8 @@ const value = { maximum: null, minimum: null, exclusiveMaximum:null, - exclusiveMinimum:null + exclusiveMinimum:null, + enum:[] } const attr = { description: { @@ -25,6 +26,10 @@ const attr = { exclusiveMinimum:{ name:'不包含最小值', type:'boolean' + }, + enum:{ + name:'枚举', + type:'array' } } const wrapper = {value, attr} diff --git a/packages/json-schema-editor/type/number.js b/packages/json-schema-editor/type/number.js index bd58dda..86f5db3 100644 --- a/packages/json-schema-editor/type/number.js +++ b/packages/json-schema-editor/type/number.js @@ -3,7 +3,8 @@ const value = { maximum: null, minimum: null, exclusiveMaximum:null, - exclusiveMinimum:null + exclusiveMinimum:null, + enum:[] } const attr = { description: { @@ -25,6 +26,10 @@ const attr = { exclusiveMinimum:{ name:'不包含最小值', type:'boolean' + }, + enum:{ + name:'枚举', + type:'array' } } const wrapper = {value, attr} diff --git a/packages/json-schema-editor/type/string.js b/packages/json-schema-editor/type/string.js index 2103ee1..197bcfb 100644 --- a/packages/json-schema-editor/type/string.js +++ b/packages/json-schema-editor/type/string.js @@ -3,7 +3,8 @@ const value = { maxLength: null, minLength: null, pattern: null, - format:null + format:undefined, + enum:[] } const attr = { description: { @@ -26,6 +27,10 @@ const attr = { name:'格式', type:'array', enums:['date','date-time','email','hostname','ipv4','ipv6','uri'] + }, + enum:{ + name:'枚举', + type:'array' } } const wrapper = {value, attr}