From 8276b445efaef8f73a117ba03629769489971912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BF=97=E5=BC=BA?= <357099073@qq.com> Date: Mon, 19 May 2025 08:52:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=9F=E8=AE=A1=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/index/view/component/foot.php | 3 +- .../temp/cb3abdcb36407244b9b613766f30573b.php | 278 ++++- .../temp/f8995f34639557c9f17f79801bc58d25.php | 1037 +++++++++++++++++ 3 files changed, 1303 insertions(+), 15 deletions(-) create mode 100644 runtime/index/temp/f8995f34639557c9f17f79801bc58d25.php diff --git a/app/index/view/component/foot.php b/app/index/view/component/foot.php index 9870926..daf0e79 100644 --- a/app/index/view/component/foot.php +++ b/app/index/view/component/foot.php @@ -1,3 +1,4 @@ - + + \ No newline at end of file diff --git a/runtime/index/temp/cb3abdcb36407244b9b613766f30573b.php b/runtime/index/temp/cb3abdcb36407244b9b613766f30573b.php index 8ca75d8..3fb2bca 100644 --- a/runtime/index/temp/cb3abdcb36407244b9b613766f30573b.php +++ b/runtime/index/temp/cb3abdcb36407244b9b613766f30573b.php @@ -1,4 +1,4 @@ - + @@ -50,10 +50,10 @@ + +
+
+
+
+

办公资源

+
+
+
全部
+ +
+
+
+
+
更多
+
+
+ +
+
+ + +
+
+
+
+

程序下载

+
+
+
全部
+ +
+
+
+
+
更多
+
+
+ +
+
+ @@ -560,6 +602,60 @@ }); } + // 加载资源下载 + function loadResources() { + fetch('/index/index/resourcesList') + .then(response => response.json()) + .then(result => { + if (result.code === 1) { + // 渲染分类标签 + if (result.categories) { + renderCategoryTabs(result.categories, 'resourcesDownload'); + } + // 渲染资源列表 + if (result.resources && result.resources.length > 0) { + // 只取最新的8条 + renderResources(result.resources.slice(0, 8), 'resourcesDownloadList'); + } else { + showNoData('resourcesDownloadList'); + } + } else { + showNoData('resourcesDownloadList'); + } + }) + .catch(error => { + console.error('请求失败:', error); + showError('resourcesDownloadList'); + }); + } + + // 加载程序下载 + function loadPrograms() { + fetch('/index/index/programList') + .then(response => response.json()) + .then(result => { + if (result.code === 1) { + // 渲染分类标签 + if (result.categories) { + renderCategoryTabs(result.categories, 'programDownload'); + } + // 渲染程序列表 + if (result.programs && result.programs.length > 0) { + // 只取最新的8条 + renderPrograms(result.programs.slice(0, 8), 'programDownloadList'); + } else { + showNoData('programDownloadList'); + } + } else { + showNoData('programDownloadList'); + } + }) + .catch(error => { + console.error('请求失败:', error); + showError('programDownloadList'); + }); + } + // 显示无数据提示 function showNoData(containerId) { document.getElementById(containerId).innerHTML = '
暂无数据
'; @@ -608,11 +704,20 @@ // 获取选中的分类ID const selectedCategoryId = this.getAttribute('data-tab'); - // 重新加载对应分类的文章 - if (moduleId === 'opencourse') { - loadCategoryArticles(selectedCategoryId, 'webArticlesList'); - } else { - loadCategoryArticles(selectedCategoryId, 'techArticlesList'); + // 根据不同模块加载对应数据 + switch(moduleId) { + case 'opencourse': + loadCategoryArticles(selectedCategoryId, 'webArticlesList'); + break; + case 'techArticles': + loadCategoryArticles(selectedCategoryId, 'techArticlesList'); + break; + case 'resourcesDownload': + loadCategoryResources(selectedCategoryId, 'resourcesDownloadList'); + break; + case 'programDownload': + loadCategoryPrograms(selectedCategoryId, 'programDownloadList'); + break; } }); }); @@ -710,10 +815,155 @@ `; } + // 渲染资源列表 + function renderResources(resources, containerId) { + const container = document.getElementById(containerId); + if (!container) return; + + let html = ''; + if (Array.isArray(resources)) { + resources.forEach(resource => { + html += createResourceHtml(resource); + }); + } + + container.innerHTML = html || '
暂无数据
'; + } + + // 创建资源HTML + function createResourceHtml(resource) { + if (!resource) return ''; + + // 格式化日期 + const uploadDate = new Date(resource.uploaddate * 1000); + const formattedDate = uploadDate.toLocaleDateString('zh-CN', { + year: 'numeric', + month: '2-digit', + day: '2-digit' + }); + + // 格式化文件大小 + const formatFileSize = (bytes) => { + if (bytes === 0) return '0 B'; + const k = 1024; + const sizes = ['B', 'KB', 'MB', 'GB', 'TB']; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; + }; + + return ` +
+
+ +
${resource.filetype || '未知类型'}
+
+
+
${resource.title || '无标题'}
+
${resource.description || '暂无描述'}
+
${formattedDate}
+
+
+
${resource.views || 0}
+
${resource.uploader || '未知作者'}
+
+
+ `; + } + + // 渲染程序列表 + function renderPrograms(programs, containerId) { + const container = document.getElementById(containerId); + if (!container) return; + + let html = ''; + if (Array.isArray(programs)) { + programs.forEach(program => { + html += createProgramHtml(program); + }); + } + + container.innerHTML = html || '
暂无数据
'; + } + + // 创建程序HTML + function createProgramHtml(program) { + if (!program) return ''; + + // 格式化日期 + const createDate = new Date(program.create_time * 1000); + const formattedDate = createDate.toLocaleDateString('zh-CN', { + year: 'numeric', + month: '2-digit', + day: '2-digit' + }); + + return ` +
+
+ +
+
+
${program.title || '无标题'}
+
${formattedDate}
+
+
+
${program.views || 0}
+
${program.uploader || '未知作者'}
+
+
+ `; + } + + // 加载分类资源 + function loadCategoryResources(categoryId, containerId) { + fetch('/index/index/resourcesList') + .then(response => response.json()) + .then(result => { + if (result.code === 1) { + if (categoryId === 'all') { + renderResources(result.resources.slice(0, 8), containerId); + } else { + const filteredResources = result.resources.filter(resource => resource.cate == categoryId); + renderResources(filteredResources, containerId); + } + } else { + showNoData(containerId); + } + }) + .catch(error => { + console.error('请求失败:', error); + showError(containerId); + }); + } + + // 加载分类程序 + function loadCategoryPrograms(categoryId, containerId) { + fetch('/index/index/programList') + .then(response => response.json()) + .then(result => { + if (result.code === 1) { + if (categoryId === 'all') { + renderPrograms(result.programs.slice(0, 8), containerId); + } else { + const filteredPrograms = result.programs.filter(program => program.cate == categoryId); + renderPrograms(filteredPrograms, containerId); + } + } else { + showNoData(containerId); + } + }) + .catch(error => { + console.error('请求失败:', error); + showError(containerId); + }); + } + // 页面加载完成后执行 document.addEventListener('DOMContentLoaded', function() { loadWebArticles(); loadTechArticles(); + loadResources(); + loadPrograms(); });