优化前端资源详情页代码

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

View File

@ -17,7 +17,7 @@
*/ */
/** /**
* 游戏下载控制器 * 资源下载控制器
*/ */
namespace app\index\controller; namespace app\index\controller;
use app\index\controller\BaseController; use app\index\controller\BaseController;
@ -27,6 +27,8 @@ use think\facade\Request;
use app\index\model\Resources\Resources; use app\index\model\Resources\Resources;
use app\index\model\Resources\ResourcesCategory; use app\index\model\Resources\ResourcesCategory;
use app\index\model\Attachments; use app\index\model\Attachments;
use app\index\model\Users;
use app\index\model\Articles\Articles;
class ResourcesController extends BaseController class ResourcesController extends BaseController
{ {
@ -66,7 +68,7 @@ class ResourcesController extends BaseController
return View::fetch(); return View::fetch();
} }
// 游戏列表页 // 资源列表页
public function list() public function list()
{ {
$cid = input('cid/d', 0); $cid = input('cid/d', 0);
@ -99,60 +101,84 @@ class ResourcesController extends BaseController
return View::fetch('list'); return View::fetch('list');
} }
// 游戏详情页 // 资源详情页
public function detail() public function detail()
{ {
$id = Request::param('id/d', 0); $id = Request::param('id/d', 0);
$game = Resources::where('id', $id)->find(); $resources = Resources::where('id', $id)->find();
if (!$game) { if (!$resources) {
return json(['code' => 0, 'msg' => '游戏不存在或已被删除']); return json(['code' => 0, 'msg' => '资源不存在或已被删除']);
} }
// 如果size没有从附件表中获取 // 如果size没有从附件表中获取
if (empty($game['size']) && !empty($game['fileurl'])) { if (empty($resources['size']) && !empty($resources['fileurl'])) {
$attachment = Attachments::where('src', $game['fileurl']) $attachment = Attachments::where('src', $resources['fileurl'])
->find(); ->find();
if ($attachment && !empty($attachment['size'])) { if ($attachment && !empty($attachment['size'])) {
$size = $attachment['size']; $size = $attachment['size'];
// 转换文件大小为合适的单位 // 转换文件大小为合适的单位
if ($size >= 1073741824) { // 1GB = 1024MB = 1024*1024KB = 1024*1024*1024B if ($size >= 1073741824) { // 1GB = 1024MB = 1024*1024KB = 1024*1024*1024B
$game['size'] = round($size / 1073741824, 2) . 'GB'; $resources['size'] = round($size / 1073741824, 2) . 'GB';
} elseif ($size >= 1048576) { // 1MB = 1024KB = 1024*1024B } elseif ($size >= 1048576) { // 1MB = 1024KB = 1024*1024B
$game['size'] = round($size / 1048576, 2) . 'MB'; $resources['size'] = round($size / 1048576, 2) . 'MB';
} else { } else {
$game['size'] = round($size / 1024, 2) . 'KB'; $resources['size'] = round($size / 1024, 2) . 'KB';
} }
} }
} }
// 获取分类名称 // 获取分类名称
$cateName = ResourcesCategory::where('id', $game['cate']) $cateName = ResourcesCategory::where('id', $resources['cate'])
->value('name'); ->value('name');
// 获取上一个和下一个游戏 // 获取作者信息
$prevGame = Resources::where('id', '<', $id) $authorInfo = Users::where('name', $resources['uploader'])->find();
// var_dump($authorInfo);
if ($authorInfo) {
// 统计作者的文章数
$resourcesCount = Articles::where('author', $resources['uploader'])->count();
// 统计作者的资源数
$resourceCount = Resources::where('uploader', $resources['uploader'])->count();
$authorData = [
'avatar' => $authorInfo['avatar'] ?: '/static/images/avatar.png',
'name' => $authorInfo['name'],
'resource_count' => $resourceCount,
'article_count' => $resourcesCount
];
} else {
$authorData = [
'avatar' => '/static/images/avatar.png',
'name' => $resources['author'],
'resource_count' => 0,
'article_count' => 0
];
}
// 获取上一个和下一个资源
$prevResources = Resources::where('id', '<', $id)
->where('delete_time', null) ->where('delete_time', null)
->where('status', 1) ->where('status', 1)
->where('cate', $game['cate']) ->where('cate', $resources['cate'])
->field(['id', 'title']) ->field(['id', 'title'])
->order('id DESC') ->order('id DESC')
->find(); ->find();
$nextGame = Resources::where('id', '>', $id) $nextResources = Resources::where('id', '>', $id)
->where('delete_time', null) ->where('delete_time', null)
->where('status', 1) ->where('status', 1)
->where('cate', $game['cate']) ->where('cate', $resources['cate'])
->field(['id', 'title']) ->field(['id', 'title'])
->order('id ASC') ->order('id ASC')
->find(); ->find();
// 获取相关游戏(同分类的其他游戏) // 获取相关资源(同分类的其他资源
$relatedGames = Db::table('yz_resources') $relatedResourcess = Db::table('yz_resources')
->alias('g') ->alias('g')
->join('yz_resources_category c', 'g.cate = c.id') ->join('yz_resources_category c', 'g.cate = c.id')
->where('g.cate', $game['cate']) ->where('g.cate', $resources['cate'])
->where('g.id', '<>', $id) ->where('g.id', '<>', $id)
->where('g.delete_time', null) ->where('g.delete_time', null)
->where('g.status', 1) ->where('g.status', 1)
@ -162,7 +188,7 @@ class ResourcesController extends BaseController
'IF(g.icon IS NULL OR g.icon = "", c.icon, g.icon) as icon' 'IF(g.icon IS NULL OR g.icon = "", c.icon, g.icon) as icon'
]) ])
->order('g.id DESC') ->order('g.id DESC')
->limit(3) ->limit(5)
->select() ->select()
->toArray(); ->toArray();
@ -172,28 +198,29 @@ class ResourcesController extends BaseController
'code' => 1, 'code' => 1,
'msg' => '获取成功', 'msg' => '获取成功',
'data' => [ 'data' => [
'game' => $game, 'resources' => $resources,
'cateName' => $cateName, 'cateName' => $cateName,
'prevGame' => $prevGame, 'prevResources' => $prevResources,
'nextGame' => $nextGame, 'nextResources' => $nextResources,
'relatedGames' => $relatedGames 'relatedResourcess' => $relatedResourcess
] ]
]); ]);
} }
// 非 AJAX 请求返回视图 // 非 AJAX 请求返回视图
View::assign([ View::assign([
'game' => $game, 'resources' => $resources,
'cateName' => $cateName, 'cateName' => $cateName,
'prevGame' => $prevGame, 'authorInfo' => $authorData,
'nextGame' => $nextGame, 'prevResources' => $prevResources,
'relatedGames' => $relatedGames 'nextResources' => $nextResources,
'relatedResourcess' => $relatedResourcess
]); ]);
return View::fetch('detail'); return View::fetch('detail');
} }
// 游戏下载 // 资源下载
public function downloadurl() public function downloadurl()
{ {
if (!Request::isAjax()) { if (!Request::isAjax()) {
@ -202,13 +229,13 @@ class ResourcesController extends BaseController
$id = Request::param('id/d', 0); $id = Request::param('id/d', 0);
// 获取游戏信息 // 获取资源信息
$game = Resources::where('id', $id) $resources = Resources::where('id', $id)
->where('delete_time', null) ->where('delete_time', null)
->find(); ->find();
if (!$game) { if (!$resources) {
return json(['code' => 0, 'msg' => '游戏不存在']); return json(['code' => 0, 'msg' => '资源不存在']);
} }
// 更新下载次数 // 更新下载次数
@ -222,7 +249,7 @@ class ResourcesController extends BaseController
'code' => 1, 'code' => 1,
'msg' => '下载成功', 'msg' => '下载成功',
'data' => [ 'data' => [
'url' => $game['url'] 'url' => $resources['url']
] ]
]); ]);
} else { } else {
@ -248,7 +275,7 @@ class ResourcesController extends BaseController
} }
/** /**
* 更新游戏访问次数 * 更新资源访问次数
*/ */
public function updateViews() public function updateViews()
{ {
@ -263,9 +290,9 @@ class ResourcesController extends BaseController
try { try {
// 更新访问次数 // 更新访问次数
$game = Resources::where('id', $id)->find(); $resources = Resources::where('id', $id)->find();
if (!$game) { if (!$resources) {
return json(['code' => 0, 'msg' => '游戏不存在']); return json(['code' => 0, 'msg' => '资源不存在']);
} }
// 更新访问次数 // 更新访问次数

View File

@ -23,7 +23,8 @@
</h3> </h3>
<ul class="category-menu"> <ul class="category-menu">
{volist name="cate.subCategories" id="subCategory"} {volist name="cate.subCategories" id="subCategory"}
<li class="menu-item {$cate.id == $subCategory.id ? 'active' : ''}" data-cateid="{$subCategory.id}"> <li class="menu-item {$cate.id == $subCategory.id ? 'active' : ''}"
data-cateid="{$subCategory.id}">
<span>{$subCategory.name}</span> <span>{$subCategory.name}</span>
<i class="layui-icon layui-icon-right"></i> <i class="layui-icon layui-icon-right"></i>
</li> </li>
@ -38,38 +39,42 @@
<div class="article-grid" id="articleList"> <div class="article-grid" id="articleList">
{volist name="cate.subCategories" id="subCategory"} {volist name="cate.subCategories" id="subCategory"}
{if $cate.id == $subCategory.id} {if $cate.id == $subCategory.id}
{if !empty($subCategory.list)} {if !empty($subCategory.list)}
{volist name="subCategory.list" id="article"} {volist name="subCategory.list" id="article"}
<article class="article-card"> <article class="article-card">
<div class="card-image"> <div class="card-image">
<img src="{$article.image}" alt="{$article.title}"> <img src="{$article.image}" alt="{$article.title}">
<div class="image-overlay"></div> <div class="image-overlay"></div>
</div> </div>
<div class="card-content"> <div class="card-content">
<div class="meta-info"> <div class="meta-info">
<span class="category-tag">${article.category_name || '未分类'}</span> <!-- <span class="category-tag">${article.category_name || '未分类'}</span> -->
<time class="publish-date">${article.create_time || ''}</time> <time class="publish-date">{:date('Y-m-d', $article['create_time'])}</time>
</div>
<h3 class="article-title">${article.title}</h3>
<div class="card-footer">
<div class="stats">
<span class="views"><i class="layui-icon layui-icon-eye"></i> ${article.views || 0}</span>
<span class="likes"><i class="layui-icon layui-icon-praise"></i> ${article.likes || 0}</span>
</div>
<a href="/index/articles/detail?id=${article.id}" class="read-more">阅读更多</a>
</div>
</div>
</article>
{/volist}
{else}
<div class="empty-state">
<div class="empty-icon">
<i class="layui-icon layui-icon-template-1"></i>
</div>
<h4>暂无文章</h4>
<p>当前分类下没有找到相关文章</p>
</div> </div>
{/if}
<a href="/index/articles/detail?id=${article.id}">
<h3 class="article-title">${article.title}</h3>
</a>
<div class="card-footer">
<div class="stats">
<span class="views"><i class="layui-icon layui-icon-eye"></i> ${article.views ||
0}</span>
<span class="likes"><i class="layui-icon layui-icon-praise"></i> ${article.likes ||
0}</span>
</div>
</div>
</div>
</article>
{/volist}
{else}
<div class="empty-state">
<div class="empty-icon">
<i class="layui-icon layui-icon-template-1"></i>
</div>
<h4>暂无文章</h4>
<p>当前分类下没有找到相关文章</p>
</div>
{/if}
{/if} {/if}
{/volist} {/volist}
</div> </div>
@ -82,25 +87,25 @@
</div> </div>
<script> <script>
layui.use(['laypage', 'jquery'], function(){ layui.use(['laypage', 'jquery'], function () {
var laypage = layui.laypage; var laypage = layui.laypage;
var $ = layui.jquery; var $ = layui.jquery;
// 分类切换 // 分类切换
$('.menu-item').on('click', function() { $('.menu-item').on('click', function () {
var cateid = $(this).data('cateid'); var cateid = $(this).data('cateid');
var $menuItems = $('.menu-item'); var $menuItems = $('.menu-item');
// 更新选中状态 // 更新选中状态
$menuItems.removeClass('active'); $menuItems.removeClass('active');
$(this).addClass('active'); $(this).addClass('active');
// 加载文章 // 加载文章
loadArticles(cateid, 1); loadArticles(cateid, 1);
}); });
// 页面加载完成后,自动触发第一个分类的点击事件 // 页面加载完成后,自动触发第一个分类的点击事件
$(document).ready(function() { $(document).ready(function () {
var $firstMenuItem = $('.menu-item').first(); var $firstMenuItem = $('.menu-item').first();
if ($firstMenuItem.length > 0) { if ($firstMenuItem.length > 0) {
$firstMenuItem.click(); $firstMenuItem.click();
@ -116,14 +121,14 @@
cate: cateid, cate: cateid,
page: page page: page
}, },
beforeSend: function() { beforeSend: function () {
$('#articleList').html('<div class="loading-state"><i class="layui-icon layui-icon-loading"></i>加载中...</div>'); $('#articleList').html('<div class="loading-state"><i class="layui-icon layui-icon-loading"></i>加载中...</div>');
}, },
success: function(res) { success: function (res) {
if(res.code === 1) { if (res.code === 1) {
var html = ''; var html = '';
if(res.data.articles && res.data.articles.length > 0) { if (res.data.articles && res.data.articles.length > 0) {
res.data.articles.forEach(function(article) { res.data.articles.forEach(function (article) {
html += `<article class="article-card"> html += `<article class="article-card">
<div class="card-image"> <div class="card-image">
<img src="${article.image}" alt="${article.title}"> <img src="${article.image}" alt="${article.title}">
@ -131,16 +136,19 @@
</div> </div>
<div class="card-content"> <div class="card-content">
<div class="meta-info"> <div class="meta-info">
<span class="category-tag">${article.category_name || '未分类'}</span>
<time class="publish-date">${article.create_time || ''}</time>
</div> </div>
<h3 class="article-title">${article.title}</h3> <a href="/index/articles/detail?id=${article.id}" class="read-more">
<h3 class="article-title">${article.title}</h3>
</a>
<div class="card-footer"> <div class="card-footer">
<div class="stats"> <div class="stats">
<span class="views"><i class="layui-icon layui-icon-eye"></i> ${article.views || 0}</span> <span class="views"><i class="layui-icon layui-icon-eye"></i> ${article.views || 0}</span>
<span class="likes"><i class="layui-icon layui-icon-praise"></i> ${article.likes || 0}</span> <span class="likes"><i class="layui-icon layui-icon-praise"></i> ${article.likes || 0}</span>
</div> </div>
<a href="/index/articles/detail?id=${article.id}" class="read-more">阅读更多</a> <div class="times">
<time class="publish-date">${article.create_time ? new Date(article.create_time * 1000).toLocaleDateString() : ''}</time>
</div>
</div> </div>
</div> </div>
</article>`; </article>`;
@ -155,7 +163,7 @@
</div>`; </div>`;
} }
$('#articleList').html(html); $('#articleList').html(html);
// 渲染分页 // 渲染分页
laypage.render({ laypage.render({
elem: 'pagination', elem: 'pagination',
@ -164,8 +172,8 @@
curr: res.data.current_page || 1, curr: res.data.current_page || 1,
theme: '#1E9FFF', theme: '#1E9FFF',
layout: ['prev', 'page', 'next'], layout: ['prev', 'page', 'next'],
jump: function(obj, first) { jump: function (obj, first) {
if(!first) { if (!first) {
loadArticles(cateid, obj.curr); loadArticles(cateid, obj.curr);
} }
} }
@ -318,7 +326,7 @@
} }
.card-image { .card-image {
height: 180px; height: 135px;
position: relative; position: relative;
overflow: hidden; overflow: hidden;
} }
@ -350,10 +358,16 @@
flex-direction: column; flex-direction: column;
} }
.card-content .read-more h3:hover {
color: #1E9FFF !important;
transition: all ease .5s;
font-weight:700;
}
.meta-info { .meta-info {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
margin-bottom: 12px; /* margin-bottom: 12px; */
font-size: 0.85rem; font-size: 0.85rem;
color: #666; color: #666;
} }
@ -398,12 +412,16 @@
} }
.stats { .stats {
font-size: 0.85rem;
color: #999;
display: flex; display: flex;
gap: 15px; gap: 15px;
} }
.times,
.stats {
font-size: 0.85rem;
color: #999;
}
.stats i { .stats i {
margin-right: 3px; margin-right: 3px;
} }
@ -429,7 +447,7 @@
margin-top: 40px; margin-top: 40px;
} }
.layui-laypage a, .layui-laypage a,
.layui-laypage span { .layui-laypage span {
border-radius: 4px !important; border-radius: 4px !important;
margin: 0 3px !important; margin: 0 3px !important;
@ -491,8 +509,13 @@
} }
@keyframes spin { @keyframes spin {
0% { transform: rotate(0deg); } 0% {
100% { transform: rotate(360deg); } transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
} }
/* 响应式设计 */ /* 响应式设计 */
@ -500,12 +523,12 @@
.modern-layout { .modern-layout {
grid-template-columns: 1fr; grid-template-columns: 1fr;
} }
.modern-sidebar { .modern-sidebar {
position: static; position: static;
margin-bottom: 30px; margin-bottom: 30px;
} }
.article-grid { .article-grid {
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
} }
@ -515,7 +538,7 @@
.modern-header { .modern-header {
padding: 60px 0 40px; padding: 60px 0 40px;
} }
.modern-title { .modern-title {
font-size: 2rem; font-size: 2rem;
} }
@ -525,11 +548,11 @@
.article-grid { .article-grid {
grid-template-columns: 1fr; grid-template-columns: 1fr;
} }
.modern-title { .modern-title {
font-size: 1.8rem; font-size: 1.8rem;
} }
.modern-subtitle { .modern-subtitle {
font-size: 1rem; font-size: 1rem;
} }

View File

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