迁移头像选择点击事件
This commit is contained in:
@@ -16,6 +16,29 @@ function callGlobal(functionName, ...args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理动态头像项选择。
|
||||||
|
* 头像列表由 Blade 旧脚本异步生成,Vite 模块只通过 data-avatar-file 接管点击入口。
|
||||||
|
*
|
||||||
|
* @param {Element} target 点击目标
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function handleAvatarOptionClick(target) {
|
||||||
|
const avatarOption = target.closest("[data-avatar-file]");
|
||||||
|
if (!(avatarOption instanceof HTMLElement)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const file = avatarOption.getAttribute("data-avatar-file") || "";
|
||||||
|
if (!file) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
callGlobal("selectAvatar", file, avatarOption);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 绑定头像选择器和个人设置弹窗事件。
|
* 绑定头像选择器和个人设置弹窗事件。
|
||||||
*
|
*
|
||||||
@@ -39,6 +62,11 @@ export function bindProfileControls() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (handleAvatarOptionClick(event.target)) {
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event.target.closest("[data-avatar-save]")) {
|
if (event.target.closest("[data-avatar-save]")) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
callGlobal("saveAvatar");
|
callGlobal("saveAvatar");
|
||||||
|
|||||||
@@ -292,8 +292,8 @@
|
|||||||
img.className = 'avatar-option';
|
img.className = 'avatar-option';
|
||||||
img.title = file;
|
img.title = file;
|
||||||
img.dataset.file = file;
|
img.dataset.file = file;
|
||||||
|
img.dataset.avatarFile = file;
|
||||||
img.onerror = () => img.style.display = 'none';
|
img.onerror = () => img.style.display = 'none';
|
||||||
img.onclick = () => selectAvatar(file, img);
|
|
||||||
grid.appendChild(img);
|
grid.appendChild(img);
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user