作者 lyh

gx

... ... @@ -21,11 +21,11 @@ class NavController extends BaseController
/**
* 列表数据
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author:dc
* @time 2023/5/8 16:37
* @remark :获取列表数据
* @name :index
* @author :lyh
* @method :post
* @time :2023/12/4 15:00
*/
public function index(BNav $nav){
$this->map['project_id'] = $this->user['project_id'];
... ... @@ -42,6 +42,24 @@ class NavController extends BaseController
}
/**
* @remark :获取当前id下的所有子集
* @name :getSubList
* @author :lyh
* @method :post
* @time :2023/12/4 15:04
*/
public function getSubList(NavLogic $logic){
$this->request->validate([
'id'=>'required',
],[
'id.required' => '产品ID不能为空',
]);
$data = $logic->getSubList();
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :保存数据
* @name :save
... ...
... ... @@ -26,6 +26,49 @@ class NavLogic extends BaseLogic
$this->model = new BNav();
}
/**
* @remark :获取当前id下所有子集
* @name :getSubList
* @author :lyh
* @method :post
* @time :2023/12/4 15:11
*/
public function getSubList(){
$str = [];
//排序掉当前id下所有子集
$str = $this->getAllSub($this->param['id'],$str);
$str[] = $this->param['id'];
$this->param['id'] = ['not in',$str];
$this->param['project_id'] = $this->user['project_id'];
$list = $this->model->list($this->param);
$data = array();
foreach ($list as $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $list);
$data[] = $v;
}
}
return $this->success($data);
}
/**
* @remark :获取当前id下所有子集
* @name :getAllSub
* @author :lyh
* @method :post
* @time :2023/10/18 15:10
*/
public function getAllSub($id,&$str = []){
$list = $this->model->list(['pid'=>$id,'status'=>1],['id','pid']);
if(!empty($list)){
foreach ($list as $v){
$str[] = $v['id'];
$this->getAllSub($v['id'],$str);
}
}
return $str;
}
/**
* @remark :保存数据
... ... @@ -71,10 +114,10 @@ class NavLogic extends BaseLogic
if($this->param['pid'] == $info['id']){
$this->fail('不允许成为自己的上级');
}
$pid_info = $this->model->read(['pid'=>$this->param['id']]);
if(($pid_info !== false) && $this->param['pid'] != $info['pid']){
$this->fail('当前菜单拥有子集不允许修改上级');
}
// $pid_info = $this->model->read(['pid'=>$this->param['id']]);
// if(($pid_info !== false) && $this->param['pid'] != $info['pid']){
// $this->fail('当前菜单拥有子集不允许修改上级');
// }
return $this->success();
}
... ...
... ... @@ -363,6 +363,7 @@ Route::middleware(['bloginauth'])->group(function () {
// 导航栏编辑
Route::prefix('nav')->group(function () {
Route::get('/', [\App\Http\Controllers\Bside\Nav\NavController::class, 'index'])->name('nav');
Route::any('/get', [\App\Http\Controllers\Bside\Nav\NavController::class, 'getSubList'])->name('nav_getSubList');
Route::post('/create', [\App\Http\Controllers\Bside\Nav\NavController::class, 'save'])->name('nav_create');
Route::post('/update', [\App\Http\Controllers\Bside\Nav\NavController::class, 'save'])->name('nav_update');
Route::delete('/delete', [\App\Http\Controllers\Bside\Nav\NavController::class, 'delete'])->name('nav_delete');
... ...