足球比分直播
`;
previewWindow.document.open();
previewWindow.document.write(previewHtml);
previewWindow.document.close();
try {
previewWindow.document.title = rawPdfTitle;
} catch (error) {}
const previewDownloadLink = previewWindow.document.getElementById('pdf-download-link');
if (previewDownloadLink) {
previewDownloadLink.addEventListener('click', function (e) {
e.preventDefault();
triggerAttachmentDownload(pdfUrl, pdfFileName, previewWindow);
});
}
const scriptEl = previewWindow.document.createElement('script');
scriptEl.src = '/res/jprocms/default/static/plugins/pdfjs-dist/build/pdf.min.js';
scriptEl.onload = function () {
const statusEl = previewWindow.document.getElementById('pdf-status');
const viewerEl = previewWindow.document.getElementById('pdf-viewer');
const pdfjsLib = previewWindow.pdfjsLib;
if (!pdfjsLib || !statusEl || !viewerEl) {
if (statusEl) {
statusEl.textContent = 'PDF 預覽初始化失敗。';
statusEl.classList.add('is-error');
}
return;
}
pdfjsLib.GlobalWorkerOptions.workerSrc = '/res/jprocms/default/static/plugins/pdfjs-dist/build/pdf.worker.min.js';
function setStatus(message, isError) {
statusEl.textContent = message;
statusEl.classList.toggle('is-error', !!isError);
statusEl.style.display = message ? 'block' : 'none';
}
function createPageCanvas(viewport, pageNum, pageWrap) {
const canvas = previewWindow.document.createElement('canvas');
const context = canvas.getContext('2d');
const outputScale = previewWindow.devicePixelRatio || 1;
canvas.width = Math.floor(viewport.width * outputScale);
canvas.height = Math.floor(viewport.height * outputScale);
canvas.style.width = Math.floor(viewport.width) + 'px';
canvas.style.height = Math.floor(viewport.height) + 'px';
pageWrap.appendChild(canvas);
return {
context: context,
outputScale: outputScale
};
}
function getScale(page) {
const containerWidth = viewerEl.clientWidth || previewWindow.innerWidth || 1200;
const baseViewport = page.getViewport({ scale: 1 });
const safeWidth = Math.max(containerWidth - 28, 320);
return safeWidth / baseViewport.width;
}
renderPdfDocumentInChunks({
pdfjsLib: pdfjsLib,
pdfUrl: pdfUrl,
cMapUrl: '/res/jprocms/default/static/plugins/pdfjs-dist/cmaps/',
setStatus: setStatus,
createPageCanvas: createPageCanvas,
getScale: getScale,
viewerEl: viewerEl,
hostDocument: previewWindow.document,
scheduleHost: previewWindow,
firstPageDelay: 220,
onError: function (error) {
console.error('PDF 預覽失敗', error);
setStatus('PDF 加載失敗,請嘗試點擊上方下載按鈕查看。', true);
return true;
}
}).catch(function (error) {
console.error('PDF 預覽失敗', error);
setStatus('PDF 加載失敗,請嘗試點擊上方下載按鈕查看。', true);
});
};
scriptEl.onerror = function () {
const statusEl = previewWindow.document.getElementById('pdf-status');
if (statusEl) {
statusEl.textContent = 'PDF 預覽腳本加載失敗。';
statusEl.classList.add('is-error');
}
};
previewWindow.document.head.appendChild(scriptEl);
return true;
}
function getBackButtonHtml() {
return `
`;
}
function bindBackButton(data, newsList, content, page) {
const backBtn = document.getElementById('backBtn2');
if (!backBtn) return;
backBtn.addEventListener('click', function () {
newsList.style.display = 'block';
content.style.display = 'none';
page.style.display = '';
const event3 = new CustomEvent('titlenone', {
detail: { isshow: true }
});
const path = data.parentChannelPath;
if (['party_work', 'monitor', 'union', 'league'].includes(path)) {
const event4 = new CustomEvent('loadsubChannels', {
detail: { parentChannelPath: data.parentChannelPath }
});
document.dispatchEvent(event4);
} else {
const event = new CustomEvent('restoreNews', {
detail: {
channelId: data.channelId,
pageSize: 7,
id: data.id,
isshowpicture: data.path == "PublicNotice_children" ? true : false
}
});
document.dispatchEvent(event);
}
document.dispatchEvent(event3);
});
}
function renderPdfPreview(container, data) {
const pdfAttachment = getPdfAttachment(data);
if (!pdfAttachment) {
container.innerHTML = '
未找到可預覽的 PDF 附件
' + getBackButtonHtml();
return Promise.resolve(false);
}
const pdfTitle = escapeHtml(data.title || pdfAttachment.name || 'PDF 預覽');
const pdfUrl = pdfAttachment.url || '';
const pdfFileName = pdfAttachment.name || (data.title ? data.title + '.pdf' : 'download.pdf');
container.innerHTML = ''
+ '
'
+ '
'
+ '
PDF 正在加載,請稍候...
'
+ '
'
+ '
'
+ getBackButtonHtml();
const statusEl = document.getElementById('pdf-status');
const viewerEl = document.getElementById('pdf-viewer');
const downloadLinkEl = document.getElementById('pdf-download-link');
const usePdfJs = shouldUsePdfJs(pdfUrl);
if (downloadLinkEl) {
downloadLinkEl.addEventListener('click', function (e) {
e.preventDefault();
triggerAttachmentDownload(pdfUrl, pdfFileName, window);
});
}
if (!statusEl || !viewerEl || !pdfUrl) {
if (statusEl) {
statusEl.textContent = 'PDF 預覽初始化失敗。';
statusEl.classList.add('is-error');
}
return Promise.resolve(true);
}
if (!usePdfJs) {
statusEl.textContent = '當前文件地址不支持 pdf.js 直連,已切換爲瀏覽器內嵌預覽。';
viewerEl.innerHTML = ''
+ '
'
+ ''
+ '
';
return Promise.resolve(true);
}
if (!window.pdfjsLib) {
statusEl.textContent = 'PDF 預覽初始化失敗。';
statusEl.classList.add('is-error');
return Promise.resolve(true);
}
pdfjsLib.GlobalWorkerOptions.workerSrc = "/res/jprocms/default/static/plugins/pdfjs-dist/build/pdf.worker.min.js";
function setStatus(message, isError) {
statusEl.textContent = message;
statusEl.classList.toggle('is-error', !!isError);
statusEl.style.display = message ? 'block' : 'none';
}
function createPageCanvas(viewport, pageNum, pageWrap) {
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
const outputScale = window.devicePixelRatio || 1;
canvas.width = Math.floor(viewport.width * outputScale);
canvas.height = Math.floor(viewport.height * outputScale);
canvas.style.width = Math.floor(viewport.width) + 'px';
canvas.style.height = Math.floor(viewport.height) + 'px';
pageWrap.appendChild(canvas);
return {
context: context,
outputScale: outputScale
};
}
function getScale(page) {
const containerWidth = viewerEl.clientWidth || container.clientWidth || window.innerWidth || 1080;
const baseViewport = page.getViewport({ scale: 1 });
const safeWidth = Math.max(containerWidth - 28, 320);
return safeWidth / baseViewport.width;
}
return renderPdfDocumentInChunks({
pdfjsLib: pdfjsLib,
pdfUrl: pdfUrl,
cMapUrl: "/res/jprocms/default/static/plugins/pdfjs-dist/cmaps/",
setStatus: setStatus,
createPageCanvas: createPageCanvas,
getScale: getScale,
viewerEl: viewerEl,
hostDocument: document,
scheduleHost: window,
firstPageDelay: 220,
onError: function (error) {
console.error('PDF 預覽失敗', error);
viewerEl.innerHTML = ''
+ '
'
+ ''
+ '
';
setStatus('PDF 加載失敗,已自動切換爲瀏覽器內嵌預覽。', true);
return true;
}
}).catch(function (error) {
console.error('PDF 預覽失敗', error);
viewerEl.innerHTML = ''
+ '
'
+ ''
+ '
';
setStatus('PDF 加載失敗,已自動切換爲瀏覽器內嵌預覽。', true);
return true;
});
}
function loadData(pageNo, pageSize, channelId, isshowpicture) {
// console.log(isshowpicture,'isshowpicture')
document.getElementById('news-list').innerHTML = getLoadingHtml()
axios.get(`/front/content/portalPage`, {
params: {
orderStrs: 'top_level_desc,release_time_desc,id_desc',
pageNo: pageNo,
pageSize: pageSize,
channelId: channelId,
}
}).then(function (response) {
const data = response.data.data
const event = new CustomEvent('data', {
detail: {
data: data,
}
});
document.dispatchEvent(event);
list = response.data.data.list || [];
let html = '
';
list.forEach((item, index) => {
console.log(item.channelName,'item.channelName')
if (isshowpicture && index === 0) {
html += '- '
+ '
'
+ '' + (item.title || '沒有標題') + ''
+
' ';
}else if(item.channelName=='視察考察'){
html += '- ' + '' + (item.title || '沒有標題') + '' +'
';
} else if(newList.includes(item.channelName)){
html += '- ' + '' + (item.title || '沒有標題') + '' +
'' + formatDate2(item.releaseTime) + '' +
'
';
}
else {
html += '- ' + '' + (item.title || '沒有標題') + '' +
'' + formatDate(item.releaseTime) + '' +
'
';
}
});
html += '
';
document.getElementById('news-list').innerHTML = html;
$('#page-wrapper').pagination({
items: data.total,
itemsOnPage: pageSize,
currentPage: data.current,
cssStyle: '',
prevText: '上一頁',
nextText: '下一頁',
onPageClick: function (page, evt) {
loadData(page, pageSize, channelId, isshowpicture);
}
});
}).catch(function (err) {
console.error('請求失敗:', err);
document.getElementById('news-list').innerHTML = '
數據加載失敗
';
});
}
//獲取具體的內容
async function fetchContent(current) {
if (!current) return;
const content = document.getElementById('content');
const content2 = document.getElementById('content');
const newsList = document.getElementById('news-list');
const page = document.getElementById('page-wrapper');
const event3 = new CustomEvent('titlenone', {
detail: { isshow: false }
});
document.dispatchEvent(event3)
try {
res = await axios.get(`/front/content/` + current);
const hot = await axios.get(`/front/content/view/` + current).catch(function (err) {
console.warn('點擊量獲取失敗:', err);
return null;
});
const viewCount = getHotViewCount(hot);
const event2 = new CustomEvent('active', {
detail: {
active: res.data.data.path,
active2: res.data.data.parentChannelPath
}
});
document.dispatchEvent(event2);
if (Number(res.data.data.channelId) === 156 || res.data.data.channelName == '社會責任報告') {
// 兜底:異步回調中用location.href跳轉(不會被攔截)
window.location.href = `/content/` + current;
return;
}
if (res.data.data.outLink) {
window.location.href = res.data.data.outLink;
return
}
newsList.style.display = 'none';
page.style.display = 'none';
content.style.display = 'block';
content.innerHTML = getLoadingHtml()
// 直接渲染詳情
const html1 = res.data.data;
const imageList = collectAllImages(html1);
let html = '';
let carouselHtml = buildTopImageCarousel(imageList);
html = html1 ? html1.text : '數據不存在';
// 將連續圖片片段就地合併爲輪播
if (Number(res.data.data.channelId) === 121 || res.data.data.channelName == '圖片報道'){
html = transformImageRuns(html);
}
// 如果有視頻需要處理
if (html1 && html1.text) {
html = html.replace(/