fix(user-center): embed official certification panel

This commit is contained in:
2026-07-28 15:22:09 +08:00
parent d3bf75fbea
commit 0a04c3e4cc
22 changed files with 415 additions and 461 deletions
+89 -1
View File
@@ -27,7 +27,7 @@
if (!tabContainer) return;
var tabs = tabContainer.querySelectorAll('[data-tab]');
var sidebarBtns = document.querySelectorAll('.uc-sidebar__btn[data-tab]');
var sidebarBtns = document.querySelectorAll('.uc-sidebar__btn[data-tab], .uc-service-grid__item[data-tab]');
var panels = {};
var defaultTab = cfg.defaultTab || 'profile';
var drawerTrigger = document.getElementById('uc-drawer-trigger');
@@ -193,6 +193,92 @@
});
}
function initAuthForm() {
var modal = document.getElementById('uc-auth-modal');
if (!modal || modal.dataset.authModalBound === '1') return;
modal.dataset.authModalBound = '1';
function openModal() {
modal.classList.add('is-open');
modal.setAttribute('aria-hidden', 'false');
document.body.style.overflow = 'hidden';
var first = modal.querySelector('input:not([type="hidden"]), select, textarea, button');
if (first) window.setTimeout(function() { first.focus(); }, 80);
}
function closeModal() {
modal.classList.remove('is-open');
modal.setAttribute('aria-hidden', 'true');
document.body.style.overflow = '';
}
document.querySelectorAll('[data-auth-modal-open]').forEach(function(button) {
button.addEventListener('click', openModal);
});
modal.querySelectorAll('[data-auth-modal-close]').forEach(function(button) {
button.addEventListener('click', closeModal);
});
document.addEventListener('keydown', function(event) {
if (event.key === 'Escape' && modal.classList.contains('is-open')) closeModal();
});
var fileInput = modal.querySelector('[data-auth-files]');
var previews = modal.querySelector('[data-auth-previews]');
if (fileInput && previews) {
fileInput.addEventListener('change', function() {
previews.innerHTML = '';
var files = Array.prototype.slice.call(fileInput.files || []);
if (files.length > 3) {
showToast('证明材料最多上传 3 张');
fileInput.value = '';
return;
}
for (var index = 0; index < files.length; index++) {
if (files[index].size > 2 * 1024 * 1024) {
showToast('单张图片不能超过 2MB');
fileInput.value = '';
previews.innerHTML = '';
return;
}
var image = document.createElement('img');
image.src = URL.createObjectURL(files[index]);
image.alt = '';
image.onload = function() { URL.revokeObjectURL(this.src); };
previews.appendChild(image);
}
});
}
var form = modal.querySelector('.aksrt-user-auth-form');
if (!form) return;
form.addEventListener('submit', function(e) {
e.preventDefault();
var button = form.querySelector('[type="submit"]');
var message = form.querySelector('[data-auth-message]');
var original = button ? button.textContent : '';
if (button) {
button.disabled = true;
button.textContent = i18n.submitting || '提交中…';
}
if (message) message.textContent = '';
fetch(ajaxUrl, { method: 'POST', body: new FormData(form), credentials: 'same-origin' })
.then(function(response) { return response.json(); })
.then(function(response) {
if (!response || response.error) throw new Error((response && response.msg) || '提交失败');
showToast(response.msg || '提交成功');
window.setTimeout(function() { window.location.assign(tabUrls.auth || '?tab=auth'); }, 500);
})
.catch(function(error) {
if (message) message.textContent = error.message || '提交失败';
showToast(error.message || '提交失败');
if (button) {
button.disabled = false;
button.textContent = original;
}
});
});
}
/* ==================== 列表内取消收藏 ==================== */
function initUnfavorite() {
var list = document.querySelector('.profile-list[data-list="favorites"]');
@@ -678,6 +764,7 @@
document.addEventListener('DOMContentLoaded', function() {
initDashboardNavigation();
initProfileForm();
initAuthForm();
initUnfavorite();
initNotifications();
initSettings();
@@ -685,6 +772,7 @@
} else {
initDashboardNavigation();
initProfileForm();
initAuthForm();
initUnfavorite();
initNotifications();
initSettings();