From 312571fba85aa4d6235bb47e197a2f33d9d265a6 Mon Sep 17 00:00:00 2001 From: chenos Date: Mon, 7 Dec 2020 08:53:18 +0800 Subject: [PATCH] feat: add developer mode support --- .../src/collections/actions.ts | 13 ++++ .../src/collections/collections.ts | 28 ++++++-- .../src/collections/fields.ts | 13 ++++ .../src/collections/tabs.ts | 13 ++++ .../src/collections/views.ts | 13 ++++ .../src/hooks/collections-after-create.ts | 69 +++++++++++++++++++ .../plugin-collections/src/models/index.ts | 1 + .../plugin-pages/src/actions/getCollection.ts | 3 + 8 files changed, 146 insertions(+), 7 deletions(-) diff --git a/packages/plugin-collections/src/collections/actions.ts b/packages/plugin-collections/src/collections/actions.ts index c7a9d9f612..39ce65b978 100644 --- a/packages/plugin-collections/src/collections/actions.ts +++ b/packages/plugin-collections/src/collections/actions.ts @@ -5,6 +5,7 @@ export default { title: '操作配置', draggable: true, model: 'ActionModel', + developerMode: true, fields: [ { interface: 'sort', @@ -55,6 +56,16 @@ export default { showInDetail: true, }, }, + { + interface: 'boolean', + type: 'boolean', + name: 'developerMode', + title: '开发者模式', + defaultValue: false, + component: { + type: 'boolean', + }, + }, { interface: 'linkTo', type: 'belongsTo', @@ -107,6 +118,7 @@ export default { name: 'form', title: '表单', template: 'DrawerForm', + developerMode: true, }, { type: 'details', @@ -114,6 +126,7 @@ export default { title: '详情', template: 'Details', actionNames: ['update'], + developerMode: true, }, { type: 'table', diff --git a/packages/plugin-collections/src/collections/collections.ts b/packages/plugin-collections/src/collections/collections.ts index 0a46b1023e..49841c9324 100644 --- a/packages/plugin-collections/src/collections/collections.ts +++ b/packages/plugin-collections/src/collections/collections.ts @@ -6,6 +6,7 @@ export default { sortable: true, draggable: true, model: 'CollectionModel', + developerMode: true, fields: [ { interface: 'sort', @@ -138,6 +139,16 @@ export default { showInDetail: true, }, }, + { + interface: 'boolean', + type: 'boolean', + name: 'developerMode', + title: '开发者模式', + defaultValue: false, + component: { + type: 'boolean', + }, + }, { interface: 'json', type: 'json', @@ -243,6 +254,7 @@ export default { name: 'form', title: '表单', template: 'DrawerForm', + developerMode: true, }, { type: 'details', @@ -250,6 +262,7 @@ export default { title: '详情', template: 'Details', actionNames: ['update'], + developerMode: true, }, { type: 'table', @@ -297,6 +310,7 @@ export default { title: '动作', association: 'actions', viewName: 'simple', + developerMode: true, }, { type: 'association', @@ -305,12 +319,12 @@ export default { association: 'tabs', viewName: 'simple', }, - { - type: 'association', - name: 'roles', - title: '权限', - association: 'roles', - viewName: 'simple2', - }, + // { + // type: 'association', + // name: 'roles', + // title: '权限', + // association: 'roles', + // viewName: 'simple2', + // }, ], } as TableOptions; diff --git a/packages/plugin-collections/src/collections/fields.ts b/packages/plugin-collections/src/collections/fields.ts index 2409dfe201..1382396a98 100644 --- a/packages/plugin-collections/src/collections/fields.ts +++ b/packages/plugin-collections/src/collections/fields.ts @@ -6,6 +6,7 @@ export default { title: '字段配置', draggable: true, model: 'FieldModel', + developerMode: true, fields: [ { interface: 'sort', @@ -206,6 +207,16 @@ export default { type: 'drawerSelect', }, }, + { + interface: 'boolean', + type: 'boolean', + name: 'developerMode', + title: '开发者模式', + defaultValue: false, + component: { + type: 'boolean', + }, + }, { interface: 'json', type: 'json', @@ -257,6 +268,7 @@ export default { name: 'form', title: '表单', template: 'DrawerForm', + developerMode: true, }, { type: 'details', @@ -264,6 +276,7 @@ export default { title: '详情', template: 'Details', actionNames: ['update'], + developerMode: true, }, { type: 'table', diff --git a/packages/plugin-collections/src/collections/tabs.ts b/packages/plugin-collections/src/collections/tabs.ts index e8a5196222..107c3ba063 100644 --- a/packages/plugin-collections/src/collections/tabs.ts +++ b/packages/plugin-collections/src/collections/tabs.ts @@ -5,6 +5,7 @@ export default { title: '标签配置', sortable: true, model: 'TabModel', + developerMode: true, fields: [ { interface: 'sort', @@ -97,6 +98,16 @@ export default { showInForm: true, }, }, + { + interface: 'boolean', + type: 'boolean', + name: 'developerMode', + title: '开发者模式', + defaultValue: false, + component: { + type: 'boolean', + }, + }, { interface: 'linkTo', type: 'belongsTo', @@ -149,6 +160,7 @@ export default { name: 'form', title: '表单', template: 'DrawerForm', + developerMode: true, }, { type: 'details', @@ -156,6 +168,7 @@ export default { title: '详情', template: 'Details', actionNames: ['update'], + developerMode: true, }, { type: 'table', diff --git a/packages/plugin-collections/src/collections/views.ts b/packages/plugin-collections/src/collections/views.ts index 816a1c7dae..941bff11d3 100644 --- a/packages/plugin-collections/src/collections/views.ts +++ b/packages/plugin-collections/src/collections/views.ts @@ -5,6 +5,7 @@ export default { title: '视图配置', sortable: true, model: 'ViewModel', + developerMode: true, fields: [ { interface: 'sort', @@ -99,6 +100,16 @@ export default { showInForm: true, }, }, + { + interface: 'boolean', + type: 'boolean', + name: 'developerMode', + title: '开发者模式', + defaultValue: false, + component: { + type: 'boolean', + }, + }, { interface: 'linkTo', type: 'belongsTo', @@ -166,6 +177,7 @@ export default { name: 'form', title: '表单', template: 'DrawerForm', + developerMode: true, }, { type: 'details', @@ -173,6 +185,7 @@ export default { title: '详情', template: 'Details', actionNames: ['update'], + developerMode: true, }, { type: 'table', diff --git a/packages/plugin-collections/src/hooks/collections-after-create.ts b/packages/plugin-collections/src/hooks/collections-after-create.ts index 51251dddfb..4b409c7e92 100644 --- a/packages/plugin-collections/src/hooks/collections-after-create.ts +++ b/packages/plugin-collections/src/hooks/collections-after-create.ts @@ -1,8 +1,77 @@ import CollectionModel from '../models/collection'; +const defaultValues = { + actions: [ + { + type: 'list', + name: 'list', + title: '查看', + }, + { + type: 'create', + name: 'create', + title: '创建', + viewName: 'form', + }, + { + type: 'update', + name: 'update', + title: '编辑', + viewName: 'form', + }, + { + type: 'destroy', + name: 'destroy', + title: '删除', + }, + ], + views: [ + { + type: 'form', + name: 'form', + title: '表单', + template: 'DrawerForm', + }, + { + type: 'details', + name: 'details', + title: '详情', + template: 'Details', + actionNames: ['update'], + }, + { + type: 'table', + name: 'simple', + title: '简易模式', + template: 'SimpleTable', + actionNames: ['create', 'destroy'], + detailsViewName: 'details', + updateViewName: 'form', + }, + { + type: 'table', + name: 'table', + title: '列表', + template: 'Table', + actionNames: ['create', 'destroy'], + default: true, + }, + ], + tabs: [ + { + type: 'details', + name: 'details', + title: '详情', + viewName: 'details', + default: true, + }, + ], +}; + export default async function (model: CollectionModel, options: any = {}) { const { migrate = true } = options; if (migrate) { await model.migrate(); } + await model.updateAssociations(defaultValues); } diff --git a/packages/plugin-collections/src/models/index.ts b/packages/plugin-collections/src/models/index.ts index 1b713505f8..64ef6f13bc 100644 --- a/packages/plugin-collections/src/models/index.ts +++ b/packages/plugin-collections/src/models/index.ts @@ -1,3 +1,4 @@ +export * from './base'; export * from './action'; export * from './collection'; export * from './field'; diff --git a/packages/plugin-pages/src/actions/getCollection.ts b/packages/plugin-pages/src/actions/getCollection.ts index e754f04c26..3ba3e9879e 100644 --- a/packages/plugin-pages/src/actions/getCollection.ts +++ b/packages/plugin-pages/src/actions/getCollection.ts @@ -21,6 +21,9 @@ export default async (ctx, next) => { collection.setDataValue('defaultViewId', get(views, [0, 'id'])); collection.setDataValue('defaultViewName', get(views, [0, 'name'])); const tabs = await collection.getTabs({ + where: { + developerMode: false, + }, order: [['sort', 'asc']], }) as Model[]; const tabItems = [];