CommunityAPP_UI/Backstage/sidebar.html

231 lines
8.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="zh-Hant">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>功能列</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
background-color: #ffffff;
}
* {
box-sizing: border-box;
}
.sidebar {
width: 100%;
height: 100%;
background-color: #f8f9fa;
border-right: 1px solid #ddd;
overflow-y: auto;
overflow-x: hidden;
}
.sidebar img {
display: block;
margin: 20px auto;
width: 60px;
height: 60px;
border-radius: 50%;
}
.sidebar ul {
list-style: none;
padding: 0;
margin: 0;
}
.sidebar ul li {
color: #333;
cursor: pointer;
padding: 12px 20px;
transition: background 0.2s ease;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
}
.sidebar ul li:hover,
.sidebar ul li.active {
background-color: #e6f0f8;
color: #007bff;
}
.has-submenu > .submenu-toggle {
display: flex;
justify-content: space-between;
align-items: center;
}
.has-submenu ul {
list-style: none;
padding-left: 15px;
margin: 0;
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease, padding 0.3s ease;
}
.has-submenu.open ul {
padding-top: 5px;
max-height: 200px; /* 您可以根據需要調整子選單展開的最大高度 */
}
.has-submenu ul li {
padding: 10px 20px;
font-size: 16px;
color: #444;
}
.has-submenu ul li:hover {
background-color: #deeaf6;
}
.submenu-arrow {
font-size: 12px;
}
.badge {
display: inline-block;
min-width: 20px;
padding: 2px 6px;
margin-left: 8px;
font-size: 12px;
font-weight: bold;
color: white;
background-color: red;
border-radius: 10px;
text-align: center;
vertical-align: middle;
}
.sidebar ul li .li-content {
display: flex;
justify-content: space-between;
align-items: center;
}
/* ---- 這部分是為了讓 "未開通居民" 完整顯示而調整的樣式 ---- */
.sidebar ul li .li-content > span:first-child {
flex-grow: 1; /* 允許文字部分伸展以佔用可用空間 */
min-width: 0; /* 在flex佈局中這有助於正確處理溢出和 ellipsis */
/* white-space, overflow, text-overflow 將從下面的通用規則繼承 */
}
.sidebar ul li .li-content .badge {
flex-shrink: 0; /* 防止徽章被壓縮 */
}
/* ---- 調整結束 ---- */
.sidebar ul li .li-content span { /* 此規則同時應用於文字 span 和徽章 span */
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<div class="sidebar">
<img src="https://cdn-icons-png.freepik.com/512/4873/4873262.png" alt="Logo" />
<ul>
<li class="active" onclick="requestNavigation('dashboard.html', this)">首頁</li>
<li class="has-submenu">
<div class="submenu-toggle" onclick="toggleSubmenu(this)">
<span>住戶居民</span>
<span class="submenu-arrow"></span>
</div>
<ul>
<li onclick="requestNavigation('resident_activation.html', this)">
<div class="li-content">
<span>未開通居民</span>
<span class="badge">8</span>
</div>
</li>
<li onclick="requestNavigation('resident_list.html', this)">居民列表</li></ul>
</li>
<li onclick="requestNavigation('some_page1.html', this)">出入管理</li>
<li onclick="requestNavigation('some_page2.html', this)">緊急通報</li>
<li onclick="requestNavigation('some_page3.html', this)">訊息通知</li>
<li onclick="requestNavigation('some_page4.html', this)">水電服務</li>
<li onclick="requestNavigation('some_page5.html', this)">佈告欄</li>
<li onclick="requestNavigation('some_page6.html', this)">報表匯出</li>
<li onclick="requestNavigation('some_page7.html', this)">設定</li>
</ul>
</div>
<script>
function requestNavigation(url, clickedElement) {
console.log('Sidebar: 發送導航請求 ->', url);
parent.postMessage({ type: 'navigate', url: url }, '*');
// 移除所有主項目和子項目的 active class
const allItems = document.querySelectorAll('.sidebar ul li, .sidebar ul ul li');
allItems.forEach(item => item.classList.remove('active'));
// 為當前點擊的項目添加 active class
// 如果點擊的是子選單項,也將其父選單項目標記為 (視覺上) active (如果需要)
clickedElement.classList.add('active');
// 如果點擊的是子選單中的項目,並且希望父選單也保持某種 'active' 或 'open' 的視覺提示
// 目前的邏輯是點擊主選單項時移除其他 active子選單項點擊時父選單的 active 狀態會被移除
// 如果希望父選單在子選單 active 時也高亮,需要調整 class 邏輯
// 例如,只移除頂層 li 的 active然後再設定。
// 但目前的 active class 主要是用於頂層 li子選單項本身高亮。
// 如果父選單本身不是導航目標,只是個切換器,那它不應該有 active 狀態,除非子項被選中時特別標記
if (!clickedElement.closest('.has-submenu > .submenu-toggle')) { // 確保不是點擊 submenu-toggle 本身
const parentLi = clickedElement.closest('.sidebar > ul > li'); // 直接父 li
if (parentLi && parentLi !== clickedElement) { // 如果點擊的是子選單項
// 可以考慮不移除父 li 的 active或者給父 li 一個不同的 "parent-active" class
// 目前邏輯:如果點擊的是子項,父項(如"住戶居民"的li的 active 會被移除,然後子項獲得 active
// 為了清晰,讓頂層選單項(非子選單展開器)和子選單項競爭 active
const topLevelListItems = document.querySelectorAll('.sidebar > ul > li');
topLevelListItems.forEach(item => {
if(item !== parentLi || !parentLi.classList.contains('has-submenu')){ // 非 submenu 的父級 li
item.classList.remove('active');
}
});
if (parentLi && !parentLi.classList.contains('has-submenu')){
parentLi.classList.add('active');
} else if (!clickedElement.closest('.has-submenu ul')) { // 如果點擊的是頂層且非 submenu-toggle
clickedElement.classList.add('active');
}
} else if (clickedElement.closest('.sidebar > ul > li')) { // 點擊的是頂層 li
const topLevelListItems = document.querySelectorAll('.sidebar > ul > li');
topLevelListItems.forEach(item => item.classList.remove('active'));
clickedElement.classList.add('active');
}
}
}
function toggleSubmenu(toggleElement) {
const parentLi = toggleElement.closest('.has-submenu');
parentLi.classList.toggle('open');
const arrow = toggleElement.querySelector('.submenu-arrow');
if (arrow) {
arrow.textContent = parentLi.classList.contains('open') ? '▲' : '▼';
}
// 當展開/收起子選單時,不要改變父選單項的 active 狀態
// 也不要觸發 requestNavigation
// event.stopPropagation(); // 如果 toggleSubmenu 是由事件直接調用且需要阻止冒泡
}
// 初始化:確保第一個 'active' 的項目在加載時是正確的
// 或者,您可以根據載入的頁面來動態設定 active class
document.addEventListener('DOMContentLoaded', () => {
// 假設 'dashboard.html' 是首頁,它已經有 active class
// 如果需要更複雜的邏輯來根據當前 URL 設定 active class可以在這裡添加
});
</script>
</body>
</html>