- 组织架构:主体管理改为组织架构页(左侧 tab:集团设置 / 下属公司),主体列表仅保留顶部下拉切换 - 新增下属公司表 principal_subsidiaries、接口与页面,按当前主体隔离 - 集团设置读取/编辑当前主体基础信息,补所属主体校验与更新字段白名单 - 权限管理:新增 permissions / roles / role_permissions 表 - 权限以现有顶级菜单为分类,每个菜单两种范围:集团全部 / 所在公司 - 系统预设角色:系统管理员(全部集团权限)、货主权限(全部所在公司权限) - 权限管理页只展示角色组,支持按菜单勾选权限;系统预设角色只读 - 员工档案:账号菜单改为员工档案 - 新增员工-下属公司多对多关联(principal_user_companies) - 创建/编辑员工必须选择角色组;除所有者外必须至少关联一家公司 - 菜单重命名与旧地址重定向;账号导出新增角色组、所属公司 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
147 lines
5.5 KiB
JavaScript
147 lines
5.5 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 权限管理相关表:
|
||
* - permissions:权限表,按「菜单」作为分类,每个菜单下两种权限子类(1 集团全部 / 2 所在公司)
|
||
* - roles:角色组(角色表),is_system=1 为系统预设角色(不可删除)
|
||
* - role_permissions:角色与权限的关联
|
||
* - principal_users.role_id:账号在当前主体下所属的角色组
|
||
*/
|
||
module.exports = {
|
||
async up(queryInterface, Sequelize) {
|
||
await queryInterface.createTable(
|
||
'permissions',
|
||
{
|
||
id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: false,
|
||
autoIncrement: true,
|
||
primaryKey: true,
|
||
},
|
||
menu_id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: false,
|
||
comment: '所属菜单(权限分类)ID',
|
||
references: { model: 'menus', key: 'id' },
|
||
},
|
||
name: { type: Sequelize.STRING(100), allowNull: false, comment: '权限名称' },
|
||
code: { type: Sequelize.STRING(100), allowNull: false, comment: '权限标识(全局唯一)' },
|
||
scope: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '权限范围:1集团全部 2所在公司' },
|
||
status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' },
|
||
remark: { type: Sequelize.STRING(255), allowNull: true, comment: '备注' },
|
||
created_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
},
|
||
updated_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
|
||
},
|
||
},
|
||
{ charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', comment: '权限表' }
|
||
);
|
||
|
||
await queryInterface.addIndex('permissions', {
|
||
fields: [ 'menu_id', 'scope' ],
|
||
unique: true,
|
||
name: 'uk_permissions_menu_scope',
|
||
});
|
||
await queryInterface.addIndex('permissions', {
|
||
fields: [ 'code' ],
|
||
unique: true,
|
||
name: 'uk_permissions_code',
|
||
});
|
||
|
||
await queryInterface.createTable(
|
||
'roles',
|
||
{
|
||
id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: false,
|
||
autoIncrement: true,
|
||
primaryKey: true,
|
||
},
|
||
name: { type: Sequelize.STRING(50), allowNull: false, comment: '角色名称' },
|
||
code: { type: Sequelize.STRING(50), allowNull: false, comment: '角色标识(全局唯一)' },
|
||
is_system: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 0, comment: '是否系统预设:1是(不可删除) 0自定义' },
|
||
status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' },
|
||
remark: { type: Sequelize.STRING(255), allowNull: true, comment: '备注' },
|
||
created_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
},
|
||
updated_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
|
||
},
|
||
},
|
||
{ charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', comment: '角色组表' }
|
||
);
|
||
|
||
await queryInterface.addIndex('roles', { fields: [ 'name' ], unique: true, name: 'uk_roles_name' });
|
||
await queryInterface.addIndex('roles', { fields: [ 'code' ], unique: true, name: 'uk_roles_code' });
|
||
|
||
await queryInterface.createTable(
|
||
'role_permissions',
|
||
{
|
||
id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: false,
|
||
autoIncrement: true,
|
||
primaryKey: true,
|
||
},
|
||
role_id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: false,
|
||
comment: '角色ID',
|
||
references: { model: 'roles', key: 'id' },
|
||
},
|
||
permission_id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: false,
|
||
comment: '权限ID',
|
||
references: { model: 'permissions', key: 'id' },
|
||
},
|
||
created_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
},
|
||
updated_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
|
||
},
|
||
},
|
||
{ charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', comment: '角色权限关联表' }
|
||
);
|
||
|
||
await queryInterface.addIndex('role_permissions', {
|
||
fields: [ 'role_id', 'permission_id' ],
|
||
unique: true,
|
||
name: 'uk_role_permissions_role_permission',
|
||
});
|
||
|
||
await queryInterface.addColumn('principal_users', 'role_id', {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: true,
|
||
comment: '角色组ID(roles.id),为空表示未分配角色组',
|
||
references: { model: 'roles', key: 'id' },
|
||
after: 'user_id',
|
||
});
|
||
await queryInterface.addIndex('principal_users', { fields: [ 'role_id' ], name: 'idx_principal_users_role_id' });
|
||
},
|
||
|
||
async down(queryInterface) {
|
||
await queryInterface.removeIndex('principal_users', 'idx_principal_users_role_id');
|
||
await queryInterface.removeColumn('principal_users', 'role_id');
|
||
await queryInterface.dropTable('role_permissions');
|
||
await queryInterface.dropTable('roles');
|
||
await queryInterface.dropTable('permissions');
|
||
},
|
||
};
|