'use strict'; /** * 新增「商品属性」菜单,挂在「商品管理」下,指向真实页面 views/ProductAttribute/Index.vue。 * 该页面左侧以 tab 切换「分类 / 品牌 / 单位」三类属性,各自独立增删查改。 * 幂等:按 name 定位,已存在则跳过。 */ module.exports = { async up(queryInterface) { const sequelize = queryInterface.sequelize; const [ goods ] = await sequelize.query( "SELECT id FROM menus WHERE name = '商品管理' AND parent_id = 0 LIMIT 1", { type: sequelize.QueryTypes.SELECT } ); if (!goods) return; // 商品管理节点不存在则跳过 const goodsId = Number(goods.id); const [ exist ] = await sequelize.query( "SELECT id FROM menus WHERE name = '商品属性' LIMIT 1", { 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 (?, '商品属性', 2, '/product-attribute', 'Collection', 'productAttribute:list', 'views/ProductAttribute/Index.vue', 90, 1, NOW(), NOW())`, { replacements: [ goodsId ] } ); }, async down(queryInterface) { const sequelize = queryInterface.sequelize; const [ goods ] = await sequelize.query( "SELECT id FROM menus WHERE name = '商品管理' AND parent_id = 0 LIMIT 1", { type: sequelize.QueryTypes.SELECT } ); if (!goods) return; await sequelize.query( "DELETE FROM menus WHERE name = '商品属性' AND parent_id = ?", { replacements: [ Number(goods.id) ] } ); }, };