refactor: 统一代码风格并迁移至 ESLint 新配置

style(backend): 格式化模型文件代码
style(frontend): 调整组件代码格式
chore: 删除旧 ESLint 配置并添加新配置
refactor(backend): 重构模型定义语法
style: 统一箭头函数和对象属性简写
This commit is contained in:
zhang1106
2026-03-27 19:12:16 +08:00
parent 6a8d4144ff
commit 63f0cb570e
166 changed files with 15483 additions and 11170 deletions
+51 -68
View File
@@ -7,41 +7,48 @@ const createDeviceSchema = Joi.object({
name: Joi.string().required().max(100).messages({
'string.empty': '设备名称不能为空',
'string.max': '设备名称不能超过100个字符',
'any.required': '设备名称是必填字段'
}),
type: Joi.string().required().valid(...DEVICE_TYPES).messages({
'any.only': `设备类型必须是以下之一: ${DEVICE_TYPES.join(', ')}`,
'any.required': '设备类型是必填字段'
'any.required': '设备名称是必填字段',
}),
type: Joi.string()
.required()
.valid(...DEVICE_TYPES)
.messages({
'any.only': `设备类型必须是以下之一: ${DEVICE_TYPES.join(', ')}`,
'any.required': '设备类型是必填字段',
}),
model: Joi.string().allow('', null).max(100),
serialNumber: Joi.string().required().max(100).messages({
'string.empty': '序列号不能为空',
'string.max': '序列号不能超过100个字符',
'any.required': '序列号是必填字段'
'any.required': '序列号是必填字段',
}),
rackId: Joi.string().allow('', null).max(50),
position: Joi.number().integer().min(1).max(100).allow(null),
height: Joi.number().integer().min(1).max(50).allow(null),
powerConsumption: Joi.number().min(0).max(100000).allow(null),
ipAddress: Joi.string().allow('', null).max(50),
status: Joi.string().valid(...DEVICE_STATUS).default('offline'),
status: Joi.string()
.valid(...DEVICE_STATUS)
.default('offline'),
purchaseDate: Joi.date().allow(null),
warrantyExpiry: Joi.date().allow(null),
description: Joi.string().allow('', null).max(500),
customFields: Joi.object().allow(null)
customFields: Joi.object().allow(null),
});
const updateDeviceSchema = Joi.object({
name: Joi.string().max(100).messages({
'string.empty': '设备名称不能为空',
'string.max': '设备名称不能超过100个字符'
}),
type: Joi.string().valid(...DEVICE_TYPES).messages({
'any.only': `设备类型必须是以下之一: ${DEVICE_TYPES.join(', ')}`
'string.max': '设备名称不能超过100个字符',
}),
type: Joi.string()
.valid(...DEVICE_TYPES)
.messages({
'any.only': `设备类型必须是以下之一: ${DEVICE_TYPES.join(', ')}`,
}),
model: Joi.string().allow('', null).max(100),
serialNumber: Joi.string().max(100).messages({
'string.max': '序列号不能超过100个字符'
'string.max': '序列号不能超过100个字符',
}),
rackId: Joi.string().allow('', null).max(50),
position: Joi.number().integer().min(1).max(100).allow(null),
@@ -52,82 +59,58 @@ const updateDeviceSchema = Joi.object({
purchaseDate: Joi.date().allow(null),
warrantyExpiry: Joi.date().allow(null),
description: Joi.string().allow('', null).max(500),
customFields: Joi.object().allow(null)
}).min(1).messages({
'object.min': '至少需要提供一个字段进行更新'
});
customFields: Joi.object().allow(null),
})
.min(1)
.messages({
'object.min': '至少需要提供一个字段进行更新',
});
const batchDeviceIdsSchema = Joi.object({
deviceIds: Joi.array()
.items(Joi.string().required())
.min(1)
.required()
.messages({
'array.base': '设备ID列表必须是数组',
'array.min': '至少需要提供一个设备ID',
'any.required': '设备ID列表是必填字段'
})
deviceIds: Joi.array().items(Joi.string().required()).min(1).required().messages({
'array.base': '设备ID列表必须是数组',
'array.min': '至少需要提供一个设备ID',
'any.required': '设备ID列表是必填字段',
}),
});
const batchStatusSchema = Joi.object({
deviceIds: Joi.array()
.items(Joi.string().required())
.min(1)
.required()
.messages({
'array.base': '设备ID列表必须是数组',
'array.min': '至少需要提供一个设备ID',
'any.required': '设备ID列表是必填字段'
}),
deviceIds: Joi.array().items(Joi.string().required()).min(1).required().messages({
'array.base': '设备ID列表必须是数组',
'array.min': '至少需要提供一个设备ID',
'any.required': '设备ID列表是必填字段',
}),
status: Joi.string()
.valid(...DEVICE_STATUS)
.required()
.messages({
'any.only': `状态必须是以下之一: ${DEVICE_STATUS.join(', ')}`,
'any.required': '状态是必填字段'
})
'any.required': '状态是必填字段',
}),
});
const batchMoveSchema = Joi.object({
deviceIds: Joi.array()
.items(Joi.string().required())
.min(1)
.required(),
targetRackId: Joi.string()
.required()
.max(50)
.messages({
'string.empty': '目标机柜ID不能为空',
'any.required': '目标机柜ID是必填字段'
}),
startPosition: Joi.number()
.integer()
.min(1)
.allow(null)
deviceIds: Joi.array().items(Joi.string().required()).min(1).required(),
targetRackId: Joi.string().required().max(50).messages({
'string.empty': '目标机柜ID不能为空',
'any.required': '目标机柜ID是必填字段',
}),
startPosition: Joi.number().integer().min(1).allow(null),
});
const queryDeviceSchema = Joi.object({
keyword: Joi.string()
.max(100)
.allow(''),
keyword: Joi.string().max(100).allow(''),
status: Joi.string()
.valid(...DEVICE_STATUS, 'all')
.allow(''),
type: Joi.string()
.valid(...DEVICE_TYPES, 'all')
.allow(''),
rackId: Joi.string()
.max(50)
.allow(''),
page: Joi.number()
.integer()
.min(1)
.default(1),
pageSize: Joi.number()
.integer()
.min(1)
.max(10000)
.default(10)
rackId: Joi.string().max(50).allow(''),
roomId: Joi.string().max(50).allow(''),
isIdle: Joi.boolean().allow('').optional(),
page: Joi.number().integer().min(1).default(1),
pageSize: Joi.number().integer().min(1).max(10000).default(10),
});
module.exports = {
@@ -138,5 +121,5 @@ module.exports = {
batchMoveSchema,
queryDeviceSchema,
DEVICE_TYPES,
DEVICE_STATUS
DEVICE_STATUS,
};
+64 -109
View File
@@ -11,70 +11,49 @@ const createRackSchema = Joi.object({
.allow('', null)
.messages({
'string.max': '机柜ID不能超过50个字符',
'string.pattern.base': '机柜ID只能包含字母、数字、下划线和横线'
'string.pattern.base': '机柜ID只能包含字母、数字、下划线和横线',
}),
name: Joi.string()
.required()
.max(100)
.messages({
'string.empty': '机柜名称不能为空',
'string.max': '机柜名称不能超过100个字符',
'any.required': '机柜名称是必填字段'
}),
name: Joi.string().required().max(100).messages({
'string.empty': '机柜名称不能为空',
'string.max': '机柜名称不能超过100个字符',
'any.required': '机柜名称是必填字段',
}),
height: Joi.number()
.integer()
.min(1)
.max(100)
.default(42)
.messages({
'number.base': '高度必须是数字',
'number.integer': '高度必须是整数',
'number.min': '高度不能小于1',
'number.max': '高度不能大于100'
}),
height: Joi.number().integer().min(1).max(100).default(42).messages({
'number.base': '高度必须是数字',
'number.integer': '高度必须是整数',
'number.min': '高度不能小于1',
'number.max': '高度不能大于100',
}),
maxPower: Joi.number()
.min(0)
.max(1000000)
.default(10000)
.messages({
'number.base': '最大功率必须是数字',
'number.min': '最大功率不能小于0',
'number.max': '最大功率不能超过1000000'
}),
maxPower: Joi.number().min(0).max(1000000).default(10000).messages({
'number.base': '最大功率必须是数字',
'number.min': '最大功率不能小于0',
'number.max': '最大功率不能超过1000000',
}),
currentPower: Joi.number()
.min(0)
.default(0)
.messages({
'number.base': '当前功率必须是数字',
'number.min': '当前功率不能小于0'
}),
currentPower: Joi.number().min(0).default(0).messages({
'number.base': '当前功率必须是数字',
'number.min': '当前功率不能小于0',
}),
status: Joi.string()
.valid(...RACK_STATUS)
.default('active')
.messages({
'any.only': `状态必须是以下之一: ${RACK_STATUS.join(', ')}`
'any.only': `状态必须是以下之一: ${RACK_STATUS.join(', ')}`,
}),
roomId: Joi.string()
.required()
.max(50)
.messages({
'string.empty': '机房ID不能为空',
'string.max': '机房ID不能超过50个字符',
'any.required': '机房ID是必填字段'
}),
roomId: Joi.string().required().max(50).messages({
'string.empty': '机房ID不能为空',
'string.max': '机房ID不能超过50个字符',
'any.required': '机房ID是必填字段',
}),
description: Joi.string()
.max(500)
.allow('', null)
.messages({
'string.max': '描述不能超过500个字符'
})
description: Joi.string().max(500).allow('', null).messages({
'string.max': '描述不能超过500个字符',
}),
});
// 更新机柜验证Schema
@@ -84,86 +63,62 @@ const updateRackSchema = Joi.object({
.pattern(/^[a-zA-Z0-9_-]+$/)
.messages({
'string.max': '机柜ID不能超过50个字符',
'string.pattern.base': '机柜ID只能包含字母、数字、下划线和横线'
'string.pattern.base': '机柜ID只能包含字母、数字、下划线和横线',
}),
name: Joi.string()
.max(100)
.messages({
'string.max': '机柜名称不能超过100个字符'
}),
name: Joi.string().max(100).messages({
'string.max': '机柜名称不能超过100个字符',
}),
height: Joi.number()
.integer()
.min(1)
.max(100)
.messages({
'number.base': '高度必须是数字',
'number.integer': '高度必须是整数',
'number.min': '高度不能小于1',
'number.max': '高度不能大于100'
}),
height: Joi.number().integer().min(1).max(100).messages({
'number.base': '高度必须是数字',
'number.integer': '高度必须是整数',
'number.min': '高度不能小于1',
'number.max': '高度不能大于100',
}),
maxPower: Joi.number()
.min(0)
.max(1000000)
.messages({
'number.base': '最大功率必须是数字',
'number.min': '最大功率不能小于0',
'number.max': '最大功率不能超过1000000'
}),
maxPower: Joi.number().min(0).max(1000000).messages({
'number.base': '最大功率必须是数字',
'number.min': '最大功率不能小于0',
'number.max': '最大功率不能超过1000000',
}),
currentPower: Joi.number()
.min(0)
.messages({
'number.base': '当前功率必须是数字',
'number.min': '当前功率不能小于0'
}),
currentPower: Joi.number().min(0).messages({
'number.base': '当前功率必须是数字',
'number.min': '当前功率不能小于0',
}),
status: Joi.string()
.valid(...RACK_STATUS)
.messages({
'any.only': `状态必须是以下之一: ${RACK_STATUS.join(', ')}`
'any.only': `状态必须是以下之一: ${RACK_STATUS.join(', ')}`,
}),
roomId: Joi.string()
.max(50),
roomId: Joi.string().max(50),
description: Joi.string()
.max(500)
.allow('', null)
.messages({
'string.max': '描述不能超过500个字符'
})
}).min(1).messages({
'object.min': '至少需要提供一个字段进行更新'
});
description: Joi.string().max(500).allow('', null).messages({
'string.max': '描述不能超过500个字符',
}),
})
.min(1)
.messages({
'object.min': '至少需要提供一个字段进行更新',
});
// 查询机柜验证Schema
const queryRackSchema = Joi.object({
roomId: Joi.string()
.max(50)
.allow(''),
roomId: Joi.string().max(50).allow(''),
status: Joi.string()
.valid(...RACK_STATUS, 'all')
.allow(''),
keyword: Joi.string()
.max(100)
.allow(''),
page: Joi.number()
.integer()
.min(1)
.default(1),
pageSize: Joi.number()
.integer()
.min(1)
.max(100)
.default(10)
keyword: Joi.string().max(100).allow(''),
page: Joi.number().integer().min(1).default(1),
pageSize: Joi.number().integer().min(1).max(100).default(10),
});
module.exports = {
createRackSchema,
updateRackSchema,
queryRackSchema,
RACK_STATUS
RACK_STATUS,
};
+50 -83
View File
@@ -10,53 +10,35 @@ const createRoomSchema = Joi.object({
'string.empty': '机房ID不能为空',
'string.max': '机房ID不能超过50个字符',
'string.pattern.base': '机房ID只能包含字母、数字、下划线和横线',
'any.required': '机房ID是必填字段'
'any.required': '机房ID是必填字段',
}),
name: Joi.string()
.required()
.max(100)
.messages({
'string.empty': '机房名称不能为空',
'string.max': '机房名称不能超过100个字符',
'any.required': '机房名称是必填字段'
}),
name: Joi.string().required().max(100).messages({
'string.empty': '机房名称不能为空',
'string.max': '机房名称不能超过100个字符',
'any.required': '机房名称是必填字段',
}),
location: Joi.string()
.max(200)
.allow('', null)
.messages({
'string.max': '位置不能超过200个字符'
}),
location: Joi.string().max(200).allow('', null).messages({
'string.max': '位置不能超过200个字符',
}),
area: Joi.number()
.min(0)
.max(1000000)
.allow(null)
.messages({
'number.base': '面积必须是数字',
'number.min': '面积不能小于0',
'number.max': '面积不能超过1000000'
}),
area: Joi.number().min(0).max(1000000).allow(null).messages({
'number.base': '面积必须是数字',
'number.min': '面积不能小于0',
'number.max': '面积不能超过1000000',
}),
capacity: Joi.number()
.integer()
.min(0)
.max(10000)
.allow(null)
.messages({
'number.base': '容量必须是数字',
'number.integer': '容量必须是整数',
'number.min': '容量不能小于0',
'number.max': '容量不能超过10000'
}),
capacity: Joi.number().integer().min(0).max(10000).allow(null).messages({
'number.base': '容量必须是数字',
'number.integer': '容量必须是整数',
'number.min': '容量不能小于0',
'number.max': '容量不能超过10000',
}),
description: Joi.string()
.max(500)
.allow('', null)
.messages({
'string.max': '描述不能超过500个字符'
})
description: Joi.string().max(500).allow('', null).messages({
'string.max': '描述不能超过500个字符',
}),
});
// 更新机房验证Schema
@@ -66,55 +48,40 @@ const updateRoomSchema = Joi.object({
.pattern(/^[a-zA-Z0-9_-]+$/)
.messages({
'string.max': '机房ID不能超过50个字符',
'string.pattern.base': '机房ID只能包含字母、数字、下划线和横线'
'string.pattern.base': '机房ID只能包含字母、数字、下划线和横线',
}),
name: Joi.string()
.max(100)
.messages({
'string.max': '机房名称不能超过100个字符'
}),
name: Joi.string().max(100).messages({
'string.max': '机房名称不能超过100个字符',
}),
location: Joi.string()
.max(200)
.allow('', null)
.messages({
'string.max': '位置不能超过200个字符'
}),
location: Joi.string().max(200).allow('', null).messages({
'string.max': '位置不能超过200个字符',
}),
area: Joi.number()
.min(0)
.max(1000000)
.allow(null)
.messages({
'number.base': '面积必须是数字',
'number.min': '面积不能小于0',
'number.max': '面积不能超过1000000'
}),
area: Joi.number().min(0).max(1000000).allow(null).messages({
'number.base': '面积必须是数字',
'number.min': '面积不能小于0',
'number.max': '面积不能超过1000000',
}),
capacity: Joi.number()
.integer()
.min(0)
.max(10000)
.allow(null)
.messages({
'number.base': '容量必须是数字',
'number.integer': '容量必须是整数',
'number.min': '容量不能小于0',
'number.max': '容量不能超过10000'
}),
capacity: Joi.number().integer().min(0).max(10000).allow(null).messages({
'number.base': '容量必须是数字',
'number.integer': '容量必须是整数',
'number.min': '容量不能小于0',
'number.max': '容量不能超过10000',
}),
description: Joi.string()
.max(500)
.allow('', null)
.messages({
'string.max': '描述不能超过500个字符'
})
}).min(1).messages({
'object.min': '至少需要提供一个字段进行更新'
});
description: Joi.string().max(500).allow('', null).messages({
'string.max': '描述不能超过500个字符',
}),
})
.min(1)
.messages({
'object.min': '至少需要提供一个字段进行更新',
});
module.exports = {
createRoomSchema,
updateRoomSchema
updateRoomSchema,
};