oms/backend/database/migrations/20260909002400-seed-stock-menus.js
liufumingren 8597cf5ac9 feat(backend): 用户鉴权、菜单权限、主体与系统基础模块
- 登录/邮箱验证码/密码流程(controller/auth.js、lib/emailCode.js、middleware/jwt_auth.js)
- 主体(principal)隔离与主体用户、对外接口配置模块及 principalCheck 中间件
- 菜单、用户、文件上传、快递公司字典(express_companies)等基础模块
- 通用工具:分页(lib/pagination.js)、缓存(service/cache.js)
- 全量接口契约(contract/index.js)与路由注册(router.js)、config.default.js 配置
- 相关迁移:菜单组件调整与菜单种子、创建 files 表
2026-09-13 02:23:34 +08:00

96 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* 24. 新增「库存管理」菜单:入库单、出库单两个页面(component 指向前端 views)。
* 按 name + parent_id 判重,重复执行不会插入多条。
*/
const menus = [
{
name: '库存管理',
type: 1,
icon: 'Box',
sort: 82,
children: [
{
name: '入库单',
type: 2,
path: '/inbound-order',
icon: 'Bottom',
permission: 'inboundOrder:list',
component: 'views/InboundOrder/Index.vue',
sort: 75,
},
{
name: '出库单',
type: 2,
path: '/outbound-order',
icon: 'Top',
permission: 'outboundOrder:list',
component: 'views/OutboundOrder/Index.vue',
sort: 70,
},
],
},
];
module.exports = {
async up(queryInterface) {
const sequelize = queryInterface.sequelize;
async function findMenu(name, parentId) {
const [ rows ] = await sequelize.query(
'SELECT id FROM menus WHERE name = ? AND parent_id = ? LIMIT 1',
{ replacements: [ name, parentId ], type: sequelize.QueryTypes.SELECT }
);
return rows ? Number(rows.id) : null;
}
async function insertMenu(m, parentId) {
await sequelize.query(
`INSERT INTO menus
(parent_id, name, type, path, icon, permission, component, sort, status, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1, NOW(), NOW())`,
{
replacements: [
parentId,
m.name,
m.type,
m.path || null,
m.icon || null,
m.permission || null,
m.component || null,
m.sort || 0,
],
}
);
const [ idRows ] = await sequelize.query('SELECT LAST_INSERT_ID() AS id', {
type: sequelize.QueryTypes.SELECT,
});
return Number(idRows.id);
}
async function upsertTree(list, parentId) {
for (const m of list) {
let id = await findMenu(m.name, parentId);
if (!id) id = await insertMenu(m, parentId);
if (m.children && m.children.length) await upsertTree(m.children, id);
}
}
await upsertTree(menus, 0);
},
async down(queryInterface) {
const sequelize = queryInterface.sequelize;
const [ rows ] = await sequelize.query(
"SELECT id FROM menus WHERE name = '库存管理' AND parent_id = 0 LIMIT 1",
{ type: sequelize.QueryTypes.SELECT }
);
if (!rows) return;
await sequelize.query('DELETE FROM menus WHERE parent_id = ? OR id = ?', {
replacements: [ Number(rows.id), Number(rows.id) ],
});
},
};