进行了一些小优化

This commit is contained in:
2026-08-25 16:33:36 +08:00
parent e5df6fdaa7
commit 4a4009133c
5 changed files with 130 additions and 63 deletions
@@ -15,10 +15,10 @@ if ($user_id <= 0) {
}
$raw_query = [
'status' => $_GET['order_status'] ?? 'all',
'type' => $_GET['order_type'] ?? '',
'order_number' => $_GET['order_number'] ?? '',
'page' => $_GET['order_page'] ?? 1,
'status' => 'all',
'type' => '',
'order_number' => '',
'page' => 1,
'per_page' => 20,
];
$query = \AKSRT\Payment\OrderCenterQuery::from_array($raw_query);
@@ -35,23 +35,6 @@ $status = $query->status();
$type = $query->product_type();
$order_number = $query->order_number();
$orders_url = static function (array $override = []) use ($status, $type, $order_number, $page): string {
$values = array_merge([
'order_status' => $status,
'order_type' => $type,
'order_number' => $order_number,
'order_page' => $page,
], $override);
$base = function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url('orders') : home_url('/profile/');
$values['tab'] = 'orders';
foreach ($values as $key => $value) {
if ($value === '' || $value === null || ($key === 'order_page' && (int) $value <= 1) || ($key === 'order_status' && $value === 'all')) {
unset($values[$key]);
}
}
return add_query_arg($values, remove_query_arg(['order_tab', 'otab', 'section'], $base));
};
$status_options = [
'all' => __('全部', 'aksrt'),
'pending' => __('待支付', 'aksrt'),
@@ -78,13 +61,10 @@ $status_options = [
</div>
</header>
<form class="aksrt-orders-page__search" method="get" action="<?php echo esc_url($orders_url(['order_page' => null])); ?>">
<input type="hidden" name="tab" value="orders">
<?php if ($status !== 'all') : ?><input type="hidden" name="order_status" value="<?php echo esc_attr($status); ?>"><?php endif; ?>
<?php if ($type !== '') : ?><input type="hidden" name="order_type" value="<?php echo esc_attr($type); ?>"><?php endif; ?>
<form class="aksrt-orders-page__search" data-aksrt-orders-search>
<label class="screen-reader-text" for="aksrt-order-number"><?php esc_html_e('按订单号查找', 'aksrt'); ?></label>
<i class="fa fas fa-search" aria-hidden="true"></i>
<input id="aksrt-order-number" name="order_number" value="<?php echo esc_attr($order_number); ?>" maxlength="32" placeholder="<?php esc_attr_e('输入订单号开头快速查找', 'aksrt'); ?>">
<input id="aksrt-order-number" value="<?php echo esc_attr($order_number); ?>" maxlength="32" placeholder="<?php esc_attr_e('输入订单号开头快速查找', 'aksrt'); ?>">
<button class="btn-primary" type="submit"><?php esc_html_e('查找', 'aksrt'); ?></button>
<button class="aksrt-orders-page__filter-toggle" type="button" data-aksrt-orders-filter-toggle aria-expanded="false" aria-controls="aksrt-orders-filter-panel"><i class="fa fas fa-sliders-h" aria-hidden="true"></i> <?php esc_html_e('筛选', 'aksrt'); ?></button>
</form>
@@ -94,10 +74,10 @@ $status_options = [
<span class="aksrt-orders-page__filter-label"><?php esc_html_e('订单状态', 'aksrt'); ?></span>
<nav class="aksrt-orders-page__status-filters" aria-label="<?php esc_attr_e('订单状态', 'aksrt'); ?>">
<?php foreach ($status_options as $key => $label) : ?>
<a class="aksrt-orders-page__filter-chip<?php echo $status === $key ? ' is-active' : ''; ?>" href="<?php echo esc_url($orders_url(['order_status' => $key, 'order_page' => null])); ?>">
<button class="aksrt-orders-page__filter-chip<?php echo $status === $key ? ' is-active' : ''; ?>" type="button" data-aksrt-order-filter="status" data-aksrt-order-filter-value="<?php echo esc_attr($key); ?>" aria-pressed="<?php echo $status === $key ? 'true' : 'false'; ?>">
<?php echo esc_html($label); ?>
<?php if ($key === 'pending' && !empty($stats['pending'])) : ?><span class="aksrt-orders-page__filter-count"><?php echo esc_html((string) $stats['pending']); ?></span><?php endif; ?>
</a>
<?php if ($key === 'pending') : ?><span class="aksrt-orders-page__filter-count"<?php echo empty($stats['pending']) ? ' hidden' : ''; ?>><?php echo esc_html((string) (int) ($stats['pending'] ?? 0)); ?></span><?php endif; ?>
</button>
<?php endforeach; ?>
</nav>
</div>
@@ -105,11 +85,11 @@ $status_options = [
<span class="aksrt-orders-page__filter-label"><?php esc_html_e('订单类型', 'aksrt'); ?></span>
<div class="aksrt-orders-page__type-filters">
<?php foreach ($type_options as $key => $label) : ?>
<a class="aksrt-orders-page__filter-chip<?php echo (string) $key === $type ? ' is-active' : ''; ?>" href="<?php echo esc_url($orders_url(['order_type' => $key, 'order_page' => null])); ?>"><?php echo esc_html((string) $label); ?></a>
<button class="aksrt-orders-page__filter-chip<?php echo (string) $key === $type ? ' is-active' : ''; ?>" type="button" data-aksrt-order-filter="type" data-aksrt-order-filter-value="<?php echo esc_attr((string) $key); ?>" aria-pressed="<?php echo (string) $key === $type ? 'true' : 'false'; ?>"><?php echo esc_html((string) $label); ?></button>
<?php endforeach; ?>
</div>
</div>
<a class="aksrt-orders-page__clear" href="<?php echo esc_url($orders_url(['order_status' => null, 'order_type' => null, 'order_number' => null, 'order_page' => null])); ?>"><?php esc_html_e('清除条件', 'aksrt'); ?></a>
<button class="aksrt-orders-page__clear" type="button" data-aksrt-orders-clear><?php esc_html_e('清除条件', 'aksrt'); ?></button>
</div>
<?php if ($orders !== []) : ?>
@@ -144,9 +124,9 @@ $status_options = [
</article>
<?php endforeach; ?>
</div>
<?php if ($total_pages > 1) : ?><nav class="aksrt-orders-page__pagination" aria-label="<?php esc_attr_e('订单分页', 'aksrt'); ?>"><?php for ($index = 1; $index <= $total_pages; $index++) : ?><a class="aksrt-orders-page__page-chip<?php echo $index === $page ? ' is-active' : ''; ?>" href="<?php echo esc_url($orders_url(['order_page' => $index])); ?>"><?php echo esc_html((string) $index); ?></a><?php endfor; ?></nav><?php endif; ?>
<?php if ($total_pages > 1) : ?><nav class="aksrt-orders-page__pagination" aria-label="<?php esc_attr_e('订单分页', 'aksrt'); ?>"><?php for ($index = 1; $index <= $total_pages; $index++) : ?><button class="aksrt-orders-page__page-chip<?php echo $index === $page ? ' is-active' : ''; ?>" type="button" data-aksrt-order-page="<?php echo esc_attr((string) $index); ?>"<?php echo $index === $page ? ' aria-current="page"' : ''; ?>><?php echo esc_html((string) $index); ?></button><?php endfor; ?></nav><?php endif; ?>
<?php else : ?>
<div class="aksrt-orders-page__empty"><i class="fa fas fa-file-alt" aria-hidden="true"></i><h3><?php echo esc_html($order_number !== '' || $type !== '' || $status !== 'all' ? __('没有匹配的订单', 'aksrt') : __('还没有购买记录', 'aksrt')); ?></h3><p><?php echo esc_html($order_number !== '' || $type !== '' || $status !== 'all' ? __('换个条件试试,或清除当前筛选。', 'aksrt') : __('购买内容或开通权益后,订单会出现在这里。', 'aksrt')); ?></p><?php if ($order_number !== '' || $type !== '' || $status !== 'all') : ?><a class="btn-outline" href="<?php echo esc_url($orders_url(['order_status' => null, 'order_type' => null, 'order_number' => null, 'order_page' => null])); ?>"><?php esc_html_e('清除条件', 'aksrt'); ?></a><?php endif; ?></div>
<div class="aksrt-orders-page__empty" data-aksrt-order-list><i class="fa fas fa-file-alt" aria-hidden="true"></i><h3><?php esc_html_e('还没有购买记录', 'aksrt'); ?></h3><p><?php esc_html_e('购买内容或开通权益后,订单会出现在这里。', 'aksrt'); ?></p></div>
<?php endif; ?>
</div>