perf: 收斂活動看板前端事件與圖表載入
All checks were successful
CD Pipeline / deploy (push) Successful in 1m3s

This commit is contained in:
OoO
2026-05-18 09:54:45 +08:00
parent e167ba1497
commit 4e71ed9ecd
4 changed files with 111 additions and 51 deletions

View File

@@ -60,17 +60,27 @@ let campaignPriceChartInstance = null;
}
function ensureCampaignChart() {
if (window.EwoooCChartTheme && window.EwoooCChartTheme.loadChartJs) {
return window.EwoooCChartTheme.loadChartJs();
}
if (typeof Chart !== 'undefined') {
return Promise.resolve();
return Promise.resolve(window.Chart);
}
if (campaignChartLoader) {
return campaignChartLoader;
}
campaignChartLoader = new Promise((resolve, reject) => {
const existing = document.querySelector('script[data-chartjs-loader="campaign"]');
if (existing) {
existing.addEventListener('load', () => resolve(window.Chart), { once: true });
existing.addEventListener('error', () => reject(new Error('Chart.js 載入失敗')), { once: true });
return;
}
const script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/chart.js';
script.src = 'https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js';
script.async = true;
script.onload = resolve;
script.dataset.chartjsLoader = 'campaign';
script.onload = () => resolve(window.Chart);
script.onerror = () => reject(new Error('Chart.js 載入失敗'));
document.head.appendChild(script);
});
@@ -257,41 +267,36 @@ let campaignPriceChartInstance = null;
});
});
function triggerEdmTask() {
if (confirm('確定要手動執行 EDM 爬蟲嗎?')) {
fetch('/api/run_edm_task', {
method: 'POST',
headers: { 'X-CSRFToken': getCSRFToken() }
})
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => alert('錯誤: ' + error));
const campaignTaskMap = {
edm: {
confirmText: '確定要手動執行 EDM 爬蟲嗎?',
url: '/api/run_edm_task'
},
festival: {
confirmText: '確定要手動執行節慶活動爬蟲嗎?',
url: '/api/run_festival_task'
},
notification: {
confirmText: '確定要發送 EDM 活動通知嗎?',
url: '/api/trigger_edm_notification'
}
};
function runCampaignTask(taskName) {
const task = campaignTaskMap[taskName];
if (!task || !confirm(task.confirmText)) return;
fetch(task.url, {
method: 'POST',
headers: { 'X-CSRFToken': getCSRFToken() }
})
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => alert('錯誤: ' + error));
}
function triggerFestivalTask() {
if (confirm('確定要手動執行節慶活動爬蟲嗎?')) {
fetch('/api/run_festival_task', {
method: 'POST',
headers: { 'X-CSRFToken': getCSRFToken() }
})
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => alert('錯誤: ' + error));
}
}
function triggerNotification() {
if (confirm('確定要發送 EDM 活動通知嗎?')) {
fetch('/api/trigger_edm_notification', {
method: 'POST',
headers: { 'X-CSRFToken': getCSRFToken() }
})
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => alert('錯誤: ' + error));
}
}
document.querySelectorAll('[data-campaign-task]').forEach(button => {
button.addEventListener('click', () => runCampaignTask(button.dataset.campaignTask));
});
function trackMomoLinkClick(event) {
const link = event.target.closest('.momo-tracked-link');