refactor: 完善导航相关接口

This commit is contained in:
2025-03-05 16:52:35 +08:00
parent 27d7fabdc8
commit 695bd5f5fe
6 changed files with 260 additions and 66 deletions

View File

@@ -0,0 +1,58 @@
<?php
declare (strict_types = 1);
namespace app\admin\validate\v1;
use think\Validate;
class NavigationItemValidate extends Validate
{
/**
* 定义验证规则
* 格式:'字段名' => ['规则1','规则2'...]
*
* @var array
*/
protected $rule = [
'id' => 'require|integer',
'nav_id' => 'require|integer',
'pid' => 'integer',
'name' => 'require|max:64',
'icon' => 'max:64',
'link_type' => 'require|integer',
'link' => 'max:255',
'sort' => 'integer',
'blank' => 'in:0,1',
'status' => 'require|in:1,-1',
];
/**
* 定义错误信息
* 格式:'字段名.规则名' => '错误信息'
*
* @var array
*/
protected $message = [
'id.require' => 'ID不能为空',
'id.integer' => 'ID必须为整数',
'nav_id.require' => '导航ID不能为空',
'nav_id.integer' => '导航ID必须为整数',
'pid.integer' => '父级ID必须为整数',
'name.require' => '导航名称不能为空',
'name.max' => '导航名称最多不能超过64个字符',
'icon.max' => '图标最多不能超过64个字符',
'link_type.require' => '链接类型不能为空',
'link_type.integer' => '链接类型必须为整数',
'link.max' => '链接最多不能超过255个字符',
'sort.integer' => '排序必须为整数',
'blank.in' => '是否新窗口打开只能是0或1',
'status.require' => '状态不能为空',
'status.in' => '状态只能是1或-1',
];
// 定义场景
protected $scene = [
'add' => ['nav_id', 'pid', 'name', 'icon', 'link_type', 'link', 'sort', 'blank', 'status'],
'edit' => ['id', 'nav_id', 'pid', 'name', 'icon', 'link_type', 'link', 'sort', 'blank', 'status'],
];
}