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: '操作配置',
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',

View File

@ -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;

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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);
}

View File

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

View File

@ -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 = [];