feat: WWJCloud 企业级全栈框架 v0.3.5 完整更新
🚀 核心更新: - ✅ 完善 NestJS 企业级架构设计 - ✅ 优化配置中心和基础设施层 - ✅ 增强第三方服务集成能力 - ✅ 完善多租户架构支持 - 🎯 对标 Java Spring Boot 和 PHP ThinkPHP 📦 新增文件: - wwjcloud-nest 完整框架结构 - Docker 容器化配置 - 管理后台界面 - 数据库迁移脚本 🔑 Key: ebb38b43ec39f355f071294fd1cf9c42
This commit is contained in:
58
src/core/language/decorators/validate-message.decorator.ts
Normal file
58
src/core/language/decorators/validate-message.decorator.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
||||
|
||||
/**
|
||||
* 验证器消息装饰器
|
||||
* 基于PHP的验证器分组方式,符合NestJS规范
|
||||
*
|
||||
* 使用方式:
|
||||
* @ValidateMessage('validate_user', 'username_require')
|
||||
* username: string;
|
||||
*/
|
||||
export const ValidateMessage = (group: string, key: string) => {
|
||||
return (target: any, propertyKey: string) => {
|
||||
// 存储验证器分组和键值信息
|
||||
if (!target.constructor._validateMessages) {
|
||||
target.constructor._validateMessages = new Map();
|
||||
}
|
||||
target.constructor._validateMessages.set(propertyKey, { group, key });
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* 场景化验证装饰器
|
||||
* 基于PHP的$scene数组方式,符合NestJS规范
|
||||
*
|
||||
* 使用方式:
|
||||
* @ValidateScene('add', ['username', 'password'])
|
||||
* @ValidateScene('edit', ['username'])
|
||||
*/
|
||||
export const ValidateScene = (scene: string, fields: string[]) => {
|
||||
return (target: any) => {
|
||||
if (!target._validateScenes) {
|
||||
target._validateScenes = new Map();
|
||||
}
|
||||
target._validateScenes.set(scene, fields);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取验证器消息键值
|
||||
* 用于在验证管道中获取正确的消息键值
|
||||
*/
|
||||
export const getValidateMessageKey = (target: any, propertyKey: string): { group: string; key: string } | null => {
|
||||
if (target.constructor._validateMessages) {
|
||||
return target.constructor._validateMessages.get(propertyKey) || null;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取验证器场景字段
|
||||
* 用于场景化验证
|
||||
*/
|
||||
export const getValidateSceneFields = (target: any, scene: string): string[] => {
|
||||
if (target._validateScenes) {
|
||||
return target._validateScenes.get(scene) || [];
|
||||
}
|
||||
return [];
|
||||
};
|
||||
Reference in New Issue
Block a user