perf(modal): unify cancellable frontend modal flows

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
kate522andClaude Fable 5 committed 2026-08-05 02:04:55 +08:00
1 parent 25ce1d8f43
commit 5375ad6429
36 files changed
+2623 -1806

No files matched your search

@@ -15,39 +15,27 @@ if (empty($vip_settings['enabled'])) {
}
$user_id = (int) ($user_id ?? get_current_user_id());
$is_vip_user = function_exists('aksrt_is_vip') && aksrt_is_vip($user_id);
$vip_level = function_exists('aksrt_get_user_vip_level') ? aksrt_get_user_vip_level($user_id) : 0;
$expires = (int) get_user_meta($user_id, 'aksrt_vip_expires', true);
$vip_level = 0;
$expires = 0;
$expires_label = __('未开通', 'aksrt');
if ($vip_level > 0) {
if ($expires <= 0) {
$expires_label = __('永久有效', 'aksrt');
} elseif ($expires < time()) {
$expires_label = __('已过期', 'aksrt');
} else {
$expires_label = sprintf(
/* translators: %s: date */
__('到期时间:%s', 'aksrt'),
wp_date('Y-m-d', $expires)
);
}
}
$is_vip_user = false;
$level_name = (string) ($vip_settings['name'] ?? __('VIP会员', 'aksrt'));
if ($vip_level >= 1 && !empty($vip_settings['levels'][$vip_level]['name'])) {
$level_name = (string) $vip_settings['levels'][$vip_level]['name'];
}
$packages = [];
$renew_desc = '';
$upgrade_desc = '';
$points_exchange = ['enabled' => false, 'packages' => [], 'desc' => ''];
$user_points = 0;
$currency_name = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_currency_name() : __('积分', 'aksrt');
$currency_name = __('积分', 'aksrt');
$methods = [['id' => 'balance', 'name' => __('站内余额', 'aksrt')]];
if (class_exists('\AKSRT\Content\VipService')) {
$catalog = \AKSRT\Content\VipService::get_instance()->get_catalog($user_id);
$vip_level = (int) ($catalog['user_level'] ?? 0);
$expires = (int) ($catalog['user_expires'] ?? 0);
$expires_label = (string) ($catalog['user_expires_label'] ?? $expires_label);
$is_vip_user = $vip_level > 0;
$packages = is_array($catalog['level_packages'] ?? null) ? $catalog['level_packages'] : [];
$methods = is_array($catalog['payment_methods'] ?? null) ? $catalog['payment_methods'] : [];
$methods = is_array($catalog['payment_methods'] ?? null) ? $catalog['payment_methods'] : $methods;
$renew_desc = (string) ($catalog['renew_desc'] ?? '');
$upgrade_desc = (string) ($catalog['upgrade_desc'] ?? '');
$points_exchange = is_array($catalog['points_exchange'] ?? null) ? $catalog['points_exchange'] : $points_exchange;
@@ -55,8 +43,11 @@ if (class_exists('\AKSRT\Content\VipService')) {
if (!empty($catalog['currency_name'])) {
$currency_name = (string) $catalog['currency_name'];
}
} else {
$methods = [['id' => 'balance', 'name' => __('站内余额', 'aksrt')]];
} elseif (class_exists('\\AKSRT\\Settings\\Settings')) {
$currency_name = \AKSRT\Settings\Settings::get_currency_name();
}
if ($vip_level >= 1 && !empty($vip_settings['levels'][$vip_level]['name'])) {
$level_name = (string) $vip_settings['levels'][$vip_level]['name'];
}
$cash_symbol = '¥';
@@ -11,22 +11,35 @@ use AKSRT\User\AuthApply;
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
$user_id = (int) ($context['user_id'] ?? get_current_user_id());
$snapshot = class_exists(AuthApply::class) ? AuthApply::snapshot($user_id) : [
'status' => '',
'stage' => '',
'can_apply' => false,
'verified' => false,
'info' => [],
'apply' => [],
'active' => null,
'latest' => null,
'poll_interval' => 5,
];
$settings = class_exists(AuthApply::class) ? AuthApply::settings() : ['enabled' => false, 'allow_apply' => false];
$status = class_exists(AuthApply::class) ? AuthApply::get_status($user_id) : '';
$info = class_exists(AuthApply::class) ? AuthApply::get_auth_info($user_id) : [];
$apply = class_exists(AuthApply::class) ? AuthApply::get_apply_payload($user_id) : [];
$record = is_array($apply['_application'] ?? null) ? $apply['_application'] : [];
$stage = sanitize_key((string) ($record['status'] ?? ''));
$locks_application = in_array($stage, ['created', 'provider_pending', 'provider_processing', 'manual_pending'], true);
$reason = (string) ($record['review_note'] ?? $record['provider_result_summary'] ?? '');
$can_apply = !empty($settings['enabled']) && !empty($settings['allow_apply']) && $status !== 'verified';
$status = (string) ($snapshot['status'] ?? '');
$info = is_array($snapshot['info'] ?? null) ? $snapshot['info'] : [];
$active = is_array($snapshot['active'] ?? null) ? $snapshot['active'] : [];
$latest = is_array($snapshot['latest'] ?? null) ? $snapshot['latest'] : [];
$stage = sanitize_key((string) ($active['status'] ?? ''));
$locks_application = $stage !== '';
$reason = (string) (($latest['review_note'] ?? '') ?: ($latest['provider_result_summary'] ?? ''));
$can_apply = !empty($snapshot['can_apply']);
$config = [
'restBase' => untrailingslashit(rest_url('aksrt/v1/identity/applications')),
'nonce' => wp_create_nonce('wp_rest'),
'currentUuid' => $locks_application ? (string) ($record['application_uuid'] ?? '') : '',
'currentUuid' => $locks_application ? (string) ($active['application_uuid'] ?? '') : '',
'currentStage' => $locks_application ? $stage : '',
'provider' => sanitize_key((string) ($settings['provider'] ?? 'aliyun')),
'allowManual' => !empty($settings['allow_manual_fallback']),
'pollInterval' => max(5, (int) ($snapshot['poll_interval'] ?? 5)),
'snapshot' => class_exists(AuthApply::class) ? AuthApply::snapshot_view($user_id) : [],
];
?>
<div class="aksrt-user-auth-panel uc-auth-panel" data-identity-root data-identity-config="<?php echo esc_attr(wp_json_encode($config)); ?>">
@@ -58,12 +71,11 @@ $config = [
<?php endif; ?>
<?php if ($can_apply) : ?>
<div class="aksrt-modal uc-auth-modal" id="uc-auth-modal" aria-hidden="true">
<div class="aksrt-modal__overlay" data-auth-modal-close></div>
<div class="aksrt-modal__box uc-auth-modal__dialog" role="dialog" aria-modal="true" aria-labelledby="uc-auth-modal-title">
<template data-auth-modal-template>
<div class="uc-auth-modal__dialog" role="dialog" aria-modal="true" aria-labelledby="uc-auth-modal-title">
<div class="aksrt-modal__header uc-auth-modal__header">
<div><span><i class="fas fa-id-badge" aria-hidden="true"></i></span><strong id="uc-auth-modal-title"><?php esc_html_e('身份认证', 'aksrt'); ?></strong></div>
<button type="button" class="aksrt-modal__close" data-auth-modal-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fas fa-times" aria-hidden="true"></i></button>
<button type="button" class="aksrt-modal__close" data-aksrt-modal-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fas fa-times" aria-hidden="true"></i></button>
</div>
<div class="aksrt-modal__body uc-auth-modal__body">
<div data-auth-status <?php echo !$locks_application ? 'hidden' : ''; ?>>
@@ -98,6 +110,6 @@ $config = [
</form>
</div>
</div>
</div>
</template>
<?php endif; ?>
</div>
@@ -87,7 +87,7 @@ extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_
</div>
<div class="uc-header__actions">
<?php if (class_exists('\AKSRT\User\Badges') && \AKSRT\User\Badges::enabled()) : ?>
<button type="button" class="btn-ghost btn-sm" data-aksrt-badges-open>
<button type="button" class="btn-ghost btn-sm" data-aksrt-badges-open data-aksrt-badges-user-id="<?php echo (int) $user_id; ?>" data-aksrt-badges-can-wear="1">
<i class="fas fa-award" aria-hidden="true"></i> <?php esc_html_e('我的徽章', 'aksrt'); ?>
</button>
<?php endif; ?>
@@ -106,28 +106,3 @@ extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_
</div>
</div>
</div>
<?php if (class_exists('\AKSRT\User\Badges') && \AKSRT\User\Badges::enabled()) : ?>
<div class="uc-modal uc-badges-modal" id="aksrt-badges-modal" hidden data-aksrt-badges-modal data-user-id="<?php echo (int) $user_id; ?>" data-can-wear="1" data-medal-bg="<?php echo esc_url(get_template_directory_uri() . '/assets/img/medal/medal-background.svg'); ?>">
<div class="uc-modal__overlay" data-aksrt-badges-close></div>
<div class="uc-modal__dialog uc-badges-dialog" role="dialog" aria-modal="true" aria-label="<?php esc_attr_e('我的徽章', 'aksrt'); ?>">
<button type="button" class="uc-modal__close" data-aksrt-badges-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fas fa-times" aria-hidden="true"></i></button>
<div class="uc-badges-view" data-aksrt-badges-view="grid">
<div class="uc-badges-head">
<span class="uc-badges-head__icon" aria-hidden="true"><i class="fas fa-award"></i></span>
<div class="uc-badges-head__title">
<?php esc_html_e('我的徽章', 'aksrt'); ?>
<span class="uc-badges-head__count" data-aksrt-badges-count></span>
</div>
<div class="uc-badges-head__wear" data-aksrt-badges-wear-slot></div>
</div>
<div class="uc-badges-body mini-scrollbar" data-aksrt-badges-body>
<div class="uc-badges-loading muted-2-color em09"><i class="fas fa-spinner fa-spin" aria-hidden="true"></i> <?php esc_html_e('加载中…', 'aksrt'); ?></div>
</div>
</div>
<div class="uc-badges-view uc-badges-view--detail" data-aksrt-badges-view="detail" hidden>
<div class="uc-badges-detail" data-aksrt-badges-detail></div>
</div>
</div>
</div>
<?php endif; ?>
@@ -110,7 +110,7 @@ $tabs = [
<div class="aksrt-orders-page__list" data-aksrt-order-list>
<?php foreach ($orders as $order) :
$number = (string) ($order['order_number'] ?? '');
$actions = (array) ($order['actions'] ?? []);
$actions = (array) ($order['allowed_actions'] ?? []);
$amount = !empty($order['is_points'])
? esc_html((string) ($order['currency_symbol'] ?? __('积分', 'aksrt')) . ' ' . (string) (int) round((float) ($order['amount'] ?? 0)))
: '¥' . esc_html(number_format((float) ($order['amount'] ?? 0), 2));
@@ -137,5 +137,4 @@ $tabs = [
<div class="aksrt-orders-page__empty"><i class="fas fa-receipt" 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>
<?php endif; ?>
<div class="aksrt-modal" data-aksrt-order-detail-modal hidden><div class="aksrt-modal__overlay" data-aksrt-order-detail-close></div><section class="aksrt-modal__dialog aksrt-order-detail-dialog" role="dialog" aria-modal="true" aria-labelledby="aksrt-order-detail-title"><header class="aksrt-modal__header"><h3 id="aksrt-order-detail-title"><?php esc_html_e('订单详情', 'aksrt'); ?></h3><button class="aksrt-modal__close" type="button" data-aksrt-order-detail-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>">×</button></header><div class="aksrt-modal__body" data-aksrt-order-detail-body></div><footer class="aksrt-modal__footer" data-aksrt-order-detail-footer></footer></section></div>
</div>