Files
crawler-plugin/app/web_source/brand.html
2026-03-26 16:42:25 +08:00

930 lines
43 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>浜氶┈閫?- 鍗楁棩AI</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: "Microsoft YaHei", "Noto Serif SC", "SimSun", "Songti SC", "Times New Roman", serif;
background: rgba(13, 13, 13, 1);
color: #e0e0e0;
overflow: hidden;
height: 100vh;
font-weight: bold;
}
.top-bar {
height: 56px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 16px;
border-bottom: 1px solid #2a2a2a;
}
.logo-area {
display: flex;
align-items: center;
gap: 10px;
}
.top-bar .app-name { font-size: 18px; font-weight: 600; color: #fff; }
.btn-home {
font-size: 13px;
color: #999;
text-decoration: none;
padding: 8px 12px;
border-radius: 6px;
transition: all 0.2s;
}
.btn-home:hover { color: #fff; background: #2a2a2a; }
/* 椤堕儴鏍忕洰瀵艰埅锛堝鍣ㄥ寲锛屼究浜庡悗缁鍔犳爮鐩級 */
.nav-tabs {
display: flex;
align-items: center;
gap: 0;
}
.nav-tab-group {
display: flex;
align-items: center;
gap: 6px;
background: rgba(77, 72, 72, 0.99);
border-radius: 10px;
}
.nav-tab-sep {
width: 1px;
height: 20px;
background: linear-gradient(to bottom, transparent, #444 15%, #444 85%, transparent);
margin: 0 10px;
flex-shrink: 0;
opacity: 0.9;
}
.nav-tab {
padding: 8px 14px;
font-size: 13px;
color: #999;
background: transparent;
border: none;
border-radius: 6px;
cursor: pointer;
transition: all 0.2s;
}
.nav-tab:hover {
color: #fff;
background: #2a2a2a;
}
.nav-tab.active {
color: #3498db;
background: rgba(52, 152, 219, 0.2);
}
.top-right {
display: flex;
align-items: center;
gap: 8px;
}
.main-content {
display: flex;
height: calc(100vh - 56px);
}
/* 鏍忕洰鍐呭瀹瑰櫒锛氭瘡涓爮鐩竴涓?.tab-panel锛岄€氳繃 data-panel 涓庡鑸搴?*/
.tab-panel {
display: none;
flex: 1;
min-width: 0;
min-height: 0;
}
.tab-panel.active {
display: flex;
}
.left-panel {
width: 380px;
background: #1e1e1e;
padding: 20px;
overflow-y: auto;
border-right: 1px solid #2a2a2a;
}
.right-panel {
flex: 1;
display: flex;
flex-direction: column;
min-width: 0;
background: #1a1a1a;
}
.section-title {
font-size: 13px;
color: #bbb;
margin-bottom: 10px;
}
.upload-zone {
border: 1px dashed #3a3a3a;
border-radius: 10px;
padding: 24px;
text-align: center;
background: #252525;
margin-bottom: 20px;
transition: all 0.2s;
}
.upload-zone:hover { border-color: #3498db; background: #2a2a2a; }
.upload-zone .hint { color: #888; font-size: 13px; margin-bottom: 12px; }
.upload-zone .btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.opt-btn {
padding: 8px 16px;
font-size: 13px;
color: #ccc;
background: #2a2a2a;
border: 1px solid #3a3a3a;
border-radius: 6px;
cursor: pointer;
transition: all 0.2s;
}
.opt-btn:hover { color: #fff; background: #333; border-color: #3498db; color: #3498db; }
.selected-files {
margin-top: 12px;
font-size: 12px;
color: #888;
max-height: 72px;
overflow-y: auto;
}
.selected-files span { display: block; margin: 4px 0; word-break: break-all; }
.option-group { margin-bottom: 20px; }
.radio-item {
display: flex;
align-items: flex-start;
gap: 10px;
cursor: pointer;
padding: 10px 12px;
border-radius: 8px;
background: #252525;
border: 1px solid #2a2a2a;
margin-bottom: 8px;
}
.radio-item:hover { background: #2a2a2a; }
.radio-item input { margin-top: 3px; }
.radio-item .label { font-weight: 500; color: #e0e0e0; font-size: 13px; }
.radio-item .desc { font-size: 12px; color: #888; margin-top: 2px; font-weight: normal; }
.run-row {
display: flex;
align-items: center;
gap: 12px;
margin-top: 16px;
}
.btn-run {
padding: 10px 22px;
background: #3498db;
color: #fff;
border: none;
border-radius: 8px;
font-size: 14px;
cursor: pointer;
transition: all 0.2s;
}
.btn-run:hover { background: #2980b9; }
.btn-run:disabled { background: #555; cursor: not-allowed; color: #999; }
.loading-msg { color: #3498db; font-size: 13px; }
.template-download-row {
margin-top: 16px;
padding: 14px 16px;
background: linear-gradient(135deg, #252525 0%, #1e2a1e 100%);
border: 1px solid #2a3a2a;
border-radius: 10px;
display: flex;
align-items: center;
gap: 14px;
transition: all 0.25s ease;
cursor: pointer;
}
.template-download-row:hover {
border-color: #2e7d32;
background: linear-gradient(135deg, #2a2a2a 0%, #243324 100%);
box-shadow: 0 4px 12px rgba(46, 125, 50, 0.15);
}
.template-download-row:hover .template-download-text .title { color: #2ecc71; }
.template-download-row:hover .template-download-icon {
transform: scale(1.05);
box-shadow: 0 6px 16px rgba(46, 125, 50, 0.45), inset 0 1px 0 rgba(255,255,255,0.15);
}
.template-download-icon {
width: 48px;
height: 48px;
flex-shrink: 0;
border-radius: 10px;
background: linear-gradient(145deg, #1b5e20 0%, #2e7d32 50%, #388e3c 100%);
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4px 12px rgba(46, 125, 50, 0.35), inset 0 1px 0 rgba(255,255,255,0.1);
transition: transform 0.2s, box-shadow 0.2s;
}
.template-download-icon svg {
width: 28px;
height: 28px;
}
.template-download-text .title { font-size: 14px; color: #e0e0e0; font-weight: 600; display: block; }
.template-download-text .hint { font-size: 12px; color: #888; margin-top: 2px; font-weight: normal; }
.panel-header {
padding: 16px 20px;
border-bottom: 1px solid #2a2a2a;
font-size: 15px;
font-weight: 600;
color: #ddd;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.panel-header-title {
flex: 1;
}
.btn-refresh-tasks {
padding: 6px 14px;
font-size: 12px;
border-radius: 6px;
border: 1px solid #3a3a3a;
background: #2a2a2a;
color: #ccc;
cursor: pointer;
transition: all 0.2s;
white-space: nowrap;
}
.btn-refresh-tasks:hover {
background: #333;
border-color: #3498db;
color: #3498db;
}
.task-list-wrap {
flex: 1;
overflow-y: auto;
padding: 16px;
}
.task-list { list-style: none; }
.task-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 14px 16px;
border: 1px solid #2a2a2a;
border-radius: 8px;
margin-bottom: 10px;
background: #1e1e1e;
}
.task-item .left { flex: 1; min-width: 0; }
.task-item .id { font-weight: 600; color: #e0e0e0; font-size: 13px; }
.task-item .files { font-size: 12px; color: #888; margin-top: 4px; }
.task-item .time { font-size: 12px; color: #666; margin-top: 2px; }
.task-item .status {
padding: 4px 10px;
border-radius: 6px;
font-size: 12px;
margin-right: 12px;
}
.task-item .status.pending { background: rgba(255,193,7,0.2); color: #d4a500; }
.task-item .status.running { background: rgba(52,152,219,0.2); color: #3498db; }
.task-item .status.success { background: rgba(46,204,113,0.2); color: #2ecc71; }
.task-item .status.failed { background: rgba(231,76,60,0.2); color: #e74c3c; }
.task-item .status.cancelled { background: rgba(149,165,166,0.2); color: #95a5a6; }
.task-item .progress-wrap { margin-top: 8px; margin-right: 8px; flex-shrink: 0; width: 120px; }
.task-item .progress-bar-bg { height: 6px; background: #2a2a2a; border-radius: 3px; overflow: hidden; }
.task-item .progress-bar-fill { height: 100%; background: #3498db; border-radius: 3px; transition: width 0.2s; }
.task-item .btn-cancel, .task-item .btn-delete {
padding: 6px 12px; font-size: 12px; border-radius: 6px; cursor: pointer; border: none; margin-left: 6px;
transition: all 0.2s;
}
.task-item .btn-cancel { background: #e67e22; color: #fff; }
.task-item .btn-cancel:hover { background: #d35400; }
.task-item .btn-delete { background: #444; color: #ccc; }
.task-item .btn-delete:hover { background: #e74c3c; color: #fff; }
.task-item .task-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.run-row .progress-wrap { margin-top: 10px; width: 100%; max-width: 280px; }
.run-row .progress-bar-bg { height: 8px; background: #2a2a2a; border-radius: 4px; overflow: hidden; }
.run-row .progress-bar-fill { height: 100%; background: #3498db; border-radius: 4px; transition: width 0.2s; }
.run-row .btn-cancel-run { margin-left: 12px; padding: 8px 16px; background: #e67e22; color: #fff; border: none; border-radius: 6px; font-size: 13px; cursor: pointer; }
.run-row .btn-cancel-run:hover { background: #d35400; }
.task-item .download {
padding: 6px 14px;
background: #3498db;
color: #fff;
border: none;
border-radius: 6px;
font-size: 13px;
cursor: pointer;
text-decoration: none;
white-space: nowrap;
transition: all 0.2s;
}
.task-item .download:hover { background: #2980b9; color: #fff; }
.task-item .download.hide { display: none; }
.empty-tasks { text-align: center; color: #666; padding: 32px; font-size: 13px; }
.toast {
position: fixed;
bottom: 32px;
left: 50%;
transform: translateX(-50%);
background: rgba(0,0,0,0.85);
color: #fff;
padding: 12px 24px;
border-radius: 8px;
font-size: 14px;
z-index: 1000;
opacity: 0;
transition: opacity 0.3s;
border: 1px solid #333;
}
.toast.show { opacity: 1; }
</style>
</head>
<body>
<header class="top-bar">
<div class="logo-area">
<span class="app-name">鍗楁棩AI-浜氶┈閫?/span>
<a href="/home" class="btn-home">杩斿洖棣栭〉</a>
</div>
<nav class="nav-tabs">
<span class="nav-tab-group">
<button type="button" class="nav-tab active" data-panel="brandCheck">鍝佺墝妫€娴?/button>
<button type="button" class="nav-tab" onclick="window.location='/new_web_source/dedupe.html'">鎬绘暟鎹幓閲?/button>
<button type="button" class="nav-tab" onclick="window.location='/new_web_source/convert.html'">鏍煎紡杞崲</button>
<button type="button" class="nav-tab" onclick="window.location='/new_web_source/split.html'">琛ㄦ牸鎷嗗垎</button>
<!-- 鍚庣画澧炲姞鏍忕洰鏃跺湪姝ゆ坊鍔狅紝渚嬪锛?button type="button" class="nav-tab" data-panel="other">鍏朵粬鏍忕洰</button> -->
</span>
<!-- 澶氱粍鏍忕洰鏃跺彲鐢ㄥ垎闅旂锛?span class="nav-tab-sep" aria-hidden="true"></span> -->
</nav>
<div class="top-right"></div>
</header>
<div class="main-content">
<!-- 鍝佺墝妫€娴嬫爮鐩鍣紱鍚庣画澧炲姞鏍忕洰鏃跺鍒舵缁撴瀯锛屾敼 data-panel 涓?id锛屽苟鍘绘帀 .active -->
<div class="tab-panel active" data-panel="brandCheck" id="panel-brandCheck">
<aside class="left-panel">
<div class="section-title">閫夋嫨鏂囦欢</div>
<div class="upload-zone" id="uploadZone">
<div class="hint">閫夋嫨 .xlsx 鏂囦欢鎴栨枃浠跺す锛堝皢璇诲彇璇ユ枃浠跺す涓嬫墍鏈?xlsx锛?/div>
<div class="btns">
<button type="button" class="opt-btn" id="btnSelectFiles">閫夋嫨 Excel 鏂囦欢</button>
<button type="button" class="opt-btn" id="btnSelectFolder">閫夋嫨鏂囦欢澶?/button>
</div>
<div class="selected-files" id="selectedFiles"></div>
</div>
<div class="section-title">杩愯鏂瑰紡</div>
<div class="option-group">
<label class="radio-item">
<input type="radio" name="runMode" value="immediate" checked>
<div>
<span class="label">绔嬪嵆杩愯</span>
<div class="desc">绔嬪埢鎵ц锛屾墽琛屽畬鎴愬悗鍙笅杞界粨鏋?/div>
</div>
</label>
<label class="radio-item">
<input type="radio" name="runMode" value="task">
<div>
<span class="label">娣诲姞浠诲姟</span>
<div class="desc">鏁伴噺杈冨鏃跺缓璁坊鍔犱换鍔★紝鍚庡彴鎵ц锛屽彲鍦ㄥ彸渚т换鍔¢槦鍒楁煡鐪嬬姸鎬佷笌涓嬭浇缁撴灉</div>
</div>
</label>
</div>
<div class="section-title">鍖归厤鏂瑰紡</div>
<div class="option-group">
<label class="radio-item">
<input type="radio" name="matchStrategy" value="Terms" checked>
<div>
<span class="label">绮剧‘鍖归厤琛ㄨ揪寮?/span>
<div class="desc">浣跨敤绮剧‘鍖归厤锛岄€傚悎涓ユ牸鍖归厤鍝佺墝鍚嶇О</div>
</div>
</label>
<label class="radio-item">
<input type="radio" name="matchStrategy" value="Simple">
<div>
<span class="label">宓屽叆锛堢粨鏋滃寘鍚緭鍏ョ殑璇嶈锛?/span>
<div class="desc">浣跨敤宓屽叆绛栫暐锛岀粨鏋滀腑鍖呭惈杈撳叆鐨勫搧鐗岃瘝璇?/div>
</div>
</label>
</div>
<div class="run-row" id="runRow">
<div style="display:flex;align-items:center;flex-wrap:wrap;gap:10px;">
<button type="button" class="btn-run" id="btnRun">绔嬪嵆杩愯</button>
<span class="loading-msg" id="loadingMsg" style="display:none;">鐢熸垚涓紝璇风◢鍊欌€?/span>
<div class="progress-wrap" id="runProgressWrap" style="display:none;">
<div class="progress-bar-bg"><div class="progress-bar-fill" id="runProgressFill" style="width:0%;"></div></div>
<span class="hint" style="font-size:12px;color:#888;" id="runProgressText">0 / 0</span>
</div>
<!-- 褰撳墠鏂囦欢琛岀骇杩涘害锛堜笉缁忔暟鎹簱涓浆锛屽彧璇诲唴瀛樻帴鍙o級 -->
<div class="progress-wrap" id="runLineProgressWrap" style="display:none;">
<div class="progress-bar-bg"><div class="progress-bar-fill" id="runLineProgressFill" style="width:0%;"></div></div>
<span class="hint" style="font-size:12px;color:#888;" id="runLineProgressText">0 / 0</span>
</div>
<button type="button" class="btn-cancel-run" id="btnCancelRun" style="display:none;">鍙栨秷鐢熸垚</button>
</div>
</div>
<div class="template-download-row" id="templateDownloadRow" role="button" tabindex="0" title="涓嬭浇鍝佺墝鏂囨。鏍煎紡妯℃澘锛堥€夋嫨淇濆瓨浣嶇疆锛?>
<span class="template-download-icon" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z" stroke="rgba(255,255,255,0.9)" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M14 2v6h6" stroke="rgba(255,255,255,0.9)" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M8 13h8M8 17h5" stroke="rgba(255,255,255,0.85)" stroke-width="1.5" stroke-linecap="round"/>
</svg>
</span>
<span class="template-download-text">
<span class="title">妯℃澘涓嬭浇</span>
<span class="hint">鍝佺墝鏂囨。鏍煎紡_妯℃澘.xlsx 路 鐐瑰嚮閫夋嫨淇濆瓨浣嶇疆</span>
</span>
</div>
<div class="template-download-row" id="templateDownloadRow2" role="button" tabindex="0" title="涓嬭浇妯℃澘2锛堜互鏂囦欢澶规柟寮忎笂浼狅級">
<span class="template-download-icon" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z" stroke="rgba(255,255,255,0.9)" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M14 2v6h6" stroke="rgba(255,255,255,0.9)" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3 7v10h4v-4h2v4h8v-4h2v4h2V7H3z" stroke="rgba(255,255,255,0.85)" stroke-width="1.5" stroke-linecap="round"/>
</svg>
</span>
<span class="template-download-text">
<span class="title">妯℃澘2涓嬭浇</span>
<span class="hint">浠ユ枃浠跺す鏂瑰紡涓婁紶.zip 路 鐐瑰嚮涓嬭浇</span>
</span>
</div>
</aside>
<div class="right-panel">
<div class="panel-header">
<span class="panel-header-title">浠诲姟闃熷垪</span>
<button type="button" class="btn-refresh-tasks" id="btnRefreshTasks">鍒锋柊浠诲姟鐘舵€?/button>
</div>
<div class="task-list-wrap">
<ul class="task-list" id="taskList"></ul>
<div class="empty-tasks" id="emptyTasks">鏆傛棤浠诲姟</div>
</div>
</div>
</div>
</div>
<div class="toast" id="toast"></div>
<script>
(function() {
var selectedPaths = [];
var cachedTasks = [];
var api = window.pywebview && window.pywebview.api;
// 椤堕儴鏍忕洰鍒囨崲锛氱偣鍑?nav-tab 鏃舵樉绀哄搴?data-panel 鐨?tab-panel
document.querySelectorAll('.nav-tab').forEach(function(tab) {
tab.addEventListener('click', function() {
var panelId = this.getAttribute('data-panel');
if (!panelId) return;
document.querySelectorAll('.nav-tab').forEach(function(t) { t.classList.remove('active'); });
document.querySelectorAll('.tab-panel').forEach(function(p) {
p.classList.toggle('active', p.getAttribute('data-panel') === panelId);
});
this.classList.add('active');
});
});
function showToast(msg) {
var el = document.getElementById('toast');
el.textContent = msg;
el.classList.add('show');
setTimeout(function() { el.classList.remove('show'); }, 2500);
}
function renderSelected() {
var el = document.getElementById('selectedFiles');
if (selectedPaths.length === 0) {
el.innerHTML = '';
return;
}
el.innerHTML = '宸查€?<b>' + selectedPaths.length + '</b> 涓枃浠讹細<br>' +
selectedPaths.slice(0, 20).map(function(p) {
var name = p.split(/[/\\]/).pop();
return '<span title="' + p + '">' + name + '</span>';
}).join('') +
(selectedPaths.length > 20 ? '<span>鈥?绛?' + selectedPaths.length + ' 涓?/span>' : '');
}
document.getElementById('btnSelectFiles').onclick = async function(e) {
e.stopPropagation();
if (!api || !api.select_brand_xlsx_files) {
showToast('褰撳墠鐜涓嶆敮鎸佹枃浠堕€夋嫨锛岃鍦ㄦ湰鏈哄鎴风涓墦寮€');
return;
}
try {
var paths = await api.select_brand_xlsx_files();
if (paths && paths.length) {
selectedPaths = paths;
renderSelected();
showToast('宸查€夋嫨 ' + paths.length + ' 涓枃浠?);
}
} catch (err) {
showToast('閫夋嫨澶辫触锛? + (err.message || err));
}
};
document.getElementById('templateDownloadRow').onclick = async function(e) {
e.preventDefault();
if (api && api.save_template_xlsx) {
try {
var res = await api.save_template_xlsx();
if (res && res.success) {
showToast('妯℃澘宸蹭繚瀛樿嚦锛? + (res.path || ''));
} else {
showToast(res && res.error ? res.error : '淇濆瓨澶辫触');
}
} catch (err) {
showToast('涓嬭浇澶辫触锛? + (err.message || err));
}
return;
}
window.location.href = '/static/鍝佺墝鏂囨。鏍煎紡_妯℃澘.xlsx';
};
document.getElementById('templateDownloadRow').onkeydown = function(e) {
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); this.click(); }
};
document.getElementById('templateDownloadRow2').onclick = async function(e) {
e.preventDefault();
if (api && api.save_template_zip) {
try {
var res = await api.save_template_zip();
if (res && res.success) {
showToast('妯℃澘宸蹭繚瀛樿嚦锛? + (res.path || ''));
} else {
showToast(res && res.error ? res.error : '淇濆瓨澶辫触');
}
} catch (err) {
showToast('涓嬭浇澶辫触锛? + (err.message || err));
}
return;
}
window.location.href = '/static/妯℃澘2-浠ユ枃浠跺す鏂瑰紡涓婁紶.zip';
};
document.getElementById('templateDownloadRow2').onkeydown = function(e) {
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); this.click(); }
};
document.getElementById('btnSelectFolder').onclick =async function(e) {
e.stopPropagation();
if (!api || !api.select_brand_folder) {
showToast('褰撳墠鐜涓嶆敮鎸佹枃浠跺す閫夋嫨锛岃鍦ㄦ湰鏈哄鎴风涓墦寮€');
return;
}
try {
var folder = await api.select_brand_folder();
if (!folder) return;
fetch('/api/brand/expand-folder', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest' },
credentials: 'same-origin',
body: JSON.stringify({ folder: folder })
})
.then(function(r) { return r.json(); })
.then(function(res) {
if (res.success && res.paths && res.paths.length) {
selectedPaths = res.paths;
renderSelected();
showToast('宸查€夋嫨鏂囦欢澶瑰唴 ' + res.paths.length + ' 涓?xlsx 鏂囦欢');
} else {
showToast(res.error || '璇ユ枃浠跺す涓嬫病鏈?xlsx 鏂囦欢');
}
})
.catch(function() { showToast('璇锋眰澶辫触'); });
} catch (err) {
showToast('閫夋嫨澶辫触锛? + (err.message || err));
}
};
function getRunMode() {
var r = document.querySelector('input[name="runMode"]:checked');
return r ? r.value : 'immediate';
}
function getMatchStrategy() {
var r = document.querySelector('input[name="matchStrategy"]:checked');
return r ? r.value : 'Terms';
}
var pollTaskId = null;
var pollTimer = null;
var runTaskEventSource = null;
function stopPollAndResetRunUI() {
pollTaskId = null;
if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
if (runTaskEventSource) {
runTaskEventSource.close();
runTaskEventSource = null;
}
var btn = document.getElementById('btnRun');
var loadingMsg = document.getElementById('loadingMsg');
var runProgressWrap = document.getElementById('runProgressWrap');
var runLineProgressWrap = document.getElementById('runLineProgressWrap');
var btnCancelRun = document.getElementById('btnCancelRun');
btn.disabled = false;
loadingMsg.style.display = 'none';
if (runProgressWrap) runProgressWrap.style.display = 'none';
if (runLineProgressWrap) runLineProgressWrap.style.display = 'none';
if (btnCancelRun) btnCancelRun.style.display = 'none';
}
function onRunTaskFinished(status) {
stopPollAndResetRunUI();
loadTasks();
if (status === 'success') showToast('鐢熸垚瀹屾垚锛屽彲涓嬭浇缁撴灉');
else if (status === 'failed') showToast('鐢熸垚澶辫触');
else if (status === 'cancelled') showToast('宸插彇娑?);
}
function pollRunTask(taskId) {
pollTaskId = taskId;
var runProgressFill = document.getElementById('runProgressFill');
var runProgressText = document.getElementById('runProgressText');
var runLineProgressWrap = document.getElementById('runLineProgressWrap');
var runLineProgressFill = document.getElementById('runLineProgressFill');
var runLineProgressText = document.getElementById('runLineProgressText');
var btnCancelRun = document.getElementById('btnCancelRun');
var runProgressWrap = document.getElementById('runProgressWrap');
runProgressWrap.style.display = 'block';
btnCancelRun.style.display = 'inline-block';
btnCancelRun.onclick = function() {
fetch('/api/brand/tasks/' + taskId + '/cancel', { method: 'POST', credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } })
.then(function(r) { return r.json(); })
.then(function(res) {
if (res.success) onRunTaskFinished('cancelled');
else showToast(res.error || '鍙栨秷澶辫触');
});
};
// 閫氳繃 SSE 璁㈤槄浠诲姟瀹屾垚浜嬩欢锛屽畬鎴愬悗鐢卞悗绔富鍔ㄦ帹閫侊紝鍓嶇鏀跺埌鍚庣珛鍗抽殣钘忚繘搴︽潯鍜屽彇娑堟寜閽?
var eventsUrl = '/api/brand/tasks/' + taskId + '/events';
runTaskEventSource = new EventSource(eventsUrl);
runTaskEventSource.onmessage = function(e) {
try {
var data = JSON.parse(e.data);
if (data && (data.status === 'success' || data.status === 'failed' || data.status === 'cancelled')) {
runTaskEventSource.close();
runTaskEventSource = null;
// tick();
onRunTaskFinished(data.status);
}
} catch (err) {}
};
runTaskEventSource.onerror = function() {
runTaskEventSource.close();
runTaskEventSource = null;
};
function tick() {
if (!pollTaskId) return;
fetch('/api/brand/tasks/' + taskId, { credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } })
.then(function(r) { return r.json(); })
.then(function(res) {
if (!res.success || !res.task) return;
var t = res.task;
var total = t.progress_total || 0;
var cur = t.progress_current || 0;
if (runProgressFill) runProgressFill.style.width = total ? (100 * cur / total) + '%' : '30%';
if (runProgressText) {
var st = (t.status || '').toLowerCase();
if (st === 'running') {
runProgressText.textContent = total ? (cur + ' / ' + total) : '鐢熸垚涓€?;
} else if (st === 'success') {
runProgressText.textContent = '宸插畬鎴?;
} else if (st === 'failed') {
runProgressText.textContent = '澶辫触';
} else if (st === 'cancelled') {
runProgressText.textContent = '宸插彇娑?;
} else {
runProgressText.textContent = '鎵ц?;
}
}
// 琛岀骇杩涘害锛氫粠鍐呭瓨鎺ュ彛 /api/brand/tasks/<id>/line-progress 鎷夊彇
if (runLineProgressWrap && runLineProgressFill && runLineProgressText) {
var st2 = (t.status || '').toLowerCase();
if (st2 === 'running') {
fetch('/api/brand/tasks/' + taskId + '/line-progress', {
credentials: 'same-origin',
headers: { 'X-Requested-With': 'XMLHttpRequest' }
})
.then(function(r) { return r.json(); })
.then(function(res2) {
if (!res2.success || !res2.has_progress || !res2.info) {
runLineProgressWrap.style.display = 'none';
return;
}
var info = res2.info;
var totalLines = info.total_lines || 0;
var curLine = info.current_line || 0;
runLineProgressWrap.style.display = 'block';
runLineProgressFill.style.width = totalLines ? (100 * curLine / totalLines) + '%' : '0%';
runLineProgressText.textContent = totalLines ? (curLine + ' / ' + totalLines) : '褰撳墠鏂囦欢澶勭悊涓€?;
})
.catch(function(err) {
console.error('loadTasks failed:', err);
showToast('浠诲姟鍒楄鍒锋柊澶辫触');
});
} else {
runLineProgressWrap.style.display = 'none';
}
}
// 缁堟€佷篃閫氳繃杞鍏滃簳锛岀‘淇?UI 涓€瀹氳閲嶇疆锛圫SE 鍙兘鍥犵綉缁滄湭鏀跺埌锛?
var st = (t.status || '').toLowerCase();
if (st === 'success' || st === 'failed' || st === 'cancelled') {
onRunTaskFinished(st);
}
});
}
tick();
pollTimer = setInterval(tick, 5000);
}
document.getElementById('btnRun').onclick = function() {
if (selectedPaths.length === 0) {
showToast('璇峰厛閫夋嫨 Excel 鏂囦欢鎴栨枃浠跺す');
return;
}
var mode = getRunMode();
var strategy = getMatchStrategy();
var btn = document.getElementById('btnRun');
var loadingMsg = document.getElementById('loadingMsg');
if (mode === 'immediate') {
btn.disabled = true;
loadingMsg.style.display = 'inline';
fetch('/api/brand/run', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest' },
credentials: 'same-origin',
body: JSON.stringify({ paths: selectedPaths, strategy: strategy, task_type: 1 })
})
.then(function(r) { return r.json(); })
.then(function(res) {
if (res.success && res.task_id) {
loadTasks();
loadingMsg.style.display = 'none';
pollRunTask(res.task_id);
} else {
stopPollAndResetRunUI();
showToast(res.error || '杩愯澶辫触');
}
})
.catch(function() {
stopPollAndResetRunUI();
showToast('璇锋眰澶辫触鎴栬秴鏃?);
});
} else {
fetch('/api/brand/tasks', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest' },
credentials: 'same-origin',
body: JSON.stringify({ paths: selectedPaths, strategy: strategy, task_type: 2 })
})
.then(function(r) { return r.json(); })
.then(function(res) {
if (res.success) {
showToast('浠诲姟宸叉坊鍔狅紝璇峰湪浠诲姟闃熷垪鏌ョ湅');
loadTasks();
} else {
showToast(res.error || '娣诲姞澶辫触');
}
})
.catch(function() { showToast('璇锋眰澶辫触'); });
}
};
function loadTasks() {
fetch('/api/brand/tasks', { credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } })
.then(function(r) { return r.json(); })
.then(function(res) {
var list = document.getElementById('taskList');
var empty = document.getElementById('emptyTasks');
if (!res.success || !res.items || res.items.length === 0) {
list.innerHTML = '';
empty.style.display = 'block';
return;
}
empty.style.display = 'none';
cachedTasks = res.items;
list.innerHTML = res.items.map(function(t) {
var statusClass = (t.status || 'pending').toLowerCase();
var statusText = { pending: '绛夊緟涓?, running: '鎵ц?, success: '宸插畬鎴?, failed: '澶辫触', cancelled: '宸插彇娑? }[t.status] || t.status;
var filesDesc = (t.file_paths && t.file_paths.length) ? t.file_paths.length + ' 涓枃浠? : '';
var total = t.progress_total || 0;
var cur = t.progress_current || 0;
var pct = total ? Math.min(100, (100 * cur / total)) : 0;
var progressHtml = (statusClass === 'running' && total > 0)
? '<div class="progress-wrap"><div class="progress-bar-bg"><div class="progress-bar-fill" style="width:' + pct + '%"></div></div><span class="hint" style="font-size:11px;color:#888;">' + cur + ' / ' + total + '</span></div>'
: '';
var hasZipUrl = t.result_paths && t.result_paths.zip_url;
var downloadHtml = hasZipUrl
? '<a class="download js-save-zip" href="#" data-task-id="' + t.id + '">涓嬭浇缁撴灉</a>'
: '<span class="download hide"></span>';
var cancelBtn = statusClass === 'running'
? '<button type="button" class="btn-cancel js-cancel-task" data-task-id="' + t.id + '">鍙栨秷</button>'
: '';
var deleteBtn = '<button type="button" class="btn-delete js-delete-task" data-task-id="' + t.id + '">鍒犻櫎</button>';
var titleDesc = (t.desc && String(t.desc).trim()) ? String(t.desc).trim() : ('浠诲姟 #' + t.id);
var displayDesc = titleDesc.length > 20 ? titleDesc.substring(0, 20) + '....' : titleDesc;
return '<li class="task-item">' +
'<div class="left">' +
'<span class="id" title="' + (titleDesc.replace(/"/g, '&quot;')) + '">' + displayDesc + '</span>' +
'<div class="files">' + filesDesc + '</div>' +
'<div class="time">' + (t.created_at || '') + '</div>' +
'</div>' +
'<div class="task-right">' +
progressHtml +
'<span class="status ' + statusClass + '">' + statusText + '</span>' +
cancelBtn +
downloadHtml +
deleteBtn +
'</div></li>';
}).join('');
})
.catch(function(err) {
console.error('loadTasks failed:', err);
showToast('浠诲姟鍒楄〃鍒锋柊澶辫触');
});
}
// 鎵嬪姩鍒锋柊浠诲姟鐘舵€佹寜閽?
var btnRefreshTasks = document.getElementById('btnRefreshTasks');
if (btnRefreshTasks) {
btnRefreshTasks.onclick = function () {
loadTasks();
showToast('浠诲姟鐘舵€佸凡鍒锋柊');
};
}
document.getElementById('taskList').addEventListener('click', function(e) {
var target = e.target && e.target.closest && (e.target.closest('a.js-save-zip') || e.target.closest('button.js-cancel-task') || e.target.closest('button.js-delete-task'));
if (!target) return;
e.preventDefault();
var taskId = target.getAttribute('data-task-id');
if (target.classList && (target.classList.contains('js-cancel-task') || target.closest('.js-cancel-task'))) {
var btn = target.classList.contains('js-cancel-task') ? target : target.closest('.js-cancel-task');
if (!btn) return;
fetch('/api/brand/tasks/' + taskId + '/cancel', { method: 'POST', credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } })
.then(function(r) { return r.json(); })
.then(function(res) {
if (res.success) { showToast('宸插彇娑?); loadTasks(); } else { showToast(res.error || '鍙栨秷澶辫触'); }
});
return;
}
if (target.classList && (target.classList.contains('js-delete-task') || target.closest('.js-delete-task'))) {
var btn = target.classList.contains('js-delete-task') ? target : target.closest('.js-delete-task');
if (!btn) return;
fetch('/api/brand/tasks/' + taskId, { method: 'DELETE', credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } })
.then(function(r) { return r.json(); })
.then(function(res) {
if (res.success) { showToast('宸插垹闄?); loadTasks(); } else { showToast(res.error || '鍒犻櫎澶辫触'); }
});
return;
}
var a = target.closest('a.js-save-zip') || target;
if (!a || !a.classList || !a.classList.contains('js-save-zip')) return;
var task = cachedTasks.filter(function(t) { return String(t.id) === String(taskId); })[0];
if (!task || !task.result_paths || !task.result_paths.zip_url) {
showToast('鏃犳硶鑾峰彇涓嬭浇鍦板潃');
return;
}
var zipUrl = task.result_paths.zip_url;
var filename = 'brand_task_' + taskId + '.zip';
if (api && api.save_file_from_url) {
a.style.pointerEvents = 'none';
var done = function(ret) {
if (ret && ret.success) {
showToast('宸蹭繚瀛橈細' + (ret.path || filename));
} else if (ret && ret.error && ret.error !== '鐢ㄦ埛鍙栨秷') {
showToast('淇濆瓨澶辫触锛? + ret.error);
}
a.style.pointerEvents = '';
};
try {
var ret = api.save_file_from_url(zipUrl, filename);
if (ret && typeof ret.then === 'function') {
ret.then(done).catch(function(err) { showToast('淇濆瓨澶辫触锛? + (err && err.message || err)); a.style.pointerEvents = ''; });
} else {
done(ret);
}
} catch (err) {
showToast('淇濆瓨澶辫触锛? + (err.message || err));
a.style.pointerEvents = '';
}
} else {
window.open('/api/brand/download/' + taskId, '_blank');
}
});
loadTasks();
setInterval(loadTasks, 5000);
if (window.addEventListener) {
window.addEventListener('pywebviewready', function() {
api = window.pywebview && window.pywebview.api;
});
}
if (window.pywebview && window.pywebview.api) api = window.pywebview.api;
})();
</script>
</body>
</html>