将分类展示改为横向按钮形式,点击切换分类,默认显示全部
This commit is contained in:
1 parent
e9d923fea9
commit
1567a3dea3
1 file changed
+82
-72
+82
-72
@@ -405,50 +405,50 @@
|
|||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.group-header {
|
.category-tabs {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
padding-bottom: 15px;
|
||||||
|
border-bottom: 2px solid #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.category-tab {
|
||||||
|
padding: 10px 20px;
|
||||||
background: #f8f9fa;
|
background: #f8f9fa;
|
||||||
padding: 15px 20px;
|
border: 2px solid transparent;
|
||||||
margin: 15px 0 10px 0;
|
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
display: flex;
|
font-size: 15px;
|
||||||
justify-content: space-between;
|
font-weight: 500;
|
||||||
align-items: center;
|
color: #666;
|
||||||
transition: background 0.3s;
|
transition: all 0.3s;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.group-header:hover {
|
.category-tab:hover {
|
||||||
background: #e9ecef;
|
background: #e9ecef;
|
||||||
}
|
|
||||||
|
|
||||||
.group-title {
|
|
||||||
font-size: 18px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: #333;
|
color: #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
.group-count {
|
.category-tab.active {
|
||||||
color: #999;
|
background: #667eea;
|
||||||
font-size: 14px;
|
color: white;
|
||||||
margin-left: 10px;
|
border-color: #667eea;
|
||||||
}
|
}
|
||||||
|
|
||||||
.group-toggle {
|
.category-count {
|
||||||
font-size: 20px;
|
display: inline-block;
|
||||||
color: #667eea;
|
margin-left: 8px;
|
||||||
transition: transform 0.3s;
|
padding: 2px 8px;
|
||||||
|
background: rgba(255, 255, 255, 0.3);
|
||||||
|
border-radius: 12px;
|
||||||
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.group-toggle.collapsed {
|
.category-tab.active .category-count {
|
||||||
transform: rotate(-90deg);
|
background: rgba(255, 255, 255, 0.25);
|
||||||
}
|
|
||||||
|
|
||||||
.group-content {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.group-content.collapsed {
|
|
||||||
display: none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.api-docs {
|
.api-docs {
|
||||||
@@ -524,6 +524,8 @@
|
|||||||
<input type="text" class="search-input" id="search-input" placeholder="🔍 搜索 Tag..." oninput="filterData()">
|
<input type="text" class="search-input" id="search-input" placeholder="🔍 搜索 Tag..." oninput="filterData()">
|
||||||
<span class="search-icon">🔍</span>
|
<span class="search-icon">🔍</span>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Category Tabs -->
|
||||||
|
<div class="category-tabs" id="category-tabs"></div>
|
||||||
<div id="data-container">
|
<div id="data-container">
|
||||||
<div class="loading">正在加载...</div>
|
<div class="loading">正在加载...</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -596,7 +598,7 @@
|
|||||||
let currentViewData = null;
|
let currentViewData = null;
|
||||||
let deleteCallback = null;
|
let deleteCallback = null;
|
||||||
let allDataItems = []; // 存储所有数据项
|
let allDataItems = []; // 存储所有数据项
|
||||||
let collapsedGroups = new Set(); // 存储折叠的分组
|
let currentCategory = '全部'; // 当前选中的分类
|
||||||
|
|
||||||
// Toast 通知
|
// Toast 通知
|
||||||
function showToast(message, type = 'success') {
|
function showToast(message, type = 'success') {
|
||||||
@@ -709,7 +711,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 渲染数据列表(支持分组)
|
// 渲染数据列表(支持分类筛选)
|
||||||
function renderDataList(items) {
|
function renderDataList(items) {
|
||||||
const container = document.getElementById('data-container');
|
const container = document.getElementById('data-container');
|
||||||
|
|
||||||
@@ -718,43 +720,27 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按分组组织数据
|
// 按分类组织数据
|
||||||
const groups = {};
|
const categories = { '全部': items };
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const colonIndex = item.tag.indexOf(':');
|
const colonIndex = item.tag.indexOf(':');
|
||||||
const groupName = colonIndex > 0 ? item.tag.substring(0, colonIndex) : '未分组';
|
const categoryName = colonIndex > 0 ? item.tag.substring(0, colonIndex) : '未分组';
|
||||||
|
|
||||||
if (!groups[groupName]) {
|
if (!categories[categoryName]) {
|
||||||
groups[groupName] = [];
|
categories[categoryName] = [];
|
||||||
}
|
}
|
||||||
groups[groupName].push(item);
|
categories[categoryName].push(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 按分组名称排序
|
// 渲染分类标签
|
||||||
const sortedGroupNames = Object.keys(groups).sort((a, b) => {
|
renderCategoryTabs(categories);
|
||||||
if (a === '未分组') return 1;
|
|
||||||
if (b === '未分组') return -1;
|
|
||||||
return a.localeCompare(b);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 渲染分组
|
// 根据当前选中分类过滤数据
|
||||||
|
const displayItems = currentCategory === '全部' ? items : (categories[currentCategory] || []);
|
||||||
|
|
||||||
|
// 渲染数据项
|
||||||
let html = '';
|
let html = '';
|
||||||
sortedGroupNames.forEach(groupName => {
|
displayItems.forEach(item => {
|
||||||
const groupItems = groups[groupName];
|
|
||||||
const isCollapsed = collapsedGroups.has(groupName);
|
|
||||||
|
|
||||||
html += `
|
|
||||||
<div class="group-header" onclick="toggleGroup('${groupName.replace(/'/g, "\\'")}')">
|
|
||||||
<div>
|
|
||||||
<span class="group-title">${groupName}</span>
|
|
||||||
<span class="group-count">(${groupItems.length})</span>
|
|
||||||
</div>
|
|
||||||
<span class="group-toggle ${isCollapsed ? 'collapsed' : ''}">▼</span>
|
|
||||||
</div>
|
|
||||||
<div class="group-content ${isCollapsed ? 'collapsed' : ''}" id="group-${groupName}">
|
|
||||||
`;
|
|
||||||
|
|
||||||
groupItems.forEach(item => {
|
|
||||||
const statusClass = `status-${item.status}`;
|
const statusClass = `status-${item.status}`;
|
||||||
const statusText = {
|
const statusText = {
|
||||||
'valid': '正常',
|
'valid': '正常',
|
||||||
@@ -787,21 +773,45 @@
|
|||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
|
|
||||||
html += '</div>';
|
container.innerHTML = html || '<div class="empty">📭 该分类暂无数据</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 渲染分类标签
|
||||||
|
function renderCategoryTabs(categories) {
|
||||||
|
const tabsContainer = document.getElementById('category-tabs');
|
||||||
|
|
||||||
|
// 按名称排序(全部放最前面)
|
||||||
|
const sortedCategories = Object.keys(categories).sort((a, b) => {
|
||||||
|
if (a === '全部') return -1;
|
||||||
|
if (b === '全部') return 1;
|
||||||
|
if (a === '未分组') return 1;
|
||||||
|
if (b === '未分组') return -1;
|
||||||
|
return a.localeCompare(b);
|
||||||
});
|
});
|
||||||
|
|
||||||
container.innerHTML = html;
|
let html = '';
|
||||||
|
sortedCategories.forEach(categoryName => {
|
||||||
|
const count = categories[categoryName].length;
|
||||||
|
const isActive = categoryName === currentCategory;
|
||||||
|
const escapedName = categoryName.replace(/'/g, "\\'");
|
||||||
|
|
||||||
|
html += `
|
||||||
|
<button class="category-tab ${isActive ? 'active' : ''}"
|
||||||
|
onclick="switchCategory('${escapedName}')">
|
||||||
|
${categoryName}
|
||||||
|
<span class="category-count">${count}</span>
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
|
||||||
|
tabsContainer.innerHTML = html;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 切换分组折叠/展开
|
// 切换分类
|
||||||
function toggleGroup(groupName) {
|
function switchCategory(categoryName) {
|
||||||
if (collapsedGroups.has(groupName)) {
|
currentCategory = categoryName;
|
||||||
collapsedGroups.delete(groupName);
|
|
||||||
} else {
|
|
||||||
collapsedGroups.add(groupName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 重新渲染当前显示的数据
|
// 应用搜索过滤(如果有)
|
||||||
const searchTerm = document.getElementById('search-input').value.trim().toLowerCase();
|
const searchTerm = document.getElementById('search-input').value.trim().toLowerCase();
|
||||||
if (searchTerm) {
|
if (searchTerm) {
|
||||||
filterData();
|
filterData();
|
||||||
|
|||||||
Reference in new issue
Block a user