mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 05:25:52 +00:00
feat: improve developer mode support
This commit is contained in:
parent
a3155f687f
commit
caa98f6d08
26
packages/app/src/api/collections/example.ts
Normal file
26
packages/app/src/api/collections/example.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { TableOptions } from '@nocobase/database';
|
||||
|
||||
export default {
|
||||
title: '示例',
|
||||
showInDataMenu: true,
|
||||
fields: [
|
||||
{
|
||||
interface: 'string',
|
||||
title: '单行文本',
|
||||
component: {
|
||||
showInTable: true,
|
||||
showInDetail: true,
|
||||
showInForm: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
interface: 'textarea',
|
||||
title: '多行文本',
|
||||
component: {
|
||||
showInTable: true,
|
||||
showInDetail: true,
|
||||
showInForm: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
@ -34,6 +34,14 @@ const api = Api.create({
|
||||
},
|
||||
});
|
||||
|
||||
api.resourcer.use(async (ctx, next) => {
|
||||
const { resourceName } = ctx.action.params;
|
||||
const table = ctx.db.getTable(resourceName);
|
||||
if (table && table.hasField('developerMode')) {
|
||||
ctx.action.setParam('filter.developerMode', false);
|
||||
}
|
||||
await next();
|
||||
});
|
||||
api.resourcer.use(associated);
|
||||
api.resourcer.registerActionHandlers({...actions.common, ...actions.associate});
|
||||
|
||||
@ -47,6 +55,8 @@ api.resourcer.registerActionHandlers({...actions.common, ...actions.associate});
|
||||
// [path.resolve(__dirname, '../../../plugin-file-manager'), {}],
|
||||
]);
|
||||
|
||||
// await api.database.getModel('collections').load();
|
||||
|
||||
api.listen(process.env.HTTP_PORT, () => {
|
||||
console.log(`http://localhost:${process.env.HTTP_PORT}/`);
|
||||
});
|
||||
|
@ -113,6 +113,7 @@ const data = {
|
||||
path: '/settings/pages',
|
||||
icon: 'dashboard',
|
||||
sort: 100,
|
||||
developerMode: true,
|
||||
},
|
||||
{
|
||||
title: '数据表配置',
|
||||
@ -179,5 +180,7 @@ const data = {
|
||||
token: "38979f07e1fca68fb3d2",
|
||||
});
|
||||
|
||||
await database.getModel('collections').import(require('./collections/example').default);
|
||||
|
||||
await database.close();
|
||||
})();
|
||||
|
@ -31,6 +31,7 @@ const defaultValues = {
|
||||
name: 'form',
|
||||
title: '表单',
|
||||
template: 'DrawerForm',
|
||||
developerMode: true,
|
||||
},
|
||||
{
|
||||
type: 'details',
|
||||
@ -38,6 +39,7 @@ const defaultValues = {
|
||||
title: '详情',
|
||||
template: 'Details',
|
||||
actionNames: ['update'],
|
||||
developerMode: true,
|
||||
},
|
||||
{
|
||||
type: 'table',
|
||||
|
@ -413,6 +413,7 @@ export const primaryKey = {
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
filterable: true,
|
||||
developerMode: true,
|
||||
component: {
|
||||
type: 'number',
|
||||
},
|
||||
@ -429,6 +430,7 @@ export const sort = {
|
||||
interface: 'sort',
|
||||
type: 'integer',
|
||||
required: true,
|
||||
developerMode: true,
|
||||
component: {
|
||||
type: 'sort',
|
||||
showInTable: true,
|
||||
@ -441,6 +443,7 @@ export const password = {
|
||||
options: {
|
||||
interface: 'password',
|
||||
type: 'password',
|
||||
developerMode: true,
|
||||
hidden: true, // hidden 用来控制 api 不输出这个字段,但是可能这个字段显示在表单里 showInForm
|
||||
component: {
|
||||
type: 'password',
|
||||
@ -454,6 +457,7 @@ export const json = {
|
||||
interface: 'json',
|
||||
type: 'json',
|
||||
dottie: true,
|
||||
developerMode: true,
|
||||
component: {
|
||||
type: 'hidden',
|
||||
},
|
||||
|
@ -35,6 +35,9 @@ export default async function getRoutes(ctx, next) {
|
||||
const database: Database = ctx.database;
|
||||
const Page = database.getModel('pages');
|
||||
let pages = await Page.findAll({
|
||||
where: {
|
||||
developerMode: false,
|
||||
},
|
||||
order: [['sort', 'asc']],
|
||||
});
|
||||
const data = flatToTree(pages.map(row => row.toJSON()), {
|
||||
|
@ -4,6 +4,7 @@ export default {
|
||||
name: 'pages',
|
||||
title: '页面配置',
|
||||
model: 'BaseModel',
|
||||
developerMode: true,
|
||||
fields: [
|
||||
{
|
||||
interface: 'sort',
|
||||
@ -158,6 +159,16 @@ export default {
|
||||
showInDetail: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
interface: 'boolean',
|
||||
type: 'boolean',
|
||||
name: 'developerMode',
|
||||
title: '开发者模式',
|
||||
defaultValue: false,
|
||||
component: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
{
|
||||
interface: 'linkTo',
|
||||
type: 'hasMany',
|
||||
|
@ -3,6 +3,7 @@ import { TableOptions } from '@nocobase/database';
|
||||
export default {
|
||||
name: 'users',
|
||||
title: '用户',
|
||||
developerMode: true,
|
||||
fields: [
|
||||
{
|
||||
interface: 'string',
|
||||
@ -95,18 +96,21 @@ export default {
|
||||
name: 'form',
|
||||
title: '表单',
|
||||
template: 'DrawerForm',
|
||||
developerMode: true,
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
name: 'login',
|
||||
title: '登录',
|
||||
template: 'Login',
|
||||
developerMode: true,
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
name: 'register',
|
||||
title: '注册',
|
||||
template: 'Register',
|
||||
developerMode: true,
|
||||
},
|
||||
{
|
||||
type: 'details',
|
||||
@ -114,6 +118,7 @@ export default {
|
||||
title: '详情',
|
||||
template: 'Details',
|
||||
actionNames: ['update'],
|
||||
developerMode: true,
|
||||
},
|
||||
{
|
||||
type: 'simple',
|
||||
|
Loading…
Reference in New Issue
Block a user