diff --git a/ui/src/components/dynamics-form/Demo.vue b/ui/src/components/dynamics-form/Demo.vue index 9fad393a4..dce7f8f0f 100644 --- a/ui/src/components/dynamics-form/Demo.vue +++ b/ui/src/components/dynamics-form/Demo.vue @@ -22,6 +22,7 @@ import type { Dict } from '@/api/type/common' const damo_data: Array = [ { field: 'name', input_type: 'PasswordInput', label: '用戶名', required: false }, + { field: 'json_text', input_type: 'JsonInput', label: 'aa', required: false }, { field: 'array_object_card_field', input_type: 'ArrayObjectCard', diff --git a/ui/src/components/dynamics-form/FormItem.vue b/ui/src/components/dynamics-form/FormItem.vue index 1c3300ad5..30b834848 100644 --- a/ui/src/components/dynamics-form/FormItem.vue +++ b/ui/src/components/dynamics-form/FormItem.vue @@ -107,13 +107,23 @@ const errMsg = computed(() => { ? props.formfield.label + '不能为空' : props.formfield.label.label + '不能为空' }) - +/** + * 反序列化 + * @param rule + */ +const to_rule = (rule: any) => { + if (rule.validator) { + let validator = (rule: any, value: string, callback: any) => {} + return { ...rule, validator } + } + return rule +} /** * 校验 */ const rules = computed(() => { return props_info.value.rules - ? props_info.value.rules + ? props_info.value.rules.map(to_rule) : { message: errMsg.value, trigger: 'blur', diff --git a/ui/src/components/dynamics-form/constructor/index.vue b/ui/src/components/dynamics-form/constructor/index.vue index 0c84e2d2a..42310516a 100644 --- a/ui/src/components/dynamics-form/constructor/index.vue +++ b/ui/src/components/dynamics-form/constructor/index.vue @@ -52,7 +52,8 @@ const props = withDefaults( { label: '滑块', value: 'SliderConstructor' }, { label: '开关', value: 'SwitchInputConstructor' }, { label: '单选框', value: 'SingleSelectConstructor' }, - { label: '日期', value: 'DatePickerConstructor' } + { label: '日期', value: 'DatePickerConstructor' }, + { label: 'JSON文本框', value: 'JsonInputConstructor' } ] } ) @@ -69,8 +70,8 @@ const form_data = ref({ input_type: '' }) const rules = { - label: [{ required: true, message: '参数 为必填属性' }], - field: [{ required: true, message: '显示名称 为必填属性' }], + label: [{ required: true, message: '显示名称 为必填属性' }], + field: [{ required: true, message: '参数 为必填属性' }], required: [{ required: true, message: '是否必填 为必填属性' }], input_type: [{ required: true, message: '组建类型 为必填属性' }] } @@ -108,7 +109,10 @@ onMounted(() => { const rander = (data: any) => { form_data.value.required = data.required ? data.required : false form_data.value.field = data.field - form_data.value.input_type = data.input_type + 'Constructor' + if (data.input_type) { + form_data.value.input_type = data.input_type + 'Constructor' + } + if (data.label && data.label.input_type === 'TooltipLabel') { form_data.value.tooltip = data.label.attrs.tooltip form_data.value.label = data.label.label diff --git a/ui/src/components/dynamics-form/constructor/items/JsonInputConstructor.vue b/ui/src/components/dynamics-form/constructor/items/JsonInputConstructor.vue new file mode 100644 index 000000000..5a7d442b6 --- /dev/null +++ b/ui/src/components/dynamics-form/constructor/items/JsonInputConstructor.vue @@ -0,0 +1,71 @@ + + + diff --git a/ui/src/components/dynamics-form/items/JsonInput.vue b/ui/src/components/dynamics-form/items/JsonInput.vue new file mode 100644 index 000000000..e4bd6fa45 --- /dev/null +++ b/ui/src/components/dynamics-form/items/JsonInput.vue @@ -0,0 +1,101 @@ + + +