feat(frontend): replicate reference header user box 1:1

顶导航点击小人弹出的用户信息浮层,从 AKSRT 定制结构改为与参考主题 zib_header_user_box() 逐行同构:头像链接包裹、钱包双瓷砖、会员条、签到、消息图标、统计徽章行全部改用参考主题遗留类,渲染交回 main.css(.sub-user-box 242px、.avatar-img 38px、.msg-news-icon、badge.top、.payvip-icon 深色渐变加 gem 水印、.vip-expdate-tag、.muted-box)。

头像改走 aksrt_get_avatar_box(用户ID, avatar-img, true, false),得到参考的 a 链接包裹 avatar-img 结构。消息图标改参考标记 msg-news-icon abs-right 加 toggle-radius msg-icon,未读徽章用 badge.top,avatar_dropdown 位置门控契约保留。管理端行在「后台管理」前插入「支付中心」,跳 admin.php?page=aksrt_pay,即参考主题「商城中心」槽位,图标 fa-credit-card。

钱包重写为参考双瓷砖:余额在前(c-blue-2 加 fa-money-bill-wave)、积分在后(c-yellow 加 fa-coins),分别按充值开关与积分总开关门控,两块皆关则不渲染,并保留 data-aksrt-wallet-value 与 data-aksrt-points-value 两个 JS 刷新钩子。会员条去掉 AKSRT 自创的 vipbg-v2 level-N 金色背景,改参考的 payvip-icon 加 badg jb-yellow vip-expdate-tag,到期文案按参考语义分为已过期、永久会员、裸日期三种。签到入口由 button 改为 a.but block c-yellow,并去掉随之失效的 compact 形参,data-signin 挂载与 wp_footer 验证码不变。统计行删掉文章徽章(本站不做帖子),图标由 SVG sprite 换 FA5+ 的 fa-comment-dots、fa-thumbs-up、fa-fire。

会员等级图标契约不动:aksrt_get_vip_icon 与 User\Level::get_badge_html 的调用与参数保持原样。

顺带清死代码:aksrt_header_user_badges_row 原本取到函数后直接返回空串,现在真正输出统计行;删掉 header-userbox.css 里整套 bespoke 规则与 vip-modal.css 的 vipbg-v2 死规则。

显式偏差:统计行链接保持扁平用户主页 URL(AKSRT 用户主页是干净 URL 加 JS tab,没有 query tab 路由);签到入口沿用积分签到总开关门控,不新增管理端可配置项。

public.css 与 public.min.css 用 tools/build-public-assets.mjs 重建:该 bundle 打包了 header-userbox.css 且作为依赖先于单模块入队,旧的 width 260px 会压过新源码、把卡片钉在 260px 而不是参考的 242px。

验证:node --test tests/**/*.test.cjs 573 项全通过;六个改动 PHP 文件 php -l 无语法错误;卡片用到的 FA5 token 逐个核对 5.15.4 全部命中。未做真实视觉效果验收。
This commit is contained in:
2026-10-10 16:17:01 +08:00
parent 8ff74f56ee
commit 6f815678ec
13 changed files with 190 additions and 577 deletions
+73 -50
View File
@@ -35,12 +35,11 @@ if (!function_exists('aksrt_header_user_checkin_btn')) :
* Check-in CTA for header dropdown and compact card placements.
*
* @param int $user_id Current user ID.
* @param bool $compact Render a short card-friendly label.
* @param string|null $class Override the classes and render the reference-parity
* <a> badge (user-card 签到书签); null keeps the header
* dropdown <button> runtime.
* dropdown <a> runtime.
*/
function aksrt_header_user_checkin_btn(int $user_id = 0, bool $compact = false, ?string $class = null): string {
function aksrt_header_user_checkin_btn(int $user_id = 0, ?string $class = null): string {
$user_id = $user_id > 0 ? $user_id : get_current_user_id();
if ($user_id <= 0 || !class_exists('\AKSRT\Credits\Signin')) {
return '';
@@ -56,27 +55,26 @@ if (!function_exists('aksrt_header_user_checkin_btn')) :
// 已签到:与参考主题一致,入口按钮变为签到详情弹窗触发链接(可点击)。
if ($signed) {
$icon = '<i class="fa fas fa-calendar-check ml3 mr6" aria-hidden="true"></i>';
if ($class !== null) {
// 用户卡片签到书签:保留书签类与 is-done 视觉,仅将行为切换为打开详情弹窗。
return aksrt_get_user_checkin_details_link(
$class . ' is-done',
$icon . '<span>' . esc_html__('已签到', 'aksrt') . '</span>'
'<i class="fa fas fa-calendar-check ml3 mr6" aria-hidden="true"></i>'
. '<span>' . esc_html__('已签到', 'aksrt') . '</span>'
);
}
return aksrt_get_user_checkin_details_link(
'but block c-yellow aksrt-header-checkin is-done',
'<i class="fa fas fa-calendar-check" aria-hidden="true"></i> ' . esc_html($compact ? __('已签到', 'aksrt') : __('今日已签到', 'aksrt'))
'but block c-yellow is-done',
'<i class="fa fas fa-calendar-check mr6" aria-hidden="true"></i>'
. esc_html__('今日已签到', 'aksrt')
);
}
$classes = $class ?? ('but block c-yellow aksrt-header-checkin' . ($compact ? ' aksrt-header-checkin--compact' : ''));
// Card badge variant (explicit $class, e.g. the user-card 签到 badge):
// reference parity renders an <a> so the badge inherits the card font
// instead of the UA button stylesheet (font/UI 1:1 with the reference).
if ($class !== null) {
return '<a class="' . esc_attr($classes) . '" href="javascript:;" data-signin-btn'
return '<a class="' . esc_attr($class) . '" href="javascript:;" data-signin-btn'
. ' data-signin-idle-label="' . esc_attr__('签到', 'aksrt') . '"'
. ' data-signin-done-label="' . esc_attr__('已签到', 'aksrt') . '">'
. '<i class="fa fas fa-calendar-check ml3 mr6" aria-hidden="true"></i>'
@@ -84,10 +82,12 @@ if (!function_exists('aksrt_header_user_checkin_btn')) :
. '</a>';
}
return '<button type="button" class="' . esc_attr($classes) . '" data-signin-btn data-signin-idle-label="' . esc_attr__('签到', 'aksrt') . '" data-signin-done-label="' . esc_attr__('已签到', 'aksrt') . '">'
. '<i class="fa fas fa-calendar-check" aria-hidden="true"></i>'
. '<span data-signin-label>' . esc_html($compact ? __('签到', 'aksrt') : __('签到领取今日奖励', 'aksrt')) . '</span>'
. '</button>';
return '<a class="but block c-yellow" href="javascript:;" data-signin-btn'
. ' data-signin-idle-label="' . esc_attr__('签到', 'aksrt') . '"'
. ' data-signin-done-label="' . esc_attr__('今日已签到', 'aksrt') . '">'
. '<i class="fa fas fa-calendar-check mr6" aria-hidden="true"></i>'
. '<span data-signin-label>' . esc_html__('签到领取今日奖励', 'aksrt') . '</span>'
. '</a>';
}
endif;
@@ -118,41 +118,63 @@ add_action('wp_footer', 'aksrt_render_signin_captcha');
if (!function_exists('aksrt_header_user_wallet_mini')) :
/**
* Mini wallet strip: credits + cash balance.
* Mini wallet tiles: cash balance + credits (reference parity).
*
* Each tile is gated by its payment switch; an all-off configuration
* renders nothing at all.
*/
function aksrt_header_user_wallet_mini(int $user_id = 0): string {
$user_id = $user_id > 0 ? $user_id : get_current_user_id();
if ($user_id <= 0) {
if ($user_id <= 0 || !class_exists('\AKSRT\Settings\Settings')) {
return '';
}
$credits = aksrt_user_points($user_id);
$currency = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_currency_name()
: __('积分', 'aksrt');
$wallet = aksrt_user_balance_decimal($user_id);
$center = function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url('credits') : '#';
$html = '<a class="aksrt-header-wallet flex ac jsb" href="' . esc_url($center) . '">';
$html .= '<span class="aksrt-header-wallet__item"><i class="fa fas fa-database" aria-hidden="true"></i> '
. esc_html($currency) . ' <b data-aksrt-points-value data-credits-value>' . esc_html(number_format_i18n($credits)) . '</b></span>';
$html .= '<span class="aksrt-header-wallet__item"><i class="fa fas fa-money-bill" aria-hidden="true"></i> '
. esc_html__('余额', 'aksrt') . ' <b data-aksrt-wallet-value>' . esc_html(number_format_i18n($wallet, 2)) . '</b></span>';
$html .= '</a>';
return $html;
$balance_on = !empty(\AKSRT\Settings\Settings::get_payment_recharge_settings()['enabled']);
$points_on = \AKSRT\Settings\Settings::credits_enabled();
if (!$balance_on && !$points_on) {
return '';
}
$center = function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url('credits') : '#';
$box = '';
if ($balance_on) {
$box .= '<a rel="nofollow" style="flex: 1;" class="muted-box padding-6 flex1 radius4" href="' . esc_url($center) . '">'
. '<div class="muted-2-color px12">' . esc_html__('余额', 'aksrt')
. '<i class="ml6 fa fas fa-angle-right em12" aria-hidden="true"></i></div>'
. '<div class="flex jsb"><span class="font-bold c-blue-2" data-aksrt-wallet-value>'
. esc_html(aksrt_cut_count((float) aksrt_user_balance_decimal($user_id)))
. '</span><i class="fa fas fa-money-bill-wave em14" aria-hidden="true"></i></div></a>';
}
if ($points_on) {
$currency = \AKSRT\Settings\Settings::get_currency_name();
$box .= '<a rel="nofollow" style="flex: 1;" class="muted-box padding-6 flex1 radius4" href="' . esc_url($center) . '">'
. '<div class="muted-2-color px12">' . esc_html($currency)
. '<i class="ml6 fa fas fa-angle-right em12" aria-hidden="true"></i></div>'
. '<div class="flex jsb"><span class="font-bold c-yellow" data-aksrt-points-value>'
. esc_html(aksrt_cut_count(aksrt_user_points($user_id)))
. '</span><i class="fa fas fa-coins em14" aria-hidden="true"></i></div></a>';
}
return '<div class="flex ab jsb col-ml6">' . $box . '</div>';
}
endif;
if (!function_exists('aksrt_header_user_badges_row')) :
/**
* Identity / medal chips under profile.
* Interaction stats row under the wallet (reference parity).
*/
function aksrt_header_user_badges_row(int $user_id = 0): string {
$user_id = $user_id > 0 ? $user_id : get_current_user_id();
if ($user_id <= 0 || !function_exists('aksrt_render_user_identity_chips')) {
if ($user_id <= 0 || !function_exists('aksrt_get_user_badges')) {
return '';
}
// Certification is displayed beside the name and level icon in the profile row.
return '';
$items = aksrt_get_user_badges($user_id);
if ($items === '') {
return '';
}
return '<div class="em09 author-tag mb10 mt6 flex jc">' . $items . '</div>';
}
endif;
@@ -173,10 +195,6 @@ if (!function_exists('aksrt_header_payvip_bar')) :
return '';
}
$settings = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_all()
: [];
$level = function_exists('aksrt_get_user_vip_level') ? (int) aksrt_get_user_vip_level($user_id) : 0;
if ($level > 0) {
$levels = is_array($vip['levels'] ?? null) ? $vip['levels'] : [];
@@ -185,18 +203,23 @@ if (!function_exists('aksrt_header_payvip_bar')) :
if (function_exists('aksrt_get_vip_info')) {
$info = aksrt_get_vip_info($user_id);
$expires = max(0, (int) ($info['expires'] ?? 0));
$exp_label = $expires > 0
? sprintf(__('到期时间:%s', 'aksrt'), wp_date('Y年m月d日', $expires))
: (string) ($info['expires_label'] ?? '');
// 到期文案对齐参考主题:已过期 / 永久会员 / 裸日期。
if ((string) ($info['state'] ?? '') === 'expired') {
$exp_label = __('会员已过期', 'aksrt');
} elseif ($expires > 0) {
$exp_label = wp_date('Y年m月d日', $expires);
} else {
$exp_label = __('永久会员', 'aksrt');
}
}
$html = '<div class="mt10 em09 aksrt-header-payvip is-vip">';
$html .= '<span class="radius4 payvip-icon btn-block text-center vipbg-v2 level-' . (int) $level . ' aksrt-header-payvip__active">';
$html .= '<span class="aksrt-header-payvip__level">';
$html .= '<i class="fa fas fa-gem" aria-hidden="true"></i>';
$html = '<div class="mt10 em09" style="padding:2px;">';
$html .= '<span class="radius4 payvip-icon btn-block text-center">';
$html .= function_exists('aksrt_get_vip_icon') ? aksrt_get_vip_icon($user_id, 'em12 mr6', false) : '';
$html .= '<span>' . esc_html($name) . '</span>';
$html .= '</span>';
if ($exp_label !== '') {
$html .= '<span class="aksrt-header-payvip__exp">' . esc_html($exp_label) . '</span>';
$html .= '<span class="ml10 badg jb-yellow vip-expdate-tag">'
. '<i class="fa fas fa-clock mr3" aria-hidden="true"></i>'
. esc_html($exp_label) . '</span>';
}
$html .= '</span></div>';
return $html;
@@ -205,10 +228,10 @@ if (!function_exists('aksrt_header_payvip_bar')) :
return '';
}
// Match check-in CTA geometry (full width, 6px radius) — not top-nav navbar-cta chips.
return '<div class="mt10 em09 aksrt-header-payvip">'
. '<a class="pay-vip but block payvip-icon aksrt-header-payvip__cta" href="javascript:;" vip-level="1">'
. '<i class="fa fas fa-gem" aria-hidden="true"></i>'
// 几何对齐参考主题 CTA(通栏、radius4)——不是顶导 navbar-cta chips。
return '<div class="mt10 em09" style="padding:2px;">'
. '<a class="pay-vip but radius4 payvip-icon btn-block" href="javascript:;" vip-level="1">'
. '<i class="fa fas fa-gem em12 mr6" aria-hidden="true"></i>'
. '<span>' . esc_html__('开通会员 尊享会员权益', 'aksrt') . '</span>'
. '</a></div>';
}