340 lines
10 KiB
HTML
340 lines
10 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>项目卡片测试</title>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
|
<style>
|
|
body {
|
|
background: #1a1a1a;
|
|
color: #fff;
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
margin: 0;
|
|
padding: 20px;
|
|
}
|
|
|
|
.projects-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
|
gap: 20px;
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.project-card {
|
|
background: #2a2a2a;
|
|
border: 1px solid #3a3a3a;
|
|
border-radius: 12px;
|
|
overflow: hidden;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.project-card:hover {
|
|
border-color: #8b5cf6;
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
/* 项目头部 - 名称和菜单 */
|
|
.project-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 12px 16px;
|
|
border-bottom: 1px solid #3a3a3a;
|
|
background: #2a2a2a;
|
|
}
|
|
|
|
.project-title {
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
color: #fff;
|
|
line-height: 1.4;
|
|
flex: 1;
|
|
margin-right: 8px;
|
|
margin-bottom: 0;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.project-menu {
|
|
width: 24px;
|
|
height: 24px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
border-radius: 4px;
|
|
color: #888;
|
|
cursor: pointer;
|
|
transition: all 0.2s ease;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.project-menu:hover {
|
|
background: #3a3a3a;
|
|
color: #fff;
|
|
}
|
|
|
|
.project-menu i {
|
|
font-size: 14px;
|
|
}
|
|
|
|
.project-header-actions {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.favorite-icon {
|
|
color: #ffd700;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.project-type-badge {
|
|
position: absolute;
|
|
top: 8px;
|
|
right: 8px;
|
|
background: rgba(139, 92, 246, 0.9);
|
|
color: #fff;
|
|
padding: 4px 8px;
|
|
border-radius: 12px;
|
|
font-size: 11px;
|
|
font-weight: 500;
|
|
backdrop-filter: blur(4px);
|
|
}
|
|
|
|
/* 项目图片 */
|
|
.project-image {
|
|
width: 100%;
|
|
height: 160px;
|
|
background: #3a3a3a;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 48px;
|
|
color: #666;
|
|
flex: 1;
|
|
}
|
|
|
|
/* 项目底部 - 时间 */
|
|
.project-footer {
|
|
padding: 12px 16px;
|
|
border-top: 1px solid #3a3a3a;
|
|
background: #2a2a2a;
|
|
}
|
|
|
|
.project-date {
|
|
font-size: 12px;
|
|
color: #888;
|
|
text-align: center;
|
|
margin: 0;
|
|
}
|
|
|
|
/* 项目右键菜单 */
|
|
.project-context-menu {
|
|
position: fixed;
|
|
background: #2a2a2a;
|
|
border: 1px solid #3a3a3a;
|
|
border-radius: 8px;
|
|
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
|
|
min-width: 180px;
|
|
padding: 8px 0;
|
|
z-index: 2000;
|
|
}
|
|
|
|
.menu-item {
|
|
display: flex;
|
|
align-items: center;
|
|
padding: 10px 16px;
|
|
color: #fff;
|
|
cursor: pointer;
|
|
transition: background-color 0.2s ease;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.menu-item:hover {
|
|
background: #3a3a3a;
|
|
}
|
|
|
|
.menu-item.danger {
|
|
color: #ff6b6b;
|
|
}
|
|
|
|
.menu-item.danger:hover {
|
|
background: rgba(255, 107, 107, 0.1);
|
|
}
|
|
|
|
.menu-item i {
|
|
width: 16px;
|
|
margin-right: 12px;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.menu-divider {
|
|
height: 1px;
|
|
background: #3a3a3a;
|
|
margin: 8px 0;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>项目卡片布局测试</h1>
|
|
<div class="projects-grid" id="projectsGrid">
|
|
<!-- 项目卡片将在这里动态生成 -->
|
|
</div>
|
|
|
|
<script>
|
|
// 测试数据
|
|
const testProjects = [
|
|
{
|
|
id: 1,
|
|
title: "智慧工厂",
|
|
date: "2024-06-08 15:56:35",
|
|
type: "industrial",
|
|
image: "🏭",
|
|
favorite: true
|
|
},
|
|
{
|
|
id: 2,
|
|
title: "智慧水务",
|
|
date: "2023-01-10 12:09:04",
|
|
type: "smart",
|
|
image: "💧",
|
|
favorite: false
|
|
},
|
|
{
|
|
id: 3,
|
|
title: "数字工厂",
|
|
date: "2024-06-07 06:57:46",
|
|
type: "industrial",
|
|
image: "🏗️",
|
|
favorite: false
|
|
}
|
|
];
|
|
|
|
// 渲染项目卡片
|
|
function renderTestCards() {
|
|
const grid = document.getElementById('projectsGrid');
|
|
grid.innerHTML = '';
|
|
|
|
testProjects.forEach(project => {
|
|
const card = document.createElement('div');
|
|
card.className = 'project-card';
|
|
card.innerHTML = `
|
|
<div class="project-header">
|
|
<div class="project-title">${project.title}</div>
|
|
<div class="project-header-actions">
|
|
${project.favorite ? '<i class="fas fa-star favorite-icon" title="已收藏"></i>' : ''}
|
|
<div class="project-menu" data-project-id="${project.id}">
|
|
<i class="fas fa-ellipsis-v"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="project-image">
|
|
${project.image}
|
|
<div class="project-type-badge">${getProjectTypeLabel(project.type)}</div>
|
|
</div>
|
|
<div class="project-footer">
|
|
<div class="project-date">${project.date}</div>
|
|
</div>
|
|
`;
|
|
|
|
// 菜单点击事件
|
|
const menuBtn = card.querySelector('.project-menu');
|
|
menuBtn.addEventListener('click', (e) => {
|
|
e.stopPropagation();
|
|
showTestMenu(project.id, e.target);
|
|
});
|
|
|
|
// 卡片点击事件
|
|
card.addEventListener('click', (e) => {
|
|
if (!e.target.closest('.project-menu')) {
|
|
alert(`打开项目: ${project.title}`);
|
|
}
|
|
});
|
|
|
|
grid.appendChild(card);
|
|
});
|
|
}
|
|
|
|
// 显示测试菜单
|
|
function showTestMenu(projectId, menuButton) {
|
|
// 移除已存在的菜单
|
|
const existingMenu = document.querySelector('.project-context-menu');
|
|
if (existingMenu) {
|
|
existingMenu.remove();
|
|
}
|
|
|
|
// 创建菜单
|
|
const menu = document.createElement('div');
|
|
menu.className = 'project-context-menu';
|
|
menu.innerHTML = `
|
|
<div class="menu-item" data-action="open">
|
|
<i class="fas fa-folder-open"></i>
|
|
<span>打开项目</span>
|
|
</div>
|
|
<div class="menu-item" data-action="rename">
|
|
<i class="fas fa-edit"></i>
|
|
<span>重命名</span>
|
|
</div>
|
|
<div class="menu-item" data-action="duplicate">
|
|
<i class="fas fa-copy"></i>
|
|
<span>复制项目</span>
|
|
</div>
|
|
<div class="menu-divider"></div>
|
|
<div class="menu-item danger" data-action="delete">
|
|
<i class="fas fa-trash"></i>
|
|
<span>删除项目</span>
|
|
</div>
|
|
`;
|
|
|
|
// 定位菜单
|
|
const rect = menuButton.getBoundingClientRect();
|
|
menu.style.position = 'fixed';
|
|
menu.style.top = rect.bottom + 5 + 'px';
|
|
menu.style.left = rect.left - 150 + 'px';
|
|
|
|
document.body.appendChild(menu);
|
|
|
|
// 菜单项点击事件
|
|
menu.addEventListener('click', (e) => {
|
|
const action = e.target.closest('.menu-item')?.dataset.action;
|
|
if (action) {
|
|
alert(`执行操作: ${action} (项目ID: ${projectId})`);
|
|
menu.remove();
|
|
}
|
|
});
|
|
|
|
// 点击其他地方关闭菜单
|
|
setTimeout(() => {
|
|
document.addEventListener('click', function closeMenu(e) {
|
|
if (!menu.contains(e.target)) {
|
|
menu.remove();
|
|
document.removeEventListener('click', closeMenu);
|
|
}
|
|
});
|
|
}, 0);
|
|
}
|
|
|
|
// 获取项目类型标签
|
|
function getProjectTypeLabel(type) {
|
|
const typeLabels = {
|
|
'industrial': '工业',
|
|
'smart': '智能',
|
|
'vr': 'VR',
|
|
'game': '游戏',
|
|
'design': '设计'
|
|
};
|
|
return typeLabels[type] || '其他';
|
|
}
|
|
|
|
// 初始化
|
|
renderTestCards();
|
|
</script>
|
|
</body>
|
|
</html>
|