You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
226 lines
8.7 KiB
226 lines
8.7 KiB
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\api\model;
|
|
|
|
use think\Model;
|
|
|
|
/**
|
|
* @mixin think\Model
|
|
*/
|
|
class Menu extends Common
|
|
{
|
|
|
|
public $table = 'system_auth_rule';
|
|
|
|
|
|
/**
|
|
* 列表数据模型
|
|
* @return array|\think\Collection
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function index()
|
|
{
|
|
$_op = config('app.app_debug') ?: $_op = $this->where('is_dev', 0); //开发者模式
|
|
return parent::parentLists($_op, 0);
|
|
}
|
|
|
|
/**
|
|
* 新增或修改前
|
|
* @param Model $model
|
|
* @return mixed|void
|
|
*/
|
|
public static function onBeforeWrite(Model $model)
|
|
{
|
|
//设定child_list
|
|
if (empty($model->getAttr('parent_id'))) {
|
|
//parent_id = 0 一级栏目填充
|
|
$child_list = self::where('parent_id', 0)->max('child_list');
|
|
$child_list = !empty($child_list) ? (int)$child_list + 1 : 100; //如果不存在设置默认值 100起始
|
|
$model->setAttr('child_list', $child_list);
|
|
} else {
|
|
//子栏目填充
|
|
$child_list = self::where('parent_id', $model->getAttr('parent_id'))->max('child_list'); //同级最大
|
|
$parent_child_list = self::where('id', $model->getAttr('parent_id'))->value('child_list'); //父级初始
|
|
$child_list = !empty($child_list) ? (int)$child_list + 1 : $parent_child_list . '100';
|
|
$model->setAttr('child_list', $child_list);
|
|
}
|
|
parent::onBeforeWrite($model);
|
|
}
|
|
|
|
|
|
public static function onAfterDelete(Model $model)
|
|
{
|
|
//删除父级栏目下所有子栏目
|
|
if ($model->getAttr('child_list')) {
|
|
self::where('child_list', 'like', $model->getAttr('child_list') . '%')->useSoftDelete('delete_time', time())->delete();
|
|
}
|
|
parent::onAfterDelete($model);
|
|
}
|
|
|
|
/**
|
|
* swagger response返回数据引用
|
|
* @OA\Schema(
|
|
* schema="MenuMsgExport",
|
|
* required={"code","msg","count","data"},
|
|
* @OA\Property(
|
|
* property="code",
|
|
* type="integer",
|
|
* format="int32",
|
|
* description="状态码"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="msg",
|
|
* type="string",
|
|
* description="提示消息"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="count",
|
|
* type="integer",
|
|
* format="int32",
|
|
* description="记录总数",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="data",
|
|
* type="array",
|
|
* description="请求结果",
|
|
* @OA\Items(
|
|
* @OA\Property(
|
|
* property="id",
|
|
* type="integer",
|
|
* description="菜单ID"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="site_id",
|
|
* type="integer",
|
|
* description="站点ID"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="name",
|
|
* type="string",
|
|
* description="菜单名称",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="parent_id",
|
|
* type="integer",
|
|
* description="父级ID",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="model_name",
|
|
* type="string",
|
|
* description="模块名/控制器/方法"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="path",
|
|
* type="string",
|
|
* description="对应前台的模板的路由地址"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="component",
|
|
* type="string",
|
|
* description="前台对应的组件路径",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="authority",
|
|
* type="string",
|
|
* description="按钮权限标识",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="icon",
|
|
* type="string",
|
|
* description="菜单图标",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="color",
|
|
* type="string",
|
|
* description="icon颜色",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="target",
|
|
* type="string",
|
|
* description="是否新窗口 _target/_self",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="iframe",
|
|
* type="integer",
|
|
* description="是否为 iframe模式 0:不是 1:是",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="hide",
|
|
* type="integer",
|
|
* description="是否显示 0:显示 1:隐藏",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="type",
|
|
* type="integer",
|
|
* description="在think_auth_rule 表中定义一条规则时,如果type为1, condition字段就可以定义规则表达式。 如定义{score}>5 and {score}<100 表示用户的分数在5-100之间时这条规则才会通过。",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="sort",
|
|
* type="integer",
|
|
* description="排序",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="menu_type",
|
|
* type="integer",
|
|
* description="菜单类型 0:菜单 1:按钮",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="open_type",
|
|
* type="integer",
|
|
* description="打开方式 0:组件 1:内链 2:外链",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="is_dev",
|
|
* type="integer",
|
|
* description="1:开发者模式(即tp调试模式开启)",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="status",
|
|
* type="integer",
|
|
* description="状态:为1正常,为0禁用",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="condition",
|
|
* type="string",
|
|
* description="规则表达式,为空表示存在就验证,不为空表示按照条件验证",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="remarks",
|
|
* type="string",
|
|
* description="备注",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="child_list",
|
|
* type="string",
|
|
* description="100100 子集菜单集合",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="children",
|
|
* type="object",
|
|
* description="子集菜单对象",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="delete_time",
|
|
* type="integer",
|
|
* description="是否删除 null:未删除"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="update_time",
|
|
* type="integer",
|
|
* description="更新时间"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="create_time",
|
|
* type="integer",
|
|
* description="创建时间"
|
|
* ),
|
|
* )
|
|
* ),
|
|
*
|
|
* ),
|
|
*/
|
|
|
|
}
|
|
|