516 lines
		
	
	
		
			21 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			516 lines
		
	
	
		
			21 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<main class="main-content">
 | 
						|
    <div class="container">
 | 
						|
        <!-- 站点资讯模块 -->
 | 
						|
        <div class="core-block core-module" id="opencourse" 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="webArticlesList">
 | 
						|
                <!-- 文章将通过JavaScript动态加载 -->
 | 
						|
            </div>
 | 
						|
        </div>
 | 
						|
 | 
						|
        <!-- 技术文章模块 -->
 | 
						|
        <div class="core-block core-module" id="techArticles" 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="techArticlesList">
 | 
						|
                <!-- 文章将通过JavaScript动态加载 -->
 | 
						|
            </div>
 | 
						|
        </div>
 | 
						|
 | 
						|
        <!-- 资源下载模块 -->
 | 
						|
        <div class="core-block core-module" id="resourcesDownload" 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="resourcesDownloadList">
 | 
						|
                <!-- 文章将通过JavaScript动态加载 -->
 | 
						|
            </div>
 | 
						|
        </div>
 | 
						|
 | 
						|
        <!-- 程序下载模块 -->
 | 
						|
        <div class="core-block core-module" id="programDownload" 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="programDownloadList">
 | 
						|
                <!-- 程序将通过JavaScript动态加载 -->
 | 
						|
            </div>
 | 
						|
        </div>
 | 
						|
 | 
						|
    </div>
 | 
						|
</main>
 | 
						|
 | 
						|
<script>
 | 
						|
    // 加载站点新闻
 | 
						|
    function loadWebArticles() {
 | 
						|
        fetch('/index/index/siteNewslist')
 | 
						|
            .then(response => response.json())
 | 
						|
            .then(result => {
 | 
						|
                if (result.code === 1) {
 | 
						|
                    // 渲染分类标签
 | 
						|
                    if (result.categories) {
 | 
						|
                        renderCategoryTabs(result.categories, 'opencourse');
 | 
						|
                    }
 | 
						|
                    // 渲染文章列表
 | 
						|
                    if (result.articles && result.articles.length > 0) {
 | 
						|
                        // 只取最新的4条
 | 
						|
                        renderWebArticles(result.articles.slice(0, 4), 'webArticlesList');
 | 
						|
                    } else {
 | 
						|
                        showNoData('webArticlesList');
 | 
						|
                    }
 | 
						|
                } else {
 | 
						|
                    showNoData('webArticlesList');
 | 
						|
                }
 | 
						|
            })
 | 
						|
            .catch(error => {
 | 
						|
                console.error('请求失败:', error);
 | 
						|
                showError('webArticlesList');
 | 
						|
            });
 | 
						|
    }
 | 
						|
 | 
						|
    // 加载技术文章
 | 
						|
    function loadTechArticles() {
 | 
						|
        fetch('/index/index/technicalArticleslist')
 | 
						|
            .then(response => response.json())
 | 
						|
            .then(result => {
 | 
						|
                if (result.code === 1) {
 | 
						|
                    // 渲染分类标签
 | 
						|
                    if (result.categories) {
 | 
						|
                        renderCategoryTabs(result.categories, 'techArticles');
 | 
						|
                    }
 | 
						|
                    // 渲染文章列表
 | 
						|
                    if (result.articles && Object.keys(result.articles).length > 0) {
 | 
						|
                        // 合并所有分类的文章
 | 
						|
                        let allArticles = [];
 | 
						|
                        Object.values(result.articles).forEach(arr => {
 | 
						|
                            allArticles = allArticles.concat(arr);
 | 
						|
                        });
 | 
						|
                        // 按发布时间排序(降序)
 | 
						|
                        allArticles.sort((a, b) => b.publishdate - a.publishdate);
 | 
						|
                        // 只取最新的12条
 | 
						|
                        allArticles = allArticles.slice(0, 12);
 | 
						|
                        renderWebArticles(allArticles, 'techArticlesList');
 | 
						|
                    } else {
 | 
						|
                        showNoData('techArticlesList');
 | 
						|
                    }
 | 
						|
                } else {
 | 
						|
                    showNoData('techArticlesList');
 | 
						|
                }
 | 
						|
            })
 | 
						|
            .catch(error => {
 | 
						|
                console.error('请求失败:', error);
 | 
						|
                showError('techArticlesList');
 | 
						|
            });
 | 
						|
    }
 | 
						|
 | 
						|
    // 加载资源下载
 | 
						|
    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 = '<div class="no-data">暂无数据</div>';
 | 
						|
    }
 | 
						|
 | 
						|
    // 显示错误提示
 | 
						|
    function showError(containerId) {
 | 
						|
        document.getElementById(containerId).innerHTML = '<div class="error-message">网络请求失败</div>';
 | 
						|
    }
 | 
						|
 | 
						|
    // 渲染分类标签
 | 
						|
    function renderCategoryTabs(categories, moduleId) {
 | 
						|
        const tabHeader = document.querySelector(`#${moduleId} .tab-header`);
 | 
						|
        if (!tabHeader) return;
 | 
						|
 | 
						|
        // 保留"全部"标签
 | 
						|
        const allTab = tabHeader.querySelector('.tab-item[data-tab="all"]');
 | 
						|
        tabHeader.innerHTML = '';
 | 
						|
        tabHeader.appendChild(allTab);
 | 
						|
 | 
						|
        // 添加分类标签
 | 
						|
        if (Array.isArray(categories)) {
 | 
						|
            categories.forEach(category => {
 | 
						|
                const tabItem = document.createElement('div');
 | 
						|
                tabItem.className = 'tab-item';
 | 
						|
                tabItem.setAttribute('data-tab', category.id);
 | 
						|
                tabItem.textContent = category.name;
 | 
						|
                tabHeader.appendChild(tabItem);
 | 
						|
            });
 | 
						|
        }
 | 
						|
 | 
						|
        // 重新绑定点击事件
 | 
						|
        bindTabEvents(moduleId);
 | 
						|
    }
 | 
						|
 | 
						|
    // 绑定标签点击事件
 | 
						|
    function bindTabEvents(moduleId) {
 | 
						|
        const tabItems = document.querySelectorAll(`#${moduleId} .tab-item`);
 | 
						|
        tabItems.forEach(tab => {
 | 
						|
            tab.addEventListener('click', function() {
 | 
						|
                // 移除所有active类
 | 
						|
                tabItems.forEach(item => item.classList.remove('active'));
 | 
						|
                // 添加active类到当前点击的tab
 | 
						|
                this.classList.add('active');
 | 
						|
                
 | 
						|
                // 获取选中的分类ID
 | 
						|
                const selectedCategoryId = this.getAttribute('data-tab');
 | 
						|
                
 | 
						|
                // 根据不同模块加载对应数据
 | 
						|
                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;
 | 
						|
                }
 | 
						|
            });
 | 
						|
        });
 | 
						|
    }
 | 
						|
 | 
						|
    // 加载分类文章
 | 
						|
    function loadCategoryArticles(categoryId, containerId) {
 | 
						|
        const url = containerId === 'webArticlesList' ? '/index/index/siteNewslist' : '/index/index/technicalArticleslist';
 | 
						|
        fetch(url)
 | 
						|
            .then(response => response.json())
 | 
						|
            .then(result => {
 | 
						|
                if (result.code === 1) {
 | 
						|
                    if (containerId === 'techArticlesList') {
 | 
						|
                        if (categoryId === 'all') {
 | 
						|
                            // 合并所有分类的文章
 | 
						|
                            let allArticles = [];
 | 
						|
                            if (typeof result.articles === 'object') {
 | 
						|
                                Object.values(result.articles).forEach(arr => {
 | 
						|
                                    allArticles = allArticles.concat(arr);
 | 
						|
                                });
 | 
						|
                            }
 | 
						|
                            // 按发布时间排序(降序)
 | 
						|
                            allArticles.sort((a, b) => b.publishdate - a.publishdate);
 | 
						|
                            // 只取最新的12条
 | 
						|
                            allArticles = allArticles.slice(0, 12);
 | 
						|
                            renderWebArticles(allArticles, containerId);
 | 
						|
                        } else {
 | 
						|
                            // 只显示选中分类的文章
 | 
						|
                            let filteredArticles = [];
 | 
						|
                            if (typeof result.articles === 'object' && result.articles[categoryId]) {
 | 
						|
                                filteredArticles = result.articles[categoryId];
 | 
						|
                            }
 | 
						|
                            renderWebArticles(filteredArticles, containerId);
 | 
						|
                        }
 | 
						|
                    } else {
 | 
						|
                        // 站点资讯部分逻辑不变
 | 
						|
                        if (categoryId === 'all') {
 | 
						|
                            renderWebArticles(result.articles.slice(0, 4), containerId);
 | 
						|
                        } else {
 | 
						|
                            const filteredArticles = result.articles.filter(article => article.cate == categoryId);
 | 
						|
                            renderWebArticles(filteredArticles, containerId);
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                } else {
 | 
						|
                    showNoData(containerId);
 | 
						|
                }
 | 
						|
            })
 | 
						|
            .catch(error => {
 | 
						|
                console.error('请求失败:', error);
 | 
						|
                showError(containerId);
 | 
						|
            });
 | 
						|
    }
 | 
						|
 | 
						|
    // 渲染文章列表
 | 
						|
    function renderWebArticles(articles, containerId) {
 | 
						|
        const container = document.getElementById(containerId);
 | 
						|
        if (!container) return;
 | 
						|
 | 
						|
        let html = '';
 | 
						|
        if (Array.isArray(articles)) {
 | 
						|
            articles.forEach(article => {
 | 
						|
                html += createArticleHtml(article);
 | 
						|
            });
 | 
						|
        }
 | 
						|
 | 
						|
        container.innerHTML = html || '<div class="no-data">暂无数据</div>';
 | 
						|
    }
 | 
						|
 | 
						|
    // 创建文章HTML
 | 
						|
    function createArticleHtml(article) {
 | 
						|
        if (!article) return '';
 | 
						|
        
 | 
						|
        // 格式化日期
 | 
						|
        const publishDate = new Date(article.publishdate * 1000);
 | 
						|
        const formattedDate = publishDate.toLocaleDateString('zh-CN', {
 | 
						|
            year: 'numeric',
 | 
						|
            month: '2-digit',
 | 
						|
            day: '2-digit'
 | 
						|
        });
 | 
						|
        
 | 
						|
        return `
 | 
						|
            <div class="opencourse product-item" onclick="window.open('/index/article/detail?id=${article.id || ''}', '_blank')">
 | 
						|
                <div class="video">
 | 
						|
                    <img src="${article.image || ''}" alt="" class="cover">
 | 
						|
                </div>
 | 
						|
                <div class="introduction">
 | 
						|
                    <div class="title">${article.title || '无标题'}</div>
 | 
						|
                    <div class="publishdate">${formattedDate}</div>
 | 
						|
                </div>
 | 
						|
                <div class="bottom">
 | 
						|
                    <div class="views"><i class="fa-solid fa-eye"></i><span style="margin-left: 5px;">${article.views || 0}</span></div>
 | 
						|
                    <div class="author"><i class="fa-regular fa-user"></i><span style="margin-left: 5px;">${article.author || '未知作者'}</span></div>
 | 
						|
                </div>
 | 
						|
            </div>
 | 
						|
        `;
 | 
						|
    }
 | 
						|
 | 
						|
    // 渲染资源列表
 | 
						|
    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 || '<div class="no-data">暂无数据</div>';
 | 
						|
    }
 | 
						|
 | 
						|
    // 创建资源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 `
 | 
						|
            <div class="opencourse product-item" onclick="window.open('/index/resource/detail?id=${resource.id || ''}', '_blank')">
 | 
						|
                <div class="video">
 | 
						|
                    <img src="${resource.thumbnail || '/static/images/default-resource.png'}" alt="" class="cover">
 | 
						|
                    <div class="file-type">${resource.filetype || '未知类型'}</div>
 | 
						|
                </div>
 | 
						|
                <div class="introduction">
 | 
						|
                    <div class="title">${resource.title || '无标题'}</div>
 | 
						|
                    <div class="description">${resource.description || '暂无描述'}</div>
 | 
						|
                    <div class="publishdate">${formattedDate}</div>
 | 
						|
                </div>
 | 
						|
                <div class="bottom">
 | 
						|
                    <div class="views"><i class="fa-solid fa-eye"></i><span style="margin-left: 5px;">${resource.views || 0}</span></div>
 | 
						|
                    <div class="author"><i class="fa-regular fa-user"></i><span style="margin-left: 5px;">${resource.uploader || '未知作者'}</span></div>
 | 
						|
                </div>
 | 
						|
            </div>
 | 
						|
        `;
 | 
						|
    }
 | 
						|
 | 
						|
    // 渲染程序列表
 | 
						|
    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 || '<div class="no-data">暂无数据</div>';
 | 
						|
    }
 | 
						|
 | 
						|
    // 创建程序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 `
 | 
						|
            <div class="opencourse product-item" onclick="window.open('/index/program/detail?id=${program.id || ''}', '_blank')">
 | 
						|
                <div class="video">
 | 
						|
                    <img src="${program.icon || '/static/images/default-program.png'}" alt="" class="cover">
 | 
						|
                </div>
 | 
						|
                <div class="introduction">
 | 
						|
                    <div class="title">${program.title || '无标题'}</div>
 | 
						|
                    <div class="publishdate">${formattedDate}</div>
 | 
						|
                </div>
 | 
						|
                <div class="bottom">
 | 
						|
                    <div class="views"><i class="fa-solid fa-eye"></i><span style="margin-left: 5px;">${program.views || 0}</span></div>
 | 
						|
                    <div class="author"><i class="fa-regular fa-user"></i><span style="margin-left: 5px;">${program.uploader || '未知作者'}</span></div>
 | 
						|
                </div>
 | 
						|
            </div>
 | 
						|
        `;
 | 
						|
    }
 | 
						|
 | 
						|
    // 加载分类资源
 | 
						|
    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();
 | 
						|
    });
 | 
						|
</script> |