更新前端首页显示文章
@ -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
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,75 +1,28 @@
|
||||
<main class="main-content">
|
||||
<div class="container">
|
||||
<!-- 文章模块 -->
|
||||
<!-- 站点资讯模块 -->
|
||||
<div class="core-block core-module" id="opencourse" style="order: 3;">
|
||||
<div class="module-header">
|
||||
<div>
|
||||
<div class="ModuleTitle_titleWrapper">
|
||||
<h3 class="ModuleTitle_title">站点新闻</h3>
|
||||
<div class="ModuleTitle_subtitle">新鲜资讯 尽在掌握</div>
|
||||
<h3 class="ModuleTitle_title">站点资讯</h3>
|
||||
<div class="tab-container">
|
||||
<div class="tab-header">
|
||||
<div class="tab-item active" data-tab="all">全部</div>
|
||||
<!-- 分类标签将通过JavaScript动态加载 -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="more-btn">更多</div>
|
||||
</div>
|
||||
<div class="product-list">
|
||||
<div class="opencourse product-item">
|
||||
<div class="video"><img data-v-4477fdbc=""
|
||||
src="https://static001.geekbang.org/resource/image/ff/b8/ff18d73bec1040abf3d7bc7bffb532b8.jpg?x-oss-process=image/resize,w_423,h_238/format,webp"
|
||||
alt="" class="cover"><!----></div>
|
||||
<div class="introduction">
|
||||
<div class="title">闪客 · 怎么理解 AI?</div>
|
||||
<div class="subtitle">闪客 | B 站知名科普 UP 主</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="desc">1025人学过</div>
|
||||
<!-- <div class="btn">观看: 123人</div> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="opencourse product-item">
|
||||
<div class="video"><img data-v-4477fdbc=""
|
||||
src="https://static001.geekbang.org/resource/image/76/cd/762ee7f34a76fbff61d20aae313833cd.jpg?x-oss-process=image/resize,w_423,h_238/format,webp"
|
||||
alt="" class="cover">
|
||||
</div>
|
||||
<div class="introduction">
|
||||
<div class="title">多模态对话引擎实战</div>
|
||||
<div class="subtitle">吴桐 | 网易云信音视频技术负责人,流媒体首席架构师</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="desc">380人学过</div>
|
||||
<!-- <div class="btn">观看: 123人</div> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="opencourse product-item">
|
||||
<div class="video"><img data-v-4477fdbc=""
|
||||
src="https://static001.geekbang.org/resource/image/4y/da/4yyfb232bfbfbdcc6ed827c16b04a9da.jpg?x-oss-process=image/resize,w_423,h_238/format,webp"
|
||||
alt="" class="cover"><!----></div>
|
||||
<div class="introduction">
|
||||
<div class="title">极客视点</div>
|
||||
<div class="subtitle">极客时间 | 编辑部</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="desc">12.4w人学过</div>
|
||||
<!-- <div class="btn">观看: 123人</div> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="opencourse product-item">
|
||||
<div class="video"><img data-v-4477fdbc=""
|
||||
src="https://static001.geekbang.org/resource/image/0f/69/0f95b62cf7yy6d6yy674f090d063b669.jpg?x-oss-process=image/resize,w_423,h_238/format,webp"
|
||||
alt="" class="cover"><!----></div>
|
||||
<div class="introduction">
|
||||
<div class="title">周志明的软件架构课</div>
|
||||
<div class="subtitle">周志明 | 博士,远光软件研究院院长,《深入理解Java虚拟机》《凤凰架构》等书作者</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="desc">6.0w人学过</div>
|
||||
<!-- <div class="btn">观看: 123人</div>d -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="product-list" id="webArticlesList">
|
||||
<!-- 文章将通过JavaScript动态加载 -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 文章模块 -->
|
||||
<div class="core-block core-module" id="opencourse" style="order: 3;">
|
||||
<!-- 技术文章模块 -->
|
||||
<div class="core-block core-module" id="techArticles" style="order: 3;">
|
||||
<div class="module-header">
|
||||
<div>
|
||||
<div class="ModuleTitle_titleWrapper">
|
||||
@ -77,96 +30,204 @@
|
||||
<div class="tab-container">
|
||||
<div class="tab-header">
|
||||
<div class="tab-item active" data-tab="all">全部</div>
|
||||
{foreach $articleList as $cateName => $articles}
|
||||
<div class="tab-item" data-tab="{$cateName}">{$cateName}</div>
|
||||
{/foreach}
|
||||
<!-- 分类标签将通过JavaScript动态加载 -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="more-btn">更多</div>
|
||||
</div>
|
||||
<div class="product-list">
|
||||
<!-- 全部文章 -->
|
||||
<div class="tab-content active" data-tab="all">
|
||||
{foreach $articleList as $cateName => $articles}
|
||||
{foreach $articles as $article}
|
||||
<div class="opencourse product-item"
|
||||
onclick="window.open('{:url('article/detail')}?id={$article.id}', '_blank')">
|
||||
<div class="video">
|
||||
<img src="{$article.image}" alt="" class="cover">
|
||||
</div>
|
||||
<div class="introduction">
|
||||
<div class="title">{$article.title}</div>
|
||||
<div class="publishdate">{$article.publishdate}</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="views"><i class="fa-solid fa-eye "></i><span style="margin-left: 5px;">{$article.views}</span></div>
|
||||
<div class="author"><i class="fa-regular fa-user"></i><span style="margin-left: 5px;">{$article.author}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
{/foreach}
|
||||
{/foreach}
|
||||
</div>
|
||||
|
||||
<!-- 分类文章 -->
|
||||
{foreach $articleList as $cateName => $articles}
|
||||
<div class="tab-content" data-tab="{$cateName}">
|
||||
{foreach $articles as $article}
|
||||
<div class="opencourse product-item"
|
||||
onclick="window.open('{:url('article/detail')}?id={$article.id}', '_blank')">
|
||||
<div class="video">
|
||||
<img src="{$article.image}" alt="" class="cover">
|
||||
</div>
|
||||
<div class="introduction">
|
||||
<div class="title">{$article.title}</div>
|
||||
<div class="publishdate">{$article.publishdate}</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="views"><i class="fa-solid fa-eye "></i><span style="margin-left: 5px;">{$article.views}</span></div>
|
||||
<div class="author"><i class="fa-regular fa-user"></i><span style="margin-left: 5px;">{$article.author}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
{/foreach}
|
||||
</div>
|
||||
{/foreach}
|
||||
<div class="product-list" id="techArticlesList">
|
||||
<!-- 文章将通过JavaScript动态加载 -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// 获取所有tab项和内容
|
||||
const tabItems = document.querySelectorAll('.tab-item');
|
||||
const tabContents = document.querySelectorAll('.tab-content');
|
||||
// 加载站点新闻
|
||||
function loadWebArticles() {
|
||||
fetch('/index/index/siteNewslist')
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.code === 1) {
|
||||
// 渲染分类标签
|
||||
if (result.categories) {
|
||||
renderCategoryTabs(result.categories, 'opencourse');
|
||||
}
|
||||
// 渲染文章列表
|
||||
if (result.articles && result.articles.length > 0) {
|
||||
renderWebArticles(result.articles, 'webArticlesList');
|
||||
} else {
|
||||
showNoData('webArticlesList');
|
||||
}
|
||||
} else {
|
||||
showNoData('webArticlesList');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('请求失败:', error);
|
||||
showError('webArticlesList');
|
||||
});
|
||||
}
|
||||
|
||||
// 为每个tab项添加点击事件
|
||||
// 加载技术文章
|
||||
function loadTechArticles() {
|
||||
fetch('/index/index/technicalArticleslist')
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.code === 1) {
|
||||
// 渲染分类标签
|
||||
if (result.categories) {
|
||||
renderCategoryTabs(result.categories, 'techArticles');
|
||||
}
|
||||
// 渲染文章列表
|
||||
if (result.articles && result.articles.length > 0) {
|
||||
renderWebArticles(result.articles, 'techArticlesList');
|
||||
} else {
|
||||
showNoData('techArticlesList');
|
||||
}
|
||||
} else {
|
||||
showNoData('techArticlesList');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('请求失败:', error);
|
||||
showError('techArticlesList');
|
||||
});
|
||||
}
|
||||
|
||||
// 显示无数据提示
|
||||
function showNoData(containerId) {
|
||||
document.getElementById(containerId).innerHTML = '<div class="no-data">暂无数据</div>';
|
||||
}
|
||||
|
||||
// 显示错误提示
|
||||
function showError(containerId) {
|
||||
document.getElementById(containerId).innerHTML = '<div class="error-message">网络请求失败</div>';
|
||||
}
|
||||
|
||||
// 渲染分类标签
|
||||
function renderCategoryTabs(categories, moduleId) {
|
||||
const tabHeader = document.querySelector(`#${moduleId} .tab-header`);
|
||||
if (!tabHeader) return;
|
||||
|
||||
// 保留"全部"标签
|
||||
const allTab = tabHeader.querySelector('.tab-item[data-tab="all"]');
|
||||
tabHeader.innerHTML = '';
|
||||
tabHeader.appendChild(allTab);
|
||||
|
||||
// 添加分类标签
|
||||
if (Array.isArray(categories)) {
|
||||
categories.forEach(category => {
|
||||
const tabItem = document.createElement('div');
|
||||
tabItem.className = 'tab-item';
|
||||
tabItem.setAttribute('data-tab', category.id);
|
||||
tabItem.textContent = category.name;
|
||||
tabHeader.appendChild(tabItem);
|
||||
});
|
||||
}
|
||||
|
||||
// 重新绑定点击事件
|
||||
bindTabEvents(moduleId);
|
||||
}
|
||||
|
||||
// 绑定标签点击事件
|
||||
function bindTabEvents(moduleId) {
|
||||
const tabItems = document.querySelectorAll(`#${moduleId} .tab-item`);
|
||||
tabItems.forEach(tab => {
|
||||
tab.addEventListener('click', function () {
|
||||
tab.addEventListener('click', function() {
|
||||
// 移除所有active类
|
||||
tabItems.forEach(item => item.classList.remove('active'));
|
||||
tabContents.forEach(content => content.classList.remove('active'));
|
||||
|
||||
// 添加active类到当前点击的tab
|
||||
this.classList.add('active');
|
||||
|
||||
// 显示对应的内容
|
||||
const tabName = this.getAttribute('data-tab');
|
||||
const activeContent = document.querySelector(`.tab-content[data-tab="${tabName}"]`);
|
||||
if (activeContent) {
|
||||
activeContent.classList.add('active');
|
||||
|
||||
// 获取选中的分类ID
|
||||
const selectedCategoryId = this.getAttribute('data-tab');
|
||||
|
||||
// 重新加载对应分类的文章
|
||||
if (moduleId === 'opencourse') {
|
||||
loadCategoryArticles(selectedCategoryId, 'webArticlesList');
|
||||
} else {
|
||||
loadCategoryArticles(selectedCategoryId, 'techArticlesList');
|
||||
}
|
||||
|
||||
// 添加切换动画效果
|
||||
activeContent.style.opacity = '0';
|
||||
setTimeout(() => {
|
||||
activeContent.style.opacity = '1';
|
||||
}, 50);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 加载分类文章
|
||||
function loadCategoryArticles(categoryId, containerId) {
|
||||
const url = containerId === 'webArticlesList' ? '/index/index/siteNewslist' : '/index/index/technicalArticleslist';
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.code === 1) {
|
||||
if (categoryId === 'all') {
|
||||
// 显示所有文章
|
||||
renderWebArticles(result.articles, containerId);
|
||||
} else {
|
||||
// 过滤显示选中分类的文章
|
||||
const filteredArticles = result.articles.filter(article => article.cate == categoryId);
|
||||
renderWebArticles(filteredArticles, containerId);
|
||||
}
|
||||
} else {
|
||||
showNoData(containerId);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('请求失败:', error);
|
||||
showError(containerId);
|
||||
});
|
||||
}
|
||||
|
||||
// 渲染文章列表
|
||||
function renderWebArticles(articles, containerId) {
|
||||
const container = document.getElementById(containerId);
|
||||
if (!container) return;
|
||||
|
||||
let html = '';
|
||||
if (Array.isArray(articles)) {
|
||||
articles.forEach(article => {
|
||||
html += createArticleHtml(article);
|
||||
});
|
||||
}
|
||||
|
||||
container.innerHTML = html || '<div class="no-data">暂无数据</div>';
|
||||
}
|
||||
|
||||
// 创建文章HTML
|
||||
function createArticleHtml(article) {
|
||||
if (!article) return '';
|
||||
|
||||
// 格式化日期
|
||||
const publishDate = new Date(article.publishdate * 1000);
|
||||
const formattedDate = publishDate.toLocaleDateString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit'
|
||||
});
|
||||
|
||||
return `
|
||||
<div class="opencourse product-item" onclick="window.open('/index/article/detail?id=${article.id || ''}', '_blank')">
|
||||
<div class="video">
|
||||
<img src="${article.image || ''}" alt="" class="cover">
|
||||
</div>
|
||||
<div class="introduction">
|
||||
<div class="title">${article.title || '无标题'}</div>
|
||||
<div class="publishdate">${formattedDate}</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="views"><i class="fa-solid fa-eye"></i><span style="margin-left: 5px;">${article.views || 0}</span></div>
|
||||
<div class="author"><i class="fa-regular fa-user"></i><span style="margin-left: 5px;">${article.author || '未知作者'}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// 页面加载完成后执行
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadWebArticles();
|
||||
loadTechArticles();
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 53 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 7.8 KiB |
|
After Width: | Height: | Size: 93 KiB |
@ -1,4 +1,4 @@
|
||||
<?php /*a:2:{s:53:"E:\Demo\PHP\yunzer\app\admin\view\article\cateadd.php";i:1746796639;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746796639;}*/ ?>
|
||||
<?php /*a:2:{s:53:"E:\Demo\PHP\yunzer\app\admin\view\article\cateadd.php";i:1746796639;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@ -6,7 +6,7 @@
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" type="text/css" href="/static/third/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/moban.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/wangeditor.css" media="all"/>
|
||||
<style type="text/css">
|
||||
@ -79,7 +79,7 @@
|
||||
}
|
||||
.close-img { background: url(/static/images/close_img.png); background-size: 20px 20px; width:20px; height: 20px; position: absolute; right: 5px; top: 5px; z-index: 2;}
|
||||
</style>
|
||||
<script type="text/javascript" src="/static/third/layui/layui.js"></script>
|
||||
<script type="text/javascript" src="/static/layui/layui.js"></script>
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer','form','table','laydate','element','upload'],function(){
|
||||
layer = layui.layer; // layui 弹框
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?php /*a:2:{s:57:"E:\Demo\PHP\yunzer\app\admin\view\article\articlelist.php";i:1746800071;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746796639;}*/ ?>
|
||||
<?php /*a:2:{s:57:"E:\Demo\PHP\yunzer\app\admin\view\article\articlelist.php";i:1746800071;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@ -6,7 +6,7 @@
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" type="text/css" href="/static/third/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/moban.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/wangeditor.css" media="all"/>
|
||||
<style type="text/css">
|
||||
@ -79,7 +79,7 @@
|
||||
}
|
||||
.close-img { background: url(/static/images/close_img.png); background-size: 20px 20px; width:20px; height: 20px; position: absolute; right: 5px; top: 5px; z-index: 2;}
|
||||
</style>
|
||||
<script type="text/javascript" src="/static/third/layui/layui.js"></script>
|
||||
<script type="text/javascript" src="/static/layui/layui.js"></script>
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer','form','table','laydate','element','upload'],function(){
|
||||
layer = layui.layer; // layui 弹框
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?php /*a:2:{s:54:"E:\Demo\PHP\yunzer\app\admin\view\article\cateedit.php";i:1746796639;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746796639;}*/ ?>
|
||||
<?php /*a:2:{s:54:"E:\Demo\PHP\yunzer\app\admin\view\article\cateedit.php";i:1746890051;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@ -6,7 +6,7 @@
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" type="text/css" href="/static/third/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/moban.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/wangeditor.css" media="all"/>
|
||||
<style type="text/css">
|
||||
@ -79,7 +79,7 @@
|
||||
}
|
||||
.close-img { background: url(/static/images/close_img.png); background-size: 20px 20px; width:20px; height: 20px; position: absolute; right: 5px; top: 5px; z-index: 2;}
|
||||
</style>
|
||||
<script type="text/javascript" src="/static/third/layui/layui.js"></script>
|
||||
<script type="text/javascript" src="/static/layui/layui.js"></script>
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer','form','table','laydate','element','upload'],function(){
|
||||
layer = layui.layer; // layui 弹框
|
||||
@ -96,6 +96,26 @@
|
||||
<div style="padding: 50px;padding-bottom: 0px;">
|
||||
<form class="layui-form" action="" method="post">
|
||||
<input type="hidden" name="id" value="<?php echo htmlentities((string) $info['id']); ?>">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">分类图片</label>
|
||||
<div class="layui-input-block">
|
||||
<button type="button" class="layui-btn" id="upload-btn">
|
||||
<i class="layui-icon layui-icon-upload"></i> 图片上传
|
||||
</button>
|
||||
<div style="width: 120px;">
|
||||
<div class="layui-upload-list">
|
||||
<img class="layui-upload-img" id="upload-img"
|
||||
style="width: 118px; height: 118px;object-fit: cover;" src="<?php echo htmlentities((string) $info['image']); ?>">
|
||||
<div id="upload-text"></div>
|
||||
</div>
|
||||
<div class="layui-progress layui-progress-big" lay-showPercent="yes" lay-filter="filter-demo">
|
||||
<div class="layui-progress-bar" lay-percent=""></div>
|
||||
</div>
|
||||
<input type="hidden" name="image" id="image" value="<?php echo htmlentities((string) $info['image']); ?>">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">分类名称</label>
|
||||
<div class="layui-input-block">
|
||||
@ -125,7 +145,8 @@
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">排序</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="number" id="sort" name="sort" value="<?php echo htmlentities((string) $info['sort']); ?>" placeholder="请输入排序值" class="layui-input">
|
||||
<input type="number" id="sort" name="sort" value="<?php echo htmlentities((string) $info['sort']); ?>" placeholder="请输入排序值"
|
||||
class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -138,23 +159,66 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
layui.use(['form', 'layer'], function () {
|
||||
// 首先定义PHP变量,确保类型正确
|
||||
var currentCid = parseInt('<?php echo htmlentities((string) (isset($info['cid']) && ($info['cid'] !== '')?$info['cid']:0)); ?>'); // 转换为数字
|
||||
var currentId = parseInt('<?php echo htmlentities((string) (isset($info['id']) && ($info['id'] !== '')?$info['id']:0)); ?>'); // 转换为数字
|
||||
|
||||
layui.use(['form', 'layer', 'upload', 'element'], function () {
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
var $ = layui.jquery;
|
||||
var upload = layui.upload;
|
||||
var element = layui.element;
|
||||
|
||||
// 获取URL中的id参数
|
||||
var urlParams = new URLSearchParams(window.location.search);
|
||||
var id = urlParams.get('id');
|
||||
var id = parseInt(urlParams.get('id')) || 0; // 转换为数字
|
||||
|
||||
// 图片上传
|
||||
var uploadInst = upload.render({
|
||||
elem: '#upload-btn',
|
||||
url: '<?php echo url("index/upload_img"); ?>',
|
||||
before: function (obj) {
|
||||
obj.preview(function (index, file, result) {
|
||||
$('#upload-img').attr('src', result);
|
||||
});
|
||||
element.progress('filter-demo', '0%');
|
||||
layer.msg('上传中', { icon: 16, time: 0 });
|
||||
},
|
||||
done: function (res) {
|
||||
if (res.code > 0) {
|
||||
return layer.msg('上传失败');
|
||||
}
|
||||
$('#image').val(res.data);
|
||||
$('#upload-text').html('');
|
||||
layer.msg('上传成功', { icon: 1 });
|
||||
},
|
||||
uploadError: function () {
|
||||
var demoText = $('#upload-text');
|
||||
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
|
||||
demoText.find('.demo-reload').on('click', function () {
|
||||
uploadInst.upload();
|
||||
});
|
||||
},
|
||||
progress: function (n, elem, e) {
|
||||
element.progress('filter-demo', n + '%');
|
||||
if (n == 100) {
|
||||
layer.msg('上传完毕', { icon: 1 });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 获取分类列表
|
||||
$.get('<?php echo url("article/getcate"); ?>', function (res) {
|
||||
if (res.code == 0) {
|
||||
var html = '<option value="0">顶级分类</option>';
|
||||
res.data.forEach(function (item) {
|
||||
// 排除自己及其子分类作为父级选项
|
||||
if(item.id != id) {
|
||||
html += '<option value="' + item.id + '"' + (item.id == <?php echo htmlentities((string) $info['cid']); ?> ? ' selected' : '') + '>' + item.name + '</option>';
|
||||
// 确保item.id是数字类型
|
||||
var itemId = parseInt(item.id);
|
||||
if (itemId !== id) { // 使用严格比较
|
||||
html += '<option value="' + itemId + '"' +
|
||||
(itemId === currentCid ? ' selected' : '') +
|
||||
'>' + item.name + '</option>';
|
||||
}
|
||||
});
|
||||
$('#cid').html(html);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?php /*a:3:{s:51:"E:\Demo\PHP\yunzer\app\admin\view\index\welcome.php";i:1745855804;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746796639;s:49:"E:\Demo\PHP\yunzer\app\admin\view\public\tail.php";i:1745855804;}*/ ?>
|
||||
<?php /*a:3:{s:51:"E:\Demo\PHP\yunzer\app\admin\view\index\welcome.php";i:1745855804;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;s:49:"E:\Demo\PHP\yunzer\app\admin\view\public\tail.php";i:1745855804;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@ -6,7 +6,7 @@
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" type="text/css" href="/static/third/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/moban.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/wangeditor.css" media="all"/>
|
||||
<style type="text/css">
|
||||
@ -79,7 +79,7 @@
|
||||
}
|
||||
.close-img { background: url(/static/images/close_img.png); background-size: 20px 20px; width:20px; height: 20px; position: absolute; right: 5px; top: 5px; z-index: 2;}
|
||||
</style>
|
||||
<script type="text/javascript" src="/static/third/layui/layui.js"></script>
|
||||
<script type="text/javascript" src="/static/layui/layui.js"></script>
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer','form','table','laydate','element','upload'],function(){
|
||||
layer = layui.layer; // layui 弹框
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?php /*a:2:{s:57:"E:\Demo\PHP\yunzer\app\admin\view\article\articlecate.php";i:1746796639;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746796639;}*/ ?>
|
||||
<?php /*a:2:{s:57:"E:\Demo\PHP\yunzer\app\admin\view\article\articlecate.php";i:1746890051;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@ -6,7 +6,7 @@
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" type="text/css" href="/static/third/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/moban.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/wangeditor.css" media="all"/>
|
||||
<style type="text/css">
|
||||
@ -79,7 +79,7 @@
|
||||
}
|
||||
.close-img { background: url(/static/images/close_img.png); background-size: 20px 20px; width:20px; height: 20px; position: absolute; right: 5px; top: 5px; z-index: 2;}
|
||||
</style>
|
||||
<script type="text/javascript" src="/static/third/layui/layui.js"></script>
|
||||
<script type="text/javascript" src="/static/layui/layui.js"></script>
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer','form','table','laydate','element','upload'],function(){
|
||||
layer = layui.layer; // layui 弹框
|
||||
@ -113,6 +113,7 @@
|
||||
<tr>
|
||||
<th width="20">ID</th>
|
||||
<th width="120">分类名称</th>
|
||||
<th width="120">分类图片</th>
|
||||
<th>描述</th>
|
||||
<th width="80">排序</th>
|
||||
<th width="80">状态</th>
|
||||
@ -125,7 +126,8 @@
|
||||
<tr>
|
||||
<td><?php echo htmlentities((string) $vo['id']); ?></td>
|
||||
<td><?php echo htmlentities((string) $vo['name']); ?></td>
|
||||
<td><?php echo htmlentities((string) $vo['desc']); ?></td>
|
||||
<td><img src="<?php echo htmlentities((string) $vo['image']); ?>" style="width: 100px;height: auto;"></td>
|
||||
<td></td><?php echo htmlentities((string) $vo['desc']); ?></td>
|
||||
<td><?php echo htmlentities((string) $vo['sort']); ?></td>
|
||||
<td><?php echo $vo['status']==1 ? '开启' : '<span style="color:red;">禁用</span>'; ?></td>
|
||||
<td><?php echo htmlentities((string) $vo['create_time']); ?></td>
|
||||
@ -146,6 +148,7 @@
|
||||
<tr>
|
||||
<td><?php echo htmlentities((string) $sub['id']); ?></td>
|
||||
<td style="padding-left: 30px;">├─ <?php echo htmlentities((string) $sub['name']); ?></td>
|
||||
<td><img src="<?php echo htmlentities((string) $sub['image']); ?>" style="width: 100px;height: auto;"></td>
|
||||
<td><?php echo htmlentities((string) $sub['desc']); ?></td>
|
||||
<td><?php echo htmlentities((string) $sub['sort']); ?></td>
|
||||
<td><?php echo $sub['status']==1 ? '开启' : '<span style="color:red;">禁用</span>'; ?></td>
|
||||
@ -190,7 +193,7 @@
|
||||
title: '编辑分类',
|
||||
shadeClose: true,
|
||||
shade: 0.8,
|
||||
area: ['500px', '400px'],
|
||||
area: ['800px', '800px'],
|
||||
content: '<?php echo url("article/cateedit"); ?>?id=' + id
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?php /*a:2:{s:49:"E:\Demo\PHP\yunzer\app\admin\view\article\add.php";i:1746802033;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746796639;}*/ ?>
|
||||
<?php /*a:2:{s:49:"E:\Demo\PHP\yunzer\app\admin\view\article\add.php";i:1746804004;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@ -6,7 +6,7 @@
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" type="text/css" href="/static/third/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/moban.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/wangeditor.css" media="all"/>
|
||||
<style type="text/css">
|
||||
@ -79,7 +79,7 @@
|
||||
}
|
||||
.close-img { background: url(/static/images/close_img.png); background-size: 20px 20px; width:20px; height: 20px; position: absolute; right: 5px; top: 5px; z-index: 2;}
|
||||
</style>
|
||||
<script type="text/javascript" src="/static/third/layui/layui.js"></script>
|
||||
<script type="text/javascript" src="/static/layui/layui.js"></script>
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer','form','table','laydate','element','upload'],function(){
|
||||
layer = layui.layer; // layui 弹框
|
||||
@ -286,36 +286,61 @@
|
||||
const { createEditor, createToolbar } = window.wangEditor
|
||||
|
||||
const editorConfig = {
|
||||
MENU_CONF: {},
|
||||
placeholder: '请输入内容...',
|
||||
onChange(editor) {
|
||||
const html = editor.getHtml()
|
||||
// console.log('editor content', html)
|
||||
// 也可以同步到 <textarea>
|
||||
},
|
||||
menus: [
|
||||
'head', // 标题
|
||||
'bold', // 粗体
|
||||
'fontSize', // 字号
|
||||
'fontName', // 字体
|
||||
'italic', // 斜体
|
||||
'underline', // 下划线
|
||||
'strikeThrough', // 删除线
|
||||
'foreColor', // 文本颜色
|
||||
'backColor', // 背景颜色
|
||||
'link', // 插入链接
|
||||
'list', // 列表
|
||||
'justify', // 对齐方式
|
||||
'quote', // 引用
|
||||
'emoticon', // 表情
|
||||
'image', // 插入图片
|
||||
'video', // 插入视频
|
||||
'audio', // 插入音频
|
||||
'table', // 表格
|
||||
'code', // 插入代码
|
||||
'undo', // 撤销
|
||||
'redo', // 重做
|
||||
],
|
||||
uploadImgServer: '/index/upload_imgs', // 图片上传接口
|
||||
}
|
||||
|
||||
// 配置图片上传
|
||||
editorConfig.MENU_CONF['uploadImage'] = {
|
||||
server: '<?php echo url("index/upload_imgs"); ?>',
|
||||
fieldName: 'file',
|
||||
maxFileSize: 10 * 1024 * 1024, // 10M
|
||||
maxNumberOfFiles: 10,
|
||||
allowedFileTypes: ['image/*'],
|
||||
meta: {
|
||||
token: 'xxx'
|
||||
},
|
||||
metaWithUrl: true,
|
||||
headers: {
|
||||
Accept: 'text/x-json'
|
||||
},
|
||||
timeout: 5 * 1000, // 5s
|
||||
|
||||
onBeforeUpload(file) {
|
||||
console.log('准备上传图片', file)
|
||||
return file
|
||||
},
|
||||
onProgress(progress) {
|
||||
console.log('上传进度', progress)
|
||||
},
|
||||
onSuccess(file, res) {
|
||||
console.log('上传成功', file, res)
|
||||
},
|
||||
onFailed(file, res) {
|
||||
layer.msg('上传失败:' + res.msg, { icon: 2 })
|
||||
console.log('上传失败', file, res)
|
||||
},
|
||||
onError(file, err, res) {
|
||||
layer.msg('上传出错:' + err.message, { icon: 2 })
|
||||
console.error('上传出错', file, err, res)
|
||||
},
|
||||
customInsert(res, insertFn) {
|
||||
// res 即服务端的返回结果
|
||||
if (res.code === 0 && res.data) {
|
||||
// 从res.data中获取src字段
|
||||
const url = String(res.data.src || '');
|
||||
if (url) {
|
||||
insertFn(url);
|
||||
} else {
|
||||
layer.msg('图片地址无效', { icon: 2 });
|
||||
}
|
||||
} else {
|
||||
layer.msg('图片上传失败', { icon: 2 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const editor = createEditor({
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?php /*a:4:{s:49:"E:\Demo\PHP\yunzer\app\index\view\index\index.php";i:1746796639;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:1746806638;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:1746985804;s:54:"E:\Demo\PHP\yunzer\app\index\view\component\footer.php";i:1746796639;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
@ -9,7 +9,10 @@
|
||||
<link rel="stylesheet" href="/static/layui/css/layui.css">
|
||||
<link rel="stylesheet" href="/static/css/style.css">
|
||||
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="/static/css/fontawesome.css">
|
||||
|
||||
<script src="/static/layui/layui.js" charset="utf-8"></script>
|
||||
<script src="/static/js/bootstrap.bundle.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -174,76 +177,29 @@ layui.use(['carousel', 'form'], function(){
|
||||
|
||||
<main class="main-content">
|
||||
<div class="container">
|
||||
<!-- 文章模块 -->
|
||||
<!-- 站点资讯模块 -->
|
||||
<div class="core-block core-module" id="opencourse" style="order: 3;">
|
||||
<div class="module-header">
|
||||
<div>
|
||||
<div class="ModuleTitle_titleWrapper">
|
||||
<h3 class="ModuleTitle_title">站点新闻</h3>
|
||||
<div class="ModuleTitle_subtitle">新鲜资讯 尽在掌握</div>
|
||||
<h3 class="ModuleTitle_title">站点资讯</h3>
|
||||
<div class="tab-container">
|
||||
<div class="tab-header">
|
||||
<div class="tab-item active" data-tab="all">全部</div>
|
||||
<!-- 分类标签将通过JavaScript动态加载 -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="more-btn">更多</div>
|
||||
</div>
|
||||
<div class="product-list">
|
||||
<div class="opencourse product-item">
|
||||
<div class="video"><img data-v-4477fdbc=""
|
||||
src="https://static001.geekbang.org/resource/image/ff/b8/ff18d73bec1040abf3d7bc7bffb532b8.jpg?x-oss-process=image/resize,w_423,h_238/format,webp"
|
||||
alt="" class="cover"><!----></div>
|
||||
<div class="introduction">
|
||||
<div class="title">闪客 · 怎么理解 AI?</div>
|
||||
<div class="subtitle">闪客 | B 站知名科普 UP 主</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="desc">1025人学过</div>
|
||||
<!-- <div class="btn">观看: 123人</div> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="opencourse product-item">
|
||||
<div class="video"><img data-v-4477fdbc=""
|
||||
src="https://static001.geekbang.org/resource/image/76/cd/762ee7f34a76fbff61d20aae313833cd.jpg?x-oss-process=image/resize,w_423,h_238/format,webp"
|
||||
alt="" class="cover">
|
||||
</div>
|
||||
<div class="introduction">
|
||||
<div class="title">多模态对话引擎实战</div>
|
||||
<div class="subtitle">吴桐 | 网易云信音视频技术负责人,流媒体首席架构师</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="desc">380人学过</div>
|
||||
<!-- <div class="btn">观看: 123人</div> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="opencourse product-item">
|
||||
<div class="video"><img data-v-4477fdbc=""
|
||||
src="https://static001.geekbang.org/resource/image/4y/da/4yyfb232bfbfbdcc6ed827c16b04a9da.jpg?x-oss-process=image/resize,w_423,h_238/format,webp"
|
||||
alt="" class="cover"><!----></div>
|
||||
<div class="introduction">
|
||||
<div class="title">极客视点</div>
|
||||
<div class="subtitle">极客时间 | 编辑部</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="desc">12.4w人学过</div>
|
||||
<!-- <div class="btn">观看: 123人</div> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="opencourse product-item">
|
||||
<div class="video"><img data-v-4477fdbc=""
|
||||
src="https://static001.geekbang.org/resource/image/0f/69/0f95b62cf7yy6d6yy674f090d063b669.jpg?x-oss-process=image/resize,w_423,h_238/format,webp"
|
||||
alt="" class="cover"><!----></div>
|
||||
<div class="introduction">
|
||||
<div class="title">周志明的软件架构课</div>
|
||||
<div class="subtitle">周志明 | 博士,远光软件研究院院长,《深入理解Java虚拟机》《凤凰架构》等书作者</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="desc">6.0w人学过</div>
|
||||
<!-- <div class="btn">观看: 123人</div>d -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="product-list" id="webArticlesList">
|
||||
<!-- 文章将通过JavaScript动态加载 -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 文章模块 -->
|
||||
<div class="core-block core-module" id="opencourse" style="order: 3;">
|
||||
<!-- 技术文章模块 -->
|
||||
<div class="core-block core-module" id="techArticles" style="order: 3;">
|
||||
<div class="module-header">
|
||||
<div>
|
||||
<div class="ModuleTitle_titleWrapper">
|
||||
@ -251,93 +207,206 @@ layui.use(['carousel', 'form'], function(){
|
||||
<div class="tab-container">
|
||||
<div class="tab-header">
|
||||
<div class="tab-item active" data-tab="all">全部</div>
|
||||
<?php foreach($articleList as $cateName => $articles): ?>
|
||||
<div class="tab-item" data-tab="<?php echo htmlentities((string) $cateName); ?>"><?php echo htmlentities((string) $cateName); ?></div>
|
||||
<?php endforeach; ?>
|
||||
<!-- 分类标签将通过JavaScript动态加载 -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="more-btn">更多</div>
|
||||
</div>
|
||||
<div class="product-list">
|
||||
<!-- 全部文章 -->
|
||||
<div class="tab-content active" data-tab="all">
|
||||
<?php foreach($articleList as $cateName => $articles): foreach($articles as $article): ?>
|
||||
<div class="opencourse product-item" onclick="window.open('<?php echo url('article/detail'); ?>?id=<?php echo htmlentities((string) $article['id']); ?>', '_blank')">
|
||||
<div class="video">
|
||||
<img src="<?php echo htmlentities((string) $article['image']); ?>" alt="" class="cover">
|
||||
</div>
|
||||
<div class="introduction">
|
||||
<div class="title"><?php echo htmlentities((string) $article['title']); ?></div>
|
||||
<div class="subtitle"><?php echo htmlentities((string) $article['author']); ?></div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="desc"><?php echo htmlentities((string) $article['desc']); ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<!-- 分类文章 -->
|
||||
<?php foreach($articleList as $cateName => $articles): ?>
|
||||
<div class="tab-content" data-tab="<?php echo htmlentities((string) $cateName); ?>">
|
||||
<?php foreach($articles as $article): ?>
|
||||
<div class="opencourse product-item" onclick="window.open('<?php echo url('article/detail'); ?>?id=<?php echo htmlentities((string) $article['id']); ?>', '_blank')">
|
||||
<div class="video">
|
||||
<img src="<?php echo htmlentities((string) $article['image']); ?>" alt="" class="cover">
|
||||
</div>
|
||||
<div class="introduction">
|
||||
<div class="title"><?php echo htmlentities((string) $article['title']); ?></div>
|
||||
<div class="subtitle"><?php echo htmlentities((string) $article['author']); ?></div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="desc"><?php echo htmlentities((string) $article['desc']); ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<div class="product-list" id="techArticlesList">
|
||||
<!-- 文章将通过JavaScript动态加载 -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// 获取所有tab项和内容
|
||||
const tabItems = document.querySelectorAll('.tab-item');
|
||||
const tabContents = document.querySelectorAll('.tab-content');
|
||||
// 加载站点新闻
|
||||
function loadWebArticles() {
|
||||
fetch('/index/index/siteNewslist')
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.code === 1) {
|
||||
// 渲染分类标签
|
||||
if (result.categories) {
|
||||
renderCategoryTabs(result.categories, 'opencourse');
|
||||
}
|
||||
// 渲染文章列表
|
||||
if (result.articles && result.articles.length > 0) {
|
||||
renderWebArticles(result.articles, 'webArticlesList');
|
||||
} else {
|
||||
showNoData('webArticlesList');
|
||||
}
|
||||
} else {
|
||||
showNoData('webArticlesList');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('请求失败:', error);
|
||||
showError('webArticlesList');
|
||||
});
|
||||
}
|
||||
|
||||
// 为每个tab项添加点击事件
|
||||
// 加载技术文章
|
||||
function loadTechArticles() {
|
||||
fetch('/index/index/technicalArticleslist')
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.code === 1) {
|
||||
// 渲染分类标签
|
||||
if (result.categories) {
|
||||
renderCategoryTabs(result.categories, 'techArticles');
|
||||
}
|
||||
// 渲染文章列表
|
||||
if (result.articles && result.articles.length > 0) {
|
||||
renderWebArticles(result.articles, 'techArticlesList');
|
||||
} else {
|
||||
showNoData('techArticlesList');
|
||||
}
|
||||
} else {
|
||||
showNoData('techArticlesList');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('请求失败:', error);
|
||||
showError('techArticlesList');
|
||||
});
|
||||
}
|
||||
|
||||
// 显示无数据提示
|
||||
function showNoData(containerId) {
|
||||
document.getElementById(containerId).innerHTML = '<div class="no-data">暂无数据</div>';
|
||||
}
|
||||
|
||||
// 显示错误提示
|
||||
function showError(containerId) {
|
||||
document.getElementById(containerId).innerHTML = '<div class="error-message">网络请求失败</div>';
|
||||
}
|
||||
|
||||
// 渲染分类标签
|
||||
function renderCategoryTabs(categories, moduleId) {
|
||||
const tabHeader = document.querySelector(`#${moduleId} .tab-header`);
|
||||
if (!tabHeader) return;
|
||||
|
||||
// 保留"全部"标签
|
||||
const allTab = tabHeader.querySelector('.tab-item[data-tab="all"]');
|
||||
tabHeader.innerHTML = '';
|
||||
tabHeader.appendChild(allTab);
|
||||
|
||||
// 添加分类标签
|
||||
if (Array.isArray(categories)) {
|
||||
categories.forEach(category => {
|
||||
const tabItem = document.createElement('div');
|
||||
tabItem.className = 'tab-item';
|
||||
tabItem.setAttribute('data-tab', category.id);
|
||||
tabItem.textContent = category.name;
|
||||
tabHeader.appendChild(tabItem);
|
||||
});
|
||||
}
|
||||
|
||||
// 重新绑定点击事件
|
||||
bindTabEvents(moduleId);
|
||||
}
|
||||
|
||||
// 绑定标签点击事件
|
||||
function bindTabEvents(moduleId) {
|
||||
const tabItems = document.querySelectorAll(`#${moduleId} .tab-item`);
|
||||
tabItems.forEach(tab => {
|
||||
tab.addEventListener('click', function () {
|
||||
tab.addEventListener('click', function() {
|
||||
// 移除所有active类
|
||||
tabItems.forEach(item => item.classList.remove('active'));
|
||||
tabContents.forEach(content => content.classList.remove('active'));
|
||||
|
||||
// 添加active类到当前点击的tab
|
||||
this.classList.add('active');
|
||||
|
||||
// 显示对应的内容
|
||||
const tabName = this.getAttribute('data-tab');
|
||||
const activeContent = document.querySelector(`.tab-content[data-tab="${tabName}"]`);
|
||||
if (activeContent) {
|
||||
activeContent.classList.add('active');
|
||||
|
||||
// 获取选中的分类ID
|
||||
const selectedCategoryId = this.getAttribute('data-tab');
|
||||
|
||||
// 重新加载对应分类的文章
|
||||
if (moduleId === 'opencourse') {
|
||||
loadCategoryArticles(selectedCategoryId, 'webArticlesList');
|
||||
} else {
|
||||
loadCategoryArticles(selectedCategoryId, 'techArticlesList');
|
||||
}
|
||||
|
||||
// 添加切换动画效果
|
||||
activeContent.style.opacity = '0';
|
||||
setTimeout(() => {
|
||||
activeContent.style.opacity = '1';
|
||||
}, 50);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 加载分类文章
|
||||
function loadCategoryArticles(categoryId, containerId) {
|
||||
const url = containerId === 'webArticlesList' ? '/index/index/siteNewslist' : '/index/index/technicalArticleslist';
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.code === 1) {
|
||||
if (categoryId === 'all') {
|
||||
// 显示所有文章
|
||||
renderWebArticles(result.articles, containerId);
|
||||
} else {
|
||||
// 过滤显示选中分类的文章
|
||||
const filteredArticles = result.articles.filter(article => article.cate == categoryId);
|
||||
renderWebArticles(filteredArticles, containerId);
|
||||
}
|
||||
} else {
|
||||
showNoData(containerId);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('请求失败:', error);
|
||||
showError(containerId);
|
||||
});
|
||||
}
|
||||
|
||||
// 渲染文章列表
|
||||
function renderWebArticles(articles, containerId) {
|
||||
const container = document.getElementById(containerId);
|
||||
if (!container) return;
|
||||
|
||||
let html = '';
|
||||
if (Array.isArray(articles)) {
|
||||
articles.forEach(article => {
|
||||
html += createArticleHtml(article);
|
||||
});
|
||||
}
|
||||
|
||||
container.innerHTML = html || '<div class="no-data">暂无数据</div>';
|
||||
}
|
||||
|
||||
// 创建文章HTML
|
||||
function createArticleHtml(article) {
|
||||
if (!article) return '';
|
||||
|
||||
// 格式化日期
|
||||
const publishDate = new Date(article.publishdate * 1000);
|
||||
const formattedDate = publishDate.toLocaleDateString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit'
|
||||
});
|
||||
|
||||
return `
|
||||
<div class="opencourse product-item" onclick="window.open('/index/article/detail?id=${article.id || ''}', '_blank')">
|
||||
<div class="video">
|
||||
<img src="${article.image || ''}" alt="" class="cover">
|
||||
</div>
|
||||
<div class="introduction">
|
||||
<div class="title">${article.title || '无标题'}</div>
|
||||
<div class="publishdate">${formattedDate}</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="views"><i class="fa-solid fa-eye"></i><span style="margin-left: 5px;">${article.views || 0}</span></div>
|
||||
<div class="author"><i class="fa-regular fa-user"></i><span style="margin-left: 5px;">${article.author || '未知作者'}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// 页面加载完成后执行
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadWebArticles();
|
||||
loadTechArticles();
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
<footer class="footer" style="background-image: url(/static/images/footer-bg-1.png)">
|
||||
<div class="container">
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?php /*a:5:{s:52:"E:\Demo\PHP\yunzer\app\index\view\article\detail.php";i:1746808591;s:52:"E:\Demo\PHP\yunzer\app\index\view\component\head.php";i:1746808024;s:61:"E:\Demo\PHP\yunzer\app\index\view\component\header-simple.php";i:1746808182;s:54:"E:\Demo\PHP\yunzer\app\index\view\component\footer.php";i:1746796639;s:52:"E:\Demo\PHP\yunzer\app\index\view\component\foot.php";i:1746808046;}*/ ?>
|
||||
<?php /*a:5:{s:52:"E:\Demo\PHP\yunzer\app\index\view\article\detail.php";i:1746808591;s:52:"E:\Demo\PHP\yunzer\app\index\view\component\head.php";i:1746890051;s:61:"E:\Demo\PHP\yunzer\app\index\view\component\header-simple.php";i:1746808182;s:54:"E:\Demo\PHP\yunzer\app\index\view\component\footer.php";i:1746796639;s:52:"E:\Demo\PHP\yunzer\app\index\view\component\foot.php";i:1746808046;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
@ -9,7 +9,10 @@
|
||||
<link rel="stylesheet" href="/static/layui/css/layui.css">
|
||||
<link rel="stylesheet" href="/static/css/style.css">
|
||||
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="/static/css/fontawesome.css">
|
||||
|
||||
<script src="/static/layui/layui.js" charset="utf-8"></script>
|
||||
<script src="/static/js/bootstrap.bundle.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||