mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 优化菜单功能
This commit is contained in:
parent
962c6b306c
commit
cbdfab5f52
@ -20,9 +20,16 @@ class Menu extends Base {
|
|||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
public function index() {
|
public function index() {
|
||||||
$origin = (new AdminMenu)->order('sort', 'ASC')->select();
|
$keywords = $this->request->get('keywords', '');
|
||||||
$origin = Tools::buildArrFromObj($origin);
|
$obj = new AdminMenu();
|
||||||
$list = Tools::listToTree($origin);
|
if ($keywords) {
|
||||||
|
$obj = $obj->whereLike('title', "%{$keywords}%");
|
||||||
|
}
|
||||||
|
$obj = $obj->order('sort', 'ASC')->select();
|
||||||
|
$list = Tools::buildArrFromObj($obj);
|
||||||
|
if (!$keywords) {
|
||||||
|
$list = Tools::listToTree($list);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->buildSuccess([
|
return $this->buildSuccess([
|
||||||
'list' => $list
|
'list' => $list
|
||||||
@ -87,6 +94,7 @@ class Menu extends Base {
|
|||||||
/**
|
/**
|
||||||
* 删除菜单
|
* 删除菜单
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws \Exception
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
public function del() {
|
public function del() {
|
||||||
@ -94,11 +102,7 @@ class Menu extends Base {
|
|||||||
if (!$id) {
|
if (!$id) {
|
||||||
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数');
|
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数');
|
||||||
}
|
}
|
||||||
$childNum = AdminMenu::where(['fid' => $id])->count();
|
(new AdminMenu())->whereIn('id', $id)->delete();
|
||||||
if ($childNum) {
|
|
||||||
return $this->buildFailed(ReturnCode::INVALID, '当前菜单存在子菜单,不可以被删除!');
|
|
||||||
}
|
|
||||||
AdminMenu::destroy($id);
|
|
||||||
|
|
||||||
return $this->buildSuccess();
|
return $this->buildSuccess();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user