feat(admin): move message compose into a header-button dialog
Replace the inline <details> compose card on users.php?page=aksrt_messages with a primary header button that opens a native <dialog>. NativeUi::header() gains dialog-type actions via NativeUi::button_dialog(). The dialog reopens automatically after a failed send. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f1bbf2411
commit
6195508481
4 files changed
+163
-21
No files matched your search
@@ -81,7 +81,9 @@ final class NativeUi {
|
||||
/**
|
||||
* 页头:图标 + 标题 + 说明 + 右侧操作。
|
||||
*
|
||||
* @param array<int, array{label:string,url:string,primary?:bool,icon?:string}> $actions
|
||||
* 带 dialog 键的动作渲染为打开对应 <dialog id> 的按钮(由页面脚本绑定),否则渲染为链接。
|
||||
*
|
||||
* @param array<int, array{label:string,url?:string,dialog?:string,primary?:bool,icon?:string}> $actions
|
||||
*/
|
||||
public static function header(string $title, string $description = '', string $icon = '', array $actions = []): void {
|
||||
echo '<div class="aksrt-native-header"><div class="aksrt-native-header__main">';
|
||||
@@ -98,7 +100,9 @@ final class NativeUi {
|
||||
if ($actions !== []) {
|
||||
echo '<div class="aksrt-native-header__actions">';
|
||||
foreach ($actions as $action) {
|
||||
echo self::button_link($action['label'], $action['url'], !empty($action['primary']), (string) ($action['icon'] ?? ''));
|
||||
echo isset($action['dialog'])
|
||||
? self::button_dialog($action['label'], (string) $action['dialog'], !empty($action['primary']), (string) ($action['icon'] ?? ''))
|
||||
: self::button_link($action['label'], (string) $action['url'], !empty($action['primary']), (string) ($action['icon'] ?? ''));
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
@@ -113,6 +117,14 @@ final class NativeUi {
|
||||
return '<a class="' . esc_attr($class) . '" href="' . esc_url($url) . '">' . $icon_html . esc_html($label) . '</a>';
|
||||
}
|
||||
|
||||
/** 打开页面内 <dialog id="$dialog_id"> 的按钮;点击行为由页面脚本按 data-aksrt-dialog-open 绑定。 */
|
||||
public static function button_dialog(string $label, string $dialog_id, bool $primary = false, string $icon = ''): string {
|
||||
$class = $primary ? 'button button-primary' : 'button';
|
||||
$icon_html = $icon !== '' ? '<span class="dashicons ' . esc_attr($icon) . '" aria-hidden="true"></span>' : '';
|
||||
return '<button type="button" class="' . esc_attr($class) . '" data-aksrt-dialog-open="' . esc_attr($dialog_id) . '" aria-haspopup="dialog" aria-controls="' . esc_attr($dialog_id) . '">'
|
||||
. $icon_html . esc_html($label) . '</button>';
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* 统计卡
|
||||
* ----------------------------------------------------------------*/
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* 消息管理后台页(users.php → aksrt_messages)。
|
||||
*
|
||||
* 单页承载:概览卡片 + 代发系统消息(折叠卡片,按用户列表或角色投递)+ 已读状态视图
|
||||
* 单页承载:概览卡片 + 代发系统消息(页头按钮打开弹窗,按用户列表或角色投递)+ 已读状态视图
|
||||
* + 类型 / 收件人 / 关键词筛选 + 全站通知列表(批量标记已读 / 删除)+ 共享分页条。
|
||||
* 查询与写操作在 AKSRT\Messages\NotificationAdminQuery / AdminBroadcast,这里只做页面与路由。
|
||||
*
|
||||
@@ -20,15 +20,20 @@ defined('ABSPATH') || exit;
|
||||
trait UsersMenusMessages {
|
||||
|
||||
private const MESSAGE_PAGE_SLUG = 'aksrt_messages';
|
||||
private const MESSAGE_COMPOSE_ID = 'aksrt-msg-compose';
|
||||
|
||||
/** 页面专属样式,只在本页入队。 */
|
||||
/** 页面专属样式与弹窗脚本,只在本页入队。 */
|
||||
public function enqueue_message_assets(string $hook): void {
|
||||
if ($hook !== 'users_page_' . self::MESSAGE_PAGE_SLUG) {
|
||||
return;
|
||||
}
|
||||
$css = '/assets/css/admin/messages.css';
|
||||
$js = '/assets/js/admin-messages.js';
|
||||
if (is_file(AKSRT_DIR . $css)) {
|
||||
wp_enqueue_style('aksrt-admin-messages', AKSRT_URI . $css, [], (string) filemtime(AKSRT_DIR . $css));
|
||||
wp_enqueue_style('aksrt-admin-messages', AKSRT_URI . $css, [NativeUi::STYLE_HANDLE], (string) filemtime(AKSRT_DIR . $css));
|
||||
}
|
||||
if (is_file(AKSRT_DIR . $js)) {
|
||||
wp_enqueue_script('aksrt-admin-messages', AKSRT_URI . $js, [], (string) filemtime(AKSRT_DIR . $js), true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,11 +47,19 @@ trait UsersMenusMessages {
|
||||
__('消息管理', 'aksrt'),
|
||||
'',
|
||||
'dashicons-email-alt',
|
||||
[[
|
||||
'label' => __('通知配置', 'aksrt'),
|
||||
'url' => admin_url('admin.php?page=aksrt-settings#/users/notifications'),
|
||||
'icon' => 'dashicons-admin-generic',
|
||||
]]
|
||||
[
|
||||
[
|
||||
'label' => __('发送系统消息', 'aksrt'),
|
||||
'dialog' => self::MESSAGE_COMPOSE_ID,
|
||||
'icon' => 'dashicons-megaphone',
|
||||
'primary' => true,
|
||||
],
|
||||
[
|
||||
'label' => __('通知配置', 'aksrt'),
|
||||
'url' => admin_url('admin.php?page=aksrt-settings#/users/notifications'),
|
||||
'icon' => 'dashicons-admin-generic',
|
||||
],
|
||||
]
|
||||
);
|
||||
$this->render_message_notices();
|
||||
|
||||
@@ -209,14 +222,28 @@ trait UsersMenusMessages {
|
||||
}
|
||||
|
||||
private function render_message_compose(): void {
|
||||
// 发送失败回跳时自动重新打开弹窗,便于修正后再发。
|
||||
$open = sanitize_key((string) wp_unslash($_GET['aksrt_msg'] ?? '')) === 'send_failed';
|
||||
|
||||
echo '<details class="aksrt-native-collapse aksrt-messages-admin__compose"' . ($open ? ' open' : '') . '>';
|
||||
echo '<summary><span class="dashicons dashicons-megaphone" aria-hidden="true"></span>' . esc_html__('发送系统消息', 'aksrt') . '</summary>';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '">';
|
||||
printf(
|
||||
'<dialog class="aksrt-msg-dialog" id="%s" aria-labelledby="%s-title"%s>',
|
||||
esc_attr(self::MESSAGE_COMPOSE_ID),
|
||||
esc_attr(self::MESSAGE_COMPOSE_ID),
|
||||
$open ? ' data-aksrt-dialog-autoopen' : ''
|
||||
);
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" class="aksrt-msg-dialog__form aksrt-messages-admin__compose">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_users_send_message" />';
|
||||
wp_nonce_field('aksrt_users_send_message');
|
||||
|
||||
printf(
|
||||
'<header class="aksrt-msg-dialog__head"><h2 id="%s-title" class="aksrt-msg-dialog__title"><span class="dashicons dashicons-megaphone" aria-hidden="true"></span>%s</h2>'
|
||||
. '<button type="button" class="aksrt-msg-dialog__close" data-aksrt-dialog-close aria-label="%s"><span class="dashicons dashicons-no-alt" aria-hidden="true"></span></button></header>',
|
||||
esc_attr(self::MESSAGE_COMPOSE_ID),
|
||||
esc_html__('发送系统消息', 'aksrt'),
|
||||
esc_attr__('关闭', 'aksrt')
|
||||
);
|
||||
echo '<div class="aksrt-msg-dialog__body">';
|
||||
|
||||
echo '<fieldset class="aksrt-messages-admin__modes"><legend>' . esc_html__('收件人', 'aksrt') . '</legend>';
|
||||
printf(
|
||||
'<label><input type="radio" name="recipient_mode" value="users" checked /> %s</label>',
|
||||
@@ -256,12 +283,14 @@ trait UsersMenusMessages {
|
||||
(int) AdminBroadcast::CONTENT_MAX
|
||||
);
|
||||
echo '</div>';
|
||||
echo '<p class="aksrt-native-muted aksrt-msg-dialog__note">' . esc_html__('以「系统通知」类型逐人投递;邮件 / 公众号提醒按通知配置同步触发。', 'aksrt') . '</p>';
|
||||
echo '</div>';
|
||||
printf(
|
||||
'<div class="aksrt-native-form-foot"><span class="aksrt-native-muted">%s</span><button type="submit" class="button button-primary">%s</button></div>',
|
||||
esc_html__('以「系统通知」类型逐人投递;邮件 / 公众号提醒按通知配置同步触发。', 'aksrt'),
|
||||
'<footer class="aksrt-msg-dialog__foot"><button type="button" class="button" data-aksrt-dialog-close>%s</button><button type="submit" class="button button-primary" data-aksrt-dialog-submit>%s</button></footer>',
|
||||
esc_html__('取消', 'aksrt'),
|
||||
esc_html__('发送', 'aksrt')
|
||||
);
|
||||
echo '</form></details>';
|
||||
echo '</form></dialog>';
|
||||
}
|
||||
|
||||
/** @param array{all:int,unread:int,read:int} $counts */
|
||||
|
||||
Reference in new issue
Block a user