feat: create system fields by default

This commit is contained in:
chenos 2022-04-16 17:07:00 +08:00
parent e002777b63
commit 28da6a5f82
5 changed files with 125 additions and 2 deletions

View File

@ -20,9 +20,9 @@ const getSchema = (schema: IField): ISchema => {
}
const properties = cloneDeep(schema.properties) as any;
const initialValue = {
name: `f_${uid()}`,
...cloneDeep(schema.default),
interface: schema.name,
name: `f_${uid()}`,
};
initialValue.uiSchema.title = schema.title;
return {

View File

@ -19,9 +19,9 @@ const getSchema = (schema: IField): ISchema => {
}
const properties = cloneDeep(schema.properties) as any;
const initialValue = {
name: `f_${uid()}`,
...cloneDeep(schema.default),
interface: schema.name,
name: `f_${uid()}`,
};
initialValue.uiSchema.title = schema.title;
console.log('initialValue', initialValue);

View File

@ -30,6 +30,81 @@ const useCollectionValues = (options) => {
createdBy: true,
updatedBy: true,
sortable: true,
fields: [
{
name: 'id',
type: 'integer',
autoIncrement: true,
primaryKey: true,
allowNull: false,
uiSchema: { type: 'number', title: '{{t("ID")}}', 'x-component': 'InputNumber', 'x-read-pretty': true },
interface: 'id',
},
{
interface: 'createdAt',
type: 'date',
field: 'createdAt',
name: 'createdAt',
uiSchema: {
type: 'datetime',
title: '{{t("Created at")}}',
'x-component': 'DatePicker',
'x-component-props': {},
'x-read-pretty': true,
},
},
{
interface: 'createdBy',
type: 'belongsTo',
target: 'users',
foreignKey: 'createdById',
name: 'createdBy',
uiSchema: {
type: 'object',
title: '{{t("Created by")}}',
'x-component': 'RecordPicker',
'x-component-props': {
fieldNames: {
value: 'id',
label: 'nickname',
},
},
'x-read-pretty': true,
},
},
{
type: 'date',
field: 'updatedAt',
name: 'updatedAt',
interface: 'updatedAt',
uiSchema: {
type: 'string',
title: '{{t("Last updated at")}}',
'x-component': 'DatePicker',
'x-component-props': {},
'x-read-pretty': true,
},
},
{
type: 'belongsTo',
target: 'users',
foreignKey: 'updatedById',
name: 'updatedBy',
interface: 'updatedBy',
uiSchema: {
type: 'object',
title: '{{t("Last updated by")}}',
'x-component': 'RecordPicker',
'x-component-props': {
fieldNames: {
value: 'id',
label: 'nickname',
},
},
'x-read-pretty': true,
},
},
],
},
}),
{

View File

@ -0,0 +1,47 @@
import { operators } from './properties';
import { IField } from './types';
export const id: IField = {
name: 'id',
type: 'object',
group: 'systemInfo',
order: 0,
title: '{{t("ID")}}',
sortable: true,
default: {
name: 'id',
type: 'integer',
autoIncrement: true,
primaryKey: true,
allowNull: false,
uiSchema: {
type: 'number',
title: '{{t("ID")}}',
'x-component': 'InputNumber',
'x-read-pretty': true,
},
},
properties: {
'uiSchema.title': {
type: 'string',
title: '{{t("Field display name")}}',
required: true,
default: 'ID',
'x-decorator': 'FormItem',
'x-component': 'Input',
},
name: {
type: 'string',
title: '{{t("Field name")}}',
required: true,
'x-disabled': true,
'x-decorator': 'FormItem',
'x-component': 'Input',
description:
"{{t('Randomly generated and can be modified. Support letters, numbers and underscores, must start with an letter.')}}",
},
},
filterable: {
operators: operators.number,
},
};

View File

@ -7,6 +7,7 @@ export * from './createdBy';
export * from './datetime';
export * from './email';
export * from './icon';
export * from './id';
export * from './input';
export * from './linkTo';
export * from './markdown';