|
...
|
...
|
@@ -4,6 +4,8 @@ namespace App\Http\Controllers\Bside; |
|
|
|
|
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Http\Logic\Bside\Nav\NavLogic;
|
|
|
|
use App\Http\Requests\Bside\Nav\NavRequest;
|
|
|
|
use App\Models\BNav;
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -16,42 +18,6 @@ use App\Models\BNav; |
|
|
|
class NavController extends BaseController
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 验证规则
|
|
|
|
* @var array[]
|
|
|
|
*/
|
|
|
|
private $verify = [
|
|
|
|
'role' => [
|
|
|
|
'pid' => ['required','integer','gte:0'],
|
|
|
|
'name' => ['required','max:100'],
|
|
|
|
'location' => ['required','in:header,footer'],
|
|
|
|
'url' => ['required','max:200'],
|
|
|
|
'status' => ['required','in:0,1'],
|
|
|
|
'target' => ['required','in:0,1'],
|
|
|
|
'sort' => ['required','integer','gte:0']
|
|
|
|
],
|
|
|
|
'message' => [
|
|
|
|
'pid.required' => '上级选择错误',
|
|
|
|
'pid.gte' => '上级选择错误',
|
|
|
|
'pid.integer' => '上级选择错误',
|
|
|
|
'name.required' => '名称必须',
|
|
|
|
'name.max' => '名称不能超过100个字符',
|
|
|
|
'location.required' => '位置选择错误',
|
|
|
|
'location.in' => '位置选择错误',
|
|
|
|
'url.required' => '链接必须',
|
|
|
|
'url.max' => '链接不能超过200个字符',
|
|
|
|
'status.required' => '状态选择错误',
|
|
|
|
'status.in' => '状态必须是显示/隐藏',
|
|
|
|
'target.required' => '打开方式必须',
|
|
|
|
'target.in' => '打开方式选择错误',
|
|
|
|
'sort.required' => '排序必须',
|
|
|
|
'sort.integer' => '排序必须是一个数字',
|
|
|
|
'sort.gte' => '排序必须大于等于0',
|
|
|
|
],
|
|
|
|
'attr' => [
|
|
|
|
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 列表数据
|
|
...
|
...
|
@@ -62,46 +28,13 @@ class NavController extends BaseController |
|
|
|
*/
|
|
|
|
public function index(){
|
|
|
|
|
|
|
|
$isTree = $this->param['tree']??false;
|
|
|
|
// 显示位置
|
|
|
|
$location = $this->param['location']??'';
|
|
|
|
|
|
|
|
$lists = BNav::_all($this->user['project_id'],$location)->toArray();
|
|
|
|
|
|
|
|
if($isTree){
|
|
|
|
$lists = list_to_tree($lists);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->success($lists);
|
|
|
|
return $this->success(NavLogic::instance()->list());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 创建导航栏
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/8 16:39
|
|
|
|
*/
|
|
|
|
public function create(){
|
|
|
|
return $this->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 修改
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
* @throws \Illuminate\Validation\ValidationException
|
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/8 17:06
|
|
|
|
*/
|
|
|
|
public function update(){
|
|
|
|
$this->verify['role']['id'] = ['required','integer','gt:0'];
|
|
|
|
$this->verify['message']['id.gt'] = $this->verify['message']['id.integer'] = $this->verify['message']['id.required'] = '编辑导航数据不存在';
|
|
|
|
return $this->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 新增修改
|
|
...
|
...
|
@@ -112,33 +45,11 @@ class NavController extends BaseController |
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/8 17:06
|
|
|
|
*/
|
|
|
|
private function save(){
|
|
|
|
$data = $this->validate(request() ,$this->verify['role'],$this->verify['message']);
|
|
|
|
|
|
|
|
if($data['pid']){
|
|
|
|
// 验证是否存在上级
|
|
|
|
$all = BNav::_all($this->user['project_id'],$data['location']);
|
|
|
|
if(!$all->where('id',$data['pid'])->count()){
|
|
|
|
return $this->response('上级栏目不存在',Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
// 上级不允许是自己的下级
|
|
|
|
if(!empty($data['id'])){
|
|
|
|
$all = list_to_tree($all->toArray(),$data['id']);
|
|
|
|
$all = tree_to_list($all);
|
|
|
|
if(in_array($data['pid'],array_column($all,'id'))){
|
|
|
|
return $this->response('上级栏目不允许为本身的下级',Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 保存
|
|
|
|
$id = BNav::_save($this->user['project_id'],$data,$data['id']??0);
|
|
|
|
|
|
|
|
if($id===-1){
|
|
|
|
return $this->response('导航菜单不存在',Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->success(BNav::_find($this->user['project_id'],$id,true));
|
|
|
|
public function save(NavRequest $request){
|
|
|
|
$data = $request->validated();
|
|
|
|
|
|
|
|
return $this->success(NavLogic::instance()->save($data));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
...
|
...
|
@@ -148,23 +59,14 @@ class NavController extends BaseController |
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/9 9:20
|
|
|
|
*/
|
|
|
|
public function delete(){
|
|
|
|
$id = $this->param['id']??0;
|
|
|
|
$data = BNav::_find($this->user['project_id'],$id);
|
|
|
|
|
|
|
|
if(empty($data)){
|
|
|
|
return $this->response('导航菜单不存在',Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
public function delete(NavRequest $request){
|
|
|
|
|
|
|
|
|
|
|
|
if(BNav::isChild($data['id'],$this->user['project_id'])){
|
|
|
|
return $this->response('存在下级无法删除',Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
$id = $request->validated()['id'];
|
|
|
|
|
|
|
|
NavLogic::instance()->delete($id);
|
|
|
|
|
|
|
|
if($data->delete()){
|
|
|
|
return $this->response('删除成功',Code::SUCCESS);
|
|
|
|
}
|
|
|
|
return $this->response('删除成功');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|