diff --git a/assets/css/routes/profile/layout.css b/assets/css/routes/profile/layout.css index 2480a6b1..68a12f67 100644 --- a/assets/css/routes/profile/layout.css +++ b/assets/css/routes/profile/layout.css @@ -479,6 +479,29 @@ padding-bottom: 12px; border-bottom: 2px solid var(--color-primary-50); } + +.creator-center-header { + align-items: flex-start; +} +.creator-center-heading { + min-width: 220px; +} +.creator-center-heading__summary { + margin: 4px 0 0; + color: var(--color-ink-4); + font-size: 12px; +} +.creator-center-actions { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: flex-end; + gap: 10px; +} +.creator-center-actions .profile-status-filter { + justify-content: flex-end; +} + .widget-title--inline { margin: 0; padding: 0; diff --git a/assets/js/routes/user-center.js b/assets/js/routes/user-center.js index 5037f184..191d71d9 100644 --- a/assets/js/routes/user-center.js +++ b/assets/js/routes/user-center.js @@ -16,6 +16,7 @@ var ajaxUrl = cfg.ajaxUrl || ''; var publicNonce = cfg.publicNonce || ''; var settingsNonce = cfg.settingsNonce || ''; + var submitNonce = cfg.submitNonce || ''; var userId = cfg.userId || 0; var i18n = cfg.i18n || {}; var tabAliases = cfg.tabAliases || {}; @@ -698,13 +699,44 @@ }); } - /* ==================== 初始化 ==================== */ + /* ==================== 创作中心文章操作 ==================== */ + function initCreatorPostActions() { + document.addEventListener('click', function(e) { + var btn = e.target.closest('[data-action="delete-post"]'); + if (!btn || btn.disabled) return; + if (!confirm(i18n.confirmDeletePost || '确定删除这篇文章?')) return; + var postId = btn.getAttribute('data-post-id'); + var nonce = btn.getAttribute('data-nonce') || submitNonce; + if (!postId || !nonce) return; + btn.disabled = true; + var body = new URLSearchParams(); + body.set('action', 'aksrt_delete_post'); + body.set('id', postId); + body.set('_nonce', nonce); + fetch(ajaxUrl, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, credentials: 'same-origin', body: body.toString() }) + .then(function(r) { return r.json(); }) + .then(function(res) { + if (res && res.success) { + var item = btn.closest('.profile-list-item'); + if (item) item.remove(); + showToast((res.data && res.data.message) || '文章已经删除'); + } else { + btn.disabled = false; + showToast((res && res.data && res.data.message) || i18n.operationFailed || '操作失败'); + } + }) + .catch(function() { btn.disabled = false; showToast(i18n.networkError || '网络错误'); }); + }); + } + + if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function() { initDashboardNavigation(); initProfileForm(); initAuthForm(); initUnfavorite(); + initCreatorPostActions(); initNotifications(); initSettings(); }); @@ -713,6 +745,7 @@ initProfileForm(); initAuthForm(); initUnfavorite(); + initCreatorPostActions(); initNotifications(); initSettings(); } diff --git a/inc/helpers/aksrt-user-center.php b/inc/helpers/aksrt-user-center.php index 5fabd13a..86eab3d6 100644 --- a/inc/helpers/aksrt-user-center.php +++ b/inc/helpers/aksrt-user-center.php @@ -344,6 +344,7 @@ if (!function_exists('aksrt_user_center_runtime_config')) { 'userId' => $user_id, 'restUrl' => rest_url('aksrt/v1'), 'restNonce' => wp_create_nonce('wp_rest'), + 'submitNonce' => wp_create_nonce('aksrt_submit'), 'defaultTab' => $default_tab, 'activeTab' => $active_tab, 'tabAliases' => [ diff --git a/inc/helpers/user-center-renderers/posts-list.php b/inc/helpers/user-center-renderers/posts-list.php index 7493e5b5..455ae3df 100644 --- a/inc/helpers/user-center-renderers/posts-list.php +++ b/inc/helpers/user-center-renderers/posts-list.php @@ -21,27 +21,37 @@ $ps_args = [ 'update_post_term_cache' => true, ]; $q = new WP_Query($ps_args); +$front_submit = class_exists('\\AKSRT\\Core\\FrontSubmit') ? \AKSRT\Core\FrontSubmit::get_instance() : null; if ($q->have_posts()) : ?> -