'use strict'; /** * 新增「创建发货单」菜单:挂在「订单管理」目录下,指向独立创建页 views/Order/Create.vue * * 背景:创建发货单改为独立整页(订单信息 + 商品明细内联,不再使用弹窗), * 便于与「订单」列表页区分。菜单按 name + parent_id 判重,可重复执行。 */ const PARENT_NAME = '订单管理'; const MENU = { name: '创建发货单', type: 2, path: '/order-create', icon: 'Plus', permission: 'orderDelivery:create', component: 'views/Order/Create.vue', sort: 80, }; module.exports = { async up(queryInterface) { const sequelize = queryInterface.sequelize; const [ parent ] = await sequelize.query( 'SELECT id FROM menus WHERE name = ? AND parent_id = 0 LIMIT 1', { replacements: [ PARENT_NAME ], type: sequelize.QueryTypes.SELECT } ); if (!parent) { // 父菜单不存在(异常数据)时跳过,避免挂错层级 return; } const parentId = Number(parent.id); const [ exist ] = await sequelize.query( 'SELECT id FROM menus WHERE name = ? AND parent_id = ? LIMIT 1', { replacements: [ MENU.name, parentId ], type: sequelize.QueryTypes.SELECT } ); if (exist) return; 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, MENU.name, MENU.type, MENU.path, MENU.icon, MENU.permission, MENU.component, MENU.sort, ], } ); }, async down(queryInterface) { const sequelize = queryInterface.sequelize; await sequelize.query('DELETE FROM menus WHERE name = ? AND path = ?', { replacements: [ MENU.name, MENU.path ], }); }, };