Skip to content

Commit

Permalink
fix: jsonschema表单下拉框类型支持多选&checkbox显示优化 #77
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 26710
  • Loading branch information
ywywZhou authored and luofann committed Dec 13, 2024
1 parent 73a0409 commit a05a561
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions frontend/src/utils/jsonFormSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import tools from './tools';

function getProperties(data = [], config = {}) {
return data.reduce((acc, cur) => {
const { key, name, desc, type, required, form_type: formType, options, meta_desc: metaDesc } = cur;
const { key, name, desc, type, required, form_type: formType, options, meta_desc: metaDesc, multiple } = cur;

let dataType = type === 'bool' ? 'boolean' : 'string';
dataType = type === 'int' ? 'number' : dataType;
Expand Down Expand Up @@ -70,14 +70,17 @@ function getProperties(data = [], config = {}) {
};
} else if (formType !== 'time_range') {
// checkbox为数组类型
acc[key].items = {
type: 'string',
enum: options.map(item => item.value || item) || [],
};
acc[key].uniqueItems = true;
acc[key]['ui:props'] = {
...config,
};
const dataSource = options.map(item => ({
label: item.text || item,
value: item.value || item,
})) || [];
acc[key]['ui:component'] = {
name: 'checkbox',
props: { datasource: dataSource },
};
return acc;
}
}
Expand Down Expand Up @@ -107,6 +110,8 @@ function getProperties(data = [], config = {}) {
return result;
}) || [];
acc[key]['ui:component'].props.datasource = dataSource;
acc[key].type = multiple ? 'array' : acc[key].type;
acc[key]['ui:component'].props.multiple = multiple;
} else if (['int', 'string', 'textarea'].includes(type)) {
// 区分文本框和数字框
let inputType = type === 'int' ? 'number' : 'text';
Expand Down

0 comments on commit a05a561

Please sign in to comment.