refactor(devices): 实现设备字段动态校验与配置同步
1. 新增动态设备校验Schema生成器,支持从数据库读取字段配置生成校验规则 2. 重构设备增改接口,使用动态校验替代硬编码Schema 3. 调整前端设备表单,适配字段配置并锁定核心系统字段 4. 修复前后端默认字段配置不一致问题 5. 新增字段管理页面防护,锁定核心字段的必填/可见配置
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
const logger = require('../utils/logger').module('ValidationMiddleware');
|
||||
|
||||
const validate = (schema, source = 'body') => {
|
||||
const validate = (schemaOrFn, source = 'body') => {
|
||||
return async (req, res, next) => {
|
||||
const data = source === 'query' ? req.query : req.body;
|
||||
|
||||
try {
|
||||
// 支持函数形式的schema(动态schema:异步函数或同步函数返回Joi schema)
|
||||
let schema = schemaOrFn;
|
||||
if (typeof schemaOrFn === 'function') {
|
||||
schema = await schemaOrFn();
|
||||
}
|
||||
|
||||
let value;
|
||||
|
||||
if (schema.validate && typeof schema.validate === 'function') {
|
||||
|
||||
Reference in New Issue
Block a user