feat: 新增网卡、端口和接线管理功能

- 添加网卡(NetworkCard)模型及相关路由
- 实现端口(DevicePort)管理功能
- 新增接线(Cable)管理功能
- 添加前端网卡和端口管理界面
- 更新机柜可视化页面显示接线
- 添加设备详情抽屉展示端口和接线信息
- 更新部署文档包含数据库迁移指南
- 添加批量创建端口功能
- 设备删除时自动清理相关接线
This commit is contained in:
zhang1106
2026-01-23 08:55:16 +08:00
parent e965be50c8
commit 8099edc5e5
21 changed files with 5080 additions and 15 deletions
+69
View File
@@ -0,0 +1,69 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Device = require('./Device');
const Cable = sequelize.define('Cable', {
cableId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
},
sourceDeviceId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: 'devices',
key: 'deviceId'
}
},
sourcePort: {
type: DataTypes.STRING,
allowNull: false
},
targetDeviceId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: 'devices',
key: 'deviceId'
}
},
targetPort: {
type: DataTypes.STRING,
allowNull: false
},
cableType: {
type: DataTypes.ENUM('ethernet', 'fiber', 'copper'),
defaultValue: 'ethernet',
allowNull: false
},
cableLength: {
type: DataTypes.DECIMAL(5, 2),
allowNull: true
},
status: {
type: DataTypes.ENUM('normal', 'fault', 'disconnected'),
defaultValue: 'normal',
allowNull: false
},
description: {
type: DataTypes.TEXT,
allowNull: true
}
}, {
tableName: 'cables',
timestamps: true,
indexes: [
{ fields: ['sourceDeviceId'] },
{ fields: ['targetDeviceId'] },
{ fields: ['status'] },
{ fields: ['cableType'] },
{ fields: ['sourceDeviceId', 'targetDeviceId'] }
]
});
Cable.belongsTo(Device, { foreignKey: 'sourceDeviceId', as: 'sourceDevice' });
Cable.belongsTo(Device, { foreignKey: 'targetDeviceId', as: 'targetDevice' });
module.exports = Cable;
+76
View File
@@ -0,0 +1,76 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Device = require('./Device');
const NetworkCard = require('./NetworkCard');
const DevicePort = sequelize.define('DevicePort', {
portId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
},
deviceId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: 'devices',
key: 'deviceId'
}
},
nicId: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: 'network_cards',
key: 'nicId'
},
comment: '所属网卡ID,可为空(向后兼容)'
},
portName: {
type: DataTypes.STRING,
allowNull: false
},
portType: {
type: DataTypes.ENUM('RJ45', 'SFP', 'SFP+', 'SFP28', 'QSFP', 'QSFP28'),
defaultValue: 'RJ45',
allowNull: false
},
portSpeed: {
type: DataTypes.ENUM('100M', '1G', '10G', '25G', '40G', '100G'),
defaultValue: '1G',
allowNull: false
},
status: {
type: DataTypes.ENUM('free', 'occupied', 'fault'),
defaultValue: 'free',
allowNull: false
},
vlanId: {
type: DataTypes.INTEGER,
allowNull: true
},
description: {
type: DataTypes.TEXT,
allowNull: true
}
}, {
tableName: 'device_ports',
timestamps: true,
indexes: [
{ fields: ['deviceId'] },
{ fields: ['nicId'] },
{ fields: ['status'] },
{ fields: ['portType'] },
{ fields: ['portSpeed'] },
{ unique: true, fields: ['deviceId', 'portName'] }
]
});
DevicePort.belongsTo(Device, { foreignKey: 'deviceId', as: 'device' });
Device.hasMany(DevicePort, { foreignKey: 'deviceId', as: 'ports' });
DevicePort.belongsTo(NetworkCard, { foreignKey: 'nicId', as: 'networkCard' });
NetworkCard.hasMany(DevicePort, { foreignKey: 'nicId', as: 'ports' });
module.exports = DevicePort;
+69
View File
@@ -0,0 +1,69 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Device = require('./Device');
const NetworkCard = sequelize.define('NetworkCard', {
nicId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
},
deviceId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: 'devices',
key: 'deviceId'
}
},
name: {
type: DataTypes.STRING,
allowNull: false,
comment: '网卡名称,如"网卡1"、"eth0"、"Primary NIC"'
},
description: {
type: DataTypes.TEXT,
allowNull: true,
comment: '网卡描述信息'
},
slotNumber: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '插槽编号'
},
portCount: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '端口数量'
},
model: {
type: DataTypes.STRING,
allowNull: true,
comment: '网卡型号'
},
manufacturer: {
type: DataTypes.STRING,
allowNull: true,
comment: '制造商'
},
status: {
type: DataTypes.ENUM('normal', 'warning', 'fault', 'offline'),
defaultValue: 'normal',
allowNull: false,
comment: '网卡状态'
}
}, {
tableName: 'network_cards',
timestamps: true,
indexes: [
{ fields: ['deviceId'] },
{ fields: ['slotNumber'] },
{ unique: true, fields: ['deviceId', 'name'] }
]
});
NetworkCard.belongsTo(Device, { foreignKey: 'deviceId', as: 'device' });
Device.hasMany(NetworkCard, { foreignKey: 'deviceId', as: 'networkCards' });
module.exports = NetworkCard;