feat: add developer mode support

This commit is contained in:
chenos 2020-12-07 08:53:18 +08:00
parent 190fc6b37a
commit 312571fba8
8 changed files with 146 additions and 7 deletions

View File

@ -5,6 +5,7 @@ export default {
title: '操作配置', title: '操作配置',
draggable: true, draggable: true,
model: 'ActionModel', model: 'ActionModel',
developerMode: true,
fields: [ fields: [
{ {
interface: 'sort', interface: 'sort',
@ -55,6 +56,16 @@ export default {
showInDetail: true, showInDetail: true,
}, },
}, },
{
interface: 'boolean',
type: 'boolean',
name: 'developerMode',
title: '开发者模式',
defaultValue: false,
component: {
type: 'boolean',
},
},
{ {
interface: 'linkTo', interface: 'linkTo',
type: 'belongsTo', type: 'belongsTo',
@ -107,6 +118,7 @@ export default {
name: 'form', name: 'form',
title: '表单', title: '表单',
template: 'DrawerForm', template: 'DrawerForm',
developerMode: true,
}, },
{ {
type: 'details', type: 'details',
@ -114,6 +126,7 @@ export default {
title: '详情', title: '详情',
template: 'Details', template: 'Details',
actionNames: ['update'], actionNames: ['update'],
developerMode: true,
}, },
{ {
type: 'table', type: 'table',

View File

@ -6,6 +6,7 @@ export default {
sortable: true, sortable: true,
draggable: true, draggable: true,
model: 'CollectionModel', model: 'CollectionModel',
developerMode: true,
fields: [ fields: [
{ {
interface: 'sort', interface: 'sort',
@ -138,6 +139,16 @@ export default {
showInDetail: true, showInDetail: true,
}, },
}, },
{
interface: 'boolean',
type: 'boolean',
name: 'developerMode',
title: '开发者模式',
defaultValue: false,
component: {
type: 'boolean',
},
},
{ {
interface: 'json', interface: 'json',
type: 'json', type: 'json',
@ -243,6 +254,7 @@ export default {
name: 'form', name: 'form',
title: '表单', title: '表单',
template: 'DrawerForm', template: 'DrawerForm',
developerMode: true,
}, },
{ {
type: 'details', type: 'details',
@ -250,6 +262,7 @@ export default {
title: '详情', title: '详情',
template: 'Details', template: 'Details',
actionNames: ['update'], actionNames: ['update'],
developerMode: true,
}, },
{ {
type: 'table', type: 'table',
@ -297,6 +310,7 @@ export default {
title: '动作', title: '动作',
association: 'actions', association: 'actions',
viewName: 'simple', viewName: 'simple',
developerMode: true,
}, },
{ {
type: 'association', type: 'association',
@ -305,12 +319,12 @@ export default {
association: 'tabs', association: 'tabs',
viewName: 'simple', viewName: 'simple',
}, },
{ // {
type: 'association', // type: 'association',
name: 'roles', // name: 'roles',
title: '权限', // title: '权限',
association: 'roles', // association: 'roles',
viewName: 'simple2', // viewName: 'simple2',
}, // },
], ],
} as TableOptions; } as TableOptions;

View File

@ -6,6 +6,7 @@ export default {
title: '字段配置', title: '字段配置',
draggable: true, draggable: true,
model: 'FieldModel', model: 'FieldModel',
developerMode: true,
fields: [ fields: [
{ {
interface: 'sort', interface: 'sort',
@ -206,6 +207,16 @@ export default {
type: 'drawerSelect', type: 'drawerSelect',
}, },
}, },
{
interface: 'boolean',
type: 'boolean',
name: 'developerMode',
title: '开发者模式',
defaultValue: false,
component: {
type: 'boolean',
},
},
{ {
interface: 'json', interface: 'json',
type: 'json', type: 'json',
@ -257,6 +268,7 @@ export default {
name: 'form', name: 'form',
title: '表单', title: '表单',
template: 'DrawerForm', template: 'DrawerForm',
developerMode: true,
}, },
{ {
type: 'details', type: 'details',
@ -264,6 +276,7 @@ export default {
title: '详情', title: '详情',
template: 'Details', template: 'Details',
actionNames: ['update'], actionNames: ['update'],
developerMode: true,
}, },
{ {
type: 'table', type: 'table',

View File

@ -5,6 +5,7 @@ export default {
title: '标签配置', title: '标签配置',
sortable: true, sortable: true,
model: 'TabModel', model: 'TabModel',
developerMode: true,
fields: [ fields: [
{ {
interface: 'sort', interface: 'sort',
@ -97,6 +98,16 @@ export default {
showInForm: true, showInForm: true,
}, },
}, },
{
interface: 'boolean',
type: 'boolean',
name: 'developerMode',
title: '开发者模式',
defaultValue: false,
component: {
type: 'boolean',
},
},
{ {
interface: 'linkTo', interface: 'linkTo',
type: 'belongsTo', type: 'belongsTo',
@ -149,6 +160,7 @@ export default {
name: 'form', name: 'form',
title: '表单', title: '表单',
template: 'DrawerForm', template: 'DrawerForm',
developerMode: true,
}, },
{ {
type: 'details', type: 'details',
@ -156,6 +168,7 @@ export default {
title: '详情', title: '详情',
template: 'Details', template: 'Details',
actionNames: ['update'], actionNames: ['update'],
developerMode: true,
}, },
{ {
type: 'table', type: 'table',

View File

@ -5,6 +5,7 @@ export default {
title: '视图配置', title: '视图配置',
sortable: true, sortable: true,
model: 'ViewModel', model: 'ViewModel',
developerMode: true,
fields: [ fields: [
{ {
interface: 'sort', interface: 'sort',
@ -99,6 +100,16 @@ export default {
showInForm: true, showInForm: true,
}, },
}, },
{
interface: 'boolean',
type: 'boolean',
name: 'developerMode',
title: '开发者模式',
defaultValue: false,
component: {
type: 'boolean',
},
},
{ {
interface: 'linkTo', interface: 'linkTo',
type: 'belongsTo', type: 'belongsTo',
@ -166,6 +177,7 @@ export default {
name: 'form', name: 'form',
title: '表单', title: '表单',
template: 'DrawerForm', template: 'DrawerForm',
developerMode: true,
}, },
{ {
type: 'details', type: 'details',
@ -173,6 +185,7 @@ export default {
title: '详情', title: '详情',
template: 'Details', template: 'Details',
actionNames: ['update'], actionNames: ['update'],
developerMode: true,
}, },
{ {
type: 'table', type: 'table',

View File

@ -1,8 +1,77 @@
import CollectionModel from '../models/collection'; 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 = {}) { export default async function (model: CollectionModel, options: any = {}) {
const { migrate = true } = options; const { migrate = true } = options;
if (migrate) { if (migrate) {
await model.migrate(); await model.migrate();
} }
await model.updateAssociations(defaultValues);
} }

View File

@ -1,3 +1,4 @@
export * from './base';
export * from './action'; export * from './action';
export * from './collection'; export * from './collection';
export * from './field'; export * from './field';

View File

@ -21,6 +21,9 @@ export default async (ctx, next) => {
collection.setDataValue('defaultViewId', get(views, [0, 'id'])); collection.setDataValue('defaultViewId', get(views, [0, 'id']));
collection.setDataValue('defaultViewName', get(views, [0, 'name'])); collection.setDataValue('defaultViewName', get(views, [0, 'name']));
const tabs = await collection.getTabs({ const tabs = await collection.getTabs({
where: {
developerMode: false,
},
order: [['sort', 'asc']], order: [['sort', 'asc']],
}) as Model[]; }) as Model[];
const tabItems = []; const tabItems = [];