fix: add createdAt/updatedAt/createdBy/updatedBy options to the collections table for developer mode
This commit is contained in:
parent
afce1142d9
commit
7e9b4a8f45
@ -3,8 +3,8 @@ import { TableOptions } from '@nocobase/database';
|
|||||||
export default {
|
export default {
|
||||||
title: '示例',
|
title: '示例',
|
||||||
showInDataMenu: true,
|
showInDataMenu: true,
|
||||||
createdBy: true,
|
// createdBy: true,
|
||||||
updatedBy: true,
|
// updatedBy: true,
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
interface: 'string',
|
interface: 'string',
|
||||||
|
@ -8,6 +8,8 @@ export default {
|
|||||||
draggable: true,
|
draggable: true,
|
||||||
model: 'CollectionModel',
|
model: 'CollectionModel',
|
||||||
developerMode: true,
|
developerMode: true,
|
||||||
|
createdAt: 'createdTime',
|
||||||
|
updatedAt: 'updatedTime',
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
interface: 'sort',
|
interface: 'sort',
|
||||||
@ -143,11 +145,62 @@ export default {
|
|||||||
showInDetail: true,
|
showInDetail: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
interface: 'boolean',
|
||||||
|
type: 'virtual',
|
||||||
|
name: 'createdAt',
|
||||||
|
title: '记录创建时间',
|
||||||
|
developerMode: true,
|
||||||
|
defaultValue: true,
|
||||||
|
component: {
|
||||||
|
type: 'checkbox',
|
||||||
|
default: true,
|
||||||
|
showInForm: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
interface: 'boolean',
|
||||||
|
type: 'virtual',
|
||||||
|
name: 'updatedAt',
|
||||||
|
title: '记录修改时间',
|
||||||
|
developerMode: true,
|
||||||
|
defaultValue: true,
|
||||||
|
component: {
|
||||||
|
type: 'checkbox',
|
||||||
|
default: true,
|
||||||
|
showInForm: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
interface: 'boolean',
|
||||||
|
type: 'virtual',
|
||||||
|
name: 'createdBy',
|
||||||
|
title: '记录创建人信息',
|
||||||
|
developerMode: true,
|
||||||
|
component: {
|
||||||
|
type: 'checkbox',
|
||||||
|
default: true,
|
||||||
|
showInForm: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
interface: 'boolean',
|
||||||
|
type: 'virtual',
|
||||||
|
name: 'updatedBy',
|
||||||
|
title: '记录修改人信息',
|
||||||
|
developerMode: true,
|
||||||
|
component: {
|
||||||
|
type: 'checkbox',
|
||||||
|
default: true,
|
||||||
|
showInForm: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
interface: 'boolean',
|
interface: 'boolean',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
name: 'developerMode',
|
name: 'developerMode',
|
||||||
title: '开发者模式',
|
title: '开发者模式',
|
||||||
|
developerMode: true,
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
component: {
|
component: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
|
@ -10,6 +10,7 @@ export default {
|
|||||||
collections: {
|
collections: {
|
||||||
beforeValidate: collectionsBeforeValidate,
|
beforeValidate: collectionsBeforeValidate,
|
||||||
afterCreate: collectionsAfterCreate,
|
afterCreate: collectionsAfterCreate,
|
||||||
|
afterUpdate: collectionsAfterCreate,
|
||||||
},
|
},
|
||||||
fields: {
|
fields: {
|
||||||
beforeValidate: fieldsBeforeValidate,
|
beforeValidate: fieldsBeforeValidate,
|
||||||
|
@ -22,7 +22,16 @@ export default async function (options = {}) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
database.addHook('afterTableInit', (table) => {
|
database.addHook('afterTableInit', (table) => {
|
||||||
const { createdBy, updatedBy } = table.getOptions();
|
let { createdBy, updatedBy, internal } = table.getOptions();
|
||||||
|
// 非内置表,默认创建 createdBy 和 updatedBy
|
||||||
|
if (!internal) {
|
||||||
|
if (typeof createdBy === 'undefined') {
|
||||||
|
createdBy = true;
|
||||||
|
}
|
||||||
|
if (typeof updatedBy === 'undefined') {
|
||||||
|
updatedBy = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
const fieldsToMake = { createdBy, updatedBy };
|
const fieldsToMake = { createdBy, updatedBy };
|
||||||
Object.keys(fieldsToMake)
|
Object.keys(fieldsToMake)
|
||||||
.filter(type => Boolean(fieldsToMake[type]))
|
.filter(type => Boolean(fieldsToMake[type]))
|
||||||
|
Loading…
Reference in New Issue
Block a user