fix(users): keep management inside center
This commit is contained in:
@@ -82,11 +82,11 @@
|
||||
}
|
||||
target.classList.add('is-loading');
|
||||
var url = restUrl.replace(/\/$/, '') + '/user-center/panel/' + encodeURIComponent(name);
|
||||
if (name === 'creator' || name === 'revenue') {
|
||||
if (name === 'creator' || name === 'revenue' || name === 'posts' || name === 'follow') {
|
||||
var params = queryParams || new URLSearchParams(window.location.search);
|
||||
var allowedParams = name === 'creator'
|
||||
? ['income_page']
|
||||
: ['reward_tab', 'commission_page', 'invite_page'];
|
||||
var allowedParams = name === 'creator' ? ['income_page'] :
|
||||
(name === 'revenue' ? ['reward_tab', 'commission_page', 'invite_page'] :
|
||||
(name === 'posts' ? ['post_status', 'posts_page'] : ['follow_list', 'follow_page']));
|
||||
allowedParams.forEach(function(key) {
|
||||
if (params.get(key)) url += (url.indexOf('?') === -1 ? '?' : '&') + key + '=' + encodeURIComponent(params.get(key));
|
||||
});
|
||||
@@ -328,6 +328,33 @@
|
||||
});
|
||||
}
|
||||
|
||||
function initPostDeletion() {
|
||||
if (document.documentElement.dataset.aksrtPostDeletionBound === 'true') return;
|
||||
document.documentElement.dataset.aksrtPostDeletionBound = 'true';
|
||||
document.addEventListener('click', function(e) {
|
||||
var btn = e.target && e.target.closest ? e.target.closest('[data-action="delete-post"]') : null;
|
||||
if (!btn || btn.disabled || !confirm('确定删除这篇文章?')) return;
|
||||
e.preventDefault();
|
||||
btn.disabled = true;
|
||||
var body = new URLSearchParams();
|
||||
body.set('action', 'aksrt_delete_post');
|
||||
body.set('post_id', btn.getAttribute('data-post-id') || '');
|
||||
body.set('nonce', btn.getAttribute('data-nonce') || submitNonce);
|
||||
fetch(ajaxUrl, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, credentials: 'same-origin', body: body.toString() })
|
||||
.then(function(response) { return response.json(); })
|
||||
.then(function(response) {
|
||||
if (!response || !response.success) throw new Error('delete-failed');
|
||||
var item = btn.closest('.profile-list-item');
|
||||
if (item) item.remove();
|
||||
if (typeof showToast === 'function') showToast('文章已删除');
|
||||
})
|
||||
.catch(function() {
|
||||
btn.disabled = false;
|
||||
if (typeof showToast === 'function') showToast(i18n.operationFailed || '操作失败');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* ==================== 通知中心 ==================== */
|
||||
function initNotifications() {
|
||||
var list = document.getElementById('aksrt-notification-list');
|
||||
@@ -755,6 +782,7 @@
|
||||
initProfileForm();
|
||||
initAuthForm();
|
||||
initUnfavorite();
|
||||
initPostDeletion();
|
||||
initNotifications();
|
||||
initSettings();
|
||||
});
|
||||
@@ -763,7 +791,8 @@
|
||||
initProfileForm();
|
||||
initAuthForm();
|
||||
initUnfavorite();
|
||||
initNotifications();
|
||||
initPostDeletion();
|
||||
initNotifications();
|
||||
initSettings();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user