feat(设备字段): 添加系统字段保护机制
为设备字段添加isSystem属性标记系统字段,防止误删核心字段 后端添加字段删除前的系统字段检查 前端在管理界面标记并禁用系统字段的删除操作 更新导入模板生成逻辑以适配动态字段配置 优化设备导入功能,支持字段名称变更
This commit is contained in:
@@ -57,9 +57,22 @@ router.put('/:fieldId', async (req, res) => {
|
||||
// 删除字段配置
|
||||
router.delete('/:fieldId', async (req, res) => {
|
||||
try {
|
||||
// 先查询字段信息
|
||||
const field = await DeviceField.findByPk(req.params.fieldId);
|
||||
|
||||
if (!field) {
|
||||
return res.status(404).json({ error: '字段不存在' });
|
||||
}
|
||||
|
||||
// 检查是否为系统字段
|
||||
if (field.isSystem) {
|
||||
return res.status(403).json({ error: '系统字段不可删除' });
|
||||
}
|
||||
|
||||
const deleted = await DeviceField.destroy({
|
||||
where: { fieldId: req.params.fieldId }
|
||||
});
|
||||
|
||||
if (deleted) {
|
||||
res.status(204).json();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user