diff --git a/assets/css/frontend/widget-batch5.css b/assets/css/frontend/widget-batch5.css index 791ea69f..f5a9e291 100644 --- a/assets/css/frontend/widget-batch5.css +++ b/assets/css/frontend/widget-batch5.css @@ -22,61 +22,170 @@ } .aksrt-user-card { - border-radius: 12px; - overflow: hidden; + position: relative; + box-sizing: border-box; + width: 100%; + max-width: 100%; + min-width: 0; + border-radius: 8px; + overflow: visible; border: 1px solid var(--color-line, #e5e7eb); background: var(--surface-1, #fff); text-align: center; margin-bottom: 0; } .aksrt-user-card__cover { - height: 90px; - background: linear-gradient(135deg, #93c5fd, #c4b5fd) center/cover no-repeat; + position: relative; + box-sizing: border-box; + width: 100%; + height: 104px; + min-height: 104px; + max-height: 104px; + margin: 0; + padding: 0 !important; + overflow: hidden; + border-radius: 7px 7px 0 0; + background-color: #93c5fd; + background-image: linear-gradient(135deg, #93c5fd, #c4b5fd); + background-position: center; + background-repeat: no-repeat; + background-size: cover; } .aksrt-user-card__cover.is-empty { background: linear-gradient(135deg, #e2e8f0, #f8fafc); } -.aksrt-user-card__body { padding: 0 14px 16px; position: relative; } +.aksrt-user-card__body { + position: relative; + display: flex; + flex-direction: column; + align-items: center; + min-width: 0; + padding: 0 16px 18px; +} .aksrt-user-card__checkin { position: absolute; - right: 10px; - top: 8px; - z-index: 2; - max-width: 48%; + top: 66%; + right: 0; + z-index: 3; + max-width: calc(100% - 56px); + transform: translateY(-50%); } -.aksrt-user-card__checkin .but { - padding: 4px 8px !important; - font-size: 12px !important; - line-height: 1.2; +.aksrt-user-card__checkin--without-cover { + position: relative; + top: auto; + right: auto; + display: flex; + justify-content: flex-end; + max-width: none; + margin: 10px 0 0; + transform: none; +} +.aksrt-user-card .aksrt-user-card__checkin .aksrt-header-checkin { + width: auto !important; + min-height: 40px; + padding: 8px 12px !important; + border-radius: 6px 0 0 6px !important; + font-size: 13px !important; + line-height: 1.25; } .aksrt-user-card__checkin .aksrt-header-checkin-details { display: none; } -.aksrt-user-card__avatar { +.aksrt-user-card__avatar-wrap { + position: relative; display: inline-block; - margin-top: -36px; - width: 72px; - height: 72px; + flex: 0 0 auto; + width: 76px; + height: 76px; + margin: -38px auto 0; +} +.aksrt-user-card.no-cover .aksrt-user-card__avatar-wrap { + margin-top: 16px; +} +.aksrt-user-card__avatar { + display: block; + box-sizing: border-box; + width: 76px; + height: 76px; border-radius: 50%; overflow: hidden; border: 3px solid var(--surface-1, #fff); background: var(--surface-2, #eee); } -.aksrt-user-card__avatar img { width: 100%; height: 100%; object-fit: cover; display: block; } +.aksrt-user-card__avatar > a { + display: block; + width: 100%; + height: 100%; +} +.aksrt-user-card__avatar > img, +.aksrt-user-card__avatar > a > img { + display: block; + width: 100%; + height: 100%; + object-fit: cover; +} +.aksrt-user-card__vip { + position: absolute; + right: -5px; + bottom: -3px; + z-index: 2; + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 28px; + height: 28px; + padding: 3px; + border: 2px solid var(--surface-1, #fff); + border-radius: 50%; + background: var(--surface-1, #fff); + box-shadow: 0 2px 6px rgba(0, 0, 0, .18); + line-height: 1; +} +.aksrt-user-card__vip .aksrt-vip-badge { + width: 100%; + height: 100%; +} +.aksrt-user-card__vip .aksrt-vip-badge__icon { + width: 100%; + height: 100%; + max-width: 100%; + object-fit: contain; +} .aksrt-user-card__name { + display: flex; + align-items: center; + justify-content: center; + width: 100%; + min-width: 0; margin: 10px 0 0; font-size: 16px; font-weight: 700; + line-height: 1.35; +} +.aksrt-user-card__name-row { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 0; + max-width: 100%; + gap: 4px; +} +.aksrt-user-card__name .display-name { + min-width: 0; + max-width: 100%; } .aksrt-user-card__name a { color: inherit; text-decoration: none; } .aksrt-user-card__bio, .aksrt-user-card__guest-title { + width: 100%; margin: 8px 0 0; font-size: 12px; color: var(--muted-2-color, #888); line-height: 1.5; + overflow-wrap: anywhere; } .aksrt-user-card__guest-title { font-size: 14px; font-weight: 600; color: inherit; } .aksrt-user-card__stats { display: flex; + width: 100%; justify-content: center; gap: 18px; margin-top: 12px; @@ -92,6 +201,7 @@ } .aksrt-user-card__actions { display: flex; + width: 100%; justify-content: center; flex-wrap: wrap; gap: 8px; diff --git a/assets/js/header-userbox.js b/assets/js/header-userbox.js index ca3559e7..c04d2dd1 100644 --- a/assets/js/header-userbox.js +++ b/assets/js/header-userbox.js @@ -119,9 +119,12 @@ btn.disabled = true; btn.setAttribute('disabled', 'disabled'); // Keep existing structure so CSS layout (.but.block flex) is not lost. + var signedLabel = btn.classList.contains('aksrt-header-checkin--compact') + ? '已签到' + : '今日已签到'; btn.innerHTML = '' + - '今日已签到'; + '' + signedLabel + ''; }) .catch(function () { toast('网络错误', 'danger'); diff --git a/inc/helpers/aksrt-header-userbox.php b/inc/helpers/aksrt-header-userbox.php index 5efaaf66..323dbcb3 100644 --- a/inc/helpers/aksrt-header-userbox.php +++ b/inc/helpers/aksrt-header-userbox.php @@ -9,9 +9,12 @@ defined('ABSPATH') || exit; if (!function_exists('aksrt_header_user_checkin_btn')) : /** - * Check-in CTA for header dropdown (uses REST /aksrt/v1/signin). + * Check-in CTA for header dropdown and compact card placements (uses REST /aksrt/v1/signin). + * + * @param int $user_id Current user ID. + * @param bool $compact Render a short card-friendly label. */ - function aksrt_header_user_checkin_btn(int $user_id = 0): string { + function aksrt_header_user_checkin_btn(int $user_id = 0, bool $compact = false): string { $user_id = $user_id > 0 ? $user_id : get_current_user_id(); if ($user_id <= 0 || !class_exists('\AKSRT\Credits\Signin')) { return ''; @@ -39,16 +42,17 @@ if (!function_exists('aksrt_header_user_checkin_btn')) : $signed = false; } + $compact_class = $compact ? ' aksrt-header-checkin--compact' : ''; if ($signed) { - return ''; } - return ''; } endif; diff --git a/src/Widgets/WidgetUserCard.php b/src/Widgets/WidgetUserCard.php index 71108346..f9d22957 100644 --- a/src/Widgets/WidgetUserCard.php +++ b/src/Widgets/WidgetUserCard.php @@ -7,13 +7,9 @@ namespace AKSRT\Widgets; -use AKSRT\Widgets\Traits\CommonWidgetFields; - defined('ABSPATH') || exit; class WidgetUserCard extends \WP_Widget { - use CommonWidgetFields; - public function __construct() { parent::__construct( 'aksrt_user_card', @@ -122,13 +118,28 @@ class WidgetUserCard extends \WP_Widget { } $name_html = function_exists('aksrt_get_user_name') - ? aksrt_get_user_name(['id' => $user_id, 'follow' => !$is_self, 'class' => 'flex ac jc']) + ? aksrt_get_user_name([ + 'id' => $user_id, + 'vip' => false, + 'follow' => !$is_self, + 'class' => 'aksrt-user-card__name-row', + ]) : '' . esc_html($user->display_name) . ''; + $vip_badge = function_exists('aksrt_render_vip_badge') + ? (string) aksrt_render_vip_badge($user_id, 'sm') + : ''; + $checkin_btn = ''; + if ($show_checkin && $is_self && function_exists('aksrt_header_user_checkin_btn')) { + $checkin_btn = aksrt_header_user_checkin_btn($user_id, true); + } + $checkin_html = $checkin_btn !== '' + ? '
' . $checkin_btn . '
' + : ''; - echo '
'; + echo '
'; if ($show_cover) { if ($cover !== '') { - echo '
'; + echo '
' . $checkin_html . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } else { // Prefer site default cover image when available. $default_cover = ''; @@ -139,22 +150,23 @@ class WidgetUserCard extends \WP_Widget { $default_cover = (string) get_theme_mod('aksrt_user_cover', ''); } if ($default_cover !== '') { - echo '
'; + echo '
' . $checkin_html . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } else { - echo '
'; + echo '
' . $checkin_html . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } + } elseif ($checkin_btn !== '') { + echo '
' . $checkin_btn . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } echo '
'; - if ($show_checkin && $is_self && function_exists('aksrt_header_user_checkin_btn')) { - $btn = aksrt_header_user_checkin_btn($user_id); - if ($btn !== '') { - echo '
' . $btn . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - } - } + echo '
'; echo '
'; $ph = get_template_directory_uri() . '/assets/img/placeholder.svg'; - echo '' . esc_attr($user->display_name) . ''; + echo '' . esc_attr($user->display_name) . ''; + echo '
'; + if ($vip_badge !== '') { + echo '' . $vip_badge . ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + } echo '
'; echo '

' . $name_html . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ($bio !== '') { @@ -212,20 +224,20 @@ class WidgetUserCard extends \WP_Widget { } } - echo '
'; + echo '
'; if ($show_cover) { $default_cover = ''; if (class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_user_cover_default')) { $default_cover = (string) \AKSRT\Settings\Settings::get_user_cover_default(); } if ($default_cover !== '') { - echo '
'; + echo '
'; } else { - echo '
'; + echo '
'; } } echo '
'; - echo '
'; + echo '
'; echo '
' . esc_html($loged_title) . '
'; echo '
'; echo ''; @@ -320,7 +332,6 @@ class WidgetUserCard extends \WP_Widget {

- render_common_form_section($instance); ?> update_common_fields($new_instance, $old_instance, [ + return [ 'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')), 'user_id' => max(0, (int) ($new_instance['user_id'] ?? 0)), 'loged_title' => sanitize_text_field((string) ($new_instance['loged_title'] ?? '')), @@ -351,7 +362,7 @@ class WidgetUserCard extends \WP_Widget { 'limit' => max(0, min(12, (int) ($new_instance['limit'] ?? 6))), 'post_style' => $post_style, 'orderby' => $orderby, - ]); + ]; } /** Zibll CFS_Module::zib_palette() gradient/solid keys (c/b/jb families). */