更新数据
This commit is contained in:
parent
f55b0068a2
commit
754db2cfee
@ -41,13 +41,14 @@ class Index extends Base
|
|||||||
'name' => $category['name']
|
'name' => $category['name']
|
||||||
];
|
];
|
||||||
|
|
||||||
// 获取该分类下的文章
|
// 获取该分类下的文章,限制4条
|
||||||
$articles = Db::name('yz_article')
|
$articles = Db::name('yz_article')
|
||||||
->where('cate', $category['id'])
|
->where('cate', $category['id'])
|
||||||
->where('delete_time', null)
|
->where('delete_time', null)
|
||||||
->where('status', 2)
|
->where('status', 2)
|
||||||
->order('id', 'desc')
|
->order('id', 'desc')
|
||||||
->field('id, cate, title, image, author, publishdate, views')
|
->field('id, cate, title, image, author, publishdate, views')
|
||||||
|
->limit(4)
|
||||||
->select()
|
->select()
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
@ -76,36 +77,41 @@ class Index extends Base
|
|||||||
// 组装分类数据,方便后续查找
|
// 组装分类数据,方便后续查找
|
||||||
$categoryData = [];
|
$categoryData = [];
|
||||||
$categoryImageMap = [];
|
$categoryImageMap = [];
|
||||||
|
$articlesByCategory = [];
|
||||||
|
|
||||||
foreach ($categories as $category) {
|
foreach ($categories as $category) {
|
||||||
$categoryData[] = [
|
$categoryData[] = [
|
||||||
'id' => $category['id'],
|
'id' => $category['id'],
|
||||||
'name' => $category['name']
|
'name' => $category['name']
|
||||||
];
|
];
|
||||||
$categoryImageMap[$category['id']] = $category['image'] ?? '';
|
$categoryImageMap[$category['id']] = $category['image'] ?? '';
|
||||||
}
|
|
||||||
|
|
||||||
// 获取所有技术分类下的文章
|
// 获取每个分类下的文章,限制12条
|
||||||
$technicalarticles = Db::name('yz_article')
|
$articles = Db::name('yz_article')
|
||||||
->whereIn('cate', array_column($categories, 'id'))
|
->where('cate', $category['id'])
|
||||||
->where('delete_time', null)
|
->where('delete_time', null)
|
||||||
->where('status', 2)
|
->where('status', 2)
|
||||||
->order('id', 'desc')
|
->order('id', 'desc')
|
||||||
->field('id, cate, title, image, author, publishdate, views')
|
->field('id, cate, title, image, author, publishdate, views')
|
||||||
->select()
|
->limit(12)
|
||||||
->toArray();
|
->select()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
// 替换image为空的文章
|
// 替换image为空的文章
|
||||||
foreach ($technicalarticles as &$article) {
|
foreach ($articles as &$article) {
|
||||||
if (empty($article['image']) && !empty($categoryImageMap[$article['cate']])) {
|
if (empty($article['image']) && !empty($categoryImageMap[$article['cate']])) {
|
||||||
$article['image'] = $categoryImageMap[$article['cate']];
|
$article['image'] = $categoryImageMap[$article['cate']];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
unset($article);
|
||||||
|
|
||||||
|
$articlesByCategory[$category['id']] = $articles;
|
||||||
}
|
}
|
||||||
unset($article);
|
|
||||||
|
|
||||||
return json([
|
return json([
|
||||||
'code' => 1,
|
'code' => 1,
|
||||||
'msg' => '获取成功',
|
'msg' => '获取成功',
|
||||||
'articles' => $technicalarticles,
|
'articles' => $articlesByCategory,
|
||||||
'categories' => $categoryData
|
'categories' => $categoryData
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,7 +58,8 @@
|
|||||||
}
|
}
|
||||||
// 渲染文章列表
|
// 渲染文章列表
|
||||||
if (result.articles && result.articles.length > 0) {
|
if (result.articles && result.articles.length > 0) {
|
||||||
renderWebArticles(result.articles, 'webArticlesList');
|
// 只取最新的4条
|
||||||
|
renderWebArticles(result.articles.slice(0, 4), 'webArticlesList');
|
||||||
} else {
|
} else {
|
||||||
showNoData('webArticlesList');
|
showNoData('webArticlesList');
|
||||||
}
|
}
|
||||||
@ -83,8 +84,17 @@
|
|||||||
renderCategoryTabs(result.categories, 'techArticles');
|
renderCategoryTabs(result.categories, 'techArticles');
|
||||||
}
|
}
|
||||||
// 渲染文章列表
|
// 渲染文章列表
|
||||||
if (result.articles && result.articles.length > 0) {
|
if (result.articles && Object.keys(result.articles).length > 0) {
|
||||||
renderWebArticles(result.articles, 'techArticlesList');
|
// 合并所有分类的文章
|
||||||
|
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 {
|
} else {
|
||||||
showNoData('techArticlesList');
|
showNoData('techArticlesList');
|
||||||
}
|
}
|
||||||
@ -163,13 +173,36 @@
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.code === 1) {
|
if (result.code === 1) {
|
||||||
if (categoryId === 'all') {
|
if (containerId === 'techArticlesList') {
|
||||||
// 显示所有文章
|
if (categoryId === 'all') {
|
||||||
renderWebArticles(result.articles, containerId);
|
// 合并所有分类的文章
|
||||||
|
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 {
|
} else {
|
||||||
// 过滤显示选中分类的文章
|
// 站点资讯部分逻辑不变
|
||||||
const filteredArticles = result.articles.filter(article => article.cate == categoryId);
|
if (categoryId === 'all') {
|
||||||
renderWebArticles(filteredArticles, containerId);
|
renderWebArticles(result.articles.slice(0, 4), containerId);
|
||||||
|
} else {
|
||||||
|
const filteredArticles = result.articles.filter(article => article.cate == categoryId);
|
||||||
|
renderWebArticles(filteredArticles, containerId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showNoData(containerId);
|
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>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
@ -235,7 +235,8 @@ layui.use(['carousel', 'form'], function(){
|
|||||||
}
|
}
|
||||||
// 渲染文章列表
|
// 渲染文章列表
|
||||||
if (result.articles && result.articles.length > 0) {
|
if (result.articles && result.articles.length > 0) {
|
||||||
renderWebArticles(result.articles, 'webArticlesList');
|
// 只取最新的4条
|
||||||
|
renderWebArticles(result.articles.slice(0, 4), 'webArticlesList');
|
||||||
} else {
|
} else {
|
||||||
showNoData('webArticlesList');
|
showNoData('webArticlesList');
|
||||||
}
|
}
|
||||||
@ -260,8 +261,17 @@ layui.use(['carousel', 'form'], function(){
|
|||||||
renderCategoryTabs(result.categories, 'techArticles');
|
renderCategoryTabs(result.categories, 'techArticles');
|
||||||
}
|
}
|
||||||
// 渲染文章列表
|
// 渲染文章列表
|
||||||
if (result.articles && result.articles.length > 0) {
|
if (result.articles && Object.keys(result.articles).length > 0) {
|
||||||
renderWebArticles(result.articles, 'techArticlesList');
|
// 合并所有分类的文章
|
||||||
|
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 {
|
} else {
|
||||||
showNoData('techArticlesList');
|
showNoData('techArticlesList');
|
||||||
}
|
}
|
||||||
@ -340,13 +350,36 @@ layui.use(['carousel', 'form'], function(){
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.code === 1) {
|
if (result.code === 1) {
|
||||||
if (categoryId === 'all') {
|
if (containerId === 'techArticlesList') {
|
||||||
// 显示所有文章
|
if (categoryId === 'all') {
|
||||||
renderWebArticles(result.articles, containerId);
|
// 合并所有分类的文章
|
||||||
|
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 {
|
} else {
|
||||||
// 过滤显示选中分类的文章
|
// 站点资讯部分逻辑不变
|
||||||
const filteredArticles = result.articles.filter(article => article.cate == categoryId);
|
if (categoryId === 'all') {
|
||||||
renderWebArticles(filteredArticles, containerId);
|
renderWebArticles(result.articles.slice(0, 4), containerId);
|
||||||
|
} else {
|
||||||
|
const filteredArticles = result.articles.filter(article => article.cate == categoryId);
|
||||||
|
renderWebArticles(filteredArticles, containerId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showNoData(containerId);
|
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