mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
Fix a issue that lora preview tooltip not disappear
This commit is contained in:
@@ -122,6 +122,12 @@ export function addLorasWidget(node, name, opts, callback) {
|
|||||||
});
|
});
|
||||||
document.body.appendChild(this.element);
|
document.body.appendChild(this.element);
|
||||||
this.hideTimeout = null; // 添加超时处理变量
|
this.hideTimeout = null; // 添加超时处理变量
|
||||||
|
|
||||||
|
// 添加全局点击事件来隐藏tooltip
|
||||||
|
document.addEventListener('click', () => this.hide());
|
||||||
|
|
||||||
|
// 添加滚动事件监听
|
||||||
|
document.addEventListener('scroll', () => this.hide(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async show(loraName, x, y) {
|
async show(loraName, x, y) {
|
||||||
@@ -131,6 +137,14 @@ export function addLorasWidget(node, name, opts, callback) {
|
|||||||
clearTimeout(this.hideTimeout);
|
clearTimeout(this.hideTimeout);
|
||||||
this.hideTimeout = null;
|
this.hideTimeout = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果已经显示同一个lora的预览,则不重复显示
|
||||||
|
if (this.element.style.display === 'block' && this.currentLora === loraName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentLora = loraName;
|
||||||
|
|
||||||
// 获取预览URL
|
// 获取预览URL
|
||||||
const response = await api.fetchApi(`/lora-preview-url?name=${encodeURIComponent(loraName)}`, {
|
const response = await api.fetchApi(`/lora-preview-url?name=${encodeURIComponent(loraName)}`, {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
@@ -202,8 +216,15 @@ export function addLorasWidget(node, name, opts, callback) {
|
|||||||
mediaContainer.appendChild(nameLabel);
|
mediaContainer.appendChild(nameLabel);
|
||||||
this.element.appendChild(mediaContainer);
|
this.element.appendChild(mediaContainer);
|
||||||
|
|
||||||
this.position(x, y);
|
// 添加淡入效果
|
||||||
|
this.element.style.opacity = '0';
|
||||||
this.element.style.display = 'block';
|
this.element.style.display = 'block';
|
||||||
|
this.position(x, y);
|
||||||
|
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
this.element.style.transition = 'opacity 0.15s ease';
|
||||||
|
this.element.style.opacity = '1';
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('Failed to load preview:', error);
|
console.warn('Failed to load preview:', error);
|
||||||
}
|
}
|
||||||
@@ -235,22 +256,29 @@ export function addLorasWidget(node, name, opts, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hide() {
|
hide() {
|
||||||
// 使用延迟来确保隐藏事件在显示事件之后执行
|
// 使用淡出效果
|
||||||
this.hideTimeout = setTimeout(() => {
|
if (this.element.style.display === 'block') {
|
||||||
this.element.style.display = 'none';
|
this.element.style.opacity = '0';
|
||||||
// 停止视频播放
|
this.hideTimeout = setTimeout(() => {
|
||||||
const video = this.element.querySelector('video');
|
this.element.style.display = 'none';
|
||||||
if (video) {
|
this.currentLora = null;
|
||||||
video.pause();
|
// 停止视频播放
|
||||||
}
|
const video = this.element.querySelector('video');
|
||||||
this.hideTimeout = null;
|
if (video) {
|
||||||
}, 50);
|
video.pause();
|
||||||
|
}
|
||||||
|
this.hideTimeout = null;
|
||||||
|
}, 150);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
if (this.hideTimeout) {
|
if (this.hideTimeout) {
|
||||||
clearTimeout(this.hideTimeout);
|
clearTimeout(this.hideTimeout);
|
||||||
}
|
}
|
||||||
|
// 移除所有事件监听器
|
||||||
|
document.removeEventListener('click', () => this.hide());
|
||||||
|
document.removeEventListener('scroll', () => this.hide(), true);
|
||||||
this.element.remove();
|
this.element.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -522,19 +550,13 @@ export function addLorasWidget(node, name, opts, callback) {
|
|||||||
|
|
||||||
// Move preview tooltip events to nameEl instead of loraEl
|
// Move preview tooltip events to nameEl instead of loraEl
|
||||||
nameEl.addEventListener('mouseenter', async (e) => {
|
nameEl.addEventListener('mouseenter', async (e) => {
|
||||||
e.stopPropagation(); // 阻止事件冒泡
|
e.stopPropagation();
|
||||||
await previewTooltip.show(name, e.clientX, e.clientY);
|
const rect = nameEl.getBoundingClientRect();
|
||||||
});
|
await previewTooltip.show(name, rect.right, rect.top);
|
||||||
|
|
||||||
nameEl.addEventListener('mousemove', (e) => {
|
|
||||||
e.stopPropagation(); // 阻止事件冒泡
|
|
||||||
if (previewTooltip.element.style.display === 'block') {
|
|
||||||
previewTooltip.position(e.clientX, e.clientY);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
nameEl.addEventListener('mouseleave', (e) => {
|
nameEl.addEventListener('mouseleave', (e) => {
|
||||||
e.stopPropagation(); // 阻止事件冒泡
|
e.stopPropagation();
|
||||||
previewTooltip.hide();
|
previewTooltip.hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user