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

View File

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

View File

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

View File

@ -49,6 +49,12 @@ const transforms = {
if (field.get('component.tooltip')) { if (field.get('component.tooltip')) {
prop.description = 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')) { if (field.get('required')) {
prop.required = true; prop.required = true;
} }
@ -59,14 +65,14 @@ const transforms = {
set(prop, 'x-component-props.showTime', field.get('showTime')); set(prop, 'x-component-props.showTime', field.get('showTime'));
} }
const defaultValue = get(field.options, 'defaultValue'); const defaultValue = get(field.options, 'defaultValue');
if (defaultValue) { if (typeof defaultValue !== 'undefined') {
prop.default = defaultValue; prop.default = defaultValue;
} }
if (interfaceType === 'boolean') { if (interfaceType === 'boolean') {
set(prop, 'x-component-props.children', prop.title); set(prop, 'x-component-props.children', prop.title);
delete prop.title; delete prop.title;
} }
if (['radio', 'select', 'checkboxes'].includes(interfaceType)) { if (['radio', 'select', 'multipleSelect', 'checkboxes'].includes(interfaceType)) {
prop.enum = get(field.options, 'dataSource', []); prop.enum = get(field.options, 'dataSource', []);
} }
schema[field.name] = { schema[field.name] = {