修复了一些问题
This commit is contained in:
@@ -23,7 +23,7 @@ export const notificationsSchema = {
|
||||
{ key: 'message_s', label: '站内通知总开关', type: 'switch', default: true },
|
||||
{ key: 'msg_center_rewrite_slug', label: '消息中心 URL 别名', type: 'input', default: 'message' },
|
||||
{ key: 'message_icon_show', label: '通知图标位置', type: 'checkbox', default: ['nav_menu'], options: [{ label: '导航菜单', value: 'nav_menu' }, { label: '用户头像', value: 'avatar' }, { label: '移动端底部', value: 'mobile_bar' }] },
|
||||
{ key: 'message_paginate_type', label: '列表翻页模式', type: 'radio', default: 'ajax_lists', options: [{ label: 'AJAX 翻页', value: 'ajax_lists' }, { label: '传统翻页', value: 'default' }] },
|
||||
{ key: 'message_paginate_type', label: '列表翻页模式', type: 'radio', default: 'ajax_lists', options: [{ label: 'AJAX 追加加载', value: 'ajax_lists' }, { label: '数字翻页按钮', value: 'default' }] },
|
||||
{ key: 'message_user_set', label: '允许用户设置推送', type: 'switch', default: true, help: '允许用户在前台自行设置通知推送偏好' },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -350,10 +350,139 @@ html.dark .message-detail {
|
||||
|
||||
/* ---- 分页 ---- */
|
||||
.messages-pagination {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
margin-top: 24px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.messages-pagination__button,
|
||||
.messages-pagination__more {
|
||||
border: 1px solid var(--color-line, rgba(50, 50, 50, 0.08));
|
||||
background: var(--surface-card, #fff);
|
||||
color: var(--color-ink-3, #666);
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease, transform 0.18s ease;
|
||||
}
|
||||
|
||||
.messages-pagination__button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 38px;
|
||||
height: 38px;
|
||||
padding: 0 10px;
|
||||
border-radius: 10px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.messages-pagination__button--edge {
|
||||
color: var(--color-ink-4, #999);
|
||||
}
|
||||
|
||||
.messages-pagination__button:hover:not(:disabled),
|
||||
.messages-pagination__button:focus-visible {
|
||||
border-color: var(--color-primary, #3b82f6);
|
||||
color: var(--color-primary, #3b82f6);
|
||||
outline: none;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.messages-pagination__button.is-current {
|
||||
border-color: var(--color-primary, #3b82f6);
|
||||
background: var(--color-primary, #3b82f6);
|
||||
color: #fff;
|
||||
box-shadow: 0 6px 16px color-mix(in srgb, var(--color-primary, #3b82f6) 24%, transparent);
|
||||
}
|
||||
|
||||
.messages-pagination__button:disabled {
|
||||
cursor: default;
|
||||
opacity: 0.42;
|
||||
}
|
||||
|
||||
.messages-pagination__button.is-current:disabled {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.messages-pagination__ellipsis {
|
||||
min-width: 18px;
|
||||
color: var(--color-ink-4, #999);
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.messages-pagination--load-more {
|
||||
width: min(100%, 440px);
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.messages-pagination__more {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
min-height: 48px;
|
||||
padding: 9px 14px 9px 18px;
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 3px 14px rgba(30, 40, 60, 0.04);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.messages-pagination__more span {
|
||||
color: var(--color-primary, #3b82f6);
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.messages-pagination__more small {
|
||||
padding: 4px 9px;
|
||||
border-radius: 999px;
|
||||
background: var(--color-primary-light, rgba(59, 130, 246, 0.08));
|
||||
color: var(--color-ink-4, #999);
|
||||
font-size: 11px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.messages-pagination__more:hover,
|
||||
.messages-pagination__more:focus-visible {
|
||||
border-color: var(--color-primary, #3b82f6);
|
||||
background: var(--color-primary-light, rgba(59, 130, 246, 0.04));
|
||||
outline: none;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.messages-center.is-loading .messages-pagination__more span::before {
|
||||
display: inline-block;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
margin-right: 7px;
|
||||
border: 2px solid currentColor;
|
||||
border-right-color: transparent;
|
||||
border-radius: 50%;
|
||||
content: "";
|
||||
vertical-align: -2px;
|
||||
animation: messages-pagination-spin 0.7s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes messages-pagination-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.messages-pagination__button,
|
||||
.messages-pagination__more {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
.messages-center.is-loading .messages-pagination__more span::before {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- 响应式 ---- */
|
||||
@@ -420,6 +549,27 @@ html.dark .message-detail {
|
||||
.message-detail__actions .message-item__action-btn {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.messages-pagination {
|
||||
gap: 5px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.messages-pagination__button {
|
||||
min-width: 34px;
|
||||
height: 34px;
|
||||
padding: 0 8px;
|
||||
border-radius: 9px;
|
||||
}
|
||||
|
||||
.messages-pagination__ellipsis {
|
||||
min-width: 10px;
|
||||
}
|
||||
|
||||
.messages-pagination__more {
|
||||
min-height: 46px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- 暗色模式 ---- */
|
||||
@@ -467,6 +617,18 @@ html.dark .message-item:hover {
|
||||
background: var(--surface-2);
|
||||
}
|
||||
|
||||
html.dark .messages-pagination__button,
|
||||
html.dark .messages-pagination__more {
|
||||
border-color: var(--color-line);
|
||||
background: var(--surface-1);
|
||||
}
|
||||
|
||||
html.dark .messages-pagination__more:hover,
|
||||
html.dark .messages-pagination__more:focus-visible {
|
||||
border-color: var(--color-primary);
|
||||
background: var(--surface-2);
|
||||
}
|
||||
|
||||
html.dark .message-item__icon,
|
||||
html.dark .message-item__icon {
|
||||
background: var(--color-primary-soft, rgba(240, 68, 148, 0.16));
|
||||
|
||||
+59
-3
@@ -13,7 +13,12 @@
|
||||
var ajaxUrl = typeof aksrtData !== 'undefined' ? aksrtData.ajaxUrl : '/wp-admin/admin-ajax.php';
|
||||
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 state = {
|
||||
view: root.dataset.view || 'unread',
|
||||
page: 1,
|
||||
detail: 0,
|
||||
paginateType: root.dataset.paginateType || 'ajax_lists',
|
||||
};
|
||||
var pollInterval = 60000;
|
||||
|
||||
function post(action, data) {
|
||||
@@ -51,6 +56,34 @@
|
||||
content.querySelector('.messages-empty__text').textContent = message || '加载失败,请稍后重试';
|
||||
}
|
||||
|
||||
function appendMessagePage(markup) {
|
||||
var incoming = document.createElement('div');
|
||||
incoming.innerHTML = markup;
|
||||
var currentList = content.querySelector('.messages-list');
|
||||
var incomingList = incoming.querySelector('.messages-list');
|
||||
if (!currentList || !incomingList) {
|
||||
content.innerHTML = markup;
|
||||
return null;
|
||||
}
|
||||
|
||||
var existingIds = new Set();
|
||||
currentList.querySelectorAll('[data-notification-id]').forEach(function (item) {
|
||||
existingIds.add(item.dataset.notificationId);
|
||||
});
|
||||
var firstAdded = null;
|
||||
incomingList.querySelectorAll('.message-item').forEach(function (item) {
|
||||
if (existingIds.has(item.dataset.notificationId)) return;
|
||||
if (!firstAdded) firstAdded = item;
|
||||
currentList.appendChild(item);
|
||||
});
|
||||
|
||||
var currentPagination = content.querySelector('.messages-pagination');
|
||||
var incomingPagination = incoming.querySelector('.messages-pagination');
|
||||
if (currentPagination) currentPagination.remove();
|
||||
if (incomingPagination) content.appendChild(incomingPagination);
|
||||
return firstAdded;
|
||||
}
|
||||
|
||||
function load(next, options) {
|
||||
var requested = {
|
||||
view: next.view || state.view,
|
||||
@@ -69,10 +102,17 @@
|
||||
if (!result.success || !result.data) {
|
||||
throw new Error(result.data && result.data.message ? result.data.message : '加载失败,请稍后重试');
|
||||
}
|
||||
requested.paginateType = result.data.paginate_type || state.paginateType;
|
||||
state = requested;
|
||||
root.dataset.view = state.view;
|
||||
root.dataset.paginateType = state.paginateType;
|
||||
nav.innerHTML = result.data.nav;
|
||||
content.innerHTML = result.data.content;
|
||||
var firstAdded = null;
|
||||
if (settings.append && state.paginateType === 'ajax_lists') {
|
||||
firstAdded = appendMessagePage(result.data.content);
|
||||
} else {
|
||||
content.innerHTML = result.data.content;
|
||||
}
|
||||
updateHeaderBadge(result.data.unread);
|
||||
|
||||
if (settings.history === 'push') {
|
||||
@@ -80,7 +120,12 @@
|
||||
} else if (settings.history === 'replace') {
|
||||
window.history.replaceState(state, '', routeFor(state.view));
|
||||
}
|
||||
content.focus({ preventScroll: true });
|
||||
if (firstAdded) {
|
||||
firstAdded.setAttribute('tabindex', '-1');
|
||||
firstAdded.focus({ preventScroll: true });
|
||||
} else {
|
||||
content.focus({ preventScroll: true });
|
||||
}
|
||||
}).catch(function (error) {
|
||||
renderError(error.message);
|
||||
}).finally(function () {
|
||||
@@ -116,9 +161,20 @@
|
||||
document.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('[data-message-page]');
|
||||
if (!button || !root.contains(button)) return;
|
||||
event.preventDefault();
|
||||
load({ view: state.view, page: button.dataset.messagePage, detail: 0 });
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('[data-message-next-page]');
|
||||
if (!button || !root.contains(button)) return;
|
||||
event.preventDefault();
|
||||
load(
|
||||
{ view: state.view, page: button.dataset.messageNextPage, detail: 0 },
|
||||
{ append: true }
|
||||
);
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('.js-msg-mark-read');
|
||||
if (!button || !root.contains(button)) return;
|
||||
|
||||
Reference in New Issue
Block a user