URL不可访问时,弹出故障窗口。
This commit is contained in:
parent
ec6393d719
commit
dc3da3af34
@ -33,6 +33,15 @@
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<!-- 故障窗口 -->
|
||||
<div id="errorModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<h2>访问失败</h2>
|
||||
<p id="errorMessage"></p>
|
||||
<button id="closeErrorModal" class="close-btn">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="module" src="./src/index.ts"></script>
|
||||
</body>
|
||||
</html>
|
@ -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;
|
||||
}
|
23
src/index.ts
23
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user