543 lines
22 KiB
HTML
543 lines
22 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-TW">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
|
<title>{% block title %}EwoooC{% endblock %}</title>
|
|
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700;800&family=Noto+Sans+TC:wght@400;500;600;700;800&display=swap" rel="stylesheet">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/ewoooc-tokens.css') }}">
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/ewoooc-shell.css') }}">
|
|
{% if active_page|default('') in [
|
|
'obs_overview', 'obs_agent_orchestration', 'obs_business_intel',
|
|
'obs_host_health', 'obs_ai_calls', 'obs_budget',
|
|
'obs_promotion_review', 'obs_rag_queries', 'obs_quality_trend',
|
|
'obs_ppt_audit'
|
|
] %}
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/observability-system.css') }}">
|
|
{% endif %}
|
|
{% block extra_css %}{% endblock %}
|
|
<style>
|
|
.momo-app[data-active-page="dashboard"] {
|
|
--momo-page-accent: var(--momo-warm-caramel);
|
|
--momo-page-accent-dark: var(--momo-warm-mahogany);
|
|
--momo-page-accent-soft: var(--momo-warm-caramel-soft);
|
|
}
|
|
.momo-app[data-active-page="edm"],
|
|
.momo-app[data-active-page="campaigns"] {
|
|
--momo-page-accent: var(--momo-warm-honey);
|
|
--momo-page-accent-dark: #7a5510;
|
|
--momo-page-accent-soft: var(--momo-warm-honey-soft);
|
|
}
|
|
.momo-app[data-active-page="sales"],
|
|
.momo-app[data-active-page="daily_sales"],
|
|
.momo-app[data-active-page="monthly"],
|
|
.momo-app[data-active-page="growth"] {
|
|
--momo-page-accent: var(--momo-warm-earth);
|
|
--momo-page-accent-dark: #65411f;
|
|
--momo-page-accent-soft: var(--momo-warm-earth-soft);
|
|
}
|
|
.momo-app[data-active-page="vendor_stockout"] {
|
|
--momo-page-accent: var(--momo-warm-rust);
|
|
--momo-page-accent-dark: #7d2520;
|
|
--momo-page-accent-soft: var(--momo-warm-rust-soft);
|
|
}
|
|
.momo-app[data-active-page="ai_recommend"],
|
|
.momo-app[data-active-page="ai_history"],
|
|
.momo-app[data-active-page="ai_intelligence"] {
|
|
--momo-page-accent: var(--momo-warm-honey);
|
|
--momo-page-accent-dark: #6e500e;
|
|
--momo-page-accent-soft: var(--momo-warm-honey-soft);
|
|
}
|
|
.momo-app[data-active-page="auto_import"],
|
|
.momo-app[data-active-page="market_intel"] {
|
|
--momo-page-accent: var(--momo-warm-mahogany);
|
|
--momo-page-accent-dark: #5e2e20;
|
|
--momo-page-accent-soft: var(--momo-warm-mahogany-soft);
|
|
}
|
|
.momo-app[data-active-page^="obs_"],
|
|
.momo-app[data-active-page="settings"],
|
|
.momo-app[data-active-page="system_settings"],
|
|
.momo-app[data-active-page="logs"],
|
|
.momo-app[data-active-page="crawler"],
|
|
.momo-app[data-active-page="user_management"],
|
|
.momo-app[data-active-page="ai_automation_smoke"] {
|
|
--momo-page-accent: var(--momo-warm-caramel);
|
|
--momo-page-accent-dark: var(--momo-warm-mahogany);
|
|
--momo-page-accent-soft: var(--momo-warm-caramel-soft);
|
|
}
|
|
|
|
.momo-app .momo-topbar-pill,
|
|
.momo-app .momo-avatar,
|
|
.momo-app .momo-shortcut,
|
|
.momo-app .momo-status-card,
|
|
.momo-app .page-header,
|
|
.momo-app .calendar-nav button,
|
|
.momo-app .kpi-card.text-white,
|
|
.momo-app .bg-purple,
|
|
.momo-app .dashboard-kpi.is-accent,
|
|
.momo-app .dashboard-segmented a.is-active,
|
|
.momo-app .dashboard-action-button.is-primary,
|
|
.momo-app .dashboard-history-range button.is-active,
|
|
.momo-app .campaign-tab.is-active,
|
|
.momo-app .campaign-slot-tab.active,
|
|
.momo-app .campaign-filter-chip.is-active,
|
|
.momo-app .campaign-history-range button.is-active,
|
|
.momo-app .vendor-action.is-primary,
|
|
.momo-app .vendor-pulse,
|
|
.momo-app .stockout-action.is-primary,
|
|
.momo-app .stockout-tab.is-active,
|
|
.momo-app .stockout-import-note,
|
|
.momo-app .filter-section,
|
|
.momo-app .monthly-version-pill,
|
|
.momo-app .nav-pills .nav-link.active,
|
|
.momo-app .nav-tabs .nav-link.active,
|
|
.momo-app .dropdown-item.active,
|
|
.momo-app .page-item.active .page-link,
|
|
.momo-app .btn-primary,
|
|
.momo-app .bg-primary,
|
|
.momo-app .bg-dark {
|
|
color: var(--momo-page-inverse) !important;
|
|
background: linear-gradient(135deg, var(--momo-page-accent), var(--momo-page-accent-dark)) !important;
|
|
border-color: var(--momo-page-accent-dark) !important;
|
|
}
|
|
|
|
.momo-app .page-header h1,
|
|
.momo-app .page-header h2,
|
|
.momo-app .page-header h3,
|
|
.momo-app .page-header h4,
|
|
.momo-app .page-header h5,
|
|
.momo-app .page-header p,
|
|
.momo-app .page-header small,
|
|
.momo-app .page-header .text-muted,
|
|
.momo-app .page-header .text-info,
|
|
.momo-app .filter-section h1,
|
|
.momo-app .filter-section h2,
|
|
.momo-app .filter-section h3,
|
|
.momo-app .filter-section h4,
|
|
.momo-app .filter-section h5,
|
|
.momo-app .filter-section h6,
|
|
.momo-app .filter-section label,
|
|
.momo-app .filter-section .form-label {
|
|
color: var(--momo-page-inverse) !important;
|
|
}
|
|
|
|
.momo-app .page-header .date-selector,
|
|
.momo-app .filter-section .form-control,
|
|
.momo-app .filter-section .form-select,
|
|
.momo-app .filter-section .custom-dropdown-btn {
|
|
color: var(--momo-text-primary) !important;
|
|
background: var(--momo-bg-elevated) !important;
|
|
border-color: rgba(255, 248, 238, 0.68) !important;
|
|
}
|
|
|
|
.momo-app .kpi-card .kpi-percent,
|
|
.momo-app .kpi-card .badge.bg-dark {
|
|
color: var(--momo-page-inverse) !important;
|
|
background: rgba(255, 248, 238, 0.18) !important;
|
|
border: 1px solid rgba(255, 248, 238, 0.24) !important;
|
|
text-shadow: none !important;
|
|
}
|
|
|
|
.momo-app .dashboard-kpi.is-accent::before,
|
|
.momo-app .momo-status-card::before {
|
|
background-image: radial-gradient(circle, rgba(255, 248, 238, 0.2) 1px, transparent 1px) !important;
|
|
}
|
|
|
|
.momo-app .dashboard-table th,
|
|
.momo-app .campaign-table th,
|
|
.momo-app .stockout-table th,
|
|
.momo-app .vendor-table th,
|
|
.momo-app .daily-sales-page .table thead th,
|
|
.momo-app .monthly-analysis-page .table thead th,
|
|
.momo-app .monthly-analysis-page .table-light th,
|
|
.momo-app .ai-intel-page .table thead th {
|
|
color: var(--momo-page-inverse) !important;
|
|
background: linear-gradient(90deg, var(--momo-page-accent-dark), var(--momo-page-accent)) !important;
|
|
border-bottom-color: color-mix(in srgb, var(--momo-page-accent-dark) 70%, #fff8ee) !important;
|
|
}
|
|
|
|
.momo-app .dashboard-table th a,
|
|
.momo-app .campaign-table th a {
|
|
color: inherit !important;
|
|
}
|
|
|
|
.momo-app .btn-outline-primary {
|
|
color: var(--momo-page-accent-dark) !important;
|
|
border-color: var(--momo-page-accent) !important;
|
|
}
|
|
|
|
.momo-app .btn-outline-primary:hover,
|
|
.momo-app .text-bg-primary,
|
|
.momo-app .badge.bg-primary,
|
|
.momo-app .progress-bar.bg-primary,
|
|
.momo-app .keyword-badge.bg-primary {
|
|
color: var(--momo-page-inverse) !important;
|
|
background-color: var(--momo-page-accent) !important;
|
|
border-color: var(--momo-page-accent) !important;
|
|
}
|
|
|
|
.momo-app .text-primary {
|
|
color: var(--momo-page-accent-dark) !important;
|
|
}
|
|
|
|
.momo-app .momo-live-dot {
|
|
background: var(--momo-page-accent);
|
|
box-shadow: 0 0 8px var(--momo-page-accent);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="momo-v2-body {% if active_page|default('') in [
|
|
'obs_overview', 'obs_agent_orchestration', 'obs_business_intel',
|
|
'obs_host_health', 'obs_ai_calls', 'obs_budget',
|
|
'obs_promotion_review', 'obs_rag_queries', 'obs_quality_trend',
|
|
'obs_ppt_audit'
|
|
] %}momo-observability-mode{% endif %}">
|
|
<div class="momo-app momo-shell" id="momo-shell" data-active-page="{{ active_page|default('') }}">
|
|
{% include 'components/_ewoooc_shell.html' %}
|
|
|
|
{% set _next_run = next_run|default(None) %}
|
|
{% set _session_username = session.get('username') if session is defined else None %}
|
|
{% set _session_role = session.get('role') if session is defined else None %}
|
|
{% set _is_logged_in = session.get('logged_in') if session is defined else false %}
|
|
|
|
<section class="momo-main-shell">
|
|
<header class="momo-topbar">
|
|
<button class="momo-mobile-menu-button" type="button" data-momo-sidebar-toggle aria-label="開啟主選單">
|
|
<i class="fas fa-bars"></i>
|
|
</button>
|
|
|
|
<form class="momo-search-box" role="search" method="GET" action="/">
|
|
<i class="fas fa-search" aria-hidden="true"></i>
|
|
<input class="momo-search-input momo-mono" type="search" name="q" value="{{ search_query|default('') }}" placeholder="搜尋商品名稱、編號、品牌...">
|
|
<kbd class="momo-shortcut momo-mono">⌘K</kbd>
|
|
</form>
|
|
|
|
<div class="momo-topbar-spacer"></div>
|
|
|
|
{% if _next_run %}
|
|
<div class="momo-topbar-pill momo-mono">
|
|
<span class="momo-live-dot"></span>
|
|
<span>下次排程</span>
|
|
<strong>{{ _next_run }}</strong>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<a class="momo-icon-button momo-obs-link" href="/observability/overview" title="AI 觀測台" id="momo-obs-link">
|
|
<i class="fas fa-satellite-dish"></i>
|
|
<span id="momo-obs-badge" class="momo-obs-badge" hidden></span>
|
|
</a>
|
|
<button class="momo-icon-button" type="button" title="說明">
|
|
<i class="fas fa-circle-question"></i>
|
|
</button>
|
|
<button class="momo-icon-button" type="button" title="通知">
|
|
<i class="fas fa-bell"></i>
|
|
</button>
|
|
|
|
{% if _is_logged_in %}
|
|
<button class="momo-user-chip" type="button">
|
|
<span class="momo-avatar">{{ (_session_username or '已')[:1] }}</span>
|
|
<span class="momo-user-meta">
|
|
<span class="momo-user-name">{{ _session_username or '已登入' }}</span>
|
|
{% if _session_role %}
|
|
<span class="momo-user-role">{{ _session_role }}</span>
|
|
{% endif %}
|
|
</span>
|
|
<i class="fas fa-chevron-down" aria-hidden="true"></i>
|
|
</button>
|
|
{% endif %}
|
|
</header>
|
|
|
|
<main class="momo-content">
|
|
{% block ewooo_content %}{% endblock %}
|
|
</main>
|
|
</section>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
|
|
<!-- MOMO 404 防呆攔截:避免自動打開 EC404 頁面 -->
|
|
<script>
|
|
(function () {
|
|
if (window.__momoLinkGuardInstalled) {
|
|
return;
|
|
}
|
|
window.__momoLinkGuardInstalled = true;
|
|
|
|
const MOMO_HOSTS = new Set(['www.momoshop.com.tw', 'm.momoshop.com.tw']);
|
|
const MOMO_CODE_RE = /^[A-Za-z0-9_-]{4,}$/;
|
|
|
|
const toText = value => (value == null ? '' : String(value));
|
|
|
|
const hasMomoHost = function (url) {
|
|
const target = toText(url).trim();
|
|
if (!target) {
|
|
return false;
|
|
}
|
|
try {
|
|
const parsed = new URL(target, location.origin);
|
|
return MOMO_HOSTS.has((parsed.hostname || '').toLowerCase());
|
|
} catch (error) {
|
|
return /(^|\/)m(?:\.momoshop\.com\.tw|\.momoshop\.com\.tw)(\/|$)|www\.momoshop\.com\.tw/i.test(target);
|
|
}
|
|
};
|
|
|
|
const isBlockedMomoUrl = function (url) {
|
|
const lowered = toText(url).toLowerCase();
|
|
if (lowered.includes('ec404.html') || lowered.includes('/ecm/js/err404/')) {
|
|
return true;
|
|
}
|
|
|
|
try {
|
|
const parsed = new URL(url, location.origin);
|
|
const path = (parsed.pathname || '').toLowerCase();
|
|
if (!path.includes('goodsdetail')) {
|
|
return false;
|
|
}
|
|
const iCode = (parsed.searchParams.get('i_code') || '').trim();
|
|
if (iCode) {
|
|
return !isLikelyMomoIcode(iCode);
|
|
}
|
|
return !/\/goodsdetail\/[^/?#]+/i.test(path);
|
|
} catch (error) {
|
|
const hasGoodsDetail = /goodsdetail\.jsp/i.test(lowered);
|
|
if (!hasGoodsDetail) {
|
|
return false;
|
|
}
|
|
const hasIcode = /[?&]i_code=([^&#]+)/i.test(lowered);
|
|
if (!hasIcode) {
|
|
return true;
|
|
}
|
|
const match = /[?&]i_code=([^&#]+)/i.exec(lowered);
|
|
const extracted = match ? (match[1] || '').trim() : '';
|
|
return !isLikelyMomoIcode(extracted);
|
|
}
|
|
};
|
|
|
|
const isLikelyMomoIcode = function (value) {
|
|
const cleaned = toText(value).trim();
|
|
if (!cleaned) {
|
|
return false;
|
|
}
|
|
const lowered = cleaned.toLowerCase();
|
|
if (lowered === 'nan' || lowered === 'none' || lowered === 'null' || lowered === 'undefined') {
|
|
return false;
|
|
}
|
|
if (lowered.startsWith('momo_')) {
|
|
return false;
|
|
}
|
|
return MOMO_CODE_RE.test(cleaned);
|
|
};
|
|
|
|
const getIcodeFromUrl = function (url) {
|
|
const target = toText(url).trim();
|
|
if (!target) {
|
|
return '';
|
|
}
|
|
|
|
try {
|
|
const parsed = new URL(target, location.origin);
|
|
const iCode = parsed.searchParams.get('i_code');
|
|
if (iCode) {
|
|
return iCode.trim();
|
|
}
|
|
} catch (error) {
|
|
// ignore
|
|
}
|
|
|
|
const match = /[?&]i_code=([^&#]+)/i.exec(target);
|
|
return match ? decodeURIComponent(match[1] || '').trim() : '';
|
|
};
|
|
|
|
const buildSafeMomoUrl = function (iCode) {
|
|
const cleaned = toText(iCode).trim();
|
|
if (!isLikelyMomoIcode(cleaned)) {
|
|
return '';
|
|
}
|
|
return `https://www.momoshop.com.tw/goods/GoodsDetail.jsp?i_code=${encodeURIComponent(cleaned)}`;
|
|
};
|
|
|
|
const resolveSafeUrl = function (link, href) {
|
|
const original = toText(link.dataset && link.dataset.momoOriginalUrl).trim();
|
|
const explicit = toText(link.dataset && (link.dataset.trackIcode || link.dataset.trackProductId)).trim();
|
|
const fallbackCode = explicit || getIcodeFromUrl(original) || getIcodeFromUrl(href);
|
|
|
|
if (fallbackCode) {
|
|
return buildSafeMomoUrl(fallbackCode);
|
|
}
|
|
return '#';
|
|
};
|
|
|
|
const openMomoUrl = function (link, url) {
|
|
if (!url || url === '#') {
|
|
return;
|
|
}
|
|
|
|
const target = toText(link.getAttribute('target') || '_self').toLowerCase();
|
|
if (target === '_blank') {
|
|
window.open(url, '_blank', 'noopener,noreferrer');
|
|
return;
|
|
}
|
|
if (target === '_self' || target === '' ) {
|
|
window.location.href = url;
|
|
return;
|
|
}
|
|
window.open(url, target);
|
|
};
|
|
|
|
const trackMomoLink = function (payload) {
|
|
const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content');
|
|
const body = {
|
|
status: 'tracked',
|
|
...payload
|
|
};
|
|
|
|
const headers = {
|
|
'Content-Type': 'application/json'
|
|
};
|
|
if (csrfToken) {
|
|
headers['X-CSRFToken'] = csrfToken;
|
|
}
|
|
|
|
fetch('/api/track_momo_link', {
|
|
method: 'POST',
|
|
headers,
|
|
body: JSON.stringify(body),
|
|
keepalive: true
|
|
}).catch(() => {});
|
|
};
|
|
|
|
const guardMomoLink = function (event) {
|
|
if (event.defaultPrevented) {
|
|
return;
|
|
}
|
|
|
|
if (event.type === 'click' && event.button && event.button !== 0) {
|
|
return;
|
|
}
|
|
if (event.type === 'auxclick' && event.button !== 1) {
|
|
return;
|
|
}
|
|
|
|
const link = event.target.closest ? event.target.closest('a') : null;
|
|
if (!link) {
|
|
return;
|
|
}
|
|
|
|
const href = toText(link.getAttribute('href') || '').trim();
|
|
if (!href || href === '#') {
|
|
return;
|
|
}
|
|
|
|
const isTrackedClass = link.classList && link.classList.contains('momo-tracked-link');
|
|
const raw = toText(link.getAttribute('href') || '').trim();
|
|
const original = toText(link.dataset && link.dataset.momoOriginalUrl).trim();
|
|
if (!isTrackedClass && !hasMomoHost(raw) && !hasMomoHost(original)) {
|
|
return;
|
|
}
|
|
|
|
const blocked = isBlockedMomoUrl(href) || isBlockedMomoUrl(original);
|
|
const payload = {
|
|
url: original || href,
|
|
page: location.pathname,
|
|
source: toText(link.dataset && link.dataset.trackSource) || 'auto-guard',
|
|
platform: toText(link.dataset && link.dataset.trackPlatform) || 'momo',
|
|
product_id: toText(link.dataset && link.dataset.trackProductId) || '',
|
|
i_code: toText(link.dataset && link.dataset.trackIcode) || '',
|
|
product_name: toText(link.dataset && link.dataset.trackProductName) || '',
|
|
label: toText(link.textContent || '').trim(),
|
|
effective_url: href,
|
|
blocked: blocked
|
|
};
|
|
|
|
if (!blocked && !isTrackedClass) {
|
|
return;
|
|
}
|
|
|
|
if (blocked) {
|
|
event.preventDefault();
|
|
|
|
const safeUrl = resolveSafeUrl(link, href);
|
|
if (safeUrl && safeUrl !== href) {
|
|
link.setAttribute('href', safeUrl);
|
|
payload.effective_url = safeUrl;
|
|
openMomoUrl(link, safeUrl);
|
|
}
|
|
|
|
trackMomoLink(payload);
|
|
return;
|
|
}
|
|
|
|
trackMomoLink(payload);
|
|
};
|
|
|
|
document.addEventListener('click', guardMomoLink, true);
|
|
document.addEventListener('auxclick', guardMomoLink, true);
|
|
})();
|
|
</script>
|
|
<script>
|
|
const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content');
|
|
|
|
const fetchWithCSRF = (url, options = {}) => {
|
|
options.headers = {
|
|
...options.headers,
|
|
'X-CSRFToken': csrfToken
|
|
};
|
|
return fetch(url, options);
|
|
};
|
|
|
|
(function () {
|
|
const shell = document.getElementById('momo-shell');
|
|
const toggle = document.querySelector('[data-momo-sidebar-toggle]');
|
|
const close = document.querySelector('[data-momo-sidebar-close]');
|
|
|
|
if (!shell || !toggle) return;
|
|
|
|
toggle.addEventListener('click', function () {
|
|
shell.classList.toggle('is-sidebar-open');
|
|
});
|
|
|
|
if (close) {
|
|
close.addEventListener('click', function () {
|
|
shell.classList.remove('is-sidebar-open');
|
|
});
|
|
}
|
|
})();
|
|
</script>
|
|
<!-- Phase 52: 觀測台 indicator polling -->
|
|
<script>
|
|
(function() {
|
|
const link = document.getElementById('momo-obs-link');
|
|
const badge = document.getElementById('momo-obs-badge');
|
|
if (!link || !badge) return;
|
|
async function refresh() {
|
|
try {
|
|
const r = await fetch('/observability/api/health_indicator', {credentials: 'same-origin'});
|
|
if (!r.ok) return;
|
|
const d = await r.json();
|
|
if (!d.ok) return;
|
|
link.title = d.tooltip || 'AI 觀測台';
|
|
if (d.alert_count > 0) {
|
|
badge.textContent = d.alert_count;
|
|
badge.hidden = false;
|
|
link.classList.add('is-alert');
|
|
} else {
|
|
badge.hidden = true;
|
|
link.classList.remove('is-alert');
|
|
}
|
|
} catch (e) { /* silent */ }
|
|
}
|
|
refresh();
|
|
setInterval(refresh, 60000); // 每 60 秒輪詢
|
|
})();
|
|
</script>
|
|
|
|
{% block extra_js %}{% endblock %}
|
|
</body>
|
|
</html>
|