fix(frontend): keep asset and homepage filters in DOM

This commit is contained in:
2026-09-03 19:21:24 +08:00
parent a0adddce59
commit 7308f055c7
23 changed files with 362 additions and 305 deletions
+14 -20
View File
@@ -150,7 +150,7 @@ if (!function_exists('aksrt_homepage_get_sort_mode')) {
$override_sort = get_query_var('aksrt_homepage_sort_override');
$sort = is_string($override_sort) && $override_sort !== ''
? sanitize_key($override_sort)
: (isset($_GET['home_sort']) ? sanitize_key(wp_unslash((string) $_GET['home_sort'])) : $default_sort);
: $default_sort;
return in_array($sort, $allowed, true) ? $sort : $default_sort;
}
@@ -279,19 +279,15 @@ if (!function_exists('aksrt_homepage_render_sortbar')) {
}
$current = aksrt_homepage_get_sort_mode();
$sort_ajax_enabled = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::homepage_sort_ajax_enabled()
: true;
$is_dropdown = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::home_list_sort_dropdown()
: false;
$base_url = remove_query_arg('home_sort', get_pagenum_link(aksrt_homepage_get_current_page()));
$sort_items = aksrt_homepage_get_sort_items();
$all_labels = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::homepage_sort_labels()
: $sort_items;
?>
<div class="aksrt-homepage__sortbar" data-sort-ajax="<?php echo $sort_ajax_enabled ? 'true' : 'false'; ?>" aria-label="<?php esc_attr_e('Homepage Sort', 'aksrt'); ?>">
<div class="aksrt-homepage__sortbar" aria-label="<?php esc_attr_e('Homepage Sort', 'aksrt'); ?>">
<?php if ($is_dropdown) : ?>
<div class="aksrt-homepage__sortbar-dropdown">
<button type="button" class="aksrt-homepage__sortbar-current" data-sort-dropdown-trigger>
@@ -300,26 +296,24 @@ if (!function_exists('aksrt_homepage_render_sortbar')) {
</button>
<div class="aksrt-homepage__sortbar-dropdown-menu" hidden>
<?php foreach ($sort_items as $sort_key => $label) : ?>
<a
class="aksrt-homepage__sortbar-dropdown-item<?php echo $sort_key === $current ? ' is-active' : ''; ?>"
href="<?php echo esc_url(add_query_arg('home_sort', $sort_key, $base_url)); ?>"
data-sort="<?php echo esc_attr($sort_key); ?>"
>
<?php echo esc_html($label); ?>
</a>
<button type="button"
class="aksrt-homepage__sortbar-dropdown-item<?php echo $sort_key === $current ? ' is-active' : ''; ?>"
data-sort="<?php echo esc_attr($sort_key); ?>"
>
<?php echo esc_html($label); ?>
</button>
<?php endforeach; ?>
</div>
</div>
<?php else : ?>
<div class="aksrt-homepage__sortbar-links">
<?php foreach ($sort_items as $sort_key => $label) : ?>
<a
class="aksrt-homepage__sortbar-link<?php echo $sort_key === $current ? ' is-active' : ''; ?>"
href="<?php echo esc_url(add_query_arg('home_sort', $sort_key, $base_url)); ?>"
data-sort="<?php echo esc_attr($sort_key); ?>"
>
<?php echo esc_html($label); ?>
</a>
<button type="button"
class="aksrt-homepage__sortbar-link<?php echo $sort_key === $current ? ' is-active' : ''; ?>"
data-sort="<?php echo esc_attr($sort_key); ?>"
>
<?php echo esc_html($label); ?>
</button>
<?php endforeach; ?>
</div>
<?php endif; ?>
@@ -17,8 +17,11 @@ defined('ABSPATH') || exit;
</h3>
</div>
<?php
$credits_page = max(1, isset($_GET['credits_page']) ? (int) $_GET['credits_page'] : 1);
$log = \AKSRT\Ledger\LedgerQuery::get_instance()->history(['user_id' => $user_id, 'asset' => 'points', 'page' => $credits_page, 'per_page' => 10]);
$asset_request = is_array($asset_request ?? null) ? $asset_request : [];
$credits_page = ($asset_request['asset'] ?? '') === 'points'
? max(1, (int) ($asset_request['page'] ?? 1))
: 1;
$log = \AKSRT\Ledger\LedgerQuery::get_instance()->history(['user_id' => $user_id, 'asset' => 'points', 'page' => $credits_page, 'per_page' => 10]);
if (!empty($log['items'])) :
?>
<div class="uc-transactions__list">
@@ -55,8 +58,8 @@ defined('ABSPATH') || exit;
</div>
<?php
$total_pages = (int) ceil((int) ($log['total'] ?? 0) / 10);
if ($total_pages > 1) {
aksrt_render_profile_pagination($total_pages, $credits_page, 'credits_page');
if ($total_pages > 1 && function_exists('aksrt_render_asset_pagination')) {
aksrt_render_asset_pagination($total_pages, $credits_page, 'points');
}
?>
<?php else : ?>
@@ -0,0 +1,73 @@
<?php
/**
* User center balance transaction list.
*
* Expects extracted $context vars.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$asset_request = is_array($asset_request ?? null) ? $asset_request : [];
$wallet_page = ($asset_request['asset'] ?? '') === 'balance'
? max(1, (int) ($asset_request['page'] ?? 1))
: 1;
$wlog = \AKSRT\Ledger\LedgerQuery::get_instance()->history([
'user_id' => (int) ($user_id ?? 0),
'asset' => 'balance',
'page' => $wallet_page,
'per_page' => 10,
]);
?>
<div class="uc-transactions uc-transactions--wallet">
<div class="uc-transactions__header">
<h3 class="uc-transactions__title">
<i class="fa fas fa-list-ul" aria-hidden="true"></i>
<?php esc_html_e('余额记录', 'aksrt'); ?>
</h3>
</div>
<?php if (!empty($wlog['items'])) : ?>
<div class="uc-transactions__list">
<?php foreach ($wlog['items'] as $row) :
$delta = (int) $row['delta_minor'];
$delta_class = $delta >= 0 ? 'is-positive' : 'is-negative';
$delta_txt = ($delta > 0 ? '+' : '-') . \AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, abs($delta))->formatted();
$record_note = (string) $row['reason'] === 'points_exchange'
? (string) $row['ref_key']
: (string) ($row['remark'] ?? '');
if (in_array((string) $row['reason'], ['withdraw_hold', 'withdraw_refund'], true)) {
$record_note = (string) ($row['withdrawal_number'] ?? '');
}
?>
<div class="uc-transactions__item">
<div class="uc-transactions__icon <?php echo esc_attr($delta_class); ?>">
<i class="fa fas fa-<?php echo $delta >= 0 ? 'arrow-up' : 'arrow-down'; ?>" aria-hidden="true"></i>
</div>
<div class="uc-transactions__info">
<div class="uc-transactions__reason">
<?php echo esc_html(aksrt_asset_reason_label((string) $row['reason'])); ?>
<?php if ($record_note !== '') : ?>
<span class="uc-transactions__remark">(<?php echo esc_html($record_note); ?>)</span>
<?php endif; ?>
</div>
<div class="uc-transactions__time"><?php echo esc_html(get_date_from_gmt((string) $row['created_at'], 'Y-m-d H:i')); ?></div>
</div>
<div class="uc-transactions__amount">
<span class="uc-transactions__delta <?php echo esc_attr($delta_class); ?>"><?php echo esc_html($delta_txt); ?></span>
</div>
</div>
<?php endforeach; ?>
</div>
<?php
$total_pages = (int) ceil((int) ($wlog['total'] ?? 0) / 10);
if ($total_pages > 1 && function_exists('aksrt_render_asset_pagination')) {
aksrt_render_asset_pagination($total_pages, $wallet_page, 'balance');
}
?>
<?php else : ?>
<div class="uc-transactions__empty">
<p><?php esc_html_e('还没有任何余额流水', 'aksrt'); ?></p>
</div>
<?php endif; ?>
</div>
@@ -234,65 +234,5 @@ endif; ?>
<?php endif; ?>
<?php if (empty($skip_wallet_ledger)) : ?>
<div class="uc-transactions uc-transactions--wallet">
<div class="uc-transactions__header">
<h3 class="uc-transactions__title">
<i class="fa fas fa-list-ul" aria-hidden="true"></i>
<?php esc_html_e('余额记录', 'aksrt'); ?>
</h3>
</div>
<?php
$wallet_page = max(1, isset($_GET['wallet_page']) ? (int) $_GET['wallet_page'] : 1);
$wlog = \AKSRT\Ledger\LedgerQuery::get_instance()->history(['user_id' => (int) $user_id, 'asset' => 'balance', 'page' => $wallet_page, 'per_page' => 10]);
if (!empty($wlog['items'])) :
?>
<div class="uc-transactions__list">
<?php foreach ($wlog['items'] as $row) :
$delta = (int) $row['delta_minor'];
$delta_class = $delta >= 0 ? 'is-positive' : 'is-negative';
$delta_txt = ($delta > 0 ? '+' : '-') . \AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, abs($delta))->formatted();
$record_note = in_array((string) $row['reason'], ['withdraw_hold', 'withdraw_refund'], true)
? (string) ($row['withdrawal_number'] ?? '')
: (string) ($row['remark'] ?? '');
?>
<div class="uc-transactions__item">
<div class="uc-transactions__icon <?php echo esc_attr($delta_class); ?>">
<i class="fa fas fa-<?php echo $delta >= 0 ? 'arrow-up' : 'arrow-down'; ?>" aria-hidden="true"></i>
</div>
<div class="uc-transactions__info">
<div class="uc-transactions__reason">
<?php echo esc_html(aksrt_asset_reason_label((string) $row['reason'])); ?>
<?php if ($record_note !== '') : ?>
<span class="uc-transactions__remark">(<?php echo esc_html($record_note); ?>)</span>
<?php endif; ?>
</div>
<div class="uc-transactions__time"><?php echo esc_html(get_date_from_gmt((string) $row['created_at'], 'Y-m-d H:i')); ?></div>
</div>
<div class="uc-transactions__amount">
<span class="uc-transactions__delta <?php echo esc_attr($delta_class); ?>"><?php echo esc_html($delta_txt); ?></span>
<span class="uc-transactions__balance">
<?php
printf(
esc_html__('余额 %s', 'aksrt'),
esc_html(\AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, (int) $row['balance_after_minor'])->formatted())
);
?>
</span>
</div>
</div>
<?php endforeach; ?>
</div>
<?php
$total_pages = (int) ceil((int) ($wlog['total'] ?? 0) / 10);
if ($total_pages > 1 && function_exists('aksrt_render_profile_pagination')) {
aksrt_render_profile_pagination($total_pages, $wallet_page, 'wallet_page');
}
?>
<?php else : ?>
<div class="uc-transactions__empty">
<div class="uc-transactions__empty-icon"><i class="fa fas fa-money-bill" aria-hidden="true"></i></div>
<p><?php esc_html_e('还没有任何余额流水', 'aksrt'); ?></p>
</div>
<?php endif; ?>
</div>
<?php endif; // skip_wallet_ledger ?>
<?php require __DIR__ . '/credits-wallet-ledger.php'; ?>
<?php endif; ?>
@@ -44,8 +44,12 @@ if ($show_wallet || $show_credits) {
// Tabbed ledgers (legacy record tabs).
if ($show_wallet || $show_credits) :
$active_record = $show_wallet ? 'balance' : 'points';
$show_tasks = $show_credits && class_exists('\AKSRT\Credits\PointsFree') && \AKSRT\Credits\PointsFree::enabled();
$asset_request = is_array($asset_request ?? null) ? $asset_request : [];
$requested_asset = in_array(($asset_request['asset'] ?? ''), ['balance', 'points'], true) ? $asset_request['asset'] : '';
$active_record = $requested_asset !== ''
? $requested_asset
: ($show_wallet ? 'balance' : 'points');
?>
<div class="uc-asset-tabs">
<ul class="uc-asset-tabs__nav list-inline tab-nav-theme font-bold">
@@ -68,58 +72,7 @@ if ($show_wallet || $show_credits) :
<div class="uc-asset-tabs__content tab-content">
<?php if ($show_wallet) : ?>
<div class="tab-pane<?php echo $active_record === 'balance' ? ' is-active' : ''; ?>" id="record_tab_balance" data-aksrt-asset-pane="balance"<?php echo $active_record === 'balance' ? '' : ' hidden'; ?>>
<?php
$skip_wallet_ledger = false;
// Render only the ledger portion by reusing balance log markup.
$user_id = (int) ($user_id ?? 0);
$wallet_page = max(1, isset($_GET['wallet_page']) ? (int) $_GET['wallet_page'] : 1);
$wlog = \AKSRT\Ledger\LedgerQuery::get_instance()->history(['user_id' => $user_id, 'asset' => 'balance', 'page' => $wallet_page, 'per_page' => 10]);
?>
<div class="uc-transactions uc-transactions--wallet">
<?php if (!empty($wlog['items'])) : ?>
<div class="uc-transactions__list">
<?php foreach ($wlog['items'] as $row) :
$delta = (int) $row['delta_minor'];
$delta_class = $delta >= 0 ? 'is-positive' : 'is-negative';
$delta_txt = ($delta > 0 ? '+' : '-') . \AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, abs($delta))->formatted();
$record_note = (string) $row['reason'] === 'points_exchange'
? (string) $row['ref_key']
: (string) $row['remark'];
if (in_array((string) $row['reason'], ['withdraw_hold', 'withdraw_refund'], true)) {
$record_note = (string) ($row['withdrawal_number'] ?? '');
}
?>
<div class="uc-transactions__item">
<div class="uc-transactions__icon <?php echo esc_attr($delta_class); ?>">
<i class="fa fas fa-<?php echo $delta >= 0 ? 'arrow-up' : 'arrow-down'; ?>" aria-hidden="true"></i>
</div>
<div class="uc-transactions__info">
<div class="uc-transactions__reason">
<?php echo esc_html(aksrt_asset_reason_label((string) $row['reason'])); ?>
<?php if ($record_note !== '') : ?>
<span class="uc-transactions__remark">(<?php echo esc_html($record_note); ?>)</span>
<?php endif; ?>
</div>
<div class="uc-transactions__time"><?php echo esc_html(get_date_from_gmt((string) $row['created_at'], 'Y-m-d H:i')); ?></div>
</div>
<div class="uc-transactions__amount">
<span class="uc-transactions__delta <?php echo esc_attr($delta_class); ?>"><?php echo esc_html($delta_txt); ?></span>
</div>
</div>
<?php endforeach; ?>
</div>
<?php
$total_pages = (int) ceil((int) ($wlog['total'] ?? 0) / 10);
if ($total_pages > 1 && function_exists('aksrt_render_profile_pagination')) {
aksrt_render_profile_pagination($total_pages, $wallet_page, 'wallet_page');
}
?>
<?php else : ?>
<div class="uc-transactions__empty">
<p><?php esc_html_e('还没有任何余额流水', 'aksrt'); ?></p>
</div>
<?php endif; ?>
</div>
<?php require $dir . '/credits-wallet-ledger.php'; ?>
</div>
<?php endif; ?>
<?php if ($show_credits) : ?>