diff --git a/app/index/controller/ArticlesController.php b/app/index/controller/ArticlesController.php index 87ef4f7..d0673b3 100644 --- a/app/index/controller/ArticlesController.php +++ b/app/index/controller/ArticlesController.php @@ -32,6 +32,144 @@ use app\index\model\Resources\Resources; class ArticlesController extends BaseController { + // 获取siteinformation分类 + public function getSiteInformationCategory() + { + // 获取名为 '站点资讯' 的分类 + $siteInfoCategory = ArticlesCategory::where('name', '站点资讯') + ->where('delete_time', null) + ->where('status', 1) + ->field('id,cid,name,image,sort') + ->find(); + + if (!$siteInfoCategory) { + return json([ + 'code' => 1, + 'msg' => '未找到站点资讯分类' + ]); + } + + // 只返回其子分类,cid等于'站点资讯'的id + $children = ArticlesCategory::where('cid', $siteInfoCategory['id']) + ->where('delete_time', null) + ->where('status', 1) + ->field('id,cid,name,image,sort') + ->select() + ->toArray(); + + return json([ + 'code' => 0, + 'msg' => '获取站点资讯子分类成功', + 'data' => $children + ]); + } + + // 获取siteinformation内容,传参 + public function getSiteInformationLists() + { + try { + // 获取前端传递的分类ID + $cateid = input('cateid/d', 0); + + // 验证分类ID + if ($cateid <= 0) { + return json([ + 'code' => 1, + 'msg' => '分类ID不能为空' + ]); + } + + // 检查分类是否存在且有效 + $category = ArticlesCategory::where('id', $cateid) + ->where('delete_time', null) + ->where('status', 1) + ->find(); + + if (!$category) { + return json([ + 'code' => 1, + 'msg' => '分类不存在或已禁用' + ]); + } + + // 获取分页参数 + $page = input('page/d', 1); + $limit = input('limit/d', 10); + + // 获取该分类下的所有子分类ID(包括自身) + $subCategoryIds = [$cateid]; + + // 查找所有子分类 + $subCategories = ArticlesCategory::where('cid', $cateid) + ->where('delete_time', null) + ->where('status', 1) + ->column('id'); + + if (!empty($subCategories)) { + $subCategoryIds = array_merge($subCategoryIds, $subCategories); + } + + // 构建查询条件 + $where = [ + ['delete_time', '=', null], + ['status', '=', 2], // 已发布的文章 + ['cate', 'in', $subCategoryIds] + ]; + + // 查询文章总数 + $total = Articles::where($where)->count(); + + // 查询文章列表 + $articles = Articles::where($where) + ->field('id,title,cate,image,desc,author,content,publishdate,views,likes,is_trans,transurl,push,create_time') + ->order('sort DESC, id DESC') + ->page($page, $limit) + ->select() + ->toArray(); + + // 处理文章数据 + foreach ($articles as &$article) { + // 如果文章没有封面图,使用分类封面图 + if (empty($article['image'])) { + $article['image'] = $category['image'] ?? ''; + } + + // 格式化时间 + $article['publishdate'] = date('Y-m-d H:i:s', strtotime($article['publishdate'])); + $article['create_time'] = date('Y-m-d H:i:s', strtotime($article['create_time'])); + + // 获取分类名称 + $articleCategory = ArticlesCategory::where('id', $article['cate'])->find(); + $article['category_name'] = $articleCategory ? $articleCategory['name'] : ''; + } + + // 返回数据 + return json([ + 'code' => 0, + 'msg' => '获取成功', + 'data' => [ + 'category' => [ + 'id' => $category['id'], + 'name' => $category['name'], + 'desc' => $category['desc'], + 'image' => $category['image'] + ], + 'articles' => $articles, + 'total' => $total, + 'page' => $page, + 'limit' => $limit, + 'total_pages' => ceil($total / $limit) + ] + ]); + + } catch (\Exception $e) { + return json([ + 'code' => 1, + 'msg' => '获取失败:' . $e->getMessage() + ]); + } + } + //文章中心 public function index() { @@ -237,7 +375,7 @@ class ArticlesController extends BaseController $articleCount = Articles::where('author', $article['author'])->count(); // 统计作者的资源数 $resourceCount = Resources::where('uploader', $article['author'])->count(); - + $authorData = [ 'avatar' => $authorInfo['avatar'] ?: '/static/images/avatar.png', 'name' => $authorInfo['name'], @@ -469,7 +607,7 @@ class ArticlesController extends BaseController //获取作者信息 public function getAuthorInfo() { - if (!Request::isPost()) { + if (!Request::isPost()) { return json(['code' => 0, 'msg' => '非法请求']); } diff --git a/app/index/controller/IndexController.php b/app/index/controller/IndexController.php index 698605f..a5d34b9 100644 --- a/app/index/controller/IndexController.php +++ b/app/index/controller/IndexController.php @@ -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() + ]); + } + } + /** * 首页 */ diff --git a/app/index/model/AdminSysMenu/AdminSysMenu.php b/app/index/model/AdminSysMenu/AdminSysMenu.php new file mode 100644 index 0000000..8240985 --- /dev/null +++ b/app/index/model/AdminSysMenu/AdminSysMenu.php @@ -0,0 +1,25 @@ + +

发布文章

+

分享您的技术见解、经验总结或其他有价值的内容

+ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+
+
+
+ +
支持富文本编辑,可插入图片、链接、代码块等
+
+
+ +
+ +
+
+ +
+ 建议尺寸:800x450px,支持 JPG、PNG 格式 +
+ +
+
+
+ +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + \ No newline at end of file diff --git a/app/index/view/user/login.php b/app/index/view/user/login.php index f1f0505..9f110ed 100644 --- a/app/index/view/user/login.php +++ b/app/index/view/user/login.php @@ -216,7 +216,7 @@
-
diff --git a/app/index/view/user/profile.php b/app/index/view/user/profile.php index 56cf58b..187bab9 100644 --- a/app/index/view/user/profile.php +++ b/app/index/view/user/profile.php @@ -56,6 +56,17 @@