mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-23 14:12:11 -03:00
Initial commit
This commit is contained in:
315
static/css/style.css
Normal file
315
static/css/style.css
Normal file
@@ -0,0 +1,315 @@
|
||||
:root {
|
||||
--bg-color: #ffffff;
|
||||
--text-color: #333333;
|
||||
--card-bg: #ffffff;
|
||||
--border-color: #e0e0e0;
|
||||
}
|
||||
|
||||
[data-theme="dark"] {
|
||||
--bg-color: #1a1a1a;
|
||||
--text-color: #e0e0e0;
|
||||
--card-bg: #2d2d2d;
|
||||
--border-color: #404040;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Segoe UI', sans-serif;
|
||||
background: var(--background-color);
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1400px;
|
||||
margin: 20px auto;
|
||||
padding: 0 15px;
|
||||
}
|
||||
|
||||
/* 文件夹标签样式 */
|
||||
.folder-tags {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
overflow-x: auto;
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.tag {
|
||||
padding: 6px 12px;
|
||||
border-radius: 20px;
|
||||
background: #e0e0e0;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.tag.active {
|
||||
background: var(--primary-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* 卡片网格布局 */
|
||||
.card-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.lora-card {
|
||||
background: var(--card-bg);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
transition: transform 0.2s;
|
||||
aspect-ratio: 896/1152;
|
||||
max-width: 240px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.lora-card:hover {
|
||||
transform: translateY(-5px);
|
||||
}
|
||||
|
||||
/* Card Preview and Footer Overlay */
|
||||
.card-preview {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.card-preview img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
|
||||
color: white;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-end;
|
||||
min-height: 80px;
|
||||
}
|
||||
|
||||
.model-name {
|
||||
font-weight: bold;
|
||||
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.model-meta {
|
||||
font-size: 0.9em;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: linear-gradient(rgba(0, 0, 0, 0.85), transparent);
|
||||
color: white;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.card-actions i {
|
||||
margin-left: 10px;
|
||||
cursor: pointer;
|
||||
color: white;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.card-actions i:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
.card-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.controls {
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
}
|
||||
|
||||
/* 新增元数据相关样式 */
|
||||
.model-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.model-meta {
|
||||
font-size: 0.8em;
|
||||
color: #666;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.base-model {
|
||||
display: inline-block;
|
||||
background: #f0f0f0;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
margin-right: 6px;
|
||||
}
|
||||
|
||||
.file-size,
|
||||
.modified {
|
||||
display: block;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.tooltip {
|
||||
position: relative;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.tooltip::after {
|
||||
content: attr(data-tooltip);
|
||||
position: absolute;
|
||||
bottom: 120%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: white;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.8em;
|
||||
white-space: nowrap;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.tooltip:hover::after {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* 模态窗口样式 */
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
z-index: 1000;
|
||||
overflow-y: auto; /* 允许模态窗口内容滚动 */
|
||||
}
|
||||
|
||||
/* 当模态窗口打开时,禁止body滚动 */
|
||||
body.modal-open {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
position: relative;
|
||||
max-width: 800px;
|
||||
margin: 2rem auto;
|
||||
background: var(--card-bg);
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.carousel {
|
||||
display: grid;
|
||||
grid-auto-flow: column;
|
||||
gap: 1rem;
|
||||
overflow-x: auto;
|
||||
scroll-snap-type: x mandatory;
|
||||
}
|
||||
|
||||
.carousel img {
|
||||
scroll-snap-align: start;
|
||||
max-height: 60vh;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
/* 主题切换按钮 */
|
||||
.theme-toggle {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
cursor: pointer;
|
||||
padding: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--card-bg);
|
||||
}
|
||||
|
||||
.base-model-label {
|
||||
max-width: 120px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: inline-block;
|
||||
color: white;
|
||||
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
backdrop-filter: blur(2px);
|
||||
}
|
||||
|
||||
.loading-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.loading-content {
|
||||
background: #fff;
|
||||
padding: 2rem;
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
border: 4px solid #f3f3f3;
|
||||
border-top: 4px solid #3498db;
|
||||
border-radius: 50%;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
animation: spin 1s linear infinite;
|
||||
margin: 0 auto 1rem;
|
||||
}
|
||||
|
||||
.loading-status {
|
||||
margin-bottom: 1rem;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.progress-container {
|
||||
width: 300px;
|
||||
background-color: #f0f0f0;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
width: 0%;
|
||||
height: 20px;
|
||||
background-color: #4CAF50;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
BIN
static/images/no-preview.png
Normal file
BIN
static/images/no-preview.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
11
static/images/theme-toggle.svg
Normal file
11
static/images/theme-toggle.svg
Normal file
@@ -0,0 +1,11 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="5"/>
|
||||
<path d="M12 1v2"/>
|
||||
<path d="M12 21v2"/>
|
||||
<path d="M4.22 4.22l1.42 1.42"/>
|
||||
<path d="M18.36 18.36l1.42 1.42"/>
|
||||
<path d="M1 12h2"/>
|
||||
<path d="M21 12h2"/>
|
||||
<path d="M4.22 19.78l1.42-1.42"/>
|
||||
<path d="M18.36 5.64l1.42-1.42"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 457 B |
229
static/js/script.js
Normal file
229
static/js/script.js
Normal file
@@ -0,0 +1,229 @@
|
||||
// 排序功能
|
||||
function sortCards(sortBy) {
|
||||
const grid = document.getElementById('loraGrid');
|
||||
const cards = Array.from(grid.children);
|
||||
|
||||
cards.sort((a, b) => {
|
||||
switch(sortBy) {
|
||||
case 'name':
|
||||
return a.dataset.name.localeCompare(b.dataset.name);
|
||||
case 'date':
|
||||
return new Date(b.dataset.date) - new Date(a.dataset.date);
|
||||
case 'size':
|
||||
return parseFloat(b.dataset.size) - parseFloat(a.dataset.size);
|
||||
}
|
||||
});
|
||||
|
||||
cards.forEach(card => grid.appendChild(card));
|
||||
}
|
||||
|
||||
// 文件夹筛选
|
||||
document.querySelectorAll('.tag').forEach(tag => {
|
||||
tag.addEventListener('click', () => {
|
||||
document.querySelectorAll('.tag').forEach(t => t.classList.remove('active'));
|
||||
tag.classList.add('active');
|
||||
const folder = tag.dataset.folder;
|
||||
filterByFolder(folder);
|
||||
});
|
||||
});
|
||||
|
||||
function filterByFolder(folder) {
|
||||
document.querySelectorAll('.lora-card').forEach(card => {
|
||||
card.style.display = card.dataset.folder === folder ? 'block' : 'none';
|
||||
});
|
||||
}
|
||||
|
||||
// 刷新功能
|
||||
async function refreshLoras() {
|
||||
try {
|
||||
const response = await fetch('/loras?refresh=true');
|
||||
if (response.ok) {
|
||||
location.reload();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Refresh failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 占位功能函数
|
||||
function openCivitai(loraName) {
|
||||
// 从卡片的data-meta属性中获取civitai ID
|
||||
const loraCard = document.querySelector(`.lora-card[data-name="${loraName}"]`);
|
||||
if (!loraCard) return;
|
||||
|
||||
const metaData = JSON.parse(loraCard.dataset.meta);
|
||||
const civitaiId = metaData.modelId; // 使用modelId作为civitai模型ID
|
||||
const versionId = metaData.id; // 使用id作为版本ID
|
||||
|
||||
// 构建URL
|
||||
if (civitaiId) {
|
||||
let url = `https://civitai.com/models/${civitaiId}`;
|
||||
if (versionId) {
|
||||
url += `?modelVersionId=${versionId}`;
|
||||
}
|
||||
window.open(url, '_blank');
|
||||
} else {
|
||||
// 如果没有ID,尝试使用名称搜索
|
||||
window.open(`https://civitai.com/models?query=${encodeURIComponent(loraName)}`, '_blank');
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteModel(modelName) {
|
||||
// Prevent event bubbling
|
||||
event.stopPropagation();
|
||||
|
||||
// Get the folder from the card's data attributes
|
||||
const card = document.querySelector(`.lora-card[data-name="${modelName}"]`);
|
||||
const folder = card ? card.dataset.folder : null;
|
||||
|
||||
// Show confirmation dialog
|
||||
const confirmed = confirm(`Are you sure you want to delete "${modelName}" and all associated files?`);
|
||||
|
||||
if (confirmed) {
|
||||
try {
|
||||
const response = await fetch('/api/delete_model', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model_name: modelName,
|
||||
folder: folder
|
||||
})
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
// Remove the card from UI
|
||||
if (card) {
|
||||
card.remove();
|
||||
}
|
||||
// Show success message
|
||||
alert('Model deleted successfully');
|
||||
} else {
|
||||
const error = await response.text();
|
||||
alert(`Failed to delete model: ${error}`);
|
||||
}
|
||||
} catch (error) {
|
||||
alert(`Error deleting model: ${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化排序
|
||||
document.getElementById('sortSelect').addEventListener('change', (e) => {
|
||||
sortCards(e.target.value);
|
||||
});
|
||||
|
||||
// 添加搜索功能
|
||||
document.getElementById('searchInput')?.addEventListener('input', (e) => {
|
||||
const term = e.target.value.toLowerCase();
|
||||
document.querySelectorAll('.lora-card').forEach(card => {
|
||||
const match = card.dataset.name.toLowerCase().includes(term) ||
|
||||
card.dataset.folder.toLowerCase().includes(term);
|
||||
card.style.display = match ? 'block' : 'none';
|
||||
});
|
||||
});
|
||||
|
||||
// 模态窗口管理
|
||||
let currentLora = null;
|
||||
let currentImageIndex = 0;
|
||||
|
||||
document.querySelectorAll('.lora-card').forEach(card => {
|
||||
card.addEventListener('click', () => {
|
||||
currentLora = JSON.parse(card.dataset.meta);
|
||||
showModal(currentLora);
|
||||
});
|
||||
});
|
||||
|
||||
function showModal(lora) {
|
||||
const modal = document.getElementById('loraModal');
|
||||
modal.innerHTML = `
|
||||
<div class="modal-content">
|
||||
<h2>${lora.name}</h2>
|
||||
<div class="carousel">
|
||||
${lora.images.map(img => `<img src="${img}" alt="Preview">`).join('')}
|
||||
</div>
|
||||
<div class="description">${lora.description}</div>
|
||||
<button class="close" onclick="closeModal()">×</button>
|
||||
</div>
|
||||
`;
|
||||
modal.style.display = 'block';
|
||||
document.body.classList.add('modal-open');
|
||||
|
||||
// 添加点击事件监听器
|
||||
modal.onclick = function(event) {
|
||||
// 如果点击的是模态窗口的背景(不是内容区域),则关闭模态窗口
|
||||
if (event.target === modal) {
|
||||
closeModal();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
const modal = document.getElementById('loraModal');
|
||||
modal.style.display = 'none';
|
||||
document.body.classList.remove('modal-open');
|
||||
// 移除点击事件监听器
|
||||
modal.onclick = null;
|
||||
}
|
||||
|
||||
// WebSocket handling for progress updates
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const loadingOverlay = document.getElementById('loading-overlay');
|
||||
const progressBar = document.querySelector('.progress-bar');
|
||||
const loadingStatus = document.querySelector('.loading-status');
|
||||
|
||||
// Show loading overlay initially
|
||||
loadingOverlay.style.display = 'flex';
|
||||
|
||||
// Listen for progress updates
|
||||
api.addEventListener("lora-scan-progress", (event) => {
|
||||
const data = event.detail;
|
||||
const progress = (data.value / data.max) * 100;
|
||||
|
||||
progressBar.style.width = `${progress}%`;
|
||||
progressBar.setAttribute('aria-valuenow', progress);
|
||||
loadingStatus.textContent = data.status;
|
||||
|
||||
if (data.value === data.max) {
|
||||
// Hide loading overlay when scan is complete
|
||||
setTimeout(() => {
|
||||
loadingOverlay.style.display = 'none';
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 主题切换
|
||||
function toggleTheme() {
|
||||
const theme = document.body.dataset.theme || 'light';
|
||||
document.body.dataset.theme = theme === 'light' ? 'dark' : 'light';
|
||||
localStorage.setItem('theme', document.body.dataset.theme);
|
||||
}
|
||||
|
||||
// 初始化主题
|
||||
function initTheme() {
|
||||
const savedTheme = localStorage.getItem('theme') || 'light';
|
||||
document.body.dataset.theme = savedTheme;
|
||||
}
|
||||
|
||||
// 检测系统主题
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addListener(e => {
|
||||
document.body.dataset.theme = e.matches ? 'dark' : 'light';
|
||||
});
|
||||
|
||||
// 键盘导航
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape') closeModal();
|
||||
if (e.key === 'ArrowLeft') prevImage();
|
||||
if (e.key === 'ArrowRight') nextImage();
|
||||
});
|
||||
|
||||
// 图片预加载
|
||||
function preloadImages(urls) {
|
||||
urls.forEach(url => {
|
||||
new Image().src = url;
|
||||
});
|
||||
}
|
||||
|
||||
initTheme();
|
||||
Reference in New Issue
Block a user