修复了一些问题
This commit is contained in:
1 parent
8eb0079bc4
commit
dbb1f776f2
19 files changed
+785
-634
No files matched your search
@@ -21,18 +21,6 @@
|
||||
<n-form-item label="资源下载就绪通知">
|
||||
<n-switch v-model:value="settings.enabled_types.download_ready" />
|
||||
</n-form-item>
|
||||
<n-form-item label="积分增加通知">
|
||||
<n-switch v-model:value="settings.enabled_types.asset_points_increase" />
|
||||
</n-form-item>
|
||||
<n-form-item label="积分扣减通知">
|
||||
<n-switch v-model:value="settings.enabled_types.asset_points_decrease" />
|
||||
</n-form-item>
|
||||
<n-form-item label="余额增加通知">
|
||||
<n-switch v-model:value="settings.enabled_types.asset_balance_increase" />
|
||||
</n-form-item>
|
||||
<n-form-item label="余额扣减通知">
|
||||
<n-switch v-model:value="settings.enabled_types.asset_balance_decrease" />
|
||||
</n-form-item>
|
||||
<n-form-item label="邮箱待验证提醒">
|
||||
<n-switch v-model:value="settings.enabled_types.verify_email" />
|
||||
</n-form-item>
|
||||
@@ -96,10 +84,6 @@ const settings = reactive({
|
||||
comment_reply: true,
|
||||
comment_approved: true,
|
||||
download_ready: true,
|
||||
asset_points_increase: true,
|
||||
asset_points_decrease: true,
|
||||
asset_balance_increase: true,
|
||||
asset_balance_decrease: true,
|
||||
verify_email: true,
|
||||
pending_comments: true,
|
||||
upload_moderation: true,
|
||||
|
||||
@@ -163,10 +163,6 @@ function getTypeTag(type) {
|
||||
system: 'info',
|
||||
comment_reply: 'success',
|
||||
comment_approved: 'success',
|
||||
asset_points_increase: 'warning',
|
||||
asset_points_decrease: 'warning',
|
||||
asset_balance_increase: 'success',
|
||||
asset_balance_decrease: 'error',
|
||||
download_ready: 'primary',
|
||||
verify_email: 'info',
|
||||
pending_comments: 'warning',
|
||||
@@ -180,10 +176,6 @@ function getTypeLabel(type) {
|
||||
system: '系统通知',
|
||||
comment_reply: '评论回复',
|
||||
comment_approved: '评论审核',
|
||||
asset_points_increase: '积分增加',
|
||||
asset_points_decrease: '积分扣减',
|
||||
asset_balance_increase: '余额增加',
|
||||
asset_balance_decrease: '余额扣减',
|
||||
download_ready: '下载就绪',
|
||||
verify_email: '邮箱验证',
|
||||
pending_comments: '待审评论',
|
||||
|
||||
@@ -101,6 +101,13 @@
|
||||
/* ---- 右侧内容 ---- */
|
||||
.messages-center__content {
|
||||
min-width: 0;
|
||||
outline: none;
|
||||
transition: opacity 0.15s ease;
|
||||
}
|
||||
|
||||
.messages-center.is-loading .messages-center__content {
|
||||
opacity: 0.55;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.messages-list {
|
||||
@@ -166,6 +173,20 @@
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
button.message-item__title {
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
font-family: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button.message-item__title:hover {
|
||||
color: var(--color-primary, #3b82f6);
|
||||
}
|
||||
|
||||
.message-item__new-badge {
|
||||
display: inline-block;
|
||||
padding: 1px 6px;
|
||||
@@ -177,6 +198,94 @@
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
/* ---- 消息详情(右侧 DOM 视图,不改变地址) ---- */
|
||||
.message-detail {
|
||||
min-height: 360px;
|
||||
padding: 28px 32px;
|
||||
background: var(--surface-card, #fff);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.message-detail__header {
|
||||
position: relative;
|
||||
padding: 48px 0 22px;
|
||||
border-bottom: 1px solid var(--color-line);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.message-detail__back {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
padding: 7px 10px;
|
||||
border: 0;
|
||||
border-radius: 6px;
|
||||
background: var(--surface-hover, rgba(0, 0, 0, 0.04));
|
||||
color: var(--color-ink-3, #666);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.message-detail__icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
margin-bottom: 14px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-primary-light, rgba(59, 130, 246, 0.1));
|
||||
color: var(--color-primary, #3b82f6);
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.message-detail__title {
|
||||
margin: 0 0 8px;
|
||||
color: var(--color-ink);
|
||||
font-size: 22px;
|
||||
}
|
||||
|
||||
.message-detail__meta {
|
||||
margin: 0;
|
||||
color: var(--color-ink-4, #999);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.message-detail__content {
|
||||
min-height: 140px;
|
||||
padding: 28px 4px;
|
||||
color: var(--color-ink-2, #444);
|
||||
font-size: 15px;
|
||||
line-height: 1.9;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.message-detail__content p {
|
||||
margin: 0 0 1em;
|
||||
}
|
||||
|
||||
.message-detail__actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
padding-top: 18px;
|
||||
border-top: 1px solid var(--color-line);
|
||||
}
|
||||
|
||||
.message-detail__primary {
|
||||
padding: 8px 16px;
|
||||
border-radius: 6px;
|
||||
background: var(--color-primary, #3b82f6);
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
html.dark .message-detail {
|
||||
background: var(--surface-1);
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.message-item__desc {
|
||||
font-size: 13px;
|
||||
color: var(--color-ink-3, #666);
|
||||
@@ -301,6 +410,25 @@
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.message-detail {
|
||||
min-height: 300px;
|
||||
padding: 20px 16px;
|
||||
}
|
||||
|
||||
.message-detail__title {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.message-detail__actions {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.message-detail__primary,
|
||||
.message-detail__actions .message-item__action-btn {
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- 暗色模式 ---- */
|
||||
|
||||
+122
-125
@@ -1,175 +1,172 @@
|
||||
/**
|
||||
* AKSRT messages center interactions.
|
||||
* AKSRT message center DOM navigation.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var root = document.querySelector('[data-message-center]');
|
||||
if (!root) return;
|
||||
|
||||
var nonce = typeof aksrtData !== 'undefined' ? aksrtData.nonce : '';
|
||||
var ajaxUrl = typeof aksrtData !== 'undefined' ? aksrtData.ajaxUrl : '/wp-admin/admin-ajax.php';
|
||||
var pollTimer = null;
|
||||
var content = root.querySelector('[data-message-content]');
|
||||
var nav = root.querySelector('[data-message-nav]');
|
||||
var state = { view: root.dataset.view || 'unread', page: 1, detail: 0 };
|
||||
var pollInterval = 60000;
|
||||
|
||||
function post(action, data) {
|
||||
var body = new URLSearchParams({ action: action, nonce: nonce });
|
||||
if (data) {
|
||||
Object.keys(data).forEach(function (key) {
|
||||
var value = data[key];
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(function (item) {
|
||||
body.append(key + '[]', item);
|
||||
});
|
||||
return;
|
||||
}
|
||||
Object.keys(data || {}).forEach(function (key) {
|
||||
var value = data[key];
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(function (item) { body.append(key + '[]', item); });
|
||||
} else {
|
||||
body.append(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
return fetch(ajaxUrl, { method: 'POST', body: body, credentials: 'same-origin' })
|
||||
.then(function (response) { return response.json(); });
|
||||
}
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var item = event.target.closest('.messages-nav__item[data-type]');
|
||||
if (!item) return;
|
||||
function routeFor(view) {
|
||||
var link = nav.querySelector('[data-message-view="' + view + '"]');
|
||||
return link ? link.href : window.location.href;
|
||||
}
|
||||
|
||||
function updateHeaderBadge(unread) {
|
||||
var count = Math.max(0, Number(unread) || 0);
|
||||
var headerBadge = document.querySelector('.aksrt-notification-badge');
|
||||
var avatarDot = document.querySelector('.nav-user__dot');
|
||||
if (headerBadge) {
|
||||
headerBadge.textContent = String(count);
|
||||
headerBadge.style.display = count > 0 ? '' : 'none';
|
||||
}
|
||||
if (avatarDot) avatarDot.style.display = count > 0 ? '' : 'none';
|
||||
}
|
||||
|
||||
function renderError(message) {
|
||||
content.innerHTML = '<div class="messages-empty"><span class="messages-empty__icon"><i class="fa fas fa-exclamation-circle"></i></span><p class="messages-empty__text"></p></div>';
|
||||
content.querySelector('.messages-empty__text').textContent = message || '加载失败,请稍后重试';
|
||||
}
|
||||
|
||||
function load(next, options) {
|
||||
var requested = {
|
||||
view: next.view || state.view,
|
||||
page: next.page || 1,
|
||||
detail: next.detail || 0,
|
||||
};
|
||||
var settings = options || {};
|
||||
root.classList.add('is-loading');
|
||||
content.setAttribute('aria-busy', 'true');
|
||||
|
||||
return post('aksrt_load_message_center', {
|
||||
view: requested.view,
|
||||
page: requested.page,
|
||||
notification_id: requested.detail,
|
||||
}).then(function (result) {
|
||||
if (!result.success || !result.data) {
|
||||
throw new Error(result.data && result.data.message ? result.data.message : '加载失败,请稍后重试');
|
||||
}
|
||||
state = requested;
|
||||
root.dataset.view = state.view;
|
||||
nav.innerHTML = result.data.nav;
|
||||
content.innerHTML = result.data.content;
|
||||
updateHeaderBadge(result.data.unread);
|
||||
|
||||
if (settings.history === 'push') {
|
||||
window.history.pushState(state, '', routeFor(state.view));
|
||||
} else if (settings.history === 'replace') {
|
||||
window.history.replaceState(state, '', routeFor(state.view));
|
||||
}
|
||||
content.focus({ preventScroll: true });
|
||||
}).catch(function (error) {
|
||||
renderError(error.message);
|
||||
}).finally(function () {
|
||||
root.classList.remove('is-loading');
|
||||
content.removeAttribute('aria-busy');
|
||||
});
|
||||
}
|
||||
|
||||
function reloadList() {
|
||||
return load({ view: state.view, page: state.page, detail: 0 });
|
||||
}
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var tab = event.target.closest('[data-message-view]');
|
||||
if (!tab || !root.contains(tab) || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
||||
event.preventDefault();
|
||||
var url = new URL(window.location.href);
|
||||
url.searchParams.set('msg_type', item.dataset.type);
|
||||
url.searchParams.delete('msg_page');
|
||||
window.location.href = url.toString();
|
||||
load({ view: tab.dataset.messageView, page: 1, detail: 0 }, { history: 'push' });
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('.js-msg-detail');
|
||||
if (!button || !root.contains(button)) return;
|
||||
event.preventDefault();
|
||||
load({ view: button.dataset.view || state.view, page: state.page, detail: button.dataset.id });
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('[data-message-back]');
|
||||
if (!button || !root.contains(button)) return;
|
||||
load({ view: button.dataset.view || state.view, page: state.page, detail: 0 });
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('[data-message-page]');
|
||||
if (!button || !root.contains(button)) return;
|
||||
load({ view: state.view, page: button.dataset.messagePage, detail: 0 });
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('.js-msg-mark-read');
|
||||
if (!button) return;
|
||||
|
||||
var id = button.dataset.id;
|
||||
var msgItem = button.closest('.message-item');
|
||||
post('aksrt_mark_notification_read', { notification_id: id }).then(function (result) {
|
||||
if (!result.success) return;
|
||||
|
||||
if (msgItem) {
|
||||
msgItem.classList.remove('is-unread');
|
||||
}
|
||||
button.remove();
|
||||
updateBadges(result.data && result.data.unread !== undefined ? result.data.unread : countUnread());
|
||||
if (!button || !root.contains(button)) return;
|
||||
post('aksrt_mark_notification_read', { notification_id: button.dataset.id }).then(function (result) {
|
||||
if (result.success) reloadList();
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('.js-msg-delete');
|
||||
if (!button) return;
|
||||
|
||||
var id = button.dataset.id;
|
||||
var msgItem = button.closest('.message-item');
|
||||
post('aksrt_delete_notification', { notification_id: id }).then(function (result) {
|
||||
if (!result.success) return;
|
||||
|
||||
if (msgItem) {
|
||||
msgItem.style.opacity = '0';
|
||||
msgItem.style.transform = 'translateX(20px)';
|
||||
msgItem.style.transition = 'all 0.2s';
|
||||
setTimeout(function () { msgItem.remove(); }, 200);
|
||||
}
|
||||
|
||||
updateBadges(result.data && result.data.unread !== undefined ? result.data.unread : countUnread());
|
||||
checkEmpty();
|
||||
if (!button || !root.contains(button)) return;
|
||||
post('aksrt_delete_notification', { notification_id: button.dataset.id }).then(function (result) {
|
||||
if (result.success) reloadList();
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('.js-msg-mark-all-read');
|
||||
if (!button) return;
|
||||
|
||||
if (!button || !root.contains(button)) return;
|
||||
post('aksrt_mark_notification_read', { mark_all: '1' }).then(function (result) {
|
||||
if (!result.success) return;
|
||||
|
||||
document.querySelectorAll('.message-item.is-unread').forEach(function (item) {
|
||||
item.classList.remove('is-unread');
|
||||
});
|
||||
document.querySelectorAll('.js-msg-mark-read').forEach(function (item) {
|
||||
item.remove();
|
||||
});
|
||||
updateBadges(0);
|
||||
if (result.success) reloadList();
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('.js-msg-clear-read');
|
||||
if (!button) return;
|
||||
|
||||
var readItems = document.querySelectorAll('.message-item:not(.is-unread)');
|
||||
if (!button || !root.contains(button)) return;
|
||||
var ids = [];
|
||||
readItems.forEach(function (item) {
|
||||
var id = item.dataset.notificationId;
|
||||
if (id) ids.push(id);
|
||||
root.querySelectorAll('.message-item:not(.is-unread)[data-notification-id]').forEach(function (item) {
|
||||
if (/^\d+$/.test(item.dataset.notificationId)) ids.push(item.dataset.notificationId);
|
||||
});
|
||||
if (!ids.length) return;
|
||||
|
||||
post('aksrt_delete_notifications', { notification_ids: ids }).then(function (result) {
|
||||
if (!result.success) return;
|
||||
|
||||
readItems.forEach(function (item) {
|
||||
item.style.opacity = '0';
|
||||
item.style.transform = 'translateX(20px)';
|
||||
item.style.transition = 'all 0.2s';
|
||||
setTimeout(function () { item.remove(); }, 200);
|
||||
});
|
||||
setTimeout(checkEmpty, 250);
|
||||
updateBadges(result.data && result.data.unread !== undefined ? result.data.unread : countUnread());
|
||||
if (result.success) reloadList();
|
||||
});
|
||||
});
|
||||
|
||||
function countUnread() {
|
||||
return document.querySelectorAll('.message-item.is-unread').length;
|
||||
}
|
||||
|
||||
function updateBadges(unread) {
|
||||
var nextUnread = unread === undefined ? countUnread() : unread;
|
||||
|
||||
document.querySelectorAll('.messages-nav__badge[data-type="unread"]').forEach(function (badge) {
|
||||
badge.textContent = String(nextUnread);
|
||||
badge.dataset.count = String(nextUnread);
|
||||
badge.style.display = nextUnread > 0 ? '' : 'none';
|
||||
});
|
||||
|
||||
// Numeric badge inside the user dropdown only — never target the pure avatar
|
||||
// .nav-user__dot.aksrt-notification-badge (no textContent on a dot indicator).
|
||||
var headerBadge = document.querySelector('.aksrt-notification-badge');
|
||||
if (headerBadge) {
|
||||
headerBadge.textContent = String(nextUnread);
|
||||
headerBadge.style.display = nextUnread > 0 ? '' : 'none';
|
||||
window.addEventListener('popstate', function (event) {
|
||||
var previous = event.state;
|
||||
if (previous && previous.view) {
|
||||
load(previous);
|
||||
}
|
||||
});
|
||||
|
||||
var avatarDot = document.querySelector('.nav-user__dot');
|
||||
if (avatarDot) {
|
||||
avatarDot.style.display = nextUnread > 0 ? '' : 'none';
|
||||
}
|
||||
}
|
||||
|
||||
function checkEmpty() {
|
||||
var list = document.querySelector('.messages-list');
|
||||
if (list && list.children.length === 0) {
|
||||
list.outerHTML = '<div class="messages-empty"><span class="messages-empty__icon"><i class="fa fas fa-bell-slash"></i></span><p class="messages-empty__text">暂无消息</p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
function startPolling() {
|
||||
pollTimer = setInterval(function () {
|
||||
post('aksrt_check_new_notifications', {}).then(function (result) {
|
||||
if (!result.success || !result.data) return;
|
||||
if (result.data.unread !== undefined) {
|
||||
updateBadges(result.data.unread);
|
||||
return;
|
||||
}
|
||||
if (result.data.count !== undefined) {
|
||||
updateBadges(result.data.count);
|
||||
}
|
||||
}).catch(function () {});
|
||||
}, pollInterval);
|
||||
}
|
||||
|
||||
startPolling();
|
||||
window.history.replaceState(state, '', routeFor(state.view));
|
||||
window.setInterval(function () {
|
||||
post('aksrt_check_new_notifications', {}).then(function (result) {
|
||||
if (result.success && result.data) updateHeaderBadge(result.data.unread);
|
||||
}).catch(function () {});
|
||||
}, pollInterval);
|
||||
})();
|
||||
Reference in new issue
Block a user