496 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			496 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| {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>
 | |
| 
 | |
|         <div class="game-navigation">
 | |
|             <div class="prev-game" id="prevGame">
 | |
|             </div>
 | |
|             <div class="next-game" id="nextGame">
 | |
|             </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-1"><?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;
 | |
|         }
 | |
| 
 | |
|         // 获取游戏详情
 | |
|         fetch('/index/game/detail?id=' + gameId, {
 | |
|             headers: {
 | |
|                 'X-Requested-With': 'XMLHttpRequest'
 | |
|             }
 | |
|         })
 | |
|         .then(response => response.json())
 | |
|         .then(result => {
 | |
|             if (result.code === 1) {
 | |
|                 // 渲染上一篇
 | |
|                 const prevGame = document.getElementById('prevGame');
 | |
|                 if (result.data.prevGame) {
 | |
|                     prevGame.innerHTML = `
 | |
|                         <a href="/index/game/detail?id=${result.data.prevGame.id}">
 | |
|                             <i class="fa fa-arrow-left"></i> 上一篇:${result.data.prevGame.title}
 | |
|                         </a>
 | |
|                     `;
 | |
|                 } else {
 | |
|                     prevGame.innerHTML = '<span class="disabled"><i class="fa fa-arrow-left"></i> 没有上一篇了</span>';
 | |
|                 }
 | |
| 
 | |
|                 // 渲染下一篇
 | |
|                 const nextGame = document.getElementById('nextGame');
 | |
|                 if (result.data.nextGame) {
 | |
|                     nextGame.innerHTML = `
 | |
|                         <a href="/index/game/detail?id=${result.data.nextGame.id}">
 | |
|                             下一篇:${result.data.nextGame.title} <i class="fa fa-arrow-right"></i>
 | |
|                         </a>
 | |
|                     `;
 | |
|                 } else {
 | |
|                     nextGame.innerHTML = '<span class="disabled">没有下一篇了 <i class="fa fa-arrow-right"></i></span>';
 | |
|                 }
 | |
|             }
 | |
|         })
 | |
|         .catch(error => {
 | |
|             console.error('获取游戏详情失败:', error);
 | |
|         });
 | |
| 
 | |
|         // 更新访问次数
 | |
|         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.open(data.data.url, '_blank');
 | |
|                             } 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 = '<?php echo $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: 30px;
 | |
|         font-weight: 700;
 | |
|         color: #333;
 | |
|         margin-bottom: 15px;
 | |
|         line-height: 1.4;
 | |
|         display: -webkit-box;
 | |
|         -webkit-line-clamp: 2;
 | |
|         -webkit-box-orient: vertical;
 | |
|         overflow: hidden;
 | |
|     }
 | |
| 
 | |
|     .game-title-1 {
 | |
|         font-size: 16px;
 | |
|         font-weight: 700;
 | |
|         color: #333;
 | |
|         margin-bottom: 15px;
 | |
|         line-height: 1.4;
 | |
|         display: -webkit-box;
 | |
|         -webkit-line-clamp: 2;
 | |
|         -webkit-box-orient: vertical;
 | |
|         overflow: hidden;
 | |
|     }
 | |
| 
 | |
|     .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;
 | |
|     }
 | |
| 
 | |
|     .game-navigation {
 | |
|         display: flex;
 | |
|         justify-content: space-between;
 | |
|         margin: 30px 0;
 | |
|     }
 | |
| 
 | |
|     .prev-game,
 | |
|     .next-game {
 | |
|         max-width: 45%;
 | |
|     }
 | |
| 
 | |
|     .prev-game a,
 | |
|     .next-game a {
 | |
|         color: #333 !important;
 | |
|         text-decoration: none;
 | |
|     }
 | |
| 
 | |
|     .prev-game a:hover,
 | |
|     .next-game a:hover {
 | |
|         color: #f57005 !important;
 | |
|         transition: all 0.3s ease;
 | |
|     }
 | |
| 
 | |
|     .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-games h3{
 | |
|         font-size: 20px;
 | |
|         font-weight: 600;
 | |
|         margin-bottom: 20px;
 | |
|         padding-bottom: 10px;
 | |
|         border-bottom: 1px solid #eee;
 | |
|     }
 | |
| 
 | |
|     .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;
 | |
|     }
 | |
| 
 | |
|     .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" /}
 | 
