diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index f14491f..9b14212 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -11,76 +11,102 @@ use think\facade\Config; class Index extends Base { - // 首页 + /** + * 首页 + */ public function index() { - // 获取文章列表 - $articles = Db::table('yz_article') - ->where('delete_time', null) - ->where('status', '<>', 3) - ->order('id DESC') - ->select() - ->toArray(); - - $articleList = []; - foreach ($articles as $article) { - $cate = $article['cate']; - // 获取分类信息 - $cateInfo = Db::table('yz_article_category') - ->where('id', $cate) - ->where('delete_time', null) - ->where('status', 1) - ->field('name, image') - ->find(); - - if ($cateInfo) { // 只添加有效的分类 - // 如果文章没有图片,使用分类的图片 - if (empty($article['image']) && !empty($cateInfo['image'])) { - $article['image'] = $cateInfo['image']; - } - - // 转换发布日期格式为Y-m-d - $article['publishdate'] = date('Y-m-d', $article['publishdate']); - - if (!isset($articleList[$cateInfo['name']])) { - $articleList[$cateInfo['name']] = []; - } - $articleList[$cateInfo['name']][] = $article; - } - } - - // 调试信息 - trace('Articles: ' . json_encode($articles, JSON_UNESCAPED_UNICODE)); - trace('ArticleList: ' . json_encode($articleList, JSON_UNESCAPED_UNICODE)); - - // 将变量传递给视图 - View::assign([ - 'articleList' => $articleList, - ]); - return view('index'); - } - - // 文章列表 - public function articlelist() - { - $articles = Db::table('yz_article') - ->where('delete_time', null) - ->where('status', 1) - ->order('id DESC') - ->select() - ->toArray(); - - $articleList = []; - foreach ($articles as $article) { - $cate = $article['cate']; - $cateName = Db::table('yz_article_category')->where('id', $cate)->value('name'); - if (!isset($articleList[$cateName])) { - $articleList[$cateName] = []; - } - $articleList[$cateName][] = $article; - } - - View::assign('articleList', $articleList); return View::fetch(); } + + /** + * 获取站点资讯列表 + */ + public function siteNewslist() + { + // 获取站点资讯分类(顶级分类id为1的子分类) + $categories = Db::name('yz_article_category') + ->where('cid', 1) + ->where('delete_time', null) + ->select() + ->toArray(); + + $articles = []; + $categoryData = []; + + // 提取分类名称和ID用于前端tab显示 + foreach ($categories as $category) { + $categoryData[] = [ + 'id' => $category['id'], + 'name' => $category['name'] + ]; + + // 获取该分类下的文章 + $articles = Db::name('yz_article') + ->where('cate', $category['id']) + ->where('delete_time', null) + ->where('status', 2) + ->order('id', 'desc') + ->field('id, cate, title, image, author, publishdate, views') + ->select() + ->toArray(); + + } + + return json([ + 'code' => 1, + 'msg' => '获取成功', + 'articles' => $articles, + 'categories' => $categoryData + ]); + } + + /** + * 获取技术文章列表 + */ + public function technicalArticleslist() + { + // 获取技术文章分类(顶级分类id为3的子分类) + $categories = Db::name('yz_article_category') + ->where('cid', 3) + ->where('delete_time', null) + ->select() + ->toArray(); + + // 组装分类数据,方便后续查找 + $categoryData = []; + $categoryImageMap = []; + foreach ($categories as $category) { + $categoryData[] = [ + 'id' => $category['id'], + 'name' => $category['name'] + ]; + $categoryImageMap[$category['id']] = $category['image'] ?? ''; + } + + // 获取所有技术分类下的文章 + $technicalarticles = Db::name('yz_article') + ->whereIn('cate', array_column($categories, 'id')) + ->where('delete_time', null) + ->where('status', 2) + ->order('id', 'desc') + ->field('id, cate, title, image, author, publishdate, views') + ->select() + ->toArray(); + + // 替换image为空的文章 + foreach ($technicalarticles as &$article) { + if (empty($article['image']) && !empty($categoryImageMap[$article['cate']])) { + $article['image'] = $categoryImageMap[$article['cate']]; + } + } + unset($article); + + return json([ + 'code' => 1, + 'msg' => '获取成功', + 'articles' => $technicalarticles, + 'categories' => $categoryData + ]); + } } diff --git a/app/index/view/component/main.php b/app/index/view/component/main.php index 11bb693..b78c4bd 100644 --- a/app/index/view/component/main.php +++ b/app/index/view/component/main.php @@ -1,75 +1,28 @@
- +
-

站点新闻

-
新鲜资讯 尽在掌握
+

站点资讯

+
+
+
全部
+ +
+
更多
-
-
-
-
-
闪客 · 怎么理解 AI?
-
闪客 | B 站知名科普 UP 主
-
-
-
1025人学过
- -
-
-
-
-
-
-
多模态对话引擎实战
-
吴桐 | 网易云信音视频技术负责人,流媒体首席架构师
-
-
-
380人学过
- -
-
-
-
-
-
极客视点
-
极客时间 | 编辑部
-
-
-
12.4w人学过
- -
-
-
-
-
-
周志明的软件架构课
-
周志明 | 博士,远光软件研究院院长,《深入理解Java虚拟机》《凤凰架构》等书作者
-
-
-
6.0w人学过
- -
-
+
+
- -
+ +
@@ -77,96 +30,204 @@
全部
- {foreach $articleList as $cateName => $articles} -
{$cateName}
- {/foreach} +
更多
-
- -
- {foreach $articleList as $cateName => $articles} - {foreach $articles as $article} -
-
- -
-
-
{$article.title}
-
{$article.publishdate}
-
-
-
{$article.views}
-
{$article.author}
-
-
- {/foreach} - {/foreach} -
- - - {foreach $articleList as $cateName => $articles} -
- {foreach $articles as $article} -
-
- -
-
-
{$article.title}
-
{$article.publishdate}
-
-
-
{$article.views}
-
{$article.author}
-
-
- {/foreach} -
- {/foreach} +
+
- \ No newline at end of file diff --git a/public/storage/uploads/20250511/04b0287390835253f890d7e7191eb872.png b/public/storage/uploads/20250511/04b0287390835253f890d7e7191eb872.png new file mode 100644 index 0000000..b09b7b4 Binary files /dev/null and b/public/storage/uploads/20250511/04b0287390835253f890d7e7191eb872.png differ diff --git a/public/storage/uploads/20250511/0ea7ab5f01fd610b089ed34d39fcd126.png b/public/storage/uploads/20250511/0ea7ab5f01fd610b089ed34d39fcd126.png new file mode 100644 index 0000000..e3cb685 Binary files /dev/null and b/public/storage/uploads/20250511/0ea7ab5f01fd610b089ed34d39fcd126.png differ diff --git a/public/storage/uploads/20250511/4611f23cb173660cbb629aa3b92d531a.webp b/public/storage/uploads/20250511/4611f23cb173660cbb629aa3b92d531a.webp new file mode 100644 index 0000000..a806b73 Binary files /dev/null and b/public/storage/uploads/20250511/4611f23cb173660cbb629aa3b92d531a.webp differ diff --git a/public/storage/uploads/20250511/51ad89d2dd317f867112f28371c47964.png b/public/storage/uploads/20250511/51ad89d2dd317f867112f28371c47964.png new file mode 100644 index 0000000..33c83a1 Binary files /dev/null and b/public/storage/uploads/20250511/51ad89d2dd317f867112f28371c47964.png differ diff --git a/public/storage/uploads/20250511/8186f389b42072ceb13d45651218c2d6.png b/public/storage/uploads/20250511/8186f389b42072ceb13d45651218c2d6.png new file mode 100644 index 0000000..42c2ca0 Binary files /dev/null and b/public/storage/uploads/20250511/8186f389b42072ceb13d45651218c2d6.png differ diff --git a/public/storage/uploads/20250511/ac6b02372b993cad5a5259f00f54d7ac.jpg b/public/storage/uploads/20250511/ac6b02372b993cad5a5259f00f54d7ac.jpg new file mode 100644 index 0000000..1620c8c Binary files /dev/null and b/public/storage/uploads/20250511/ac6b02372b993cad5a5259f00f54d7ac.jpg differ diff --git a/public/storage/uploads/20250511/c9914d6b4676239a8e9197e5a5ca9f04.jpg b/public/storage/uploads/20250511/c9914d6b4676239a8e9197e5a5ca9f04.jpg new file mode 100644 index 0000000..ad7a821 Binary files /dev/null and b/public/storage/uploads/20250511/c9914d6b4676239a8e9197e5a5ca9f04.jpg differ diff --git a/public/storage/uploads/20250511/cc147a1b3ed867857752c3dcd8b1052a.jpg b/public/storage/uploads/20250511/cc147a1b3ed867857752c3dcd8b1052a.jpg new file mode 100644 index 0000000..971c1f0 Binary files /dev/null and b/public/storage/uploads/20250511/cc147a1b3ed867857752c3dcd8b1052a.jpg differ diff --git a/public/storage/uploads/20250511/d99c29549f9116959686d0f72f75a845.jpg b/public/storage/uploads/20250511/d99c29549f9116959686d0f72f75a845.jpg new file mode 100644 index 0000000..fd2a062 Binary files /dev/null and b/public/storage/uploads/20250511/d99c29549f9116959686d0f72f75a845.jpg differ diff --git a/public/storage/uploads/20250511/ec1016e940b10a89f44450a7e8968573.png b/public/storage/uploads/20250511/ec1016e940b10a89f44450a7e8968573.png new file mode 100644 index 0000000..146e326 Binary files /dev/null and b/public/storage/uploads/20250511/ec1016e940b10a89f44450a7e8968573.png differ diff --git a/runtime/admin/temp/533c54f343e8a61c5a95c12da17f30ac.php b/runtime/admin/temp/533c54f343e8a61c5a95c12da17f30ac.php index 120df42..1a3b501 100644 --- a/runtime/admin/temp/533c54f343e8a61c5a95c12da17f30ac.php +++ b/runtime/admin/temp/533c54f343e8a61c5a95c12da17f30ac.php @@ -1,4 +1,4 @@ - + @@ -6,7 +6,7 @@ - + - + + + + + + + @@ -174,76 +177,29 @@ layui.use(['carousel', 'form'], function(){
- +
-

站点新闻

-
新鲜资讯 尽在掌握
+

站点资讯

+
+
+
全部
+ +
+
更多
-
-
-
-
-
闪客 · 怎么理解 AI?
-
闪客 | B 站知名科普 UP 主
-
-
-
1025人学过
- -
-
-
-
-
-
-
多模态对话引擎实战
-
吴桐 | 网易云信音视频技术负责人,流媒体首席架构师
-
-
-
380人学过
- -
-
-
-
-
-
极客视点
-
极客时间 | 编辑部
-
-
-
12.4w人学过
- -
-
-
-
-
-
周志明的软件架构课
-
周志明 | 博士,远光软件研究院院长,《深入理解Java虚拟机》《凤凰架构》等书作者
-
-
-
6.0w人学过
- -
-
+
+
- -
+ +
@@ -251,93 +207,206 @@ layui.use(['carousel', 'form'], function(){
全部
- $articles): ?> -
- +
更多
-
- -
- $articles): foreach($articles as $article): ?> -
-
- -
-
-
-
-
-
-
-
-
- - -
- - - $articles): ?> -
- -
-
- -
-
-
-
-
-
-
-
-
- -
- +
+
-