From 40caef19dd20d3ae429c0125b0415f34d91b4a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BF=97=E5=BC=BA?= <357099073@qq.com> Date: Tue, 20 May 2025 11:28:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E7=AB=A0=E7=82=B9?= =?UTF-8?q?=E8=B5=9E=E5=92=8C=E5=88=86=E4=BA=AB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/index/controller/ArticlesController.php | 20 ++- app/index/view/articles/detail.php | 143 +++++++++++------ app/index/view/program/detail.php | 143 ++++++++++------- .../temp/745a6917c29d4d1aec94c5bc5dbce0b2.php | 149 ++++++++++++------ .../temp/f8995f34639557c9f17f79801bc58d25.php | 145 ++++++++++------- 5 files changed, 391 insertions(+), 209 deletions(-) diff --git a/app/index/controller/ArticlesController.php b/app/index/controller/ArticlesController.php index f25871f..91b65d5 100644 --- a/app/index/controller/ArticlesController.php +++ b/app/index/controller/ArticlesController.php @@ -142,6 +142,16 @@ class ArticlesController extends BaseController $id = Request::param('id/d', 0); + // 检查文章是否存在 + $article = Articles::where('id', $id) + ->where('delete_time', null) + ->where('status', 2) + ->find(); + + if (!$article) { + return json(['code' => 0, 'msg' => '文章不存在或已被删除']); + } + // 更新点赞数 $result = Articles::where('id', $id) ->where('delete_time', null) @@ -149,7 +159,15 @@ class ArticlesController extends BaseController ->update(); if ($result) { - return json(['code' => 1, 'msg' => '点赞成功']); + // 返回更新后的点赞数 + $newLikes = $article['likes'] + 1; + return json([ + 'code' => 1, + 'msg' => '点赞成功', + 'data' => [ + 'likes' => $newLikes + ] + ]); } else { return json(['code' => 0, 'msg' => '点赞失败']); } diff --git a/app/index/view/articles/detail.php b/app/index/view/articles/detail.php index 681d624..63c8b61 100644 --- a/app/index/view/articles/detail.php +++ b/app/index/view/articles/detail.php @@ -30,12 +30,12 @@
-
+ -
@@ -44,12 +45,16 @@
+
+ +
+
立即下载
-
+ @@ -203,7 +208,7 @@ margin: 30px 0; } - .program-navigation a{ + .program-navigation a { color: #333; text-decoration: none; } @@ -363,25 +368,25 @@ function renderProgramDetail(data) { // 渲染分类链接 document.getElementById('cateLink').textContent = data.cateName; - + // 渲染程序标题 document.getElementById('programTitle').textContent = data.program.title; - + // 渲染程序元信息 document.getElementById('programAuthor').textContent = data.program.author; document.getElementById('programDate').textContent = formatDate(data.program.create_time); document.getElementById('programViews').textContent = data.program.views; document.getElementById('programDownloads').textContent = data.program.downloads; - + // 渲染程序内容 document.getElementById('programContent').innerHTML = data.program.content; - + // 渲染程序信息 document.getElementById('programSize').textContent = data.program.size || '未知'; document.getElementById('programEnvironment').textContent = data.program.environment || '通用'; document.getElementById('programUpdateTime').textContent = formatDate(data.program.update_time); document.getElementById('programVersion').textContent = data.program.version || '1.0.0'; - + // 渲染上一个程序 const prevProgram = document.getElementById('prevProgram'); if (data.prevProgram) { @@ -393,7 +398,7 @@ } else { prevProgram.innerHTML = ' 没有上一个了'; } - + // 渲染下一个程序 const nextProgram = document.getElementById('nextProgram'); if (data.nextProgram) { @@ -405,7 +410,7 @@ } else { nextProgram.innerHTML = '没有下一个了 '; } - + // 渲染相关程序 const relatedPrograms = document.getElementById('relatedPrograms'); if (data.relatedPrograms && data.relatedPrograms.length > 0) { @@ -428,7 +433,7 @@ } // 页面加载完成后执行 - document.addEventListener('DOMContentLoaded', function() { + document.addEventListener('DOMContentLoaded', function () { // 获取程序ID const programId = new URLSearchParams(window.location.search).get('id'); if (!programId) { @@ -442,61 +447,63 @@ 'X-Requested-With': 'XMLHttpRequest' } }) - .then(response => response.json()) - .then(result => { - if (result.code === 1) { - renderProgramDetail(result.data); - // 更新访问次数 - updateProgramViews(programId); - } else { - alert(result.msg || '获取程序详情失败'); - } - }) - .catch(error => { - console.error('获取程序详情失败:', error); - alert('获取程序详情失败,请检查网络连接或刷新页面重试'); - }); + .then(response => response.json()) + .then(result => { + if (result.code === 1) { + renderProgramDetail(result.data); + // 更新访问次数 + updateProgramViews(programId); + // 初始化分享功能 + initShareFunction(); + } else { + alert(result.msg || '获取程序详情失败'); + } + }) + .catch(error => { + console.error('获取程序详情失败:', error); + alert('获取程序详情失败,请检查网络连接或刷新页面重试'); + }); // 下载功能 const downloadBtn = document.getElementById('downloadBtn'); if (downloadBtn) { - downloadBtn.addEventListener('click', function() { + downloadBtn.addEventListener('click', function () { fetch('/index/program/download?id=' + programId, { method: 'POST', headers: { 'X-Requested-With': 'XMLHttpRequest' } }) - .then(response => response.json()) - .then(data => { - if (data.code === 1 && data.data && data.data.fileurl) { - const downloadUrl = window.location.origin + data.data.fileurl; - window.location.href = downloadUrl; - } else { - alert('下载地址不存在'); - } - }) - .catch(error => { - console.error('下载请求失败:', error); - alert('下载请求失败,请稍后重试'); - }); + .then(response => response.json()) + .then(data => { + if (data.code === 1 && data.data && data.data.fileurl) { + const downloadUrl = window.location.origin + data.data.fileurl; + window.location.href = downloadUrl; + } else { + alert('下载地址不存在'); + } + }) + .catch(error => { + console.error('下载请求失败:', error); + alert('下载请求失败,请稍后重试'); + }); }); } // 返回顶部功能 const goToTop = document.getElementById('goToTop'); - + // 监听滚动事件 - window.addEventListener('scroll', function() { + window.addEventListener('scroll', function () { if (window.pageYOffset > 300) { goToTop.classList.add('show'); } else { goToTop.classList.remove('show'); } }); - + // 点击返回顶部 - goToTop.addEventListener('click', function() { + goToTop.addEventListener('click', function () { window.scrollTo({ top: 0, behavior: 'smooth' @@ -516,19 +523,45 @@ id: programId }) }) - .then(response => response.json()) - .then(result => { - if (result.code === 1) { - // 更新成功,更新页面上的访问次数显示 - const viewsElement = document.getElementById('programViews'); - if (viewsElement) { - viewsElement.textContent = result.data.views; + .then(response => response.json()) + .then(result => { + if (result.code === 1) { + // 更新成功,更新页面上的访问次数显示 + const viewsElement = document.getElementById('programViews'); + if (viewsElement) { + viewsElement.textContent = result.data.views; + } } - } - }) - .catch(error => { - console.error('更新访问次数失败:', error); - }); + }) + .catch(error => { + console.error('更新访问次数失败:', error); + }); + } + + // 初始化分享功能 + function initShareFunction() { + const shareBtn = document.getElementById('shareBtn'); + if (shareBtn) { + shareBtn.addEventListener('click', function () { + // 获取当前页面URL + const currentUrl = window.location.href; + + // 创建临时输入框 + const tempInput = document.createElement('input'); + tempInput.value = currentUrl; + document.body.appendChild(tempInput); + + // 选择并复制文本 + tempInput.select(); + document.execCommand('copy'); + + // 移除临时输入框 + document.body.removeChild(tempInput); + + // 提示用户复制成功 + layer.msg('链接已复制到剪贴板'); + }); + } } {include file="component/foot" /} \ No newline at end of file diff --git a/runtime/index/temp/745a6917c29d4d1aec94c5bc5dbce0b2.php b/runtime/index/temp/745a6917c29d4d1aec94c5bc5dbce0b2.php index 345bf86..963a5c7 100644 --- a/runtime/index/temp/745a6917c29d4d1aec94c5bc5dbce0b2.php +++ b/runtime/index/temp/745a6917c29d4d1aec94c5bc5dbce0b2.php @@ -1,4 +1,4 @@ - + @@ -48,7 +48,7 @@