feat: improve field options

This commit is contained in:
chenos 2020-12-13 17:20:54 +08:00
parent d03f927bc1
commit 71b2d9bfeb
4 changed files with 40 additions and 21 deletions

View File

@ -88,7 +88,7 @@ export default {
{
"type": "value:visible",
"target": "timeFormat",
"condition": "{{ ['time', 'datetime', 'createdAt', 'updatedAt'].indexOf($self.value) !== -1 }}"
"condition": "{{ ['time'].indexOf($self.value) !== -1 }}"
},
],
},
@ -100,6 +100,7 @@ export default {
title: '可选项',
component: {
type: 'table',
default: [{}],
// showInTable: true,
// showInDetail: true,
showInForm: true,
@ -147,13 +148,13 @@ export default {
type: 'virtual',
name: 'precision',
title: '精度',
defaultValue: 0,
defaultValue: 1,
dataSource: [
{value: 0, label: '1'},
{value: 1, label: '1.0'},
{value: 2, label: '1.00'},
{value: 3, label: '1.000'},
{value: 4, label: '1.0000'},
{value: 1, label: '1'},
{value: 0.1, label: '1.0'},
{value: 0.01, label: '1.00'},
{value: 0.001, label: '1.000'},
{value: 0.0001, label: '1.0000'},
],
component: {
type: 'number',
@ -165,9 +166,11 @@ export default {
type: 'virtual',
name: 'dateFormat',
title: '日期格式',
defaultValue: 'YYYY-MM-DD',
defaultValue: 'YYYY/MM/DD',
dataSource: [
{value: 'YYYY-MM-DD', label: 'YYYY-MM-DD'},
{value: 'YYYY/MM/DD', label: '年/月/日'},
{value: 'YYYY-MM-DD', label: '年-月-日'},
{value: 'DD/MM/YYYY', label: '日/月/年'},
],
component: {
type: 'string',
@ -199,7 +202,8 @@ export default {
title: '时间格式',
defaultValue: 'HH:mm:ss',
dataSource: [
{ value: 'HH:mm:ss', label: 'HH:mm:ss' },
{ value: 'HH:mm:ss', label: '24小时制' },
{ value: 'hh:mm:ss a', label: '12小时制' },
],
component: {
type: 'string',

View File

@ -65,11 +65,12 @@ export const options = [
types.json,
],
}
].map(({title, children}) => ({
].map(({title, children}: any) => ({
label: title,
children: children.map(child => ({
label: child.title,
value: child.options.interface,
disabled: child.disabled,
})),
}));

View File

@ -38,6 +38,7 @@ export const phone = {
format: 'phone', // 验证的问题
component: {
type: 'string',
'x-rules': 'phone',
},
},
};
@ -51,6 +52,7 @@ export const email = {
format: 'email',
component: {
type: 'string',
'x-rules': 'email',
},
},
};
@ -62,10 +64,10 @@ export const number = {
title: '数字',
options: {
interface: 'number',
type: 'integer',
type: 'float',
filterable: true,
sortable: true,
precision: 0, // 需要考虑
precision: 1, // 需要考虑
component: {
type: 'number',
},
@ -80,19 +82,19 @@ export const percent = {
title: '百分比',
options: {
interface: 'percent',
type: 'integer',
type: 'float',
filterable: true,
sortable: true,
precision: 0,
precision: 1,
component: {
type: 'percent',
suffix: '%',
},
},
};
export const wysiwyg = {
title: '可视化编辑器',
disabled: true,
options: {
interface: 'wysiwyg',
type: 'text',
@ -107,6 +109,7 @@ export const wysiwyg = {
*/
export const attachment = {
title: '附件',
disabled: true,
options: {
interface: 'attachment',
type: 'belongsToMany',
@ -267,6 +270,7 @@ export const time = {
// });
export const subTable = {
title: '子表格',
disabled: true,
options: {
interface: 'subTable',
type: 'hasMany',
@ -320,6 +324,7 @@ export const subTable = {
export const linkTo = {
title: '关联数据',
disabled: true,
options: {
interface: 'linkTo',
multiple: true, // 可能影响 type
@ -335,6 +340,7 @@ export const linkTo = {
export const createdBy = {
title: '创建者',
disabled: true,
options: {
interface: 'createdBy',
type: 'belongsTo',
@ -352,7 +358,7 @@ export const createdAt = {
type: 'date',
name: 'created_at',
showTime: true,
dateFormat: 'YYYY-MM-DD',
dateFormat: 'YYYY/MM/DD',
timeFormat: 'HH:mm:ss',
required: true,
filterable: true,
@ -365,6 +371,7 @@ export const createdAt = {
export const updatedBy = {
title: '更新人',
disabled: true,
options: {
interface: 'updatedBy',
type: 'belongsTo',
@ -382,7 +389,7 @@ export const updatedAt = {
type: 'date',
name: 'updated_at',
showTime: true,
dateFormat: 'YYYY-MM-DD',
dateFormat: 'YYYY/MM/DD',
timeFormat: 'HH:mm:ss',
required: true,
filterable: true,
@ -400,6 +407,7 @@ export const updatedAt = {
*/
export const group = {
title: '字段组',
disabled: true,
options: {
interface: 'group',
// name: 'id',
@ -465,7 +473,7 @@ export const json = {
interface: 'json',
type: 'json',
dottie: true,
developerMode: true,
// developerMode: true,
component: {
type: 'hidden',
},

View File

@ -49,6 +49,12 @@ const transforms = {
if (field.get('component.tooltip')) {
prop.description = field.get('component.tooltip');
}
// if (field.get('name') === 'dataSource') {
// set(prop, 'items.properties.value.visible', false);
// }
if (['number', 'percent'].includes(interfaceType) && field.get('precision')) {
set(prop, 'x-component-props.step', field.get('precision'));
}
if (field.get('required')) {
prop.required = true;
}
@ -59,14 +65,14 @@ const transforms = {
set(prop, 'x-component-props.showTime', field.get('showTime'));
}
const defaultValue = get(field.options, 'defaultValue');
if (defaultValue) {
if (typeof defaultValue !== 'undefined') {
prop.default = defaultValue;
}
if (interfaceType === 'boolean') {
set(prop, 'x-component-props.children', prop.title);
delete prop.title;
}
if (['radio', 'select', 'checkboxes'].includes(interfaceType)) {
if (['radio', 'select', 'multipleSelect', 'checkboxes'].includes(interfaceType)) {
prop.enum = get(field.options, 'dataSource', []);
}
schema[field.name] = {