This commit is contained in:
李志强 2025-05-21 16:51:36 +08:00
commit 40d1625a22
120 changed files with 5545 additions and 286 deletions

View File

@ -354,7 +354,7 @@ class IndexController extends Base{
try {
// 验证上传的文件
validate([
'image'=>'filesize:10240|fileExt:jpg,png,gif,jpeg'
'image'=>'filesize:51200|fileExt:jpg,png,gif,jpeg'
])->check($file);
// 存储文件到public磁盘的uploads目录

View File

@ -106,9 +106,13 @@ class ResourcesController extends BaseController
'url' => input('post.url'),
'fileurl' => input('post.fileurl'),
'code' => input('post.code'),
'zipcode' => input('post.zipcode'),
'uploader' => input('post.uploader'),
'desc' => input('post.desc'),
'content' => input('post.content'),
'number' => input('post.number'),
'status' => input('post.status', 1),
'create_time' => time()
];
@ -131,9 +135,7 @@ class ResourcesController extends BaseController
}
}
/**
* 编辑资源
*/
// 编辑资源
public function edit()
{
if (Request::isPost()) {
@ -154,7 +156,10 @@ class ResourcesController extends BaseController
'fileurl' => $data['fileurl'],
'url' => $data['url'],
'code' => $data['code'],
'zipcode' => $data['zipcode'],
'sort' => $data['sort'],
'number' => $data['number'],
'content' => $data['content'],
'update_time' => time()
];
@ -179,7 +184,7 @@ class ResourcesController extends BaseController
$resource = Resource::where('id', $id)
->where('delete_time', null)
->find();
if (!$resource) {
Log::record('编辑资源', 0, '资源不存在', '资源管理');
$this->error('资源不存在');
@ -226,6 +231,29 @@ class ResourcesController extends BaseController
->order('sort asc, id asc')
->select()
->toArray();
// 获取每个分类下的资源总数
foreach ($lists as &$item) {
if ($item['cid'] == 0) {
// 父级分类 - 统计所有子分类的资源总数
$childIds = ResourceCategory::where('cid', $item['id'])
->where('delete_time', null)
->where('status', 1)
->column('id');
$item['total'] = Resource::where('cate', 'in', array_merge([$item['id']], $childIds))
->where('delete_time', null)
->where('status', '<>', 3)
->count();
} else {
// 子分类 - 只统计当前分类的资源
$item['total'] = Resource::where('cate', $item['id'])
->where('delete_time', null)
->where('status', '<>', 3)
->count();
}
}
$tree = $this->buildParentChild($lists);
return json(['code' => 0, 'msg' => '获取成功', 'data' => $tree]);
}
@ -238,6 +266,7 @@ class ResourcesController extends BaseController
'name' => input('post.name'),
'icon' => input('post.icon'),
'cid' => input('post.cid'),
'number' => input('post.number'),
'sort' => input('post.sort', 0),
'status' => input('post.status', 1),
'create_time' => time()
@ -276,6 +305,7 @@ class ResourcesController extends BaseController
'name' => input('post.name'),
'icon' => input('post.icon'),
'cid' => input('post.cid'),
'number' => input('post.number'),
'sort' => input('post.sort', 0),
'status' => input('post.status', 1),
'update_time' => time()

View File

@ -22,12 +22,20 @@
<div class="layui-form-item">
<label class="layui-form-label">分类</label>
<div class="layui-input-block">
<select name="cate" lay-verify="required">
<select name="cate" lay-verify="required" lay-filter="cate">
<option value="">请选择分类</option>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">资源编号</label>
<div class="layui-input-block">
<input type="text" name="number" required lay-verify="required" placeholder="选取分类后系统自动生成" autocomplete="off"
class="layui-input" lay-affix="clear" disabled>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">描述</label>
<div class="layui-input-block">
@ -39,7 +47,7 @@
<label class="layui-form-label">上传者</label>
<div class="layui-input-block">
<input type="text" name="uploader" required lay-verify="required" placeholder="请输入上传者"
autocomplete="off" class="layui-input" lay-affix="clear">
autocomplete="off" class="layui-input" lay-affix="clear" value="{$aUser['name']}">
</div>
</div>
@ -104,6 +112,14 @@
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">解压密码</label>
<div class="layui-input-block">
<input type="text" name="zipcode" required placeholder="请输入解压密码" autocomplete="off"
class="layui-input" lay-affix="clear">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">排序</label>
<div class="layui-input-block">
@ -111,6 +127,16 @@
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">内容</label>
<div class="layui-input-block">
<div id="editor—wrapper" id="content" name="content" style="border: 1px solid #ccc;">
<div id="toolbar-container" style="border-bottom: 1px solid #ccc;"><!-- 工具栏 --></div>
<div id="editor-container" style="height: 800px;"><!-- 编辑器 --></div>
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="formSubmit">立即提交</button>
@ -120,6 +146,7 @@
</form>
</div>
<script src="/static/js/wangeditor.js"></script>
<script>
layui.use(['form', 'layer'], function () {
var form = layui.form;
@ -220,14 +247,92 @@
});
$('select[name="cate"]').html(html);
form.render('select');
// 存储分类数据供后续使用
window.categoryData = res.data;
} else {
layer.msg(res.msg, { icon: 2 });
}
});
// 监听分类选择变化
form.on('select(cate)', function(data) {
var selectedId = data.value;
if (!selectedId) {
$('input[name="number"]').val('');
return;
}
// 递归查找分类信息的函数
function findCategory(categories, targetId) {
for (let category of categories) {
// 检查当前分类
if (category.id == targetId) {
return {
parent: null,
current: category,
total: category.total || 0
};
}
// 检查子分类
if (category.children && category.children.length > 0) {
for (let child of category.children) {
if (child.id == targetId) {
return {
parent: category,
current: child,
total: child.total || 0
};
}
// 递归检查更深层级的子分类
if (child.children && child.children.length > 0) {
const result = findCategory([child], targetId);
if (result) {
return result;
}
}
}
}
}
return null;
}
// 查找选中的分类信息
const categoryInfo = findCategory(window.categoryData, selectedId);
if (categoryInfo) {
// 生成资源编号
var nextNumber = categoryInfo.total + 1;
var numberStr = nextNumber.toString().padStart(5, '0');
var resourceNumber = '';
// 构建编号前缀
if (categoryInfo.parent) {
resourceNumber = categoryInfo.parent.number + categoryInfo.current.number;
} else {
resourceNumber = categoryInfo.current.number;
}
// 添加序号
resourceNumber += numberStr;
// 设置资源编号
$('input[name="number"]').val(resourceNumber);
}
});
// 表单提交
form.on('submit(formSubmit)', function (data) {
// 获取编辑器内容
var content = editor.getHtml();
if (!content || content === '<p><br></p>') {
layer.msg('请输入文章内容', { icon: 2 });
return false;
}
var loadIndex = layer.load(2);
data.field.content = content;
$.ajax({
url: '{:url("resources/add")}',
type: 'POST',
@ -272,6 +377,86 @@
});
</script>
<!-- wangeditor编辑器脚本 -->
<script>
const { createEditor, createToolbar } = window.wangEditor
const editorConfig = {
MENU_CONF: {},
placeholder: '请输入内容...',
onChange(editor) {
const html = editor.getHtml()
},
}
// 配置图片上传
editorConfig.MENU_CONF['uploadImage'] = {
server: '{:url("index/upload_img")}',
fieldName: 'file',
maxFileSize: 50 * 1024 * 1024, // 50M
maxNumberOfFiles: 10,
allowedFileTypes: ['image/*'],
meta: {
token: 'xxx'
},
metaWithUrl: true,
headers: {
Accept: 'text/x-json'
},
timeout: 30 * 1000, // 30s
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) {
// 只使用返回的url字段并确保使用完整的URL
if (res.code === 0 && res.url) {
// 如果URL不是以http开头添加https://
let imageUrl = res.url;
if (!imageUrl.startsWith('http')) {
imageUrl = 'https://' + imageUrl;
}
// 移除可能存在的重复域名和路径
imageUrl = imageUrl.replace(/^https?:\/\/[^\/]+\/admin\/resources\//, 'https://www.yunzer.cn/');
insertFn(imageUrl);
} else {
layer.msg('图片上传失败:' + (res.msg || '未知错误'), { icon: 2 });
}
}
}
const editor = createEditor({
selector: '#editor-container',
html: '<p><br></p>',
config: editorConfig,
mode: 'default', // or 'simple'
})
const toolbarConfig = {}
const toolbar = createToolbar({
editor,
selector: '#toolbar-container',
config: toolbarConfig,
mode: 'default', // or 'simple'
})
</script>
<script>
//返回资源列表
function goBack() {

View File

@ -50,6 +50,13 @@
<!-- 分类表单 -->
<form class="layui-form category-form" lay-filter="categoryForm" style="display: none;">
<input type="hidden" name="id" id="categoryId">
<div class="layui-form-item">
<label class="layui-form-label">分类编号</label>
<div class="layui-input-block">
<input type="text" name="number" required lay-verify="required" placeholder="请输入分类编号"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">分类名称</label>
@ -403,6 +410,7 @@
form.val('categoryForm', {
id: data ? data.info.id : '',
name: data ? data.info.name : '',
number: data ? data.info.number : '',
cid: data ? data.info.cid : parentId,
sort: data ? data.info.sort : 0,
status: data ? data.info.status : 1

View File

@ -23,11 +23,19 @@
<div class="layui-form-item">
<label class="layui-form-label">分类</label>
<div class="layui-input-block">
<select name="cate" lay-verify="required">
<select name="cate" lay-verify="required" lay-filter="cate">
<option value="">请选择分类</option>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">资源编号</label>
<div class="layui-input-block">
<input type="text" name="number" required lay-verify="required" placeholder="请输入分类编号" autocomplete="off"
class="layui-input" value="{$resource.number|default=''}" lay-affix="clear" disabled>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">描述</label>
@ -105,6 +113,14 @@
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">解压密码</label>
<div class="layui-input-block">
<input type="text" name="zipcode" required placeholder="请输入解压密码" autocomplete="off"
class="layui-input" value="{$resource.zipcode|default=''}" lay-affix="clear">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">排序</label>
<div class="layui-input-block">
@ -112,6 +128,16 @@
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">内容</label>
<div class="layui-input-block">
<div id="editor—wrapper" id="content" name="content" style="border: 1px solid #ccc;">
<div id="toolbar-container" style="border-bottom: 1px solid #ccc;"><!-- 工具栏 --></div>
<div id="editor-container" style="height: 800px;"><!-- 编辑器 --></div>
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="formSubmit">立即提交</button>
@ -121,6 +147,7 @@
</form>
</div>
<script src="/static/js/wangeditor.js"></script>
<script>
layui.use(['form', 'layer'], function () {
var form = layui.form;
@ -245,6 +272,9 @@
// 获取分类列表
$.get('{:url("resources/getcate")}', function (res) {
if (res.code == 0) {
// 存储分类数据供后续使用
window.categoryData = res.data;
var html = '<option value="">请选择分类</option>';
res.data.forEach(function (item) {
html += '<option value="' + item.id + '">' + item.name + '</option>';
@ -269,9 +299,50 @@
}
});
// 监听分类选择变化
form.on('select(cate)', function(data) {
var selectedId = data.value;
if (!selectedId) {
$('input[name="number"]').val('');
return;
}
// 查找选中的分类信息
var parentCategory = null;
var childCategory = null;
window.categoryData.forEach(function(parent) {
if (parent.children) {
parent.children.forEach(function(child) {
if (child.id == selectedId) {
parentCategory = parent;
childCategory = child;
}
});
}
});
if (parentCategory && childCategory) {
// 生成资源编号
var total = childCategory.total || 0;
// 判断是否是初始化时的分类
var isInitialCategory = resourceData && resourceData.cate == selectedId;
var nextNumber = isInitialCategory ? total : total + 1;
var numberStr = nextNumber.toString().padStart(5, '0');
var resourceNumber = parentCategory.number + childCategory.number + numberStr;
// 设置资源编号
$('input[name="number"]').val(resourceNumber);
}
});
// 表单提交
form.on('submit(formSubmit)', function (data) {
// 获取编辑器内容
var content = editor.getHtml();
var loadIndex = layer.load(2);
data.field.content = content;
$.ajax({
url: '{:url("resources/edit")}',
type: 'POST',
@ -324,6 +395,86 @@
});
</script>
<!-- wangeditor编辑器脚本 -->
<script>
const { createEditor, createToolbar } = window.wangEditor
const editorConfig = {
MENU_CONF: {},
placeholder: '请输入内容...',
onChange(editor) {
const html = editor.getHtml()
},
}
// 配置图片上传
editorConfig.MENU_CONF['uploadImage'] = {
server: '{:url("index/upload_img")}',
fieldName: 'file',
maxFileSize: 50 * 1024 * 1024, // 50M
maxNumberOfFiles: 10,
allowedFileTypes: ['image/*'],
meta: {
token: 'xxx'
},
metaWithUrl: true,
headers: {
Accept: 'text/x-json'
},
timeout: 30 * 1000, // 30s
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) {
// 只使用返回的url字段并确保使用完整的URL
if (res.code === 0 && res.url) {
// 如果URL不是以http开头添加https://
let imageUrl = res.url;
if (!imageUrl.startsWith('http')) {
imageUrl = 'https://' + imageUrl;
}
// 移除可能存在的重复域名和路径
imageUrl = imageUrl.replace(/^https?:\/\/[^\/]+\/admin\/resources\//, 'https://www.yunzer.cn/');
insertFn(imageUrl);
} else {
layer.msg('图片上传失败:' + (res.msg || '未知错误'), { icon: 2 });
}
}
}
const editor = createEditor({
selector: '#editor-container',
html: `{$resource.content|raw|default=''}`,
config: editorConfig,
mode: 'default', // or 'simple'
})
const toolbarConfig = {}
const toolbar = createToolbar({
editor,
selector: '#toolbar-container',
config: toolbarConfig,
mode: 'default', // or 'simple'
})
</script>
<script>
//返回资源列表
function goBack() {

View File

@ -60,7 +60,7 @@
{{# if(d.status == '0'){ }}
<span style="color:red;">未审核</span>
{{# } else if(d.status == '1'){ }}
<span style="color:orange;">已审核</span>
<span style="color:green;">已审核</span>
{{# } }}
</script>
@ -87,6 +87,7 @@
method: 'post',
cols: [[
{ field: 'id', title: 'ID', align: 'center', width: 80 },
{ field: 'number', title: '资源编号', width: 100 },
{ field: 'title', title: '资源名称' },
{ field: 'cate', title: '分类', align: 'center', width: 120 },
{ field: 'icon', title: '图标', templet: '#iconTemplate', align: 'center', width: 100 },

View File

@ -1 +0,0 @@

View File

@ -0,0 +1,242 @@
<?php
/**
* 游戏下载控制器
*/
namespace app\index\controller;
use app\index\controller\BaseController;
use think\facade\Db;
use think\facade\View;
use think\facade\Request;
use app\index\model\Resources\Resources;
use app\index\model\Resources\ResourcesCategory;
use app\index\model\Attachments;
class GameController extends BaseController
{
// 游戏列表页
public function list()
{
// 获取分类ID
$cateId = Request::param('cate/d', 0);
// 构建查询条件
$where = [
['delete_time', '=', null],
['status', '=', 1]
];
if ($cateId > 0) {
$where[] = ['cate', '=', $cateId];
}
// 获取游戏列表
$games = Resources::where($where)
->order('id DESC')
->paginate([
'list_rows' => 10,
'query' => Request::param()
]);
// 获取分类信息
$category = null;
if ($cateId > 0) {
$category = ResourcesCategory::where('id', $cateId)
->where('delete_time', null)
->where('status', 1)
->find();
}
// 获取所有分类
$categories = ResourcesCategory::where('delete_time', null)
->where('status', 1)
->select()
->toArray();
// 将变量传递给视图
View::assign([
'games' => $games,
'category' => $category,
'categories' => $categories
]);
return View::fetch('list');
}
// 游戏详情页
public function detail()
{
$id = Request::param('id/d', 0);
$game = Resources::where('id', $id)->find();
if (!$game) {
return json(['code' => 0, 'msg' => '游戏不存在或已被删除']);
}
// 如果size没有从附件表中获取
if (empty($game['size']) && !empty($game['fileurl'])) {
$attachment = Attachments::where('src', $game['fileurl'])
->find();
if ($attachment && !empty($attachment['size'])) {
$size = $attachment['size'];
// 转换文件大小为合适的单位
if ($size >= 1073741824) { // 1GB = 1024MB = 1024*1024KB = 1024*1024*1024B
$game['size'] = round($size / 1073741824, 2) . 'GB';
} elseif ($size >= 1048576) { // 1MB = 1024KB = 1024*1024B
$game['size'] = round($size / 1048576, 2) . 'MB';
} else {
$game['size'] = round($size / 1024, 2) . 'KB';
}
}
}
// 获取分类名称
$cateName = ResourcesCategory::where('id', $game['cate'])
->value('name');
// 获取上一个和下一个游戏
$prevGame = Resources::where('id', '<', $id)
->where('delete_time', null)
->where('status', 1)
->order('id DESC')
->find();
$nextGame = Resources::where('id', '>', $id)
->where('delete_time', null)
->where('status', 1)
->order('id ASC')
->find();
// 获取相关游戏(同分类的其他游戏)
$relatedGames = Db::table('yz_resources')
->alias('g')
->join('yz_resources_category c', 'g.cate = c.id')
->where('g.cate', $game['cate'])
->where('g.id', '<>', $id)
->where('g.delete_time', null)
->where('g.status', 1)
->field([
'g.id',
'g.title',
'g.desc',
'IF(g.icon IS NULL OR g.icon = "", c.icon, g.icon) as icon'
])
->order('g.id DESC')
->limit(3)
->select()
->toArray();
// 如果是 AJAX 请求,返回 JSON 数据
if (Request::isAjax()) {
return json([
'code' => 1,
'msg' => '获取成功',
'data' => [
'game' => $game,
'cateName' => $cateName,
'prevGame' => $prevGame,
'nextGame' => $nextGame,
'relatedGames' => $relatedGames
]
]);
}
// 非 AJAX 请求返回视图
View::assign([
'game' => $game,
'cateName' => $cateName,
'prevGame' => $prevGame,
'nextGame' => $nextGame,
'relatedGames' => $relatedGames
]);
return View::fetch('detail');
}
// 游戏下载
public function downloadurl()
{
if (!Request::isAjax()) {
return json(['code' => 0, 'msg' => '非法请求']);
}
$id = Request::param('id/d', 0);
// 获取游戏信息
$game = Resources::where('id', $id)
->where('delete_time', null)
->find();
if (!$game) {
return json(['code' => 0, 'msg' => '游戏不存在']);
}
// 更新下载次数
$result = Resources::where('id', $id)
->where('delete_time', null)
->inc('downloads', 1)
->update();
if ($result) {
return json([
'code' => 1,
'msg' => '下载成功',
'data' => [
'url' => $game['url']
]
]);
} else {
return json(['code' => 0, 'msg' => '下载失败']);
}
}
// 获取访问统计
public function viewStats()
{
$id = Request::param('id/d', 0);
// 获取总访问量
$totalViews = Resources::where('id', $id)
->value('views');
return json([
'code' => 1,
'data' => [
'total' => $totalViews
]
]);
}
/**
* 更新游戏访问次数
*/
public function updateViews()
{
if (!Request::isPost()) {
return json(['code' => 0, 'msg' => '非法请求']);
}
$id = Request::post('id');
if (!$id) {
return json(['code' => 0, 'msg' => '参数错误']);
}
try {
// 更新访问次数
$game = Resources::where('id', $id)->find();
if (!$game) {
return json(['code' => 0, 'msg' => '游戏不存在']);
}
// 更新访问次数
Resources::where('id', $id)->inc('views')->update();
// 获取更新后的访问次数
$newViews = Resources::where('id', $id)->value('views');
return json(['code' => 1, 'msg' => '更新成功', 'data' => ['views' => $newViews]]);
} catch (\Exception $e) {
return json(['code' => 0, 'msg' => '更新失败:' . $e->getMessage()]);
}
}
}

View File

@ -270,4 +270,75 @@ class IndexController extends BaseController
'categories' => $categoryData
]);
}
/**
* 获取游戏下载列表
*/
public function gameList()
{
// 获取游戏分类顶级分类id为8的子分类
$categories = ResourcesCategory::where('cid', 8)
->where('delete_time', null)
->select()
->toArray();
// 组装分类数据
$categoryData = [];
$categoryImageMap = [];
$programsByCategory = [];
foreach ($categories as $category) {
$categoryData[] = [
'id' => $category['id'],
'name' => $category['name'],
'image' => $category['image'] ?? ''
];
// 获取每个分类下的游戏限制8条
$programs = Resources::where('cate', $category['id'])
->where('delete_time', null)
->where('status', 1)
->order('id', 'desc')
->field('id, cate, title, desc, downloads, create_time, icon, views, uploader, number, url, code')
->limit(8)
->select()
->toArray();
// 处理游戏数据
foreach ($programs as &$program) {
// 如果没有图标,使用分类图片
if (empty($program['icon']) && !empty($category['image'])) {
$program['icon'] = $category['image'];
}
// 格式化时间
$program['create_time'] = date('Y-m-d H:i:s', $program['create_time']);
}
unset($program);
$programsByCategory[$category['id']] = $programs;
}
// 合并所有分类的游戏
$allPrograms = [];
foreach ($programsByCategory as $programs) {
$allPrograms = array_merge($allPrograms, $programs);
}
// 按上传时间排序
usort($allPrograms, function($a, $b) {
return strtotime($b['create_time']) - strtotime($a['create_time']);
});
// 只取最新的8条
$allPrograms = array_slice($allPrograms, 0, 8);
return json([
'code' => 0,
'msg' => '获取成功',
'data' => [
'games' => $allPrograms,
'categories' => $categoryData
]
]);
}
}

View File

@ -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>

View File

@ -0,0 +1,496 @@
{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" /}

View File

@ -17,9 +17,8 @@
<div class="program-meta">
<span class="program-author"><i class="fa fa-user"></i> <span id="programAuthor"></span></span>
<span class="program-date"><i class="fa fa-calendar"></i> <span id="programDate"></span></span>
<span class="program-views"><i class="fa-solid fa-eye"></i> <span id="programViews"></span> 浏览</span>
<span class="program-downloads"><i class="fa-solid fa-download"></i> <span id="programDownloads"></span>
下载</span>
<span class="program-views"><i class="fa-solid fa-eye"></i> <span id="programViews"></span></span>
<span class="program-downloads"><i class="fa-solid fa-download"></i> <span id="programDownloads"></span></span>
</div>
</div>

File diff suppressed because it is too large Load Diff

View File

@ -561,3 +561,8 @@ pre code {
color: #212529 !important;
border: 1px solid #212529;
}
.program-content img,.game-content img {
width: 100%;
margin: 20px auto;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 653 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 653 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 485 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 485 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 412 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 603 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Some files were not shown because too many files have changed in this diff Show More