chore(admin-platform-order): disable clear-error buttons unless in failed scopes

This commit is contained in:
萝卜
2026-03-16 13:12:21 +08:00
parent e23ae4de61
commit 50e5b35a14
2 changed files with 67 additions and 2 deletions

View File

@@ -1061,6 +1061,14 @@
<div class="tool-group focus-box">
<div class="tool-group-title">清理失败标记:同步订阅</div>
@php
// 清理同步失败标记:前端治理提示(后端仍有 confirm=YES 等安全阀,这里只做“减少误点/更可治理”)
$clearSyncBlockedReason = '';
if ((string) ($filters['sync_status'] ?? '') !== 'failed' && (string) ($filters['fail_only'] ?? '') === '') {
$clearSyncBlockedReason = '建议先筛选「同步失败」集合sync_status=failed后再执行清理避免误清理。';
}
$clearSyncBlocked = $clearSyncBlockedReason !== '';
@endphp
<form method="post" action="/admin/platform-orders/clear-sync-errors" data-action="disable-on-submit" onsubmit="return confirm('确认清除当前筛选范围内命中的订单的“同步失败”标记?');" class="mb-10">
@csrf
<input type="hidden" name="scope" value="filtered">
@@ -1087,7 +1095,10 @@
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
<input type="hidden" name="refund_inconsistent" value="{{ $filters['refund_inconsistent'] ?? '' }}">
<div class="mt-6">
<button class="btn btn-danger btn-sm" type="submit">清除同步失败标记(当前筛选范围)</button>
<button class="btn btn-danger btn-sm" type="submit" @disabled($clearSyncBlocked) title="{{ $clearSyncBlockedReason }}">清除同步失败标记(当前筛选范围)</button>
@if($clearSyncBlocked)
<div class="muted muted-xs text-danger mt-6" data-role="clear-sync-errors-blocked-hint">提示:{{ $clearSyncBlockedReason }}</div>
@endif
</div>
</form>
@@ -1109,6 +1120,14 @@
<div class="tool-group focus-box">
<div class="tool-group-title">清理失败标记:批量 BMPA</div>
@php
// 清理 BMPA 失败标记:前端治理提示(建议先进入 BMPA 失败集合再清理,避免误清理)
$clearBmpaBlockedReason = '';
if ((string) ($filters['bmpa_failed_only'] ?? '') === '' && (string) ($filters['bmpa_error_keyword'] ?? '') === '' && (string) ($filters['batch_mark_paid_and_activate_24h'] ?? '') === '') {
$clearBmpaBlockedReason = '建议先筛选「BMPA失败」集合bmpa_failed_only=1 或失败原因关键词)后再执行清理,避免误清理。';
}
$clearBmpaBlocked = $clearBmpaBlockedReason !== '';
@endphp
<form method="post" action="/admin/platform-orders/clear-bmpa-errors" data-action="disable-on-submit" onsubmit="return confirm('确认清除当前筛选范围内命中的订单的“批量标记支付失败”标记?');" class="mb-10">
@csrf
<input type="hidden" name="scope" value="filtered">
@@ -1135,7 +1154,10 @@
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
<input type="hidden" name="refund_inconsistent" value="{{ $filters['refund_inconsistent'] ?? '' }}">
<div class="mt-6">
<button class="btn btn-danger btn-sm" type="submit">清除批量标记支付失败标记(当前筛选范围)</button>
<button class="btn btn-danger btn-sm" type="submit" @disabled($clearBmpaBlocked) title="{{ $clearBmpaBlockedReason }}">清除批量标记支付失败标记(当前筛选范围)</button>
@if($clearBmpaBlocked)
<div class="muted muted-xs text-danger mt-6" data-role="clear-bmpa-errors-blocked-hint">提示:{{ $clearBmpaBlockedReason }}</div>
@endif
</div>
</form>

View File

@@ -0,0 +1,43 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderIndexClearErrorButtonsShouldDisableWhenNotInFailedScopeTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->seed();
$this->post('/admin/login', [
'email' => 'platform.admin@demo.local',
'password' => 'Platform@123456',
])->assertRedirect('/admin');
}
public function test_clear_error_buttons_should_disable_when_filters_not_in_failed_scopes(): void
{
$this->loginAsPlatformAdmin();
// 默认列表(未进入失败集合)
$res = $this->get('/admin/platform-orders');
$res->assertOk();
$html = (string) $res->getContent();
$this->assertStringContainsString('清除同步失败标记(当前筛选范围)', $html);
$this->assertStringContainsString('data-role="clear-sync-errors-blocked-hint"', $html);
$this->assertStringContainsString('同步失败', $html);
$this->assertStringContainsString('清除批量标记支付失败标记(当前筛选范围)', $html);
$this->assertStringContainsString('data-role="clear-bmpa-errors-blocked-hint"', $html);
$this->assertStringContainsString('BMPA失败', $html);
// 按钮 disabled宽松断言
$this->assertTrue(str_contains($html, 'type="submit" disabled') || str_contains($html, 'disabled="disabled"'));
}
}