首页

25秋一年级语文上册课文预习过关单.pdf

2026-03-04 8 次 PDF 2元/次
资源预览图1
资源预览图2
资源预览图3
资源预览图4
您当前为游客身份,每日免费限额1次,超出后需付费下载。
文件大小
47.20 MB
文件格式
PDF
分类
未分类
版本
通用版
newHref = newHref.replace('/search?', `/search?grade=${encodeURIComponent(currentGrade)}&semester=${encodeURIComponent(currentSemester)}&`); } link.setAttribute('href', newHref); } }); } // 处理下载按钮点击 // 创建付费下载订单 function createSingleDownloadOrder(resourceId, paymentMethod) { // 关闭弹窗 const modalEl = document.getElementById('noTermPermissionModal'); if (modalEl) { const modal = bootstrap.Modal.getInstance(modalEl); if (modal) { modal.hide(); } } // 显示加载提示 if (typeof layer !== 'undefined') { layer.load(2, {time: 0}); } // 创建订单 $.ajax({ url: '/wpan-api/v1/payments/single-download', method: 'POST', contentType: 'application/json', data: JSON.stringify({ resource_id: resourceId, payment_method: paymentMethod }), headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }) .done(function(res) { if (typeof layer !== 'undefined') { layer.closeAll('loading'); } if (res.code === 0 && res.data && res.data.pay_url) { // 跳转到支付页面 if (res.data.payment_type === 'redirect') { window.location.href = res.data.pay_url; } else { window.open(res.data.pay_url, '_blank'); } } else if (res.data && res.data.has_existing_order) { // 已有待支付订单 alert('您已有待支付订单,请先完成支付或取消订单后再重新下单'); } else { alert(res.msg || '创建订单失败'); } }) .fail(function(xhr) { if (typeof layer !== 'undefined') { layer.closeAll('loading'); } try { var res = JSON.parse(xhr.responseText); alert(res.msg || '创建订单失败'); } catch (e) { alert('系统错误,请稍后重试'); } }); } function handleDownload(resourceId) { // 防止重复点击 const downloadBtn = event.target; if (downloadBtn.disabled) return; // 禁用所有下载按钮防止重复点击 const allDownloadBtns = document.querySelectorAll('.download-btn, #mobileDownloadBtn'); allDownloadBtns.forEach(btn => { btn.disabled = true; if (btn.classList.contains('download-btn')) { btn.innerHTML = '处理中...'; } else { btn.innerHTML = '处理中...'; } }); $.get('/wpan-api/v1/download-links/' + resourceId, { _t: new Date().getTime() // 添加时间戳避免缓存 }) .done(function (res) { if (res.code === 0 && res.data && res.data.url) { // 权限检查通过,直接触发下载(不打开新页面) const downloadUrl = res.data.url; // 创建隐藏的 a 标签触发下载 const link = document.createElement('a'); link.href = downloadUrl; link.style.display = 'none'; document.body.appendChild(link); link.click(); // 延迟移除元素,确保下载已开始 setTimeout(function() { document.body.removeChild(link); }, 100); } else { // 权限不足或其他错误,检查是否有 limit_info 显示对应弹窗 if (res.data && res.data.limit_info) { showDownloadLimitModal(res); } else { // 没有 limit_info,显示错误信息 alert(res.msg || '下载链接获取失败'); } } }) .fail(function (xhr) { try { var res = JSON.parse(xhr.responseText); // 检查是否有 limit_info 显示对应弹窗 if (res.data && res.data.limit_info) { showDownloadLimitModal(res); } else { alert(res.msg || '系统错误,请稍后重试。'); } } catch (e) { alert('系统错误,请稍后重试。'); } }) .always(function() { // 恢复所有下载按钮状态 const allDownloadBtns = document.querySelectorAll('.download-btn, #mobileDownloadBtn'); allDownloadBtns.forEach(btn => { btn.disabled = false; if (btn.classList.contains('download-btn')) { btn.innerHTML = ' 前往下载'; } else { btn.innerHTML = '立即下载'; } }); }); } // 使用 a 标签跳转,避免 window.open 被拦截 // function openDownloadUrl(url) { // // 通过AJAX调用API,而不是直接访问下载链接 // $.get(url) // .done(function (res) { // if (res.code === 403 && res.data && res.data.limit_info) { // showDownloadLimitModal(res.data); // } else { // // 如果没有限制,直接跳转 // window.open(url, '_blank'); // } // }) // .fail(function (xhr) { // try { // var res = JSON.parse(xhr.responseText); // if (res.code === 403 && res.data && res.data.limit_info) { // showDownloadLimitModal(res.data); // } else { // // 如果不是403错误,直接跳转 // window.open(url, '_blank'); // } // } catch (e) { // // 如果解析失败,直接跳转 // window.open(url, '_blank'); // } // }); // } function showDownloadLimitModal(data) { // 确保Bootstrap已加载 if (typeof bootstrap === 'undefined') { alert('系统错误,请刷新页面重试'); return; } // 修复:API返回结构是 {code, data: {limit_info}, msg},需要从 data.data 获取 limit_info const apiData = data.data || {}; const limit = apiData.limit_info || {}; const used = limit.used || 0; const message = limit.message || '下载次数已达上限'; // 更严谨的游客判断 const isGuest = (typeof limit.is_guest !== 'undefined' ? limit.is_guest : (apiData.isGuest || apiData.user_type === 'guest')); // 优先检查是否需要登录(访客下载功能关闭) if (limit.need_login) { showLoginModal(); return; } // 优先检查是否需要付费下载(不管是否有学期权限) const needPayment = limit.need_payment && limit.payment_type === 'single_download'; const allowPaidDownload = limit.allow_paid_download; if (needPayment || allowPaidDownload || message === '您没有该学期资源的访问权限' || message.indexOf('需要付费下载') !== -1) { const modalEl = document.getElementById('noTermPermissionModal'); if (modalEl) { try { // 检查是否是付费下载 const needPayment = limit.need_payment && limit.payment_type === 'single_download'; const price = limit.price ? limit.price : 0; const resourceId = limit.resource_id ? limit.resource_id : null; if (needPayment && price > 0 && resourceId) { // 付费下载 document.getElementById('noTermPermissionTitle').textContent = '需要付费下载'; document.getElementById('noTermPermissionMessage').innerHTML = '该资源需要付费下载,价格为 ¥' + parseFloat(price).toFixed(2) + ''; document.getElementById('noTermPermissionTip').textContent = '支付成功后即可立即下载该资源'; // 修改按钮 const actionsEl = document.getElementById('noTermPermissionActions'); actionsEl.innerHTML = ` 前往会员中心购买学期权限 `; } else { // 普通无权限提示 document.getElementById('noTermPermissionTitle').textContent = '无学期权限,无法下载'; document.getElementById('noTermPermissionMessage').textContent = '您没有该学期资源的下载权限,请升级购买相应学期权限。'; document.getElementById('noTermPermissionTip').textContent = '如需开通更多学期权限,请前往会员中心或联系客服。'; const actionsEl = document.getElementById('noTermPermissionActions'); actionsEl.innerHTML = ` 前往会员中心 `; } const modal = new bootstrap.Modal(modalEl); modal.show(); // 监听模态框关闭事件,清理背景 modalEl.addEventListener('hidden.bs.modal', function() { cleanupModalBackdrop(); }); } catch (e) { alert('系统错误,请刷新页面重试'); } } return; } if (isGuest) { const countEl = document.getElementById('guestUsedCount'); const ipLimitInfoEl = document.getElementById('guestIpLimitInfo'); const ipLimitTextEl = document.getElementById('guestIpLimitText'); if (countEl) { countEl.textContent = used; } // 检查是否是IP限制 if (limit.ip_limit && limit.ip_limit.exceeded) { if (ipLimitInfoEl) { ipLimitInfoEl.style.display = 'block'; } if (ipLimitTextEl) { ipLimitTextEl.textContent = `该IP今日下载次数已达上限 (${limit.ip_limit.used}/${limit.ip_limit.limit})`; } } else { if (ipLimitInfoEl) ipLimitInfoEl.style.display = 'none'; } const modalEl = document.getElementById('guestDownloadLimitModal'); if (modalEl) { try { const modal = new bootstrap.Modal(modalEl); modal.show(); // 监听模态框关闭事件,清理背景 modalEl.addEventListener('hidden.bs.modal', function() { cleanupModalBackdrop(); }); // 强制显示弹窗 setTimeout(() => { if (!modalEl.classList.contains('show')) { modalEl.classList.add('show'); modalEl.style.display = 'block'; const backdrop = document.createElement('div'); backdrop.className = 'modal-backdrop fade show'; backdrop.style.zIndex = '9998'; document.body.appendChild(backdrop); } }, 100); } catch (e) { // 尝试手动显示弹窗 try { modalEl.classList.add('show'); modalEl.style.display = 'block'; const backdrop = document.createElement('div'); backdrop.className = 'modal-backdrop fade show'; backdrop.style.zIndex = '9998'; document.body.appendChild(backdrop); } catch (e2) { alert('系统错误,请刷新页面重试'); } } } else { alert('系统错误,请刷新页面重试'); } } else { const countEl = document.getElementById('memberUsedCount'); if (countEl) countEl.textContent = used; const modalEl = document.getElementById('memberDownloadLimitModal'); if (modalEl) { try { const modal = new bootstrap.Modal(modalEl); modal.show(); // 监听模态框关闭事件,清理背景 modalEl.addEventListener('hidden.bs.modal', function() { cleanupModalBackdrop(); }); } catch (e) { alert('系统错误,请刷新页面重试'); } } else { alert('系统错误,请刷新页面重试'); } } } // 清理模态框背景遮罩 function cleanupModalBackdrop() { // 移除所有模态框背景遮罩 const backdrops = document.querySelectorAll('.modal-backdrop'); backdrops.forEach(backdrop => { backdrop.remove(); }); // 移除body上的modal-open类 document.body.classList.remove('modal-open'); // 移除body上的padding-right样式 document.body.style.paddingRight = ''; } // 显示复制成功的模态框 function showModal() { const modal = new bootstrap.Modal(document.getElementById('copyModal')); modal.show(); setTimeout(() => modal.hide(), 2000); } // 复制提取码 function copyExtractionCode() { const code = document.getElementById('copyValue').textContent.trim(); navigator.clipboard.writeText(code).then(() => { document.getElementById('modalCode').textContent = code; showModal(); }); } // 显示打赏弹窗 function showDonate() { const modal = new bootstrap.Modal(document.getElementById('donateModal')); modal.show(); // 8秒后自动关闭 setTimeout(() => { modal.hide(); }, 8000); } // 显示推广分享弹窗 function showPromotionShare() { const modal = new bootstrap.Modal(document.getElementById('promotionShareModal')); modal.show(); // 生成二维码 setTimeout(function() { const resourceUrl = ''; if (resourceUrl) { // PC端二维码 const qrPC = new QRious({ element: document.getElementById('resourceQrCode'), value: resourceUrl, size: 160, background: '#ffffff', foreground: '#000000' }); // 移动端二维码 const qrMobile = new QRious({ element: document.getElementById('resourceQrCodeMobile'), value: resourceUrl, size: 120, background: '#ffffff', foreground: '#000000' }); } }, 100); // 15秒后自动关闭(推广分享需要更多时间查看) setTimeout(() => { modal.hide(); }, 15000); } // 复制文本到剪贴板 function copyToClipboard(text) { navigator.clipboard.writeText(text).then(() => { // 显示复制成功提示 const toast = document.createElement('div'); toast.className = 'position-fixed top-0 start-50 translate-middle-x p-3'; toast.style.zIndex = '9999'; toast.innerHTML = ` `; document.body.appendChild(toast); // 3秒后自动移除 setTimeout(() => { if (toast.parentElement) { toast.remove(); } }, 3000); }).catch(err => { console.error('复制失败:', err); alert('复制失败,请手动复制'); }); } // 显示登录弹窗 function showLoginModal() { document.getElementById('loginModal').style.display = 'flex'; // 刷新验证码 refreshCaptcha('login'); refreshCaptcha('register'); } // 关闭登录弹窗 function closeLoginModal() { document.getElementById('loginModal').style.display = 'none'; // 清空表单 clearForms(); } // 显示错误弹窗 function showErrorModal(message) { document.getElementById('error-message').textContent = message; document.getElementById('errorModal').style.display = 'flex'; } // 关闭错误弹窗 function closeErrorModal() { document.getElementById('errorModal').style.display = 'none'; } // 切换登录/注册标签 function switchLoginTab(tab) { // 更新标签状态 document.querySelectorAll('.login-tab').forEach(t => t.classList.remove('active')); event.target.classList.add('active'); // 更新表单显示 document.querySelectorAll('.login-form').forEach(f => f.classList.remove('active')); document.getElementById(tab + '-form').classList.add('active'); // 刷新验证码 refreshCaptcha(tab); } // 刷新验证码 function refreshCaptcha(type) { const img = document.getElementById(type + '-captcha-img'); img.src = '/captcha/' + type + '?' + new Date().getTime(); } // 清空表单 function clearForms() { const inputs = document.querySelectorAll('.form-input'); inputs.forEach(input => input.value = ''); } // 提交登录 function submitLogin() { const username = document.getElementById('login-username').value.trim(); const password = document.getElementById('login-password').value.trim(); const captcha = document.getElementById('login-captcha').value.trim(); // 输入验证和安全检查 if (!username || !password || !captcha) { showErrorModal('请填写完整信息'); return; } // 防止XSS攻击 if (username.length > 50 || password.length > 100) { showErrorModal('输入信息过长,请检查'); return; } // 验证用户名格式(只允许中文、英文、数字、下划线) if (!/^[a-zA-Z0-9_\u4e00-\u9fa5]{2,20}$/.test(username)) { showErrorModal('用户名格式不正确,只允许2-20位中文、英文、数字、下划线'); return; } // 验证密码强度 if (password.length < 6 || password.length > 20) { showErrorModal('密码长度必须在6-20位之间'); return; } const submitBtn = document.querySelector('#login-form .submit-btn'); submitBtn.disabled = true; submitBtn.textContent = '登录中...'; const formData = new FormData(); formData.append('username', username); formData.append('password', password); formData.append('captcha', captcha); // 添加CSRF令牌 const csrfToken = document.querySelector('meta[name="csrf-token"]').content; formData.append('_token', csrfToken); fetch('/members/login', { method: 'POST', headers: { 'X-CSRF-TOKEN': csrfToken }, body: formData }) .then(response => response.json()) .then(data => { if (data.code === 0) { // 登录成功,直接更新页面状态 closeLoginModal(); window.location.reload(); } else { showErrorModal(data.msg || '登录失败'); refreshCaptcha('login'); } }) .catch(error => { showErrorModal('网络错误,请重试'); console.error('Error:', error); }) .finally(() => { submitBtn.disabled = false; submitBtn.textContent = '登录'; }); } // 提交注册 function submitRegister() { const username = document.getElementById('register-username').value.trim(); const phone = document.getElementById('register-phone').value.trim(); const password = document.getElementById('register-password').value.trim(); const confirmPassword = document.getElementById('register-confirm-password').value.trim(); const captcha = document.getElementById('register-captcha').value.trim(); // 输入验证和安全检查 if (!username || !phone || !password || !confirmPassword || !captcha) { showErrorModal('请填写完整信息'); return; } // 防止XSS攻击 if (username.length > 50 || phone.length > 20 || password.length > 100) { showErrorModal('输入信息过长,请检查'); return; } // 验证用户名格式(只允许中文、英文、数字、下划线) if (!/^[a-zA-Z0-9_\u4e00-\u9fa5]{2,20}$/.test(username)) { showErrorModal('用户名格式不正确,只允许2-20位中文、英文、数字、下划线'); return; } // 验证手机号格式 if (!/^1[3-9]\d{9}$/.test(phone)) { showErrorModal('手机号格式不正确'); return; } // 验证密码强度 if (password.length < 6 || password.length > 20) { showErrorModal('密码长度必须在6-20位之间'); return; } if (password !== confirmPassword) { showErrorModal('两次输入的密码不一致'); return; } const submitBtn = document.querySelector('#register-form .submit-btn'); submitBtn.disabled = true; submitBtn.textContent = '注册中...'; const formData = new FormData(); formData.append('username', username); formData.append('phone', phone); formData.append('password', password); formData.append('captcha', captcha); // 添加CSRF令牌 const csrfToken = document.querySelector('meta[name="csrf-token"]').content; formData.append('_token', csrfToken); fetch('/members/register', { method: 'POST', headers: { 'X-CSRF-TOKEN': csrfToken }, body: formData }) .then(response => response.json()) .then(data => { if (data.code === 0) { showErrorModal('注册成功!请登录'); // 切换到登录标签 switchLoginTab('login'); // 清空注册表单 document.getElementById('register-username').value = ''; document.getElementById('register-phone').value = ''; document.getElementById('register-password').value = ''; document.getElementById('register-confirm-password').value = ''; document.getElementById('register-captcha').value = ''; } else { showErrorModal(data.msg || '注册失败'); refreshCaptcha('register'); } }) .catch(error => { showErrorModal('网络错误,请重试'); console.error('Error:', error); }) .finally(() => { submitBtn.disabled = false; submitBtn.textContent = '注册'; }); } // 侧边栏控制函数 function toggleSidebar() { const sidebar = document.getElementById('sidebar'); const overlay = document.getElementById('sidebarOverlay'); if (sidebar.classList.contains('open')) { // 关闭侧边栏 sidebar.classList.remove('open'); overlay.classList.remove('show'); document.body.style.overflow = ''; // 隐藏内容区域 hideContentArea(); } else { // 打开侧边栏 sidebar.classList.add('open'); overlay.classList.add('show'); document.body.style.overflow = 'hidden'; } } // 关闭侧边栏(用于VIP按钮的关闭功能) function closeSidebar() { const sidebar = document.getElementById('sidebar'); const overlay = document.getElementById('sidebarOverlay'); sidebar.classList.remove('open'); overlay.classList.remove('show'); document.body.style.overflow = ''; hideContentArea(); } // 切换分类菜单 function toggleCategoryMenu() { const submenu = document.getElementById('categorySubmenu'); const toggle = document.querySelector('.category-toggle'); if (submenu.classList.contains('expanded')) { submenu.classList.remove('expanded'); toggle.classList.remove('rotated'); } else { submenu.classList.add('expanded'); toggle.classList.add('rotated'); } } // 显示年级内容 function showGradeContent(grade) { const contentArea = document.getElementById('sidebarContentArea'); const contentTitle = document.getElementById('contentTitle'); const contentBody = document.getElementById('contentBody'); contentTitle.textContent = grade + '资料'; // 生成学期标签,完全按照category.html的实现方式 let semesterTabs = ''; if (grade === '一年级') { semesterTabs = `
`; } else if (grade === '二年级') { semesterTabs = `
`; } else if (grade === '三年级') { semesterTabs = `
`; } else if (grade === '四年级') { semesterTabs = `
`; } else if (grade === '五年级') { semesterTabs = `
`; } else if (grade === '六年级') { semesterTabs = `
`; } else if (grade === '七年级') { semesterTabs = `
`; } else if (grade === '八年级') { semesterTabs = `
`; } else if (grade === '九年级') { semesterTabs = `
`; } else { // 其他年级(幼小衔接、小升初、中考、高考)只有一个学期 semesterTabs = `
`; } // 设置全局变量,完全按照category.html的实现方式 currentGrade = grade; currentCategory = 'type'; // 默认显示按类型 // 根据年级设置默认学期,完全按照category.html的实现方式 if (grade === '一年级') { currentSemester = '一年级上'; } else if (grade === '二年级') { currentSemester = '二年级上'; } else if (grade === '三年级') { currentSemester = '三年级上'; } else if (grade === '四年级') { currentSemester = '四年级上'; } else if (grade === '五年级') { currentSemester = '五年级上'; } else if (grade === '六年级') { currentSemester = '六年级上'; } else if (grade === '七年级') { currentSemester = '七年级上'; } else if (grade === '八年级') { currentSemester = '八年级上'; } else if (grade === '九年级') { currentSemester = '九年级上'; } else { // 其他年级(幼小衔接、小升初、中考、高考)只有一个学期 currentSemester = grade; } // 生成年级内容,完全参考分类页面的结构 let content = ` ${semesterTabs}
语文
📁
寒假
📁
暑假
📁
预习单
📁
知识点
📁
课时练习
📁
专项练习
📁
单元测试
📁
月考试卷
📁
期中试卷
📁
期末试卷
数学
📁
寒假
📁
暑假
📁
预习单
📁
知识点
📁
课时练习
📁
专项练习
📁
单元测试
📁
月考试卷
📁
期中试卷
📁
期末试卷
英语
📁
寒假
📁
暑假
📁
预习单
📁
知识点
📁
课时练习
📁
专项练习
📁
单元测试
📁
月考试卷
📁
期中试卷
📁
期末试卷
`; contentBody.innerHTML = content; contentArea.classList.add('show'); // 验证链接中的年级参数 const links = document.querySelectorAll('.category-folder-item'); // 在内容生成后更新所有链接中的年级参数 setTimeout(() => { updateAllLinks(); }, 100); } // 切换学期 - 完全按照category.html的实现 function switchSemester(semester) { currentSemester = semester; // 更新学期按钮状态 const semesterButtons = event.target.parentElement.querySelectorAll('.btn'); semesterButtons.forEach(btn => { btn.classList.remove('active'); }); event.target.classList.add('active'); // 重置所有学科为按类型显示 resetAllSubjectsToType(); // 更新所有链接中的年级和学期参数 updateAllLinks(); } // 重置所有学科为按类型显示 - 完全按照category.html的实现 function resetAllSubjectsToType() { // 重置语文 const chineseTypeGrid = document.getElementById('chinese-type-grid'); const chineseVersionGrid = document.getElementById('chinese-version-grid'); if (chineseTypeGrid && chineseVersionGrid) { chineseTypeGrid.style.display = 'grid'; chineseVersionGrid.style.display = 'none'; } // 重置数学 const mathTypeGrid = document.getElementById('math-type-grid'); const mathVersionGrid = document.getElementById('math-version-grid'); if (mathTypeGrid && mathVersionGrid) { mathTypeGrid.style.display = 'grid'; mathVersionGrid.style.display = 'none'; } // 重置英语 const englishTypeGrid = document.getElementById('english-type-grid'); const englishVersionGrid = document.getElementById('english-version-grid'); if (englishTypeGrid && englishVersionGrid) { englishTypeGrid.style.display = 'grid'; englishVersionGrid.style.display = 'none'; } // 重置所有分类按钮状态 - 使用新的颜色类 document.querySelectorAll('.category-options .btn').forEach(option => { option.classList.remove('active'); if (option.textContent.includes('按类型')) { option.classList.add('active'); } }); currentCategory = 'type'; } // 显示VIP侧边栏 function showVipSidebar() { const sidebar = document.getElementById('sidebar'); const overlay = document.getElementById('sidebarOverlay'); // 直接打开侧边栏,不调用toggleSidebar()避免显示菜单内容 sidebar.classList.add('open'); overlay.classList.add('show'); document.body.style.overflow = 'hidden'; // 立即显示VIP内容 showVipContent(); } // 显示VIP内容 function showVipContent() { const contentArea = document.getElementById('sidebarContentArea'); const contentTitle = document.getElementById('contentTitle'); const contentBody = document.getElementById('contentBody'); contentTitle.textContent = 'VIP会员'; // 检查用户登录状态 const isLoggedIn = document.getElementById('userLoginStatus') ? document.getElementById('userLoginStatus').getAttribute('data-logged-in') === 'true' : false; let userInfoHtml = ''; if (isLoggedIn) { userInfoHtml = `
💎
欢迎回来,!
`; } else { userInfoHtml = `
💎
游客用户
登录后享受更多会员特权
`; } contentBody.innerHTML = ` ${userInfoHtml}
`; contentArea.classList.add('show'); // 加载VIP数据 loadVipLevels(); } // 隐藏内容区域 function hideContentArea() { const contentArea = document.getElementById('sidebarContentArea'); contentArea.classList.remove('show'); } // 处理内容区域返回按钮 function handleContentBack() { const contentArea = document.getElementById('sidebarContentArea'); const contentTitle = document.getElementById('contentTitle'); // 检查当前显示的内容类型 if (contentTitle.textContent === 'VIP会员') { // 如果是VIP内容,直接关闭整个侧边栏 closeSidebar(); } else { // 如果是其他内容(如分类内容),只隐藏内容区域 hideContentArea(); } } // 处理遮罩层点击 function handleOverlayClick() { const contentArea = document.getElementById('sidebarContentArea'); const contentTitle = document.getElementById('contentTitle'); // 检查当前显示的内容类型 if (contentTitle.textContent === 'VIP会员') { // 如果是VIP内容,直接关闭整个侧边栏 closeSidebar(); } else { // 如果是其他内容,使用原来的toggleSidebar逻辑 toggleSidebar(); } } // 查看资源详情 function viewResource(resourceId) { // 这里可以跳转到资源详情页面 window.location.href = '/resources/' + resourceId + '.html'; } // 按分类搜索 function searchByCategory(grade, subject, category, categoryType) { // 构建搜索URL const searchUrl = `/search?grade=${encodeURIComponent(grade)}&subject=${encodeURIComponent(subject)}&category=${category}&categoryType=${encodeURIComponent(categoryType)}`; // 跳转到搜索结果页面 window.location.href = searchUrl; } // 显示学科按类型分类内容 // 显示学科按类型分类内容 - 完全按照category.html的实现 function showSubjectTypeContent(subject) { try { // 找到对应的学科section const subjectSection = document.querySelector(`[id*="${subject}-type-grid"]`)?.closest('.mb-4') || document.querySelector(`[id*="${subject}-version-grid"]`)?.closest('.mb-4'); if (subjectSection) { // 显示类型网格,隐藏版本网格 - 完全按照category.html的实现 const typeGrid = subjectSection.querySelector(`#${subject}-type-grid`); const versionGrid = subjectSection.querySelector(`#${subject}-version-grid`); if (typeGrid) { typeGrid.style.display = 'grid'; } if (versionGrid) { versionGrid.style.display = 'none'; } } else { console.warn(`未找到 ${subject} 学科的section`); } } catch (error) { console.error('显示学科按类型分类内容时出错:', error); } } // 显示学科按版本分类内容 function showSubjectVersionContent(subject) { try { // 找到对应的学科section const subjectSection = document.querySelector(`[id*="${subject}-type-grid"]`)?.closest('.mb-4') || document.querySelector(`[id*="${subject}-version-grid"]`)?.closest('.mb-4'); if (subjectSection) { // 隐藏类型网格,显示版本网格 - 完全按照category.html的实现 const typeGrid = subjectSection.querySelector(`#${subject}-type-grid`); const versionGrid = subjectSection.querySelector(`#${subject}-version-grid`); if (typeGrid) { typeGrid.style.display = 'none'; } if (versionGrid) { versionGrid.style.display = 'grid'; } } else { console.warn(`未找到 ${subject} 学科的section`); } } catch (error) { console.error('显示学科按版本分类内容时出错:', error); } } // 切换分类方式 - 完全按照category.html的实现 function switchCategory(category) { currentCategory = category; // 更新分类按钮状态 const options = event.target.parentElement.querySelectorAll('.btn'); options.forEach(option => { option.classList.remove('active'); }); event.target.classList.add('active'); // 获取当前学科section const subjectSection = event.target.closest('.subject-section'); const subjectName = subjectSection.querySelector('.subject-name').textContent; // 根据学科切换对应的文件夹网格 if (subjectName === '语文') { const chineseTypeGrid = document.getElementById('chinese-type-grid'); const chineseVersionGrid = document.getElementById('chinese-version-grid'); if (category === 'type') { chineseTypeGrid.style.display = 'grid'; chineseVersionGrid.style.display = 'none'; } else if (category === 'version') { chineseTypeGrid.style.display = 'none'; chineseVersionGrid.style.display = 'grid'; } } else if (subjectName === '数学') { const mathTypeGrid = document.getElementById('math-type-grid'); const mathVersionGrid = document.getElementById('math-version-grid'); if (category === 'type') { mathTypeGrid.style.display = 'grid'; mathVersionGrid.style.display = 'none'; } else if (category === 'version') { mathTypeGrid.style.display = 'none'; mathVersionGrid.style.display = 'grid'; } } else if (subjectName === '英语') { const englishTypeGrid = document.getElementById('english-type-grid'); const englishVersionGrid = document.getElementById('english-version-grid'); if (category === 'type') { englishTypeGrid.style.display = 'grid'; englishVersionGrid.style.display = 'none'; } else if (category === 'version') { englishTypeGrid.style.display = 'none'; englishVersionGrid.style.display = 'grid'; } } } // 切换VIP标签页 function switchVipTab(tabName) { // 更新标签状态 document.querySelectorAll('.vip-nav-tab').forEach(tab => { tab.classList.remove('active'); }); event.target.classList.add('active'); // 更新内容显示 document.querySelectorAll('.vip-tab-content').forEach(content => { content.classList.remove('active'); }); if (tabName === 'site') { document.getElementById('vip-site-content').classList.add('active'); } else { document.getElementById('vip-category-content').classList.add('active'); loadTermVip(); } } // 渲染VIP等级列表 function renderVipLevels(levels) { const container = document.getElementById('vip-list'); if (!container) return; container.innerHTML = ''; levels.forEach(level => { let disabled = level.disabled; let buttonText = level.button_text; // 移动端按钮文本优化 let mobileButtonText = buttonText; if (!disabled && buttonText === '立即升级') { mobileButtonText = '立即开通'; } else if (!disabled && buttonText === '立即续费') { mobileButtonText = '立即续费'; } // 根据等级类型确定价格显示 let priceDisplay = ''; let priceType = ''; if (level.type === 'lifetime' && level.price_lifetime > 0) { priceDisplay = `¥${level.price_lifetime}`; priceType = 'lifetime'; } else if (level.type === 'yearly' && level.price_year > 0) { priceDisplay = `¥${level.price_year}`; priceType = 'yearly'; } else if (level.type === 'monthly' && level.price_month > 0) { priceDisplay = `¥${level.price_month}`; priceType = 'monthly'; } else { // 如果没有价格信息,尝试使用其他字段 if (level.price_lifetime > 0) { priceDisplay = `¥${level.price_lifetime}`; priceType = 'lifetime'; } else if (level.price_year > 0) { priceDisplay = `¥${level.price_year}`; priceType = 'yearly'; } else if (level.price_month > 0) { priceDisplay = `¥${level.price_month}`; priceType = 'monthly'; } else { priceDisplay = '价格待定'; priceType = level.type || 'normal'; } } let nameDisplay = level.name; let descDisplay = level.description || '会员特权: 免费下载所有资源'; // 处理终身会员的学期权限 if (level.type === 'lifetime' && level.term_permissions) { const termPermissions = (function normalize(raw) { if (!raw) return []; if (Array.isArray(raw)) return raw.filter(Boolean); let text = String(raw).trim(); // 反转义常见 HTML 实体 text = text .replace(/"/g, '"') .replace(/"/g, '"') .replace(/'|'/g, "'") .replace(/&/g, '&'); // 直接 JSON 结构 if (text.startsWith('[') || text.startsWith('{')) { try { const parsed = JSON.parse(text); if (Array.isArray(parsed)) return parsed.filter(Boolean); if (parsed && Array.isArray(parsed.permissions)) return parsed.permissions.filter(Boolean); } catch (e) {} } // 可能是单引号数组,如 ['A','B'] if (/^\s*\[.*\]\s*$/.test(text)) { try { const fixed = text.replace(/'/g, '"'); const parsed = JSON.parse(fixed); if (Array.isArray(parsed)) return parsed.filter(Boolean); } catch (e) {} } // 兜底:去掉方括号并按中英文逗号切分 text = text.replace(/^\[|\]$/g, ''); return text .split(/[,,]/) .map(s => s.replace(/^["']|["']$/g, '').trim()) .filter(Boolean); })(level.term_permissions); } // 根据卡片状态设置样式 let cardClass = 'vip-item'; let cardStyle = ''; if (level.card_status === 'current') { cardClass += ' selected'; cardStyle = 'border-color: #3498db; box-shadow: 0 4px 16px rgba(52,152,219,0.18);'; } else if (level.card_status === 'disabled') { cardClass += ' disabled'; cardStyle = 'opacity: 0.6; background-color: #f5f5f5;'; } // 如果有背景色设置,应用背景色 if (level.background_color) { cardStyle += `background-color: ${level.background_color};`; } const vipItem = document.createElement('div'); vipItem.className = cardClass; vipItem.setAttribute('data-level', level.id); vipItem.setAttribute('data-type', level.type); vipItem.setAttribute('data-price-type', priceType); if (cardStyle) { vipItem.style.cssText = cardStyle; } vipItem.innerHTML = `
${priceDisplay}
${nameDisplay}
有效期: ${level.expire_days}天
${descDisplay}
${level.status_tip ? `
${level.status_tip}
` : ''}
`; // 添加卡片点击事件(仅用于查看信息,不触发支付) if (!disabled && level.card_status !== 'disabled') { vipItem.addEventListener('click', function(e) { // 如果点击的是按钮或学期权限信息,不处理选中状态 if (e.target.classList.contains('vip-btn') || e.target.classList.contains('lifetime-term-info')) { return; } // 移除所有选中状态 document.querySelectorAll('.vip-item').forEach(i => i.classList.remove('selected')); // 添加选中状态 this.classList.add('selected'); }); } container.appendChild(vipItem); }); // 自动选择全站VIP终身会员(等级6) setTimeout(() => { const fullVipLevel = levels.find(level => level.id === 6); if (fullVipLevel) { const fullVipOption = document.querySelector('[data-level="6"]'); if (fullVipOption) { fullVipOption.click(); } } }, 100); } // 加载VIP等级数据 function loadVipLevels() { const container = document.getElementById('vip-list'); if (!container) return; // 显示加载状态 container.innerHTML = '
正在加载VIP等级数据...
'; fetch('/wpan-api/v1/members/levels') .then(res => { if (!res.ok) { throw new Error(`HTTP error! status: ${res.status}`); } return res.json(); }) .then(res => { if (res.code === 0) { if (res.data && res.data.length > 0) { renderVipLevels(res.data); } else { container.innerHTML = '
暂无VIP等级数据
'; } } else { console.error('加载会员等级失败:', res.msg); const errorDiv = document.createElement('div'); errorDiv.className = 'error-state'; errorDiv.textContent = '加载失败:' + (res.msg || '未知错误'); container.appendChild(errorDiv); } }) .catch(error => { console.error('加载会员等级出错:', error); const errorDiv = document.createElement('div'); errorDiv.className = 'error-state'; errorDiv.textContent = '加载失败,请稍后重试。错误:' + (error.message || '未知错误'); container.appendChild(errorDiv); }); } // 购买VIP等级 function buyVipLevel(levelId, priceType) { // 检查用户登录状态 const isLoggedIn = document.getElementById('userLoginStatus') ? document.getElementById('userLoginStatus').getAttribute('data-logged-in') === 'true' : false; if (!isLoggedIn) { showLoginModal(); return; } const csrfToken = document.querySelector('meta[name="csrf-token"]').content; fetch('/wpan-payment/create', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrfToken }, body: JSON.stringify({ level_id: levelId, payment_method: 'wxpay', type: priceType }) }) .then(response => response.json()) .then(data => { if (data.code === 0) { if (data.data.has_existing_order) { showExistingOrderModal(data.data); } else { window.location.href = data.data.pay_url; } } else { showErrorModal(data.msg || '创建订单失败'); } }) .catch(error => { showErrorModal('网络错误,请重试'); console.error('Error:', error); }); } // 加载学期VIP数据 function loadTermVip() { const container = document.getElementById('term-grid'); if (!container) return; fetch('/wpan-api/v1/members/me/terms') .then(res => res.json()) .then(res => { if(res.code === 0 && res.data && res.data.terms && res.data.terms.length > 0){ container.innerHTML = ''; const terms = res.data.terms || []; terms.forEach(term => { let btnClass = 'term-btn'; let disabled = ''; let text = term.name; if ((res.data && res.data.is_site_vip) || term.is_bought) { btnClass += ' disabled'; disabled = 'disabled'; if (term.is_bought) { text = `${term.name}`; } } const btn = document.createElement('button'); btn.className = btnClass; btn.setAttribute('data-term', term.id); btn.setAttribute('data-term-data', JSON.stringify(term)); btn.disabled = disabled === 'disabled'; btn.innerHTML = text; if (!btn.disabled) { btn.addEventListener('click', function() { document.querySelectorAll('.term-btn').forEach(b => { b.classList.remove('selected'); }); this.classList.add('selected'); selectedTerm = this.dataset.term; const selectedTip = document.querySelector('.selected-tip'); const selectedTermSpan = document.querySelector('.selected-term'); const countdownSpan = document.querySelector('.countdown'); selectedTip.style.display = 'flex'; selectedTermSpan.textContent = term.name; countdownSpan.textContent = `¥${term.price}`; const vipInfoCard = document.querySelector('.vip-info-card'); vipInfoCard.style.display = 'block'; vipInfoCard.innerHTML = `
¥${term.price}
有效期: ${term.expire_days || 365}天
${term.desc || '会员特权: 免费下载当前类目下的所有资料'}
`; const activateBtn = document.querySelector('.activate-btn'); activateBtn.style.display = 'block'; }); } container.appendChild(btn); }); } else { container.innerHTML = '
暂无分类VIP数据
'; } }) .catch(error => { console.error('加载学期VIP失败:', error); container.innerHTML = '
加载失败,请稍后重试
'; }); } // 分类VIP选择 let selectedTerm = null; // 分类VIP激活 function activateCategoryVip() { if (!selectedTerm) { showErrorModal('请先选择要激活的学期'); return; } const isLoggedIn = document.getElementById('userLoginStatus') ? document.getElementById('userLoginStatus').getAttribute('data-logged-in') === 'true' : false; if (!isLoggedIn) { showLoginModal(); return; } const csrfToken = document.querySelector('meta[name="csrf-token"]').content; fetch('/term-vip/create-order', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrfToken }, body: JSON.stringify({term_code: selectedTerm, payment_method: 'wxpay'}) }) .then(res => res.json()) .then(res => { if (res.code === 0) { if (res.data.has_existing_order) { showExistingOrderModal(res.data); } else { window.location.href = res.data.pay_url; } } else { showErrorModal(res.msg || '创建订单失败'); } }) .catch(error => { console.error('创建学期VIP订单失败:', error); showErrorModal('创建订单失败,请重试'); }); } // 显示重复订单弹窗 function showExistingOrderModal(orderData) { document.getElementById('existing-order-no').textContent = orderData.order_no; document.getElementById('existing-order-amount').textContent = `¥${orderData.amount}`; // 计算剩余时间 const expireTime = new Date(orderData.expire_time); const now = new Date(); const remainingTime = Math.max(0, Math.floor((expireTime - now) / 1000)); const minutes = Math.floor(remainingTime / 60); const seconds = remainingTime % 60; const timeStr = `${minutes}:${seconds.toString().padStart(2, '0')}`; document.getElementById('existing-order-time').textContent = timeStr; // 存储订单数据用于后续操作 window.existingOrderData = orderData; document.getElementById('existingOrderModal').style.display = 'flex'; } // 关闭重复订单弹窗 function closeExistingOrderModal() { document.getElementById('existingOrderModal').style.display = 'none'; window.existingOrderData = null; } // 取消重复订单 function cancelExistingOrder() { if (!window.existingOrderData) { closeExistingOrderModal(); return; } const csrfToken = document.querySelector('meta[name="csrf-token"]').content; // 显示加载提示 const loadingText = '正在取消订单...'; const loadingElement = document.createElement('div'); loadingElement.style.cssText = ` position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,0.8); color: white; padding: 20px; border-radius: 8px; z-index: 10003; font-size: 14px; `; loadingElement.textContent = loadingText; document.body.appendChild(loadingElement); fetch('/wpan-payment/cancel-order', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrfToken }, body: JSON.stringify({ order_no: window.existingOrderData.order_no }) }) .then(response => { if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.json(); }) .then(data => { document.body.removeChild(loadingElement); if (data.code === 0) { showErrorModal('订单已取消,可以重新下单'); closeExistingOrderModal(); } else { showErrorModal(data.msg || '取消订单失败'); } }) .catch(error => { document.body.removeChild(loadingElement); showErrorModal('网络错误,请重试'); console.error('Error:', error); }); } // 点击弹窗外部关闭弹窗 document.addEventListener('DOMContentLoaded', function() { document.getElementById('loginModal').addEventListener('click', function(e) { if (e.target === this) { closeLoginModal(); } }); document.getElementById('errorModal').addEventListener('click', function(e) { if (e.target === this) { closeErrorModal(); } }); document.getElementById('existingOrderModal').addEventListener('click', function(e) { if (e.target === this) { closeExistingOrderModal(); } }); // 监听ESC键关闭侧边栏 document.addEventListener('keydown', function(e) { if (e.key === 'Escape') { const sidebar = document.getElementById('sidebar'); if (sidebar.classList.contains('open')) { toggleSidebar(); } } }); // 点击弹窗外部关闭弹窗 document.getElementById('loginModal').addEventListener('click', function(e) { if (e.target === this) { closeLoginModal(); } }); document.getElementById('errorModal').addEventListener('click', function(e) { if (e.target === this) { closeErrorModal(); } }); });