refactor(devices): 实现设备字段动态校验与配置同步

1. 新增动态设备校验Schema生成器,支持从数据库读取字段配置生成校验规则
2. 重构设备增改接口,使用动态校验替代硬编码Schema
3. 调整前端设备表单,适配字段配置并锁定核心系统字段
4. 修复前后端默认字段配置不一致问题
5. 新增字段管理页面防护,锁定核心字段的必填/可见配置
This commit is contained in:
zhang1106
2026-06-12 16:01:41 +08:00
parent 85d6b2c633
commit 1b9a5571ae
8 changed files with 621 additions and 22 deletions
+3 -4
View File
@@ -16,13 +16,12 @@ const {
} = require('../utils/operationLogger');
const { validateBody, validateQuery } = require('../middleware/validation');
const {
createDeviceSchema,
updateDeviceSchema,
batchDeviceIdsSchema,
batchStatusSchema,
batchMoveSchema,
queryDeviceSchema,
} = require('../validation/deviceSchema');
const { createDeviceSchema } = require('../validation/dynamicDeviceSchema');
const PREVIEW_COUNT = 20;
@@ -736,7 +735,7 @@ async function generateDeviceId() {
}
// 创建设备
router.post('/', validateBody(createDeviceSchema), async (req, res) => {
router.post('/', validateBody(() => createDeviceSchema(false)), async (req, res) => {
try {
const deviceData = { ...req.body };
@@ -2285,7 +2284,7 @@ router.get('/:deviceId/tickets', async (req, res) => {
});
// 更新设备
router.put('/:deviceId', validateBody(updateDeviceSchema), async (req, res) => {
router.put('/:deviceId', validateBody(() => createDeviceSchema(true)), async (req, res) => {
try {
const oldDevice = await Device.findByPk(req.params.deviceId);
if (!oldDevice) {