改接口匹配新前端
This commit is contained in:
@@ -25,6 +25,7 @@ use think\facade\Db;
|
||||
use think\facade\View;
|
||||
use think\facade\Env;
|
||||
use think\facade\Config;
|
||||
use app\index\model\MenuFront\MenuFront;
|
||||
use app\index\model\Banner;
|
||||
use app\index\model\Resources\ResourcesCategory;
|
||||
use app\index\model\Articles\ArticlesCategory;
|
||||
@@ -37,6 +38,50 @@ use app\index\model\Attachments;
|
||||
|
||||
class IndexController extends BaseController
|
||||
{
|
||||
//获取主体菜单
|
||||
/**
|
||||
* 获取主菜单列表
|
||||
* @return \think\Response|\think\response\Json
|
||||
*/
|
||||
public function getmainmenu()
|
||||
{
|
||||
try {
|
||||
// 查询所有未删除且启用的一级菜单,只筛选所需字段
|
||||
$menuList = MenuFront::where('status', 1)
|
||||
->where('view', 1)
|
||||
->where('parent_id', 0)
|
||||
->whereNull('delete_time')
|
||||
->order('sort desc,id asc')
|
||||
->field('id,parent_id,title,path,url,icon,sort')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 递归查询每个一级菜单的子菜单,只筛选所需字段
|
||||
foreach ($menuList as &$menu) {
|
||||
$children = MenuFront::where('status', 1)
|
||||
->where('view', 1)
|
||||
->where('parent_id', $menu['id'])
|
||||
->whereNull('delete_time')
|
||||
->order('sort desc,id asc')
|
||||
->field('id,parent_id,title,path,url,icon,sort')
|
||||
->select()
|
||||
->toArray();
|
||||
$menu['children'] = $children;
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '获取主菜单成功',
|
||||
'data' => $menuList
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => 1,
|
||||
'msg' => '获取主菜单失败: ' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user