first commit
This commit is contained in:
40
app/common/validate/system/Admin.php
Normal file
40
app/common/validate/system/Admin.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\common\validate\system;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class Admin extends Validate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
* 格式:'字段名' => ['规则1','规则2'...]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'name' => 'require|min:2|max:12|chsAlphaNum',
|
||||
'pwd|密码' => 'require|min:6|max:64',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
* 格式:'字段名.规则名' => '错误信息'
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'name.require' => '用户名不能为空',
|
||||
'name.min' => '用户名不能少于2个字符',
|
||||
'name.max' => '用户名不能超过12个字符',
|
||||
'name.filters' => '用户名包含禁止注册字符',
|
||||
'name.chsAlphaNum' => '用户名只能是汉字、字母和数字',
|
||||
];
|
||||
|
||||
// 测试验证场景
|
||||
protected $scene = [
|
||||
'edit' => ['name']
|
||||
];
|
||||
}
|
||||
54
app/common/validate/system/AdminGroup.php
Normal file
54
app/common/validate/system/AdminGroup.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\common\validate\system;
|
||||
|
||||
use think\Validate;
|
||||
use app\common\model\system\AdminGroup as AdminGroupModel;
|
||||
|
||||
class AdminGroup extends Validate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
* 格式:'字段名' => ['规则1','规则2'...]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'pid' => 'notEqId',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
* 格式:'字段名.规则名' => '错误信息'
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'pid.notEqId' => '选择上级分类错误!',
|
||||
];
|
||||
|
||||
/**
|
||||
* 自定义验证规则
|
||||
* @param $value
|
||||
* @param $rules
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
protected function notEqId($value, $rules ,$data): bool
|
||||
{
|
||||
if ($value == $data['id']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($data['id']) && $value > $data['id']) {
|
||||
if (AdminGroupModel::getByPid($data['id'])) {
|
||||
$this->message['pid.notEqId'] = '禁止修改存在子类的栏目';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
46
app/common/validate/system/AdminRules.php
Normal file
46
app/common/validate/system/AdminRules.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\common\validate\system;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class AdminRules extends Validate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
* 格式:'字段名' => ['规则1','规则2'...]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'pid' => 'notEqId',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
* 格式:'字段名.规则名' => '错误信息'
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'pid.notEqId' => '选择上级分类错误!',
|
||||
];
|
||||
|
||||
/**
|
||||
* 自定义验证规则
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
protected function notEqId($value, $rule, $data): bool
|
||||
{
|
||||
if ($value == $data['id']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
45
app/common/validate/system/Department.php
Normal file
45
app/common/validate/system/Department.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\common\validate\system;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class Department extends Validate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
* 格式:'字段名' => ['规则1','规则2'...]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'pid' => 'notEqId',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
* 格式:'字段名.规则名' => '错误信息'
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'pid.notEqId' => '选择上级分类错误!',
|
||||
];
|
||||
|
||||
/**
|
||||
* 自定义验证规则
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $post
|
||||
* @return bool
|
||||
*/
|
||||
protected function notEqId($value, $rule, $post): bool
|
||||
{
|
||||
if ($value == $post['id']) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
21
app/common/validate/system/Dictionary.php
Normal file
21
app/common/validate/system/Dictionary.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\common\validate\system;
|
||||
|
||||
use app\common\model\system\Dictionary as SystemDictionary;
|
||||
use think\Validate;
|
||||
|
||||
class Dictionary extends Validate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
* 格式:'字段名' => ['规则1','规则2'...]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'name' => 'require',
|
||||
'value' => 'require',
|
||||
];
|
||||
}
|
||||
45
app/common/validate/system/Jobs.php
Normal file
45
app/common/validate/system/Jobs.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\common\validate\system;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class Jobs extends Validate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
* 格式:'字段名' => ['规则1','规则2'...]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'pid' => 'notEqId',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
* 格式:'字段名.规则名' => '错误信息'
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'pid.notEqId' => '选择上级分类错误!',
|
||||
];
|
||||
|
||||
/**
|
||||
* 自定义验证规则
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $post
|
||||
* @return bool
|
||||
*/
|
||||
protected function notEqId($value, $rule, $post): bool
|
||||
{
|
||||
if ($value == $post['id']) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
31
app/common/validate/system/LoginLog.php
Normal file
31
app/common/validate/system/LoginLog.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\validate\system;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class LoginLog extends Validate
|
||||
{
|
||||
/**
|
||||
* 验证规则
|
||||
*/
|
||||
protected $rule = [
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 提示消息
|
||||
*/
|
||||
protected $message = [
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'add' => [],
|
||||
'edit' => [],
|
||||
];
|
||||
|
||||
}
|
||||
38
app/common/validate/system/UploadFile.php
Normal file
38
app/common/validate/system/UploadFile.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\common\validate\system;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class UploadFile extends Validate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
* 格式:'字段名' => ['规则1','规则2'...]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $rule = [
|
||||
'images'=>[
|
||||
'fileSize' => 419430400,
|
||||
'fileExt' => 'jpg,jpeg,png,bmp,gif,svg',
|
||||
'fileMime' => 'image/jpeg,image/png,image/gif,image/svg+xml'],
|
||||
'video'=>[
|
||||
'fileSize' => 419430400,
|
||||
'fileExt' => 'flv,swf,mkv,avi,rm,rmvb,mpeg,mpg,ogg,ogv,mov,wmv,mp4,webm,mp3,wav,mid'],
|
||||
'document'=>[
|
||||
'fileSize' => 419430400,
|
||||
'fileExt' => 'txt,doc,xls,ppt,docx,xlsx,pptx'],
|
||||
'files'=>[
|
||||
'fileSize' => 419430400,
|
||||
'fileExt' => 'exe,dll,sys,so,dmg,iso,zip,rar,7z,sql,pem,pdf,psd']
|
||||
];
|
||||
/**
|
||||
* 定义错误信息
|
||||
* 格式:'字段名.规则名' => '错误信息'
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [];
|
||||
}
|
||||
59
app/common/validate/system/User.php
Normal file
59
app/common/validate/system/User.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\validate\system;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class User extends Validate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
* 格式:'字段名' => ['规则1','规则2'...]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'test_filed' => 'max:255',
|
||||
'nickname' => 'require|min:2|max:12|filters|chsAlphaNum',
|
||||
'pwd|密码' => 'require|min:6|max:64',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
* 格式:'字段名.规则名' => '错误信息'
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'nickname.require' => '用户名不能为空',
|
||||
'nickname.min' => '用户名不能少于2个字符',
|
||||
'nickname.max' => '用户名不能超过12个字符',
|
||||
'nickname.filters' => '用户名包含禁止注册字符',
|
||||
'nickname.chsAlphaNum' => '用户名只能是汉字、字母和数字',
|
||||
'test_filed.max' => '测试场景用',
|
||||
];
|
||||
|
||||
// 测试验证场景
|
||||
protected $scene = [
|
||||
'test' => ['test_filed'],
|
||||
];
|
||||
|
||||
/**
|
||||
* 自定义验证规则
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
protected function filters($value): bool
|
||||
{
|
||||
$notAllow = saenv('user_reg_notallow');
|
||||
$notAllow = explode(',', $notAllow);
|
||||
foreach ($notAllow as $values) {
|
||||
if ($value == $values) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user