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.

597 lines
18 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: #f5f5f5;
color: #333;
-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: white;
height: 100%;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
position: relative;
padding: 20px;
}
.header {
display: flex;
align-items: center;
justify-content: center;
padding: 16px;
background-color: #28a745;
color: white;
position: sticky;
top: 0;
z-index: 100;
margin: -20px -20px 20px;
}
.header h1 {
font-size: 18px;
font-weight: 600;
}
.header-actions {
display: flex;
gap: 12px;
}
.more-btn {
background: none;
border: none;
color: white;
font-size: 18px;
cursor: pointer;
}
.filter-section {
margin-bottom: 20px;
}
.filter-section h3 {
font-size: 16px;
color: #333;
margin-bottom: 10px;
}
.filter-buttons {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.filter-btn {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 16px;
background-color: white;
color: #666;
font-size: 14px;
cursor: pointer;
transition: all 0.3s;
}
.filter-btn.active {
background-color: #28a745;
color: white;
border-color: #28a745;
}
.qr-section {
margin-bottom: 30px;
}
.qr-section h3 {
font-size: 16px;
color: #333;
margin-bottom: 15px;
padding-bottom: 8px;
border-bottom: 1px solid #f0f0f0;
}
.qr-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 15px;
}
.qr-item {
background-color: #f8f9fa;
border-radius: 8px;
padding: 12px;
text-align: center;
}
.qr-item img {
max-width: 100%;
max-height: 150px;
margin-bottom: 10px;
border-radius: 4px;
}
.qr-info {
font-size: 12px;
color: #666;
}
.qr-info p {
margin-bottom: 4px;
}
.qr-info .name {
font-weight: 500;
color: #333;
}
.empty-state {
text-align: center;
padding: 40px 20px;
color: #999;
}
.empty-state img {
max-width: 100px;
margin-bottom: 15px;
opacity: 0.5;
}
.action-buttons {
display: flex;
flex-direction: column;
gap: 15px;
margin-top: 30px;
}
.btn {
padding: 15px;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 500;
cursor: pointer;
text-align: center;
transition: background-color 0.3s;
}
.btn-primary {
background-color: #28a745;
color: white;
}
.btn-primary:hover {
background-color: #218838;
}
.btn-secondary {
background-color: #6c757d;
color: white;
}
.btn-secondary:hover {
background-color: #5a6268;
}
.footer {
text-align: center;
margin-top: 40px;
padding: 20px 0;
font-size: 14px;
color: #999;
border-top: 1px solid #f0f0f0;
}
@media (max-width: 480px) {
.container {
max-width: 100%;
padding: 15px;
}
.header {
margin: -15px -15px 15px;
}
.header h1 {
font-size: 16px;
}
.qr-grid {
grid-template-columns: 1fr;
}
.qr-item img {
max-height: 200px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>二维码合集</h1>
</div>
<div class="filter-section">
<div style="display: flex; align-items: center; justify-content: space-between;">
<h3>筛选</h3>
<button id="filterSidebarBtn" class="filter-sidebar-btn" style="display: none; background: #28a745; color: white; border: none; padding: 6px 12px; border-radius: 4px; font-size: 14px; cursor: pointer;">筛选</button>
</div>
<div class="filter-buttons">
<button class="filter-btn active" data-filter="all">全部</button>
<button class="filter-btn" data-filter="me">我的二维码</button>
</div>
</div>
<!-- 筛选侧边栏 -->
<div id="filterSidebar" class="filter-sidebar" style="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;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h3>筛选用户</h3>
<button id="closeSidebarBtn" style="background: none; border: none; font-size: 20px; cursor: pointer;">&times;</button>
</div>
<div id="sidebarFilterButtons" style="display: flex; flex-direction: column; gap: 10px;">
<!-- 动态生成的筛选按钮 -->
</div>
</div>
<!-- 遮罩层 -->
<div id="sidebarOverlay" class="sidebar-overlay" style="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;"></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 class="action-buttons">
<button class="btn btn-primary" onclick="window.location.href='invite.html'">生成邀请二维码</button>
<button class="btn btn-secondary" onclick="window.location.href='invite.html'">返回主页面</button>
</div>
<div class="footer">
技术支持:四川又鸟蛋贸易有限公司
</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) {
// 渲染二维码合集
renderQrCollection(data.qrCodes, user, data.isAdmin);
} 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 filterButtonsContainer = document.querySelector('.filter-buttons');
const filterSidebarBtn = document.getElementById('filterSidebarBtn');
const sidebarFilterButtons = document.getElementById('sidebarFilterButtons');
if (!filterButtonsContainer) return;
// 清空现有按钮,只保留"全部"和"我的"
filterButtonsContainer.innerHTML = `
<button class="filter-btn active" data-filter="all">全部</button>
<button class="filter-btn" data-filter="me">我的</button>
`;
// 为管理员显示筛选按钮并填充侧边栏
if (invitees && invitees.length > 0) {
// 显示筛选按钮
if (filterSidebarBtn) {
filterSidebarBtn.style.display = 'block';
}
// 填充侧边栏筛选按钮
if (sidebarFilterButtons) {
sidebarFilterButtons.innerHTML = '';
invitees.forEach(invitee => {
// 跳过当前用户自己
if (invitee.inviter && invitee.inviter !== (currentUser.name || currentUser.userName)) {
const button = document.createElement('button');
button.className = 'filter-btn';
button.style.width = '100%';
button.style.textAlign = 'left';
button.style.padding = '8px 12px';
button.style.border = '1px solid #ddd';
button.style.borderRadius = '4px';
button.style.backgroundColor = 'white';
button.style.color = '#666';
button.style.fontSize = '14px';
button.style.cursor = 'pointer';
button.style.transition = 'all 0.3s';
button.dataset.filter = `invitee_${encodeURIComponent(invitee.inviter)}`;
button.dataset.inviter = invitee.inviter;
button.textContent = invitee.inviter;
// 添加点击事件
button.addEventListener('click', function() {
filterQrCodes(this.dataset.filter, this.dataset.inviter);
closeSidebar();
});
sidebarFilterButtons.appendChild(button);
}
});
}
}
// 绑定筛选按钮事件
document.querySelectorAll('.filter-btn').forEach(btn => {
btn.addEventListener('click', function() {
if (!this.disabled) {
filterQrCodes(this.dataset.filter, this.dataset.inviter);
}
});
});
}
// 打开筛选侧边栏
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) {
const qrCollectionElement = document.getElementById('qrCollection');
// 按邀请者分组
const groupedQrCodes = {};
qrCodes.forEach(qrCode => {
const inviterName = qrCode.inviter || '未知邀请者';
if (!groupedQrCodes[inviterName]) {
groupedQrCodes[inviterName] = [];
}
groupedQrCodes[inviterName].push(qrCode);
});
// 生成HTML
let html = '';
Object.keys(groupedQrCodes).forEach(inviterName => {
const inviterQrCodes = groupedQrCodes[inviterName];
// 生成唯一的section ID
const sectionId = `section_${encodeURIComponent(inviterName)}`;
html += `
<div class="qr-section">
<div class="section-header" onclick="toggleSection('${sectionId}')" style="cursor: pointer; display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #f8f9fa; border-radius: 8px; margin-bottom: 10px;">
<div>
<h3 style="margin: 0; font-size: 16px; color: #333;">${inviterName}</h3>
<div style="font-size: 12px; color: #666; margin-top: 4px;">
<p style="margin: 2px 0;">主体名称: ${inviterQrCodes[0].company || '未知'}</p>
<p style="margin: 2px 0;">电话号码: ${inviterQrCodes[0].phoneNumber || '未知'}</p>
<p style="margin: 2px 0;">开具日期: ${inviterQrCodes[0].createdAt || '未知'}</p>
</div>
</div>
<span class="toggle-icon" id="toggle_${sectionId}" style="font-size: 18px; color: #28a745;"></span>
</div>
<div id="${sectionId}" class="qr-grid" style="display: none; padding: 10px; background-color: #fafafa; border-radius: 8px;">
`;
inviterQrCodes.forEach(qrCode => {
// 使用数据库中存储的二维码URL
const qrImageUrl = qrCode.qrCodeUrl || `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(qrCode.url)}`;
html += `
<div class="qr-item">
<img src="${qrImageUrl}" alt="邀请二维码">
<div class="qr-info">
<p class="name">${qrCode.inviter || '未知'}</p>
<p>${qrCode.inviterProjectName || '无职位'}</p>
<p>${qrCode.createdAt || ''}</p>
</div>
</div>
`;
});
html += `
</div>
</div>
`;
});
qrCollectionElement.innerHTML = html;
}
// 切换展开/收起状态
function toggleSection(sectionId) {
const section = document.getElementById(sectionId);
const toggleIcon = document.getElementById(`toggle_${sectionId}`);
if (section && toggleIcon) {
if (section.style.display === 'none') {
section.style.display = 'block';
toggleIcon.textContent = '▲';
} else {
section.style.display = 'none';
toggleIcon.textContent = '▼';
}
}
}
// 筛选二维码
function filterQrCodes(filter, inviterName) {
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 (filteredQrCodes.length > 0) {
renderQrCollection(filteredQrCodes, user, data.isAdmin);
} 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);
}
};
</script>
</body>
</html>