From dc3da3af3446078b221d477f4211173d907a7106 Mon Sep 17 00:00:00 2001 From: Allen Date: Wed, 30 Apr 2025 18:04:22 +0800 Subject: [PATCH] =?UTF-8?q?URL=E4=B8=8D=E5=8F=AF=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=BC=B9=E5=87=BA=E6=95=85=E9=9A=9C=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 9 +++++++++ src/index.css | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/index.ts | 23 +++++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/index.html b/index.html index 2694071..9a5d38e 100644 --- a/index.html +++ b/index.html @@ -33,6 +33,15 @@ + + + \ No newline at end of file diff --git a/src/index.css b/src/index.css index 7e667b8..301a03f 100644 --- a/src/index.css +++ b/src/index.css @@ -110,4 +110,52 @@ body { width: 100%; height: 100%; border: none; +} + +/* 故障窗口样式 */ +.modal { + display: none; + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: rgba(0, 0, 0, 0.5); + z-index: 1000; +} + +.modal-content { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + background-color: white; + padding: 20px; + border-radius: 5px; + min-width: 300px; + text-align: center; +} + +.modal-content h2 { + color: #e74c3c; + margin-bottom: 15px; +} + +.modal-content p { + margin-bottom: 20px; + color: #333; +} + +.close-btn { + background-color: #3498db; + color: white; + border: none; + padding: 8px 20px; + border-radius: 4px; + cursor: pointer; + font-size: 14px; +} + +.close-btn:hover { + background-color: #2980b9; } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index a3c4355..06c6c3d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -92,6 +92,7 @@ function createMenuItem(item: MenuItem): HTMLLIElement { (document.querySelector("webview") as WebviewTag).src = url; } else { console.warn('❌ URL 不可访问:', result.error ?? `status ${result.status}`); + showErrorModal(`无法访问 ${url}\r\n异常原因:${result.error ?? `status ${result.status}`}\r\n请联系10000技术支持。`); } }); } @@ -120,6 +121,14 @@ function renderMenu(menuList: MenuItem[]) { }); } +// 显示故障窗口 +function showErrorModal(message: string) { + const errorModal = document.getElementById('errorModal') as HTMLDivElement; + const errorMessage = document.getElementById('errorMessage') as HTMLParagraphElement; + errorMessage.textContent = message; + errorModal.style.display = 'block'; +} + // 初始化 async function initialize() { // 检查登录状态 @@ -134,6 +143,20 @@ async function initialize() { if (logoutBtn) { logoutBtn.addEventListener('click', handleLogout); } + + const errorModal = document.getElementById('errorModal') as HTMLDivElement; + const closeErrorModal = document.getElementById('closeErrorModal') as HTMLButtonElement; + // 关闭按钮点击事件 + closeErrorModal.addEventListener('click', (event)=>{ + errorModal.style.display = 'none'; + }); + + // 点击窗口外部关闭 + window.addEventListener('click', (event) => { + if (event.target === errorModal) { + errorModal.style.display = 'none'; + } + }); } catch (error) { console.error('初始化失败:', error); }