You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

709 lines
20 KiB

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>二维码合集</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
background-color: #F5F7FA;
color: #333333;
-webkit-overflow-scrolling: touch;
overflow-x: hidden;
position: relative;
touch-action: manipulation;
}
html, body {
height: 100%;
overflow: hidden;
overscroll-behavior: none;
}
.container {
max-width: 480px;
margin: 0 auto;
background-color: #F5F7FA;
height: 100%;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
position: relative;
padding: 0;
}
.header {
display: flex;
align-items: center;
justify-content: center;
padding: 16px;
background-color: #2E7D32;
color: white;
position: relative;
border-bottom: 1px solid #E0E0E0;
}
.header h1 {
font-size: 18px;
font-weight: 600;
margin: 0;
}
.back-btn {
position: absolute;
left: 16px;
background: none;
border: none;
color: white;
font-size: 20px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
padding: 4px;
}
.filter-section {
padding: 16px;
background-color: white;
border-bottom: 1px solid #E0E0E0;
display: flex;
align-items: center;
gap: 12px;
}
.filter-section .filter-toggle {
flex-shrink: 0;
}
.filter-section .search-box {
flex: 1;
min-width: 150px;
}
.filter-section .search-box input:focus {
border-color: #4CAF50;
}
.filter-section .filter-sidebar-btn {
flex-shrink: 0;
}
.filter-title {
font-size: 14px;
color: #666666;
display: flex;
align-items: center;
gap: 4px;
}
.filter-toggle {
display: flex;
background-color: #F0F0F0;
border-radius: 20px;
padding: 4px;
gap: 4px;
}
.filter-toggle-btn {
padding: 6px 12px;
border: none;
border-radius: 16px;
background-color: transparent;
color: #666666;
font-size: 14px;
cursor: pointer;
transition: all 0.3s;
}
.filter-toggle-btn.active {
background-color: #4CAF50;
color: white;
}
.qr-section {
padding: 0 16px;
margin-top: 16px;
}
.qr-item {
background-color: white;
border-radius: 8px;
padding: 12px 16px;
margin-bottom: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
transition: transform 0.2s;
}
.qr-item:active {
transform: scale(0.98);
}
.qr-item-info {
flex: 1;
}
.qr-item-name {
font-size: 16px;
font-weight: 500;
color: #333333;
line-height: 24px;
margin-bottom: 4px;
}
.qr-item-details {
font-size: 14px;
color: #666666;
line-height: 20px;
}
.qr-item-arrow {
color: #999999;
font-size: 16px;
margin-left: 12px;
}
.qr-content {
background-color: white;
border-radius: 8px;
padding: 16px;
margin-top: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
display: none;
}
.qr-content img {
max-width: 100%;
max-height: 250px;
margin: 0 auto;
display: block;
border-radius: 4px;
}
.qr-info {
margin-top: 12px;
font-size: 14px;
color: #666666;
text-align: center;
}
.qr-info p {
margin-bottom: 4px;
}
.qr-info .name {
font-weight: 500;
color: #333333;
}
.empty-state {
text-align: center;
padding: 40px 20px;
color: #999999;
}
.empty-state img {
max-width: 100px;
margin-bottom: 15px;
opacity: 0.5;
}
.filter-sidebar-btn {
background-color: #4CAF50;
color: white;
border: none;
border-radius: 8px;
padding: 8px 12px;
font-size: 14px;
cursor: pointer;
display: flex;
align-items: center;
gap: 6px;
}
.filter-sidebar {
position: fixed;
top: 0;
right: -300px;
width: 250px;
height: 100%;
background: white;
box-shadow: -2px 0 5px rgba(0,0,0,0.1);
z-index: 1000;
transition: right 0.3s;
padding: 20px;
}
.sidebar-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.5);
z-index: 999;
display: none;
transition: opacity 0.3s;
}
.sidebar-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.sidebar-header h3 {
font-size: 16px;
color: #333333;
margin: 0;
}
.close-sidebar-btn {
background: none;
border: none;
font-size: 20px;
cursor: pointer;
color: #999999;
}
.sidebar-filter-buttons {
display: flex;
flex-direction: column;
gap: 10px;
}
.sidebar-filter-btn {
padding: 10px 12px;
border: 1px solid #E0E0E0;
border-radius: 8px;
background-color: white;
color: #666666;
font-size: 14px;
cursor: pointer;
text-align: left;
transition: all 0.3s;
}
.sidebar-filter-btn:hover {
background-color: #F5F5F5;
}
.highlight {
background-color: #FFF3CD;
color: #856404;
padding: 0 2px;
border-radius: 2px;
font-weight: 500;
}
@media (max-width: 480px) {
.container {
max-width: 100%;
}
.header h1 {
font-size: 16px;
}
.qr-item {
padding: 12px;
}
.filter-section {
padding: 12px 16px;
}
.filter-sidebar-btn {
padding: 6px 10px;
font-size: 13px;
}
.qr-item-name {
font-size: 15px;
}
.qr-item-details {
font-size: 13px;
}
.filter-toggle-btn {
padding: 5px 10px;
font-size: 13px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<button class="back-btn" onclick="window.location.href='invite.html'"></button>
<h1>二维码合集</h1>
</div>
<div class="filter-section">
<div class="filter-toggle">
<button class="filter-toggle-btn active" data-filter="all">全部</button>
<button class="filter-toggle-btn" data-filter="me">我的</button>
</div>
<div class="search-box">
<input type="text" id="searchInput" placeholder="搜索电话号码/主体名称" style="width: 100%; padding: 8px 12px; border: 1px solid #E0E0E0; border-radius: 8px; font-size: 14px; outline: none; transition: border-color 0.3s;">
</div>
<button id="filterSidebarBtn" class="filter-sidebar-btn" style="display: flex;">
<span>🔍</span>
<span>筛选</span>
</button>
</div>
<!-- 筛选侧边栏 -->
<div id="filterSidebar" class="filter-sidebar">
<div class="sidebar-header">
<h3>筛选用户</h3>
<button id="closeSidebarBtn" class="close-sidebar-btn">&times;</button>
</div>
<div id="sidebarFilterButtons" class="sidebar-filter-buttons">
<!-- 动态生成的筛选按钮 -->
</div>
</div>
<!-- 遮罩层 -->
<div id="sidebarOverlay" class="sidebar-overlay"></div>
<div id="qrCollection">
<div class="empty-state">
<img src="https://api.qrserver.com/v1/create-qr-code/?size=100x100&data=empty" alt="空状态">
<p>暂无二维码</p>
<p style="font-size: 14px; margin-top: 5px;">请先生成邀请二维码</p>
</div>
</div>
<div style="padding: 16px;">
<button class="btn btn-primary" onclick="window.location.href='invite.html'" style="width: 100%; padding: 12px; background-color: #4CAF50; color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: 500; cursor: pointer; text-align: center; transition: background-color 0.3s;">生成邀请二维码</button>
</div>
</div>
<script>
// 加载用户信息
function loadUserInfo() {
const userInfo = localStorage.getItem('userInfo');
if (userInfo) {
try {
return JSON.parse(userInfo);
} catch (error) {
console.error('解析用户信息失败:', error);
return null;
}
}
return null;
}
// 加载二维码合集
async function loadQrCollection() {
const user = loadUserInfo();
const qrCollectionElement = document.getElementById('qrCollection');
try {
// 构建请求URL,包含用户信息
let apiUrl = '/getQrCollection';
if (user) {
apiUrl += `?userName=${encodeURIComponent(user.name || user.userName)}&projectName=${encodeURIComponent(user.projectName || '')}`;
}
// 从服务器获取二维码合集
const response = await fetch(apiUrl);
const data = await response.json();
if (data.success) {
// 动态生成筛选按钮
if (data.isAdmin && data.invitees && data.invitees.length > 0) {
generateFilterButtons(data.invitees, user);
}
if (data.qrCodes && data.qrCodes.length > 0) {
// 渲染二维码合集
const searchInput = document.getElementById('searchInput');
renderQrCollection(data.qrCodes, user, data.isAdmin, searchInput ? searchInput.value : '');
} else {
// 显示空状态
qrCollectionElement.innerHTML = `
<div class="empty-state">
<img src="https://api.qrserver.com/v1/create-qr-code/?size=100x100&data=empty" alt="空状态">
<p>暂无二维码</p>
<p style="font-size: 14px; margin-top: 5px;">请先生成邀请二维码</p>
</div>
`;
}
} else {
// 显示错误状态
qrCollectionElement.innerHTML = `
<div class="empty-state">
<img src="https://api.qrserver.com/v1/create-qr-code/?size=100x100&data=error" alt="错误状态">
<p>加载失败</p>
<p style="font-size: 14px; margin-top: 5px;">请稍后重试</p>
</div>
`;
}
} catch (error) {
console.error('获取二维码合集失败:', error);
qrCollectionElement.innerHTML = `
<div class="empty-state">
<img src="https://api.qrserver.com/v1/create-qr-code/?size=100x100&data=error" alt="错误状态">
<p>加载失败</p>
<p style="font-size: 14px; margin-top: 5px;">请稍后重试</p>
</div>
`;
}
}
// 动态生成筛选按钮
function generateFilterButtons(invitees, currentUser) {
const filterSidebarBtn = document.getElementById('filterSidebarBtn');
const sidebarFilterButtons = document.getElementById('sidebarFilterButtons');
// 为管理员显示筛选按钮并填充侧边栏
if (invitees && invitees.length > 0) {
// 显示筛选按钮
if (filterSidebarBtn) {
filterSidebarBtn.style.display = 'flex';
}
// 填充侧边栏筛选按钮
if (sidebarFilterButtons) {
sidebarFilterButtons.innerHTML = '';
invitees.forEach(invitee => {
// 跳过当前用户自己
if (invitee.inviter && invitee.inviter !== (currentUser.name || currentUser.userName)) {
const button = document.createElement('button');
button.className = 'sidebar-filter-btn';
button.dataset.filter = `invitee_${encodeURIComponent(invitee.inviter)}`;
button.dataset.inviter = invitee.inviter;
button.textContent = invitee.inviter;
// 添加点击事件
button.addEventListener('click', function() {
const searchInput = document.getElementById('searchInput');
filterQrCodes(this.dataset.filter, this.dataset.inviter, searchInput ? searchInput.value : '');
closeSidebar();
});
sidebarFilterButtons.appendChild(button);
}
});
}
}
}
// 打开筛选侧边栏
function openSidebar() {
const sidebar = document.getElementById('filterSidebar');
const overlay = document.getElementById('sidebarOverlay');
if (sidebar && overlay) {
sidebar.style.right = '0';
overlay.style.display = 'block';
}
}
// 关闭筛选侧边栏
function closeSidebar() {
const sidebar = document.getElementById('filterSidebar');
const overlay = document.getElementById('sidebarOverlay');
if (sidebar && overlay) {
sidebar.style.right = '-300px';
overlay.style.display = 'none';
}
}
// 渲染二维码合集
function renderQrCollection(qrCodes, currentUser, isAdmin, searchKeyword = '') {
const qrCollectionElement = document.getElementById('qrCollection');
// 生成HTML
let html = '';
qrCodes.forEach((qrCode, index) => {
// 生成唯一的item ID
const itemId = `item_${index}_${encodeURIComponent(qrCode.sessionId || Math.random().toString(36).substr(2, 9))}`;
// 高亮处理
let highlightedCompany = qrCode.company || '未知';
let highlightedPhoneNumber = qrCode.phoneNumber || '未知';
if (searchKeyword) {
const keyword = searchKeyword.toLowerCase();
if (qrCode.company && qrCode.company.toLowerCase().includes(keyword)) {
const regex = new RegExp(`(${keyword})`, 'gi');
highlightedCompany = qrCode.company.replace(regex, '<span class="highlight">$1</span>');
}
if (qrCode.phoneNumber && qrCode.phoneNumber.toLowerCase().includes(keyword)) {
const regex = new RegExp(`(${keyword})`, 'gi');
highlightedPhoneNumber = qrCode.phoneNumber.replace(regex, '<span class="highlight">$1</span>');
}
}
html += `
<div class="qr-item" onclick="toggleSection('${itemId}')">
<div class="qr-item-info">
<div class="qr-item-name">${highlightedCompany}</div>
<div class="qr-item-details">
${highlightedPhoneNumber} / ${qrCode.createdAt || '未知'}
</div>
</div>
<div class="qr-item-arrow">▼</div>
</div>
<div id="${itemId}" class="qr-content" style="display: none;">
<img src="${qrCode.qrCodeUrl || `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(qrCode.url)}`}" alt="邀请二维码">
<div class="qr-info">
<p class="name">${qrCode.inviter || '未知'}</p>
<p>${qrCode.inviterProjectName || '无职位'}</p>
<p>${qrCode.createdAt || ''}</p>
</div>
</div>
`;
});
qrCollectionElement.innerHTML = html;
}
// 切换展开/收起状态
function toggleSection(sectionId) {
const section = document.getElementById(sectionId);
const qrItem = section ? section.previousElementSibling : null;
const arrowIcon = qrItem ? qrItem.querySelector('.qr-item-arrow') : null;
if (section && arrowIcon) {
if (section.style.display === 'none') {
section.style.display = 'block';
arrowIcon.textContent = '▲';
} else {
section.style.display = 'none';
arrowIcon.textContent = '▼';
}
}
}
// 筛选二维码
function filterQrCodes(filter, inviterName, searchKeyword = '') {
const user = loadUserInfo();
const qrCollectionElement = document.getElementById('qrCollection');
// 更新筛选按钮状态
document.querySelectorAll('.filter-btn').forEach(btn => {
btn.classList.remove('active');
if (btn.dataset.filter === filter) {
btn.classList.add('active');
}
});
// 构建请求URL,包含用户信息
let apiUrl = '/getQrCollection';
if (user) {
apiUrl += `?userName=${encodeURIComponent(user.name || user.userName)}&projectName=${encodeURIComponent(user.projectName || '')}`;
}
// 重新加载并筛选二维码
fetch(apiUrl)
.then(response => response.json())
.then(data => {
if (data.success && data.qrCodes && data.qrCodes.length > 0) {
let filteredQrCodes = data.qrCodes;
if (filter === 'me' && user) {
// 筛选当前用户自己的二维码
filteredQrCodes = data.qrCodes.filter(qrCode =>
qrCode.inviter === (user.name || user.userName)
);
} else if (filter.startsWith('invitee_') && inviterName) {
// 筛选特定邀请者的二维码
filteredQrCodes = data.qrCodes.filter(qrCode =>
qrCode.inviter === inviterName
);
}
// 搜索功能
if (searchKeyword) {
const keyword = searchKeyword.toLowerCase();
filteredQrCodes = filteredQrCodes.filter(qrCode => {
return (
(qrCode.phoneNumber && qrCode.phoneNumber.toLowerCase().includes(keyword)) ||
(qrCode.company && qrCode.company.toLowerCase().includes(keyword))
);
});
}
if (filteredQrCodes.length > 0) {
renderQrCollection(filteredQrCodes, user, data.isAdmin, searchKeyword);
} else {
qrCollectionElement.innerHTML = `
<div class="empty-state">
<img src="https://api.qrserver.com/v1/create-qr-code/?size=100x100&data=empty" alt="空状态">
<p>暂无二维码</p>
</div>
`;
}
}
})
.catch(error => {
console.error('筛选二维码失败:', error);
});
}
// 页面加载时加载二维码合集
window.onload = function() {
loadQrCollection();
// 绑定筛选侧边栏按钮事件
const filterSidebarBtn = document.getElementById('filterSidebarBtn');
if (filterSidebarBtn) {
filterSidebarBtn.addEventListener('click', openSidebar);
}
// 绑定关闭侧边栏按钮事件
const closeSidebarBtn = document.getElementById('closeSidebarBtn');
if (closeSidebarBtn) {
closeSidebarBtn.addEventListener('click', closeSidebar);
}
// 点击遮罩层关闭侧边栏
const sidebarOverlay = document.getElementById('sidebarOverlay');
if (sidebarOverlay) {
sidebarOverlay.addEventListener('click', closeSidebar);
}
// 绑定筛选切换按钮事件
document.querySelectorAll('.filter-toggle-btn').forEach(btn => {
btn.addEventListener('click', function() {
// 更新按钮状态
document.querySelectorAll('.filter-toggle-btn').forEach(b => {
b.classList.remove('active');
});
this.classList.add('active');
// 执行筛选
const searchInput = document.getElementById('searchInput');
filterQrCodes(this.dataset.filter, null, searchInput ? searchInput.value : '');
});
});
// 绑定搜索框输入事件
const searchInput = document.getElementById('searchInput');
if (searchInput) {
searchInput.addEventListener('input', function() {
const activeFilterBtn = document.querySelector('.filter-toggle-btn.active');
const filter = activeFilterBtn ? activeFilterBtn.dataset.filter : 'all';
filterQrCodes(filter, null, this.value);
});
}
};
</script>
</body>
</html>