首页 行业资讯 政策解读

相关资讯推荐

相关课程推荐

查看全部课程
html = html.replace(/^]*>]*><\/head>]*>/i, ''); html = html.replace(/<\/body><\/html>$/i, ''); html = html.replace(/^]*>/i, '').replace(/<\/ucapcontent>$/i, ''); html = html.trim(); // Create a temporary DOM element to parse and clean var tmp = document.createElement('div'); tmp.innerHTML = html; // Remove unwanted elements var removeSelectors = ['script','style','iframe','.breadcrumb','.breadcrumbs','.share','.social-share','.font-size','.fontsize','.toolbar','.position','.current-position','.location','.crumb','.meta-info','.article-meta','.publish-time','.author-info','.ad','.advertisement','.sidebar','.menu','nav','footer','header','ul.tabs-nav','.am-print-hide','#links']; removeSelectors.forEach(function(sel) { try { var els = tmp.querySelectorAll(sel); for (var i = els.length - 1; i >= 0; i--) els[i].parentNode.removeChild(els[i]); } catch(e) {} }); // Remove prefix noise text patterns from remaining content var allText = tmp.innerHTML; allText = allText.replace(/当前位置[::][\s\S]*?(?=[\s\S]*?(?= tags if (result && !/<(p|div|h[1-6]|ul|ol|blockquote|table|pre)[\s>]/i.test(result)) { var segments = result.split(/\n\s*\n|\n/).filter(function(s) { return s.trim().length > 0; }); if (segments.length > 1) { result = segments.map(function(s) { return '

' + s.trim() + '

'; }).join(''); } else { result = '

' + result + '

'; } } // Remove empty paragraphs result = result.replace(/]*>\s*<\/p>/gi, ''); // Ensure Chinese paragraph formatting: add text-indent to

tags without inline style var tmpDiv = document.createElement('div'); tmpDiv.innerHTML = result; var pTags = tmpDiv.querySelectorAll('p'); for (var pi = 0; pi < pTags.length; pi++) { var p = pTags[pi]; var txt = p.textContent.trim(); // Skip if contains only images or is very short if (txt.length < 2) continue; // Add Chinese paragraph indent if not already styled if (!p.getAttribute('style') || !p.getAttribute('style').includes('text-indent')) { p.style.textIndent = '2em'; p.style.lineHeight = '2'; p.style.marginBottom = '0.8em'; } } // Fix lazy-loaded images: move data-src to src var allImgs = tmpDiv.querySelectorAll('img'); for (var fi = 0; fi < allImgs.length; fi++) { var imgEl = allImgs[fi]; var imgSrc = imgEl.getAttribute('src') || ''; var imgDataSrc = imgEl.getAttribute('data-src') || imgEl.getAttribute('data-original') || imgEl.getAttribute('data-lazy-src') || ''; var isPh = imgSrc.indexOf('data:image') === 0 || imgSrc === '' || imgSrc.indexOf('placeholder') >= 0 || imgSrc.indexOf('spacer') >= 0 || imgSrc.indexOf('blank.gif') >= 0; if (isPh && imgDataSrc) { imgEl.setAttribute('src', imgDataSrc); } else if (!imgSrc && imgDataSrc) { imgEl.setAttribute('src', imgDataSrc); } // Remove base64 placeholder images that have no real src var finalSrc = imgEl.getAttribute('src') || ''; if (finalSrc.indexOf('data:image') === 0) { imgEl.parentNode.removeChild(imgEl); } } // Ensure images are responsive var imgs = tmpDiv.querySelectorAll('img'); for (var ii = 0; ii < imgs.length; ii++) { imgs[ii].style.maxWidth = '100%'; imgs[ii].style.height = 'auto'; imgs[ii].style.display = 'block'; imgs[ii].style.margin = '1em auto'; imgs[ii].style.borderRadius = '4px'; } result = tmpDiv.innerHTML; return result; } async function loadNewsDetail() { const urlParams = new URLSearchParams(window.location.search); const newsId = urlParams.get('id') || ''; if (!newsId) { document.getElementById('news-loading').classList.add('hidden'); document.getElementById('news-error').classList.remove('hidden'); return; } try { const res = await fetch('/api/industry-news/detail/' + newsId); const json = await res.json(); if (json.code !== 200 || !json.data) { document.getElementById('news-loading').classList.add('hidden'); document.getElementById('news-error').classList.remove('hidden'); return; } const news = json.data; // Set page title only - meta info displayed in page header, not repeated in body document.title = (news.title || '行业资讯') + ' - 信托物业教培平台'; // Content: use HTML content if available, with cleanup and paragraph formatting if (news.content && news.content.length > 0) { var cleanedContent = cleanArticleContent(news.content); document.getElementById('news-body').innerHTML = cleanedContent; } else { document.getElementById('news-body').innerHTML = '

暂无详细内容,点击查看原文

'; } // Update breadcrumb const bcSpan = document.querySelector('.container .text-gray-600.truncate'); if (bcSpan && news.title) { bcSpan.textContent = news.title; } // Show content document.getElementById('news-loading').classList.add('hidden'); document.getElementById('news-dynamic-content').classList.remove('hidden'); } catch (e) { console.error('Load news detail failed:', e); document.getElementById('news-loading').classList.add('hidden'); document.getElementById('news-error').classList.remove('hidden'); } } // ========= 相关资讯推荐动态加载 ========= async function loadRelatedNews() { const container = document.getElementById('related-news-list'); if (!container) return; const urlParams = new URLSearchParams(window.location.search); const currentId = urlParams.get('id') || ''; try { const res = await fetch('/api/industry-news/list?page=1&pageSize=6'); const json = await res.json(); if (json.code !== 200 || !json.data || !json.data.list) { container.innerHTML = '
暂无相关资讯
'; return; } const items = json.data.list.filter(n => String(n._id) !== currentId).slice(0, 4); if (items.length === 0) { container.innerHTML = '
暂无相关资讯
'; return; } container.innerHTML = items.map(function(n) { const nid = String(n._id || n.id || ''); const title = escapeHtml(n.title || '未命名资讯'); const date = n.publishDate ? new Date(n.publishDate).toLocaleDateString('zh-CN') : ''; const imgSeed = 'news' + nid.substring(0,8); return '' + '
' + '' + title + '' + '
' + '
' + '

' + title + '

' + '

' + date + '

' + '
'; }).join(''); } catch(e) { console.warn('相关资讯加载失败:', e.message); container.innerHTML = '
资讯加载失败
'; } } document.addEventListener('DOMContentLoaded', function() { // 加载资讯详情 loadNewsDetail(); // 加载Logo loadLogo(); // 加载相关资讯推荐 loadRelatedNews(); // 加载相关课程 loadRelatedCourses(); // 移动端菜单切换 const mobileMenuButton = document.getElementById('mobile-menu-button'); const mobileMenu = document.getElementById('mobile-menu'); if (mobileMenuButton && mobileMenu) { mobileMenuButton.addEventListener('click', function() { mobileMenu.classList.toggle('hidden'); }); } // 导航栏滚动效果 const navbar = document.getElementById('navbar'); if (navbar) { window.addEventListener('scroll', function() { if (window.scrollY > 50) { navbar.classList.add('nav-scroll', 'shadow-md'); } else { navbar.classList.remove('nav-scroll', 'shadow-md'); } }); } // 返回部按钮 const backToTopButton = document.getElementById('back-to-top'); if (backToTopButton) { window.addEventListener('scroll', function() { if (window.scrollY > 300) { backToTopButton.classList.remove('opacity-0', 'invisible'); backToTopButton.classList.add('opacity-100', 'visible'); } else { backToTopButton.classList.add('opacity-0', 'invisible'); backToTopButton.classList.remove('opacity-100', 'visible'); } }); backToTopButton.addEventListener('click', function() { window.scrollTo({ top: 0, behavior: 'smooth' }); }); } // 评论提交功能 const commentSubmitButton = document.querySelector('.comment-form button[type="button"]'); if (commentSubmitButton) { commentSubmitButton.addEventListener('click', function() { alert('请先登录后发表评论'); window.location.href = 'trust-login.html'; }); } // 平滑滚动到评论区 const commentLinks = document.querySelectorAll('a[href="#comments"]'); commentLinks.forEach(link => { link.addEventListener('click', function(e) { e.preventDefault(); const commentsSection = document.getElementById('comments'); if (commentsSection) { commentsSection.scrollIntoView({ behavior: 'smooth' }); } }); }); });