增加游戏模块
This commit is contained in:
@@ -84,6 +84,27 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏下载模块 -->
|
||||
<div class="core-block core-module" id="gameDownload" style="order: 3;">
|
||||
<div class="module-header">
|
||||
<div>
|
||||
<div class="ModuleTitle_titleWrapper">
|
||||
<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" id="gameDownloadList">
|
||||
<!-- 游戏将通过JavaScript动态加载 -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -204,6 +225,32 @@
|
||||
});
|
||||
}
|
||||
|
||||
// 加载游戏下载
|
||||
function loadGames() {
|
||||
fetch('/index/index/gameList')
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.code === 0) {
|
||||
// 渲染分类标签
|
||||
if (result.data.categories) {
|
||||
renderCategoryTabs(result.data.categories, 'gameDownload');
|
||||
}
|
||||
// 渲染游戏列表
|
||||
if (result.data.games && result.data.games.length > 0) {
|
||||
renderGames(result.data.games, 'gameDownloadList');
|
||||
} else {
|
||||
showNoData('gameDownloadList');
|
||||
}
|
||||
} else {
|
||||
showNoData('gameDownloadList');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('请求失败:', error);
|
||||
showError('gameDownloadList');
|
||||
});
|
||||
}
|
||||
|
||||
// 显示无数据提示
|
||||
function showNoData(containerId) {
|
||||
document.getElementById(containerId).innerHTML = '<div class="no-data">暂无数据</div>';
|
||||
@@ -266,6 +313,9 @@
|
||||
case 'programDownload':
|
||||
loadCategoryPrograms(selectedCategoryId, 'programDownloadList');
|
||||
break;
|
||||
case 'gameDownload':
|
||||
loadCategoryGames(selectedCategoryId, 'gameDownloadList');
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -506,11 +556,70 @@
|
||||
});
|
||||
}
|
||||
|
||||
// 渲染游戏列表
|
||||
function renderGames(games, containerId) {
|
||||
const container = document.getElementById(containerId);
|
||||
if (!container) return;
|
||||
|
||||
let html = '';
|
||||
if (Array.isArray(games)) {
|
||||
games.forEach(game => {
|
||||
html += createGameHtml(game);
|
||||
});
|
||||
}
|
||||
|
||||
container.innerHTML = html || '<div class="no-data">暂无数据</div>';
|
||||
}
|
||||
|
||||
// 创建游戏HTML
|
||||
function createGameHtml(game) {
|
||||
if (!game) return '';
|
||||
|
||||
return `
|
||||
<div class="opencourse product-item" onclick="window.open('/index/game/detail?id=${game.id || ''}', '_blank')">
|
||||
<div class="video">
|
||||
<img src="${game.icon || '/static/images/default-game.png'}" alt="" class="cover">
|
||||
</div>
|
||||
<div class="introduction">
|
||||
<div class="title">${game.title || '无标题'}</div>
|
||||
<div class="publishdate">${game.create_time || ''}</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="views"><i class="fa-solid fa-eye"></i><span style="margin-left: 5px;">${game.views || 0}</span></div>
|
||||
<div class="author"><i class="fa-regular fa-user"></i><span style="margin-left: 5px;">${game.uploader || '未知作者'}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// 加载分类游戏
|
||||
function loadCategoryGames(categoryId, containerId) {
|
||||
fetch('/index/index/gameList')
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.code === 0) {
|
||||
if (categoryId === 'all') {
|
||||
renderGames(result.data.games, containerId);
|
||||
} else {
|
||||
const filteredGames = result.data.games.filter(game => game.cate == categoryId);
|
||||
renderGames(filteredGames, containerId);
|
||||
}
|
||||
} else {
|
||||
showNoData(containerId);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('请求失败:', error);
|
||||
showError(containerId);
|
||||
});
|
||||
}
|
||||
|
||||
// 页面加载完成后执行
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadWebArticles();
|
||||
loadTechArticles();
|
||||
loadResources();
|
||||
loadPrograms();
|
||||
loadGames();
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,414 @@
|
||||
{include file="component/head" /}
|
||||
{include file="component/header-simple" /}
|
||||
<div class="main">
|
||||
<div class="location">
|
||||
<div class="container">
|
||||
<div class="location-item">
|
||||
<a href="/">首页</a>
|
||||
<span>></span>
|
||||
<a href="/index/game/list" id="cateLink"><?php echo $cateName; ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="game-detail">
|
||||
<div class="game-info">
|
||||
<div class="game-header">
|
||||
<h1 class="game-title"><?php echo $game['title']; ?></h1>
|
||||
<div class="game-meta">
|
||||
<span class="game-category"><?php echo $cateName; ?></span>
|
||||
<span class="game-views"><i class="fa-solid fa-eye"></i> <?php echo $game['views']; ?> 次浏览</span>
|
||||
<span class="game-downloads"><i class="fa-solid fa-download"></i> <span
|
||||
id="gameDownloads"><?php echo $game['downloads']; ?></span> 次下载</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="game-content">
|
||||
<div class="game-cover">
|
||||
<img src="<?php echo $game['icon'] ?: '/static/images/default-game.png'; ?>"
|
||||
alt="<?php echo $game['title']; ?>">
|
||||
</div>
|
||||
<div class="game-desc">
|
||||
<?php echo $game['content']; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="game-actions">
|
||||
<div style="display: flex;gap: 30px;}">
|
||||
<button id="downloadBtn" class="btn btn-primary">
|
||||
<i class="fa-solid fa-download"></i> 立即下载
|
||||
</button>
|
||||
<button id="codeBtn" class="codebtn">
|
||||
<i class="fa-solid fa-download"></i> 分享码:<?php echo $game['code']; ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 相关游戏 -->
|
||||
<?php if (!empty($relatedGames)): ?>
|
||||
<div class="related-games">
|
||||
<h3>相关游戏</h3>
|
||||
<div class="game-list">
|
||||
<?php foreach ($relatedGames as $related): ?>
|
||||
<div class="game-item"
|
||||
onclick="window.location.href='/index/game/detail?id=<?php echo $related['id']; ?>'">
|
||||
<div class="game-cover">
|
||||
<img src="<?php echo $related['icon'] ?: '/static/images/default-game.png'; ?>"
|
||||
alt="<?php echo $related['title']; ?>">
|
||||
</div>
|
||||
<div class="game-info">
|
||||
<h4 class="game-title"><?php echo $related['title']; ?></h4>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 返回顶部按钮 -->
|
||||
<div class="go-to-top" id="goToTop">
|
||||
<i class="layui-icon layui-icon-top"></i>
|
||||
</div>
|
||||
|
||||
{include file="component/footer" /}
|
||||
|
||||
<script>
|
||||
// 页面加载完成后执行
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// 获取游戏ID
|
||||
const gameId = new URLSearchParams(window.location.search).get('id');
|
||||
if (!gameId) {
|
||||
alert('游戏ID不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新访问次数
|
||||
updateGameViews(gameId);
|
||||
|
||||
// 下载功能
|
||||
const downloadBtn = document.getElementById('downloadBtn');
|
||||
if (downloadBtn) {
|
||||
downloadBtn.addEventListener('click', function () {
|
||||
fetch('/index/game/downloadurl?id=' + gameId, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.code === 1) {
|
||||
const downloadsElement = document.getElementById('gameDownloads');
|
||||
let downloads = parseInt(downloadsElement.textContent);
|
||||
downloadsElement.textContent = downloads + 1;
|
||||
|
||||
// 直接使用返回的URL
|
||||
if (data.data && data.data.url) {
|
||||
window.location.href = data.data.url;
|
||||
} else {
|
||||
alert('下载地址不存在');
|
||||
}
|
||||
} else {
|
||||
alert('下载失败:' + data.msg);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('下载请求失败:', error);
|
||||
alert('下载请求失败,请稍后重试');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//复制分享码
|
||||
const codeBtn = document.getElementById('codeBtn');
|
||||
if (codeBtn) {
|
||||
codeBtn.addEventListener('click', function() {
|
||||
const code = '{$game.code}';
|
||||
if (code) {
|
||||
// 创建一个临时输入框
|
||||
const tempInput = document.createElement('input');
|
||||
tempInput.value = code;
|
||||
document.body.appendChild(tempInput);
|
||||
tempInput.select();
|
||||
|
||||
try {
|
||||
// 尝试使用传统的复制方法
|
||||
document.execCommand('copy');
|
||||
layer.msg('分享码已复制到剪贴板');
|
||||
} catch (err) {
|
||||
console.error('复制失败:', err);
|
||||
layer.msg('复制失败,请手动复制');
|
||||
} finally {
|
||||
// 移除临时输入框
|
||||
document.body.removeChild(tempInput);
|
||||
}
|
||||
} else {
|
||||
layer.msg('分享码不存在');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 返回顶部功能
|
||||
const goToTop = document.getElementById('goToTop');
|
||||
|
||||
// 监听滚动事件
|
||||
window.addEventListener('scroll', function () {
|
||||
if (window.pageYOffset > 300) {
|
||||
goToTop.classList.add('show');
|
||||
} else {
|
||||
goToTop.classList.remove('show');
|
||||
}
|
||||
});
|
||||
|
||||
// 点击返回顶部
|
||||
goToTop.addEventListener('click', function () {
|
||||
window.scrollTo({
|
||||
top: 0,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// 更新游戏访问次数
|
||||
function updateGameViews(gameId) {
|
||||
fetch('/index/game/updateViews', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: 'id=' + gameId
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.code === 1) {
|
||||
const viewsElement = document.querySelector('.game-views');
|
||||
if (viewsElement) {
|
||||
viewsElement.innerHTML = `<i class="fa-solid fa-eye"></i> ${result.data.views} 次浏览`;
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('更新访问次数失败:', error);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.location {
|
||||
max-width: 1000px;
|
||||
margin: 30px auto;
|
||||
}
|
||||
|
||||
.game-detail {
|
||||
max-width: 1000px;
|
||||
margin: 30px auto;
|
||||
padding: 50px;
|
||||
background: #fff;
|
||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.game-header {
|
||||
margin-bottom: 30px;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.game-title {
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
margin-bottom: 15px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.game-meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 20px;
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.game-meta span {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.game-meta i {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.game-content {
|
||||
line-height: 1.8;
|
||||
color: #333;
|
||||
font-size: 16px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.game-cover {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.game-cover img {
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.game-desc {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.game-actions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 40px;
|
||||
margin: 30px 0;
|
||||
padding: 20px 0;
|
||||
border-top: 1px solid #eee;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.btn {
|
||||
/* background: #f57005; */
|
||||
color: #fff;
|
||||
padding: 15px 30px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
/* background: #e66600; */
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.codebtn{
|
||||
color:#0d6efd;
|
||||
padding: 15px 30px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #0d6efd;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.codebtn:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.related-games {
|
||||
margin: 40px 0;
|
||||
}
|
||||
|
||||
.related-title {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.game-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.game-item {
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.game-item:hover {
|
||||
transform: translateY(-5px);
|
||||
}
|
||||
|
||||
.game-item a {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.game-cover img {
|
||||
width: 100%;
|
||||
height: 150px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.game-info {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.game-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 5px;
|
||||
color: #333;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.go-to-top {
|
||||
position: fixed;
|
||||
right: 30px;
|
||||
bottom: 30px;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background: #f57005;
|
||||
color: #fff;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.go-to-top.show {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.go-to-top:hover {
|
||||
background: #e66600;
|
||||
transform: translateY(-3px);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.game-title {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.game-list {
|
||||
grid-template-columns: repeat(1, 1fr);
|
||||
}
|
||||
|
||||
.game-meta {
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.go-to-top {
|
||||
right: 20px;
|
||||
bottom: 20px;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
}
|
||||
}
|
||||
|
||||
.location-item a {
|
||||
color: #000 !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
{include file="component/foot" /}
|
||||
Reference in New Issue
Block a user