后台同步异常时前端显示错误提示,不再卡住页面
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -192,6 +192,12 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function escapeHtml(s) {
|
||||
var d = document.createElement('div');
|
||||
d.appendChild(document.createTextNode(s));
|
||||
return d.innerHTML;
|
||||
}
|
||||
|
||||
var syncTimer = null;
|
||||
var progressShownAt = 0;
|
||||
|
||||
@@ -218,6 +224,19 @@ function pollProgress() {
|
||||
document.getElementById('sync-progress-pct').textContent = pct + '%';
|
||||
document.getElementById('sync-progress-label').textContent = data.label;
|
||||
|
||||
if (data.error) {
|
||||
clearInterval(syncTimer);
|
||||
syncTimer = null;
|
||||
document.getElementById('sync-progress-bar').style.background = 'var(--danger)';
|
||||
document.getElementById('sync-progress-label').innerHTML =
|
||||
'<span style="color:var(--danger-fg);">✕ ' + escapeHtml(data.label) + '</span>' +
|
||||
'<span style="display:block;font-size:0.78rem;color:var(--danger-fg);margin-top:4px;">' + escapeHtml(data.error) + '</span>';
|
||||
document.getElementById('sync-progress-pct').textContent = '';
|
||||
document.getElementById('sync-progress').insertAdjacentHTML('beforeend',
|
||||
'<button onclick="hideProgress()" style="display:block;margin-top:10px;padding:4px 14px;border:1px solid var(--border);border-radius:5px;background:var(--surface);color:var(--fg);cursor:pointer;font-size:0.8rem;">关闭</button>');
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.finished) {
|
||||
var elapsed = Date.now() - progressShownAt;
|
||||
var delay = elapsed < 1000 ? 1000 - elapsed : 0;
|
||||
|
||||
Reference in New Issue
Block a user