diff --git a/packages/app/src/api/collections/example.ts b/packages/app/src/api/collections/example.ts index 10a46f457..5c61b0573 100644 --- a/packages/app/src/api/collections/example.ts +++ b/packages/app/src/api/collections/example.ts @@ -3,8 +3,8 @@ import { TableOptions } from '@nocobase/database'; export default { title: '示例', showInDataMenu: true, - createdBy: true, - updatedBy: true, + // createdBy: true, + // updatedBy: true, fields: [ { interface: 'string', diff --git a/packages/plugin-collections/src/collections/collections.ts b/packages/plugin-collections/src/collections/collections.ts index fe172d4f1..cd364e2d0 100644 --- a/packages/plugin-collections/src/collections/collections.ts +++ b/packages/plugin-collections/src/collections/collections.ts @@ -8,6 +8,8 @@ export default { draggable: true, model: 'CollectionModel', developerMode: true, + createdAt: 'createdTime', + updatedAt: 'updatedTime', fields: [ { interface: 'sort', @@ -143,11 +145,62 @@ export default { 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', type: 'boolean', name: 'developerMode', title: '开发者模式', + developerMode: true, defaultValue: false, component: { type: 'boolean', diff --git a/packages/plugin-collections/src/hooks/index.ts b/packages/plugin-collections/src/hooks/index.ts index b2d3e5acd..aebc0b9b1 100644 --- a/packages/plugin-collections/src/hooks/index.ts +++ b/packages/plugin-collections/src/hooks/index.ts @@ -10,6 +10,7 @@ export default { collections: { beforeValidate: collectionsBeforeValidate, afterCreate: collectionsAfterCreate, + afterUpdate: collectionsAfterCreate, }, fields: { beforeValidate: fieldsBeforeValidate, diff --git a/packages/plugin-users/src/server.ts b/packages/plugin-users/src/server.ts index 911e98bea..43915eaee 100644 --- a/packages/plugin-users/src/server.ts +++ b/packages/plugin-users/src/server.ts @@ -22,7 +22,16 @@ export default async function (options = {}) { }); 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 }; Object.keys(fieldsToMake) .filter(type => Boolean(fieldsToMake[type]))