Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: jsonschema表单下拉框类型支持多选&checkbox显示优化 #77 #79

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading