优化前端资源详情页代码

This commit is contained in:
2025-07-10 11:32:20 +08:00
parent 48829a5e2a
commit 6b32df5368
3 changed files with 367 additions and 204 deletions
+217 -104
View File
@@ -9,14 +9,14 @@
<div class="main-top">
<div class="main-top-main">
<div class="main-title">
<?php echo $game['title']; ?>
<?php echo $resources['title']; ?>
</div>
<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>
<a href="/index/resources/list" id="cateLink"><?php echo $cateName; ?></a>
</div>
</div>
</div>
@@ -29,27 +29,27 @@
<div class="detail-top-card">
<div class="detail-top-card-left">
<div class="article-cover">
<div class="swiper game-swiper">
<div class="swiper resources-swiper">
<div class="swiper-wrapper">
{php}
// 兼容字符串和数组
$images = isset($game['images']) ? $game['images'] : [];
$images = isset($resources['images']) ? $resources['images'] : [];
if (is_string($images)) {
$images = explode(',', $images);
}
$images = array_filter($images); // 移除空值
if (empty($images) && !empty($game['icon'])) {
$images = [$game['icon']];
if (empty($images) && !empty($resources['icon'])) {
$images = [$resources['icon']];
}
{/php}
{volist name="images" id="image"}
<div class="swiper-slide">
<a href="<?php $img = trim($image, ', ');
echo (strpos($img, 'http') === 0 ? $img : request()->domain() . $img); ?>"
data-lightbox="game-gallery">
data-lightbox="resources-gallery">
<img src="<?php $img = trim($image, ', ');
echo (strpos($img, 'http') === 0 ? $img : request()->domain() . $img); ?>"
alt="<?php echo $game['title']; ?>">
alt="<?php echo $resources['title']; ?>">
</a>
</div>
{/volist}
@@ -64,7 +64,7 @@
<!-- <div class="detail-top-card-right-top">
<div class="collect-btn">
<button class="btn btn-primary" id="collectBtn"
data-game-id="<?php echo $game['id']; ?>">
data-resources-id="<?php echo $resources['id']; ?>">
<i class="fa-solid fa-heart"></i> 收藏
</button>
</div>
@@ -75,13 +75,13 @@
</div>
</div> -->
<div class="detail-top-card-right-middle">
<div class="game-info">
<div class="resources-info">
<div class="title">Free</div>
<div class="infos">
<div style="display: flex;">
<div class="infoitem">
<span>程序编号:</span>
<span class="infoitem-value"><?php echo $game['number']; ?></span>
<span class="infoitem-value"><?php echo $resources['number']; ?></span>
</div>
<div class="infoitem">
<span>所属分类:</span>
@@ -92,16 +92,16 @@
<div class="infoitem">
<span>更新时间:</span>
<span
class="infoitem-value"><?php echo date('Y-m-d', $game['create_time']); ?></span>
class="infoitem-value"><?php echo date('Y-m-d', $resources['create_time']); ?></span>
</div>
<div class="infoitem">
<span>查看:</span>
<span class="infoitem-value"><?php echo $game['views']; ?></span>
<span class="infoitem-value"><?php echo $resources['views']; ?></span>
<span>次</span>
</div>
<div class="infoitem">
<span>下载:</span>
<span class="infoitem-value"><?php echo $game['downloads']; ?></span>
<span class="infoitem-value"><?php echo $resources['downloads']; ?></span>
<span>次</span>
</div>
</div>
@@ -109,13 +109,13 @@
</div>
</div>
<div class="detail-top-card-right-bottom">
<div class="game-actions1">
<div class="resources-actions1">
<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']; ?>
<i class="fa-solid fa-download"></i> 分享码:<?php echo $resources['code']; ?>
</button>
</div>
</div>
@@ -124,25 +124,61 @@
</div>
</div>
<div class="detail-top-right">
这里放个人信息
<div class="aboutauthor-main">
<div class="aboutauthor-main-top">
<div class="aboutauthor-avatar">
<img src="{$authorInfo.avatar}" alt="作者头像">
</div>
<div class="aboutauthor-info">
<div class="author-name">{$authorInfo.name}</div>
</div>
</div>
<div class="aboutauthor-main-middle">
<div class="author-stats">
<div class="author-stats-item">
<h6>资源</h6>
<span class="count">{$authorInfo.resource_count}</span>
</div>
<div class="author-stats-item">
<h6>文章</h6>
<span class="count">{$authorInfo.article_count}</span>
</div>
<div class="author-stats-item">
<h6>粉丝</h6>
<span class="count">
0
</span>
</div>
</div>
</div>
</div>
<div class="aboutauthor-btn">
<button class="follow-btn">
<i class="fa fa-user-plus"></i> 关注他
</button>
<button class="message-btn">
<i class="fa fa-envelope"></i> 发私信
</button>
</div>
</div>
</div>
<div class="detail-middle">
<div class="detial-middle-left">
<div class="game-detail">
<div class="game-info">
<div class="game-content">
<div class="game-desc">
<?php echo $game['content']; ?>
<div class="resources-detail">
<div class="resources-info">
<div class="resources-content">
<div class="resources-desc">
<?php echo $resources['content']; ?>
</div>
</div>
<div class="game-actions">
<div class="resources-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']; ?>
<i class="fa-solid fa-download"></i> 分享码:<?php echo $resources['code']; ?>
</button>
</div>
</div>
@@ -157,27 +193,27 @@
</div>
</div>
<div class="game-navigation">
<div class="prev-game" id="prevGame">
<div class="resources-navigation">
<div class="prev-resources" id="prevResources">
</div>
<div class="next-game" id="nextGame">
<div class="next-resources" id="nextResources">
</div>
</div>
<!-- 相关游戏 -->
<?php if (!empty($relatedGames)): ?>
<div class="related-games">
<!-- 相关资源 -->
<?php if (!empty($relatedResourcess)): ?>
<div class="related-resourcess">
<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'; ?>"
<div class="resources-list">
<?php foreach ($relatedResourcess as $related): ?>
<div class="resources-item"
onclick="window.location.href='/index/resources/detail?id=<?php echo $related['id']; ?>'">
<div class="resources-cover">
<img src="<?php echo $related['icon'] ?: '/static/images/default-resources.png'; ?>"
alt="<?php echo $related['title']; ?>">
</div>
<div class="game-info">
<h4 class="game-title-1"><?php echo $related['title']; ?></h4>
<div class="resources-info">
<h4 class="resources-title-1"><?php echo $related['title']; ?></h4>
</div>
</div>
<?php endforeach; ?>
@@ -205,15 +241,15 @@
// 页面加载完成后执行
document.addEventListener('DOMContentLoaded', function () {
// 获取游戏ID
const gameId = new URLSearchParams(window.location.search).get('id');
if (!gameId) {
alert('游戏ID不存在');
// 获取资源ID
const resourcesId = new URLSearchParams(window.location.search).get('id');
if (!resourcesId) {
alert('资源ID不存在');
return;
}
// 获取游戏详情
fetch('/index/game/detail?id=' + gameId, {
// 获取资源详情
fetch('/index/resources/detail?id=' + resourcesId, {
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
@@ -222,42 +258,42 @@
.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}
const prevResources = document.getElementById('prevResources');
if (result.data.prevResources) {
prevResources.innerHTML = `
<a href="/index/resources/detail?id=${result.data.prevResources.id}">
<i class="fa fa-arrow-left"></i> 上一篇:${result.data.prevResources.title}
</a>
`;
} else {
prevGame.innerHTML = '<span class="disabled"><i class="fa fa-arrow-left"></i> 没有上一篇了</span>';
prevResources.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>
const nextResources = document.getElementById('nextResources');
if (result.data.nextResources) {
nextResources.innerHTML = `
<a href="/index/resources/detail?id=${result.data.nextResources.id}">
下一篇:${result.data.nextResources.title} <i class="fa fa-arrow-right"></i>
</a>
`;
} else {
nextGame.innerHTML = '<span class="disabled">没有下一篇了 <i class="fa fa-arrow-right"></i></span>';
nextResources.innerHTML = '<span class="disabled">没有下一篇了 <i class="fa fa-arrow-right"></i></span>';
}
}
})
.catch(error => {
console.error('获取游戏详情失败:', error);
console.error('获取资源详情失败:', error);
});
// 更新访问次数
updateGameViews(gameId);
updateResourcesViews(resourcesId);
// 下载功能
const downloadBtn = document.getElementById('downloadBtn');
if (downloadBtn) {
downloadBtn.addEventListener('click', function () {
fetch('/index/game/downloadurl?id=' + gameId, {
fetch('/index/resources/downloadurl?id=' + resourcesId, {
method: 'GET',
headers: {
'X-Requested-With': 'XMLHttpRequest'
@@ -271,7 +307,7 @@
})
.then(data => {
if (data.code === 1) {
const downloadsElement = document.getElementById('gameDownloads');
const downloadsElement = document.getElementById('resourcesDownloads');
if (downloadsElement) {
let downloads = parseInt(downloadsElement.textContent);
downloadsElement.textContent = downloads + 1;
@@ -295,7 +331,7 @@
}
const swiper = new Swiper('.game-swiper', {
const swiper = new Swiper('.resources-swiper', {
slidesPerView: 1,
spaceBetween: 30,
loop: true,
@@ -332,7 +368,7 @@
const codeBtn = document.getElementById('codeBtn');
if (codeBtn) {
codeBtn.addEventListener('click', function () {
const code = '<?php echo $game['code']; ?>';
const code = '<?php echo $resources['code']; ?>';
if (code) {
// 创建一个临时输入框
const tempInput = document.createElement('input');
@@ -376,20 +412,20 @@
}
});
// 更新游戏访问次数
function updateGameViews(gameId) {
fetch('/index/game/updateViews', {
// 更新资源访问次数
function updateResourcesViews(resourcesId) {
fetch('/index/resources/updateViews', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
},
body: 'id=' + gameId
body: 'id=' + resourcesId
})
.then(response => response.json())
.then(result => {
if (result.code === 1) {
const viewsElement = document.querySelector('.game-views');
const viewsElement = document.querySelector('.resources-views');
if (viewsElement) {
viewsElement.innerHTML = `<i class="fa-solid fa-eye"></i> ${result.data.views}`;
}
@@ -494,31 +530,31 @@
.detail-top-card-right-middle {}
.detail-top-card-right-middle .game-info {
.detail-top-card-right-middle .resources-info {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 100%;
}
.detail-top-card-right-middle .game-info .title {
.detail-top-card-right-middle .resources-info .title {
font-size: 30px;
font-weight: 700;
color: #42d697;
margin-bottom: 15px;
}
.detail-top-card-right-middle .game-info .infos {
.detail-top-card-right-middle .resources-info .infos {
display: flex;
flex-direction: column;
gap: 20px;
}
.detail-top-card-right-middle .game-info .infos .infoitem {
.detail-top-card-right-middle .resources-info .infos .infoitem {
margin-right: 40px;
}
.detail-top-card-right-middle .game-info .infos .infoitem span {
.detail-top-card-right-middle .resources-info .infos .infoitem span {
color: #7d879c;
}
@@ -545,20 +581,20 @@
color: #fff !important;
}
.game-detail {
.resources-detail {
padding: 50px;
background: #fff;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
.game-header {
.resources-header {
margin-bottom: 30px;
border-bottom: 1px solid #eee;
padding-bottom: 20px;
}
.game-title {
.resources-title {
font-size: 30px;
font-weight: 700;
color: #333;
@@ -570,7 +606,7 @@
overflow: hidden;
}
.game-title-1 {
.resources-title-1 {
font-size: 16px;
font-weight: 700;
color: #333;
@@ -582,7 +618,7 @@
overflow: hidden;
}
.game-meta {
.resources-meta {
display: flex;
flex-wrap: wrap;
gap: 20px;
@@ -590,38 +626,38 @@
font-size: 14px;
}
.game-meta span {
.resources-meta span {
display: flex;
align-items: center;
}
.game-meta i {
.resources-meta i {
margin-right: 5px;
}
.game-content {
.resources-content {
line-height: 1.8;
color: #333;
font-size: 16px;
margin-bottom: 30px;
}
.game-cover {
.resources-cover {
margin-bottom: 20px;
}
.game-cover img {
.resources-cover img {
width: 100%;
height: 300px;
object-fit: cover;
border-radius: 8px;
}
.game-desc {
.resources-desc {
margin-bottom: 30px;
}
.game-actions {
.resources-actions {
display: flex;
justify-content: center;
gap: 40px;
@@ -631,30 +667,30 @@
border-bottom: 1px solid #eee;
}
.game-actions1 {
.resources-actions1 {
display: flex;
margin: 20px 0;
}
.game-navigation {
.resources-navigation {
display: flex;
justify-content: space-between;
margin: 30px 0;
}
.prev-game,
.next-game {
.prev-resources,
.next-resources {
max-width: 45%;
}
.prev-game a,
.next-game a {
.prev-resources a,
.next-resources a {
color: #333 !important;
text-decoration: none;
}
.prev-game a:hover,
.next-game a:hover {
.prev-resources a:hover,
.next-resources a:hover {
color: #f57005 !important;
transition: all 0.3s ease;
}
@@ -687,11 +723,11 @@
transform: translateY(-2px);
}
.related-games {
.related-resourcess {
margin: 40px 0;
}
.related-games h3 {
.related-resourcess h3 {
font-size: 20px;
font-weight: 600;
margin-bottom: 20px;
@@ -707,35 +743,35 @@
border-bottom: 1px solid #eee;
}
.game-list {
.resources-list {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-columns: repeat(5, 1fr);
gap: 20px;
}
.game-item {
.resources-item {
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
transition: transform 0.3s;
}
.game-item:hover {
.resources-item:hover {
transform: translateY(-5px);
}
.game-item a {
.resources-item a {
text-decoration: none;
color: inherit;
}
.game-cover img {
.resources-cover img {
width: 100%;
height: 150px;
object-fit: cover;
}
.game-info {
.resources-info {
padding: 10px;
}
@@ -770,15 +806,15 @@
}
@media (max-width: 768px) {
.game-title {
.resources-title {
font-size: 24px;
}
.game-list {
.resources-list {
grid-template-columns: repeat(1, 1fr);
}
.game-meta {
.resources-meta {
gap: 10px;
}
@@ -838,6 +874,83 @@
.swiper .swiper-button-next:after {
font-size: 18px;
}
/* about author css */
.detail-top-right .aboutauthor-main {
display: flex;
flex-direction: column;
padding: 20px;
}
.detail-top-right .aboutauthor-main .aboutauthor-main-top {
display: flex;
align-items: center;
padding-left: 20px !important;
padding: 20px 0;
border-bottom: 1px solid #efefef;
margin-bottom: 20px;
}
.detail-top-right .aboutauthor-main .aboutauthor-main-top .aboutauthor-avatar {
margin-right: 12px;
}
.detail-top-right .aboutauthor-main .aboutauthor-main-top .aboutauthor-info .author-name {
font-size: 20px;
font-weight: 700;
}
.detail-top-right .aboutauthor-main .aboutauthor-main-top .aboutauthor-avatar img {
width: 60px;
height: 60px;
border-radius: 4px;
box-sizing: border-box;
margin: 0px;
min-width: 0px;
max-width: 100%;
background-color: #fff;
}
.detail-top-right .aboutauthor-main .aboutauthor-main-middle {
/* margin-left: 20px; */
}
.detail-top-right .aboutauthor-main .aboutauthor-main-middle .author-stats {
display: flex;
justify-content: space-evenly;
}
.detail-top-right .aboutauthor-main .aboutauthor-main-middle .author-stats .author-stats-item {
display: flex;
flex-direction: column;
align-items: center;
}
.detail-top-right .aboutauthor-main .aboutauthor-main-middle .author-stats .author-stats-item .count {
/* font-size: 30px; */
font-weight: 700;
}
.detail-top-right .aboutauthor-btn {
display: flex;
justify-content: space-evenly;
padding: 20px 0;
}
.detail-top-right .aboutauthor-btn .follow-btn {
background-color: #0081ff;
color: #fff;
padding: 10px 20px;
border-radius: 8px;
border: none;
}
.detail-top-right .aboutauthor-btn .message-btn {
color: #0081ff;
padding: 10px 20px;
border-radius: 8px;
border: 1px solid #eee;
}
</style>
{include file="component/foot" /}