From 1517509776e7b4d4c87dfea39f60f557b606e18a Mon Sep 17 00:00:00 2001 From: wzj <244142824@qq.com> Date: Fri, 11 Jul 2025 16:54:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=A1=E7=89=87=E5=A2=9E=E5=8A=A0=E5=8F=B3?= =?UTF-8?q?=E9=94=AE=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/index.html | 232 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 217 insertions(+), 15 deletions(-) diff --git a/templates/index.html b/templates/index.html index d79b18d..bb493ea 100644 --- a/templates/index.html +++ b/templates/index.html @@ -874,6 +874,49 @@ body.dark-theme .secondary-filters-container::after { box-sizing: border-box; } + + + @@ -927,6 +970,15 @@ body.dark-theme .secondary-filters-container::after { + +
+
打开
+
复制地址
+
+ + +
+ @@ -1842,25 +1894,175 @@ body.dark-theme .secondary-filters-container::after { }); } - // 页面加载完成后初始化 - document.addEventListener('DOMContentLoaded', () => { - loadData(); - loadSettings(); - setupSearch(); - setupThemeSwitcher(); - setupCompactToggle(); - setupAdminButton(); - setupBackToTop(); // 初始化返回顶部功能 +// 右键菜单功能 +function setupContextMenu() { + const contextMenu = document.getElementById('contextMenu'); + let currentApp = null; + let currentAppIndex = -1; - // 为静态的一级筛选容器添加滚轮事件 - primaryFilters.addEventListener('wheel', (e) => { - if (e.deltaY !== 0) { - e.preventDefault(); - primaryFilters.scrollLeft += e.deltaY; + // 显示右键菜单 + document.addEventListener('contextmenu', (e) => { + // 检查是否点击的是应用卡片 + const appItem = e.target.closest('.app-item'); + if (appItem) { + e.preventDefault(); + + // 找到对应的应用数据 + const appTitle = appItem.querySelector('.app-title').textContent; + currentApp = apps.find(app => app.title === appTitle); + currentAppIndex = apps.findIndex(app => app.title === appTitle); + + // 更新菜单位置 + contextMenu.style.left = `${e.pageX}px`; + contextMenu.style.top = `${e.pageY}px`; + contextMenu.style.display = 'block'; + + // 根据主题设置菜单样式 + if (document.body.classList.contains('dark-theme')) { + contextMenu.classList.add('dark'); + contextMenu.querySelectorAll('.context-menu-item').forEach(item => item.classList.add('dark')); + contextMenu.querySelectorAll('.context-menu-divider').forEach(divider => divider.classList.add('dark')); + } else { + contextMenu.classList.remove('dark'); + contextMenu.querySelectorAll('.context-menu-item').forEach(item => item.classList.remove('dark')); + contextMenu.querySelectorAll('.context-menu-divider').forEach(divider => divider.classList.remove('dark')); } - }); + + // 显示/隐藏编辑和删除按钮(仅管理员可见) + const editItem = contextMenu.querySelector('[data-action="edit"]'); + const deleteItem = contextMenu.querySelector('[data-action="delete"]'); + + if (isLoggedIn) { + editItem.style.display = 'block'; + deleteItem.style.display = 'block'; + } else { + editItem.style.display = 'none'; + deleteItem.style.display = 'none'; + } + } }); + // 隐藏右键菜单 + document.addEventListener('click', (e) => { + if (!contextMenu.contains(e.target)) { + contextMenu.style.display = 'none'; + } + }); + + // 菜单项点击处理 + contextMenu.addEventListener('click', (e) => { + const menuItem = e.target.closest('.context-menu-item'); + if (!menuItem || !currentApp) return; + + const action = menuItem.dataset.action; + + switch (action) { + case 'open': + window.open(currentApp.url, '_blank'); + break; + + case 'copy': + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(currentApp.url) + .then(() => { + showCopyNotification('已复制到剪贴板'); + }) + .catch(err => { + console.error('复制失败:', err); + fallbackCopyText(currentApp.url); + }); + } else { + fallbackCopyText(currentApp.url); + } + break; + + case 'edit': + if (isLoggedIn) { + window.location.href = `/app/edit/${currentAppIndex}`; + } + break; + + case 'delete': + if (isLoggedIn) { + if (confirm(`确定要删除 "${currentApp.title}" 吗?`)) { + fetch(`/app/delete/${currentAppIndex}`, { + method: 'GET' + }) + .then(response => { + if (response.ok) { + // 重新加载数据 + loadData(); + } else { + alert('删除失败'); + } + }) + .catch(error => { + console.error('删除失败:', error); + alert('删除失败'); + }); + } + } + break; + } + + contextMenu.style.display = 'none'; + }); +} + +// 在DOMContentLoaded事件中添加setupContextMenu调用 +document.addEventListener('DOMContentLoaded', () => { + loadData(); + loadSettings(); + setupSearch(); + setupThemeSwitcher(); + setupCompactToggle(); + setupAdminButton(); + setupBackToTop(); + setupContextMenu(); // 添加右键菜单功能 + + // 为静态的一级筛选容器添加滚轮事件 + primaryFilters.addEventListener('wheel', (e) => { + if (e.deltaY !== 0) { + e.preventDefault(); + primaryFilters.scrollLeft += e.deltaY; + } + }); +}); + + +// 显示复制成功的提示 +function showCopyNotification(message) { + const notification = document.createElement('div'); + notification.className = 'copy-notification'; + notification.textContent = message; + document.body.appendChild(notification); + + setTimeout(() => { + notification.classList.add('fade-out'); + setTimeout(() => notification.remove(), 300); + }, 1000); +} + +// 备用的复制方法 +function fallbackCopyText(text) { + const textarea = document.createElement('textarea'); + textarea.value = text; + textarea.style.position = 'fixed'; // 防止页面滚动 + document.body.appendChild(textarea); + textarea.select(); + + try { + const successful = document.execCommand('copy'); + const msg = successful ? '已复制到剪贴板' : '复制失败,请手动复制'; + showCopyNotification(msg); + } catch (err) { + console.error('备用复制方法失败:', err); + showCopyNotification('复制失败,请手动复制'); + } + + document.body.removeChild(textarea); +} + function checkScrollable() { document.querySelectorAll('.filter-row, .secondary-filters-container').forEach(container => { // 检查内容宽度是否大于容器宽度