tachybase_todo/packages/app/src/api/migrations/add-menus.ts
chenos 6c39ac3538
Develop (#68)
* refactor: fields/views/pages...

* update

* update

* update

* updates

* updates

* add yarn.lock

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* developerMode

* 一大波更新

* bugfix

* fix: hide the sorting settings

* fix: reload menu when menu is updated

* 页面重构

* modify text

* 补充细节

* system settings

* 继续更新补充

* fix: 多级菜单支持

* 无限嵌套

* fix: icon

* 省市区参数调整

* 表单描述、文案调整

* 支持草稿

* 邮箱登录

* 细节补充

* 菜单页面权限初步

* 详情页打开方式

* 菜单父级、草稿问题

* 描述文字

* 详情分组显示

* 状态改为 radio

* 菜单权限

* 跳过省市区 api

* 修复权限数据范围

* onDraft

* 页面跳转

* 修改文案

* 注册、登录

* fix: 权限过滤问题

* 微调上传组件样式

* 0.4.0-alpha.0

* father-build

* remove father-build

* 细节调整
2021-03-16 14:31:54 +08:00

182 lines
3.9 KiB
TypeScript

import api from '../app';
import Database from '@nocobase/database';
import views_v2 from '@nocobase/plugin-pages/src/collections/views_v2';
import { Op } from 'sequelize';
(async () => {
await api.loadPlugins();
const database: Database = api.database;
await api.database.sync();
await api.database.getModel('collections').load({skipExisting: true});
const [Collection, Field, Page, Menu, View] = database.getModels(['collections', 'fields', 'pages_v2', 'menus', 'views_v2']);
// await Collection.import(require('./collections/authors').default, { update: true });
// await Collection.import(require('./collections/books').default, { update: true });
await Menu.truncate();
await Page.destroy({
where: {
id: {
[Op.not]: null,
},
}
});
await View.destroy({
where: {
id: {
[Op.not]: null,
},
}
});
const collection = await Collection.findOne({
where: {
name: 'views_v2',
}
});
await collection.updateAssociations({
fields: views_v2.fields,
views_v2: views_v2.views_v2,
});
// const authors = require('./collections/authors').default;
console.log('views_v2.fields', views_v2.fields.map(field=>field.name));
// await collection.updateAssociations({
// views_v2: authors.views_v2,
// });
const tables = database.getTables([
'collections',
'fields',
'menus',
'pages_v2',
'views_v2',
'pages_views_v2',
'automations',
'automations_jobs',
'action_logs',
'users',
'roles',
'scopes',
'views_actions_v2',
'views_pages_v2',
'views_fields_v2',
]);
for (let table of tables) {
console.log(table.getName());
await Collection.import(table.getOptions(), { update: true, migrate: false });
}
const menus = [
{
title: '仪表盘',
icon: 'DashboardOutlined',
type: 'group',
children: [
{
title: '欢迎光临',
icon: 'DatabaseOutlined',
type: 'page',
pageName: 'welcome'
},
],
},
{
title: '数据',
icon: 'DatabaseOutlined',
type: 'group',
children: [
{
title: '作者',
icon: 'DatabaseOutlined',
type: 'page',
pageName: 'authors.all',
},
{
title: '申请表单',
icon: 'DatabaseOutlined',
type: 'page',
pageName: 'authors.form',
},
],
},
{
title: '用户',
icon: 'TeamOutlined',
type: 'group',
children: [
{
title: '用户管理',
icon: 'DatabaseOutlined',
type: 'page',
pageName: 'users.all',
},
],
},
{
title: '动态',
icon: 'NotificationOutlined',
type: 'group',
children: [
{
title: '操作日志',
icon: 'DatabaseOutlined',
type: 'page',
pageName: 'action_logs.all',
},
],
},
{
title: '配置',
icon: 'SettingOutlined',
type: 'group',
children: [
{
title: '数据表配置',
icon: 'DatabaseOutlined',
type: 'page',
pageName: 'collections.all',
},
{
title: '菜单配置',
icon: 'MenuOutlined',
type: 'page',
pageName: 'menus.all',
},
{
title: '页面配置',
icon: 'MenuOutlined',
type: 'page',
pageName: 'pages_v2.globals',
},
{
title: '权限配置',
icon: 'MenuOutlined',
type: 'page',
pageName: 'roles.all',
},
{
title: '自动化配置',
icon: 'MenuOutlined',
type: 'page',
pageName: 'automations.all',
},
],
},
];
for (const item of menus) {
const menu = await Menu.create(item);
await menu.updateAssociations(item);
}
})();