fix: improve field options

This commit is contained in:
chenos 2020-12-18 18:25:06 +08:00
parent 184adb924d
commit afce1142d9
5 changed files with 75 additions and 48 deletions

View File

@ -115,13 +115,16 @@ export function DataSourceField(props: any) {
export function RealtionField(props: any) { export function RealtionField(props: any) {
const { schema: { labelField }, value } = props; const { schema: { labelField }, value } = props;
if (!value) { if (!value) {
return; return null;
} }
console.log(labelField, value);
const items = Array.isArray(value) ? value : [value]; const items = Array.isArray(value) ? value : [value];
return items.map(item => ( return (
<>
{items.map(item => (
<span>{get(item, labelField)}</span> <span>{get(item, labelField)}</span>
)); ))}
</>
);
} }
registerFieldComponents({ registerFieldComponents({

View File

@ -15,7 +15,6 @@ export default {
name: 'sort', name: 'sort',
scope: ['collection'], scope: ['collection'],
title: '排序', title: '排序',
defaultValue: 1,
component: { component: {
type: 'sort', type: 'sort',
className: 'drag-visible', className: 'drag-visible',
@ -57,6 +56,7 @@ export default {
type: 'string', type: 'string',
name: 'interface', name: 'interface',
title: '字段类型', title: '字段类型',
required: true,
dataSource: options, dataSource: options,
createOnly: true, createOnly: true,
component: { component: {
@ -90,6 +90,16 @@ export default {
"target": "timeFormat", "target": "timeFormat",
"condition": "{{ ['time'].indexOf($self.value) !== -1 }}" "condition": "{{ ['time'].indexOf($self.value) !== -1 }}"
}, },
{
"type": "value:visible",
"target": "component.showInForm",
"condition": "{{ ['createdAt', 'updatedAt', 'createdBy', 'updatedBy'].indexOf($self.value) === -1 }}"
},
{
"type": "value:visible",
"target": "required",
"condition": "{{ ['createdAt', 'updatedAt', 'createdBy', 'updatedBy'].indexOf($self.value) === -1 }}"
},
], ],
}, },
}, },

View File

@ -6,6 +6,7 @@ export * as types from './types';
export const options = [ export const options = [
{ {
key: 'basic',
title: '基本类型', title: '基本类型',
children: [ children: [
types.string, types.string,
@ -17,6 +18,7 @@ export const options = [
], ],
}, },
{ {
key: 'media',
title: '多媒体类型', title: '多媒体类型',
children: [ children: [
types.wysiwyg, types.wysiwyg,
@ -24,6 +26,7 @@ export const options = [
], ],
}, },
{ {
key: 'choices',
title: '选择类型', title: '选择类型',
children: [ children: [
types.boolean, types.boolean,
@ -34,6 +37,7 @@ export const options = [
], ],
}, },
{ {
key: 'datetime',
title: '日期和时间', title: '日期和时间',
children: [ children: [
types.datetime, types.datetime,
@ -41,6 +45,7 @@ export const options = [
], ],
}, },
{ {
key: 'relation',
title: '关系类型', title: '关系类型',
children: [ children: [
types.subTable, types.subTable,
@ -48,15 +53,17 @@ export const options = [
], ],
}, },
{ {
key: 'systemInfo',
title: '系统信息', title: '系统信息',
children: [ children: [
types.createdAt, types.createdAt,
types.createdBy,
types.updatedAt, types.updatedAt,
types.createdBy,
types.updatedBy, types.updatedBy,
], ],
}, },
{ {
key: 'developerMode',
title: '开发者模式', title: '开发者模式',
children: [ children: [
types.primaryKey, types.primaryKey,
@ -66,7 +73,8 @@ export const options = [
types.icon, types.icon,
], ],
} }
].map(({title, children}: any) => ({ ].map(({key, title, children}: any) => ({
key,
label: title, label: title,
children: children.map(child => ({ children: children.map(child => ({
label: child.title, label: child.title,

View File

@ -338,30 +338,13 @@ export const linkTo = {
}, },
}; };
export const createdBy = {
title: '创建者',
// disabled: true,
options: {
interface: 'createdBy',
type: 'createdBy',
name: 'createdBy',
filterable: true,
target: 'users',
labelField: 'nickname',
foreignKey: 'created_by_id',
appends: true,
component: {
type: 'drawerSelect',
},
},
};
export const createdAt = { export const createdAt = {
title: '创建时间', title: '创建时间',
options: { options: {
interface: 'createdAt', interface: 'createdAt',
type: 'date', type: 'date',
name: 'created_at', // name: 'created_at',
field: 'created_at',
showTime: true, showTime: true,
dateFormat: 'YYYY/MM/DD', dateFormat: 'YYYY/MM/DD',
timeFormat: 'HH:mm:ss', timeFormat: 'HH:mm:ss',
@ -374,12 +357,49 @@ export const createdAt = {
}, },
}; };
export const updatedAt = {
title: '修改时间',
options: {
interface: 'updatedAt',
type: 'date',
// name: 'updated_at',
field: 'updated_at',
showTime: true,
dateFormat: 'YYYY/MM/DD',
timeFormat: 'HH:mm:ss',
required: true,
filterable: true,
sortable: true,
component: {
type: 'date',
},
},
};
export const createdBy = {
title: '创建人',
// disabled: true,
options: {
interface: 'createdBy',
type: 'createdBy',
// name: 'createdBy',
filterable: true,
target: 'users',
labelField: 'nickname',
foreignKey: 'created_by_id',
appends: true,
component: {
type: 'drawerSelect',
},
},
};
export const updatedBy = { export const updatedBy = {
title: '更新人', title: '修改人',
// disabled: true, // disabled: true,
options: { options: {
interface: 'updatedBy', interface: 'updatedBy',
name: 'updatedBy', // name: 'updatedBy',
type: 'updatedBy', type: 'updatedBy',
filterable: true, filterable: true,
target: 'users', target: 'users',
@ -392,24 +412,6 @@ export const updatedBy = {
}, },
}; };
export const updatedAt = {
title: '更新时间',
options: {
interface: 'updatedAt',
type: 'date',
name: 'updated_at',
showTime: true,
dateFormat: 'YYYY/MM/DD',
timeFormat: 'HH:mm:ss',
required: true,
filterable: true,
sortable: true,
component: {
type: 'date',
},
},
};
/** /**
* *
* *

View File

@ -32,6 +32,10 @@ const transforms = {
title: field.title||field.name, title: field.title||field.name,
...(field.component||{}), ...(field.component||{}),
} }
if (field.get('name') === 'interface' && ctx.state.developerMode === false) {
const dataSource = field.get('dataSource').filter(item => item.key !== 'developerMode');
field.set('dataSource', dataSource);
}
if (field.get('name') === 'filter' && field.get('collection_name') === 'views') { if (field.get('name') === 'filter' && field.get('collection_name') === 'views') {
const { values } = ctx.action.params; const { values } = ctx.action.params;
const all = await Field.findAll({ const all = await Field.findAll({
@ -76,7 +80,7 @@ const transforms = {
set(prop, 'x-component-props.mode', 'multiple'); set(prop, 'x-component-props.mode', 'multiple');
} }
if (['radio', 'select', 'multipleSelect', 'checkboxes'].includes(interfaceType)) { if (['radio', 'select', 'multipleSelect', 'checkboxes'].includes(interfaceType)) {
prop.enum = get(field.options, 'dataSource', []); prop.enum = field.get('dataSource');
} }
schema[field.name] = { schema[field.name] = {
...prop, ...prop,