改接口匹配新前端

This commit is contained in:
2025-12-24 17:41:33 +08:00
parent 5691a3f677
commit 2161113eae
18 changed files with 1134 additions and 96 deletions
+45
View File
@@ -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()
]);
}
}
/**
* 首页
*/