feat: 添加用户分页/详情/新增/更新/删除接口

This commit is contained in:
2025-02-25 17:03:11 +08:00
parent 999c70cb0b
commit 4bbdc99a7e
9 changed files with 338 additions and 5 deletions

View File

@@ -0,0 +1,68 @@
<?php
declare (strict_types = 1);
namespace app\admin\validate\v1;
use think\Validate;
class SysUserValidate extends Validate
{
/**
* 定义验证规则
* 格式:'字段名' => ['规则1','规则2'...]
*
* @var array
*/
protected $rule = [
'id' => 'require|integer',
'username' => 'require|unique:sys_user|max:64',
'password' => 'require|max:64',
'repassword' => 'requireWith:password|confirm:password',
'salt' => 'require|max:16',
'role_id' => 'require|integer',
'nickname' => 'max:64',
'avatar' => 'max:255',
'mobile' => 'mobile',
'email' => 'email',
'status' => 'in:-1,1',
];
/**
* 定义错误信息
* 格式:'字段名.规则名' => '错误信息'
*
* @var array
*/
protected $message = [
'id.require' => 'ID不能为空',
'id.integer' => 'ID必须为整数',
'username.require' => '用户名不能为空',
'username.unique' => '用户名已存在',
'username.max' => '用户名最多不能超过64个字符',
'password.require' => '密码不能为空',
'password.max' => '密码最多不能超过64个字符',
'repassword.requireWith' => '确认密码不能为空',
'repassword.confirm' => '两次密码输入不一致',
'salt.require' => '盐不能为空',
'salt.max' => '盐最多不能超过16个字符',
'role_id.require' => '角色ID不能为空',
'role_id.integer' => '角色ID必须为整数',
'nickname.max' => '昵称最多不能超过64个字符',
'avatar.max' => '头像最多不能超过255个字符',
'mobile' => '手机号格式错误',
'email' => '邮箱格式错误',
'status.in' => '状态值必须是-1或1',
];
// 新增校验场景
public function sceneCreate()
{
return $this->remove('id', 'require|integer');
}
// 更新校验场景
public function sceneUpdate()
{
return $this->remove('repassword', 'requireWith:password|confirm:password');
}
}