更新数据
This commit is contained in:
parent
f55b0068a2
commit
754db2cfee
@ -41,13 +41,14 @@ class Index extends Base
|
||||
'name' => $category['name']
|
||||
];
|
||||
|
||||
// 获取该分类下的文章
|
||||
// 获取该分类下的文章,限制4条
|
||||
$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')
|
||||
->limit(4)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
@ -76,36 +77,41 @@ class Index extends Base
|
||||
// 组装分类数据,方便后续查找
|
||||
$categoryData = [];
|
||||
$categoryImageMap = [];
|
||||
$articlesByCategory = [];
|
||||
|
||||
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();
|
||||
// 获取每个分类下的文章,限制12条
|
||||
$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')
|
||||
->limit(12)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 替换image为空的文章
|
||||
foreach ($technicalarticles as &$article) {
|
||||
if (empty($article['image']) && !empty($categoryImageMap[$article['cate']])) {
|
||||
$article['image'] = $categoryImageMap[$article['cate']];
|
||||
// 替换image为空的文章
|
||||
foreach ($articles as &$article) {
|
||||
if (empty($article['image']) && !empty($categoryImageMap[$article['cate']])) {
|
||||
$article['image'] = $categoryImageMap[$article['cate']];
|
||||
}
|
||||
}
|
||||
unset($article);
|
||||
|
||||
$articlesByCategory[$category['id']] = $articles;
|
||||
}
|
||||
unset($article);
|
||||
|
||||
return json([
|
||||
'code' => 1,
|
||||
'msg' => '获取成功',
|
||||
'articles' => $technicalarticles,
|
||||
'articles' => $articlesByCategory,
|
||||
'categories' => $categoryData
|
||||
]);
|
||||
}
|
||||
|
||||
@ -58,7 +58,8 @@
|
||||
}
|
||||
// 渲染文章列表
|
||||
if (result.articles && result.articles.length > 0) {
|
||||
renderWebArticles(result.articles, 'webArticlesList');
|
||||
// 只取最新的4条
|
||||
renderWebArticles(result.articles.slice(0, 4), 'webArticlesList');
|
||||
} else {
|
||||
showNoData('webArticlesList');
|
||||
}
|
||||
@ -83,8 +84,17 @@
|
||||
renderCategoryTabs(result.categories, 'techArticles');
|
||||
}
|
||||
// 渲染文章列表
|
||||
if (result.articles && result.articles.length > 0) {
|
||||
renderWebArticles(result.articles, 'techArticlesList');
|
||||
if (result.articles && Object.keys(result.articles).length > 0) {
|
||||
// 合并所有分类的文章
|
||||
let allArticles = [];
|
||||
Object.values(result.articles).forEach(arr => {
|
||||
allArticles = allArticles.concat(arr);
|
||||
});
|
||||
// 按发布时间排序(降序)
|
||||
allArticles.sort((a, b) => b.publishdate - a.publishdate);
|
||||
// 只取最新的12条
|
||||
allArticles = allArticles.slice(0, 12);
|
||||
renderWebArticles(allArticles, 'techArticlesList');
|
||||
} else {
|
||||
showNoData('techArticlesList');
|
||||
}
|
||||
@ -163,13 +173,36 @@
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.code === 1) {
|
||||
if (categoryId === 'all') {
|
||||
// 显示所有文章
|
||||
renderWebArticles(result.articles, containerId);
|
||||
if (containerId === 'techArticlesList') {
|
||||
if (categoryId === 'all') {
|
||||
// 合并所有分类的文章
|
||||
let allArticles = [];
|
||||
if (typeof result.articles === 'object') {
|
||||
Object.values(result.articles).forEach(arr => {
|
||||
allArticles = allArticles.concat(arr);
|
||||
});
|
||||
}
|
||||
// 按发布时间排序(降序)
|
||||
allArticles.sort((a, b) => b.publishdate - a.publishdate);
|
||||
// 只取最新的12条
|
||||
allArticles = allArticles.slice(0, 12);
|
||||
renderWebArticles(allArticles, containerId);
|
||||
} else {
|
||||
// 只显示选中分类的文章
|
||||
let filteredArticles = [];
|
||||
if (typeof result.articles === 'object' && result.articles[categoryId]) {
|
||||
filteredArticles = result.articles[categoryId];
|
||||
}
|
||||
renderWebArticles(filteredArticles, containerId);
|
||||
}
|
||||
} else {
|
||||
// 过滤显示选中分类的文章
|
||||
const filteredArticles = result.articles.filter(article => article.cate == categoryId);
|
||||
renderWebArticles(filteredArticles, containerId);
|
||||
// 站点资讯部分逻辑不变
|
||||
if (categoryId === 'all') {
|
||||
renderWebArticles(result.articles.slice(0, 4), containerId);
|
||||
} else {
|
||||
const filteredArticles = result.articles.filter(article => article.cate == categoryId);
|
||||
renderWebArticles(filteredArticles, containerId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
showNoData(containerId);
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 8.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
@ -1,4 +1,4 @@
|
||||
<?php /*a:4:{s:49:"E:\Demo\PHP\yunzer\app\index\view\index\index.php";i:1746890051;s:54:"E:\Demo\PHP\yunzer\app\index\view\component\header.php";i:1746796639;s:52:"E:\Demo\PHP\yunzer\app\index\view\component\main.php";i:1746985804;s:54:"E:\Demo\PHP\yunzer\app\index\view\component\footer.php";i:1746796639;}*/ ?>
|
||||
<?php /*a:4:{s:49:"E:\Demo\PHP\yunzer\app\index\view\index\index.php";i:1746890051;s:54:"E:\Demo\PHP\yunzer\app\index\view\component\header.php";i:1746796639;s:52:"E:\Demo\PHP\yunzer\app\index\view\component\main.php";i:1746986804;s:54:"E:\Demo\PHP\yunzer\app\index\view\component\footer.php";i:1746796639;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
@ -235,7 +235,8 @@ layui.use(['carousel', 'form'], function(){
|
||||
}
|
||||
// 渲染文章列表
|
||||
if (result.articles && result.articles.length > 0) {
|
||||
renderWebArticles(result.articles, 'webArticlesList');
|
||||
// 只取最新的4条
|
||||
renderWebArticles(result.articles.slice(0, 4), 'webArticlesList');
|
||||
} else {
|
||||
showNoData('webArticlesList');
|
||||
}
|
||||
@ -260,8 +261,17 @@ layui.use(['carousel', 'form'], function(){
|
||||
renderCategoryTabs(result.categories, 'techArticles');
|
||||
}
|
||||
// 渲染文章列表
|
||||
if (result.articles && result.articles.length > 0) {
|
||||
renderWebArticles(result.articles, 'techArticlesList');
|
||||
if (result.articles && Object.keys(result.articles).length > 0) {
|
||||
// 合并所有分类的文章
|
||||
let allArticles = [];
|
||||
Object.values(result.articles).forEach(arr => {
|
||||
allArticles = allArticles.concat(arr);
|
||||
});
|
||||
// 按发布时间排序(降序)
|
||||
allArticles.sort((a, b) => b.publishdate - a.publishdate);
|
||||
// 只取最新的12条
|
||||
allArticles = allArticles.slice(0, 12);
|
||||
renderWebArticles(allArticles, 'techArticlesList');
|
||||
} else {
|
||||
showNoData('techArticlesList');
|
||||
}
|
||||
@ -340,13 +350,36 @@ layui.use(['carousel', 'form'], function(){
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.code === 1) {
|
||||
if (categoryId === 'all') {
|
||||
// 显示所有文章
|
||||
renderWebArticles(result.articles, containerId);
|
||||
if (containerId === 'techArticlesList') {
|
||||
if (categoryId === 'all') {
|
||||
// 合并所有分类的文章
|
||||
let allArticles = [];
|
||||
if (typeof result.articles === 'object') {
|
||||
Object.values(result.articles).forEach(arr => {
|
||||
allArticles = allArticles.concat(arr);
|
||||
});
|
||||
}
|
||||
// 按发布时间排序(降序)
|
||||
allArticles.sort((a, b) => b.publishdate - a.publishdate);
|
||||
// 只取最新的12条
|
||||
allArticles = allArticles.slice(0, 12);
|
||||
renderWebArticles(allArticles, containerId);
|
||||
} else {
|
||||
// 只显示选中分类的文章
|
||||
let filteredArticles = [];
|
||||
if (typeof result.articles === 'object' && result.articles[categoryId]) {
|
||||
filteredArticles = result.articles[categoryId];
|
||||
}
|
||||
renderWebArticles(filteredArticles, containerId);
|
||||
}
|
||||
} else {
|
||||
// 过滤显示选中分类的文章
|
||||
const filteredArticles = result.articles.filter(article => article.cate == categoryId);
|
||||
renderWebArticles(filteredArticles, containerId);
|
||||
// 站点资讯部分逻辑不变
|
||||
if (categoryId === 'all') {
|
||||
renderWebArticles(result.articles.slice(0, 4), containerId);
|
||||
} else {
|
||||
const filteredArticles = result.articles.filter(article => article.cate == categoryId);
|
||||
renderWebArticles(filteredArticles, containerId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
showNoData(containerId);
|
||||
|
||||
1
runtime/session/sess_21407922a0f26ec34d122559f4e833f7
Normal file
1
runtime/session/sess_21407922a0f26ec34d122559f4e833f7
Normal file
@ -0,0 +1 @@
|
||||
a:1:{s:7:"captcha";a:1:{s:3:"key";s:60:"$2y$10$ElMjfwS/Yfdt4SJWe1bo7uS8gfLv8ZTge6Fu87kNO/b/m5yGxkKUe";}}
|
||||
Loading…
x
Reference in New Issue
Block a user