Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
(function () {
|
||||
var form = document.querySelector("[data-edit-profile-form]");
|
||||
var nickInput = document.querySelector("[data-edit-profile-nickname]");
|
||||
var bioInput = document.querySelector("[data-edit-profile-bio]");
|
||||
var submitBtn = document.querySelector("[data-edit-profile-submit]");
|
||||
if (!form) return;
|
||||
|
||||
var originalNick = nickInput ? String(nickInput.value || "").trim() : "";
|
||||
var originalBio = bioInput ? String(bioInput.value || "").trim() : "";
|
||||
|
||||
function toast(message, type) {
|
||||
if (window.AuthAPI) AuthAPI.toast(message, type);
|
||||
else if (typeof showToast === "function") showToast(message, type);
|
||||
}
|
||||
|
||||
form.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
if (!window.AuthAPI || !window.HttpRequest) {
|
||||
return;
|
||||
}
|
||||
|
||||
var nick = nickInput ? String(nickInput.value || "").trim() : "";
|
||||
var bio = bioInput ? String(bioInput.value || "").trim() : "";
|
||||
if (!nick) {
|
||||
toast("请输入昵称", "error");
|
||||
return;
|
||||
}
|
||||
if (nick.length > 20) {
|
||||
toast("昵称最多 20 个字符", "error");
|
||||
return;
|
||||
}
|
||||
if (bio.length > 120) {
|
||||
toast("个人简介最多 120 个字符", "error");
|
||||
return;
|
||||
}
|
||||
|
||||
var nickChanged = nick !== originalNick;
|
||||
var bioChanged = bio !== originalBio;
|
||||
if (!nickChanged && !bioChanged) {
|
||||
toast("暂无修改", "info");
|
||||
return;
|
||||
}
|
||||
|
||||
var payload = {};
|
||||
if (nickChanged) payload.nickName = nick;
|
||||
if (bioChanged) payload.introduction = bio;
|
||||
if (!payload.nickName && !payload.introduction) {
|
||||
toast(bioChanged ? "请填写个人简介或修改昵称" : "暂无修改", "error");
|
||||
return;
|
||||
}
|
||||
|
||||
if (submitBtn) submitBtn.disabled = true;
|
||||
|
||||
AuthAPI.updateProfile(payload)
|
||||
.then(function () {
|
||||
toast("保存成功", "success");
|
||||
setTimeout(function () {
|
||||
window.location.href = "/setting/";
|
||||
}, 400);
|
||||
})
|
||||
.catch(function (err) {
|
||||
toast((err && err.message) || "保存失败", "error");
|
||||
})
|
||||
.finally(function () {
|
||||
if (submitBtn) submitBtn.disabled = false;
|
||||
});
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user