订阅列表:快捷筛选仅保留上下文字段避免互斥叠加
This commit is contained in:
@@ -52,18 +52,57 @@
|
|||||||
<div class="card mb-20">
|
<div class="card mb-20">
|
||||||
<h3>快捷筛选</h3>
|
<h3>快捷筛选</h3>
|
||||||
<div class="muted mb-10">用于运营快速定位需要处理的订阅集合(口径基于筛选条件组合)。</div>
|
<div class="muted mb-10">用于运营快速定位需要处理的订阅集合(口径基于筛选条件组合)。</div>
|
||||||
|
|
||||||
|
@php
|
||||||
|
// 快捷筛选:仅保留“上下文”字段(站点/套餐/back/关键词),避免把其它筛选条件叠加导致空结果
|
||||||
|
$buildQuickFilterUrl = function (array $overrides) {
|
||||||
|
$path = '/' . ltrim(request()->path(), '/');
|
||||||
|
|
||||||
|
$contextKeys = [
|
||||||
|
'merchant_id' => 1,
|
||||||
|
'plan_id' => 1,
|
||||||
|
'back' => 1,
|
||||||
|
'keyword' => 1,
|
||||||
|
];
|
||||||
|
|
||||||
|
$q = array_intersect_key(request()->query(), $contextKeys);
|
||||||
|
|
||||||
|
foreach ($overrides as $k => $v) {
|
||||||
|
if ($v === null) {
|
||||||
|
unset($q[$k]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$q[$k] = $v;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($q) === 0) {
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $path . '?' . \Illuminate\Support\Arr::query($q);
|
||||||
|
};
|
||||||
|
|
||||||
|
// “全部”:清空筛选,但保留 back(用于返回来源页)
|
||||||
|
$incomingBack = (string) request()->query('back', '');
|
||||||
|
$safeBack = str_starts_with($incomingBack, '/') ? $incomingBack : '';
|
||||||
|
$allUrl = '/admin/site-subscriptions';
|
||||||
|
if ($safeBack !== '') {
|
||||||
|
$allUrl .= '?' . \Illuminate\Support\Arr::query(['back' => $safeBack]);
|
||||||
|
}
|
||||||
|
@endphp
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<a href="/admin/site-subscriptions" class="muted">全部</a>
|
<a href="{!! $allUrl !!}" class="muted">全部</a>
|
||||||
<span class="muted">|</span>
|
<span class="muted">|</span>
|
||||||
<a href="/admin/site-subscriptions?status=activated" class="muted">已生效</a>
|
<a href="{!! $buildQuickFilterUrl(['status' => 'activated', 'expiry' => null]) !!}" class="muted">已生效</a>
|
||||||
<span class="muted">|</span>
|
<span class="muted">|</span>
|
||||||
<a href="/admin/site-subscriptions?status=pending" class="muted">待生效</a>
|
<a href="{!! $buildQuickFilterUrl(['status' => 'pending', 'expiry' => null]) !!}" class="muted">待生效</a>
|
||||||
<span class="muted">|</span>
|
<span class="muted">|</span>
|
||||||
<a href="/admin/site-subscriptions?status=cancelled" class="muted">已取消</a>
|
<a href="{!! $buildQuickFilterUrl(['status' => 'cancelled', 'expiry' => null]) !!}" class="muted">已取消</a>
|
||||||
<span class="muted">|</span>
|
<span class="muted">|</span>
|
||||||
<a href="/admin/site-subscriptions?expiry=expired" class="muted">已过期</a>
|
<a href="{!! $buildQuickFilterUrl(['status' => null, 'expiry' => 'expired']) !!}" class="muted">已过期</a>
|
||||||
<span class="muted">|</span>
|
<span class="muted">|</span>
|
||||||
<a href="/admin/site-subscriptions?expiry=expiring_7d" class="muted">7天内到期</a>
|
<a href="{!! $buildQuickFilterUrl(['status' => null, 'expiry' => 'expiring_7d']) !!}" class="muted">7天内到期</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminSiteSubscriptionIndexQuickFilterLinksKeepContextTest 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_quick_filter_links_should_keep_context_and_drop_other_filters(): void
|
||||||
|
{
|
||||||
|
$this->loginAsPlatformAdmin();
|
||||||
|
|
||||||
|
$res = $this->get('/admin/site-subscriptions?merchant_id=2&plan_id=3&back=%2Fadmin%2Fplatform-orders&keyword=abc&page=9&status=pending&expiry=expired');
|
||||||
|
$res->assertOk();
|
||||||
|
|
||||||
|
$html = (string) $res->getContent();
|
||||||
|
preg_match_all('/href="([^"]+)"/', $html, $m);
|
||||||
|
$hrefs = $m[1] ?? [];
|
||||||
|
$this->assertGreaterThan(0, count($hrefs));
|
||||||
|
|
||||||
|
// 找到“已生效”快捷筛选链接(status=activated)
|
||||||
|
$activatedLinks = array_values(array_filter($hrefs, fn ($u) => str_contains($u, '/admin/site-subscriptions') && str_contains($u, 'status=activated')));
|
||||||
|
$this->assertGreaterThanOrEqual(1, count($activatedLinks));
|
||||||
|
|
||||||
|
$parts = parse_url($activatedLinks[0]);
|
||||||
|
parse_str($parts['query'] ?? '', $q);
|
||||||
|
|
||||||
|
// 保留上下文:merchant/plan/back/keyword
|
||||||
|
$this->assertSame('2', (string) ($q['merchant_id'] ?? ''));
|
||||||
|
$this->assertSame('3', (string) ($q['plan_id'] ?? ''));
|
||||||
|
$this->assertSame('/admin/platform-orders', (string) ($q['back'] ?? ''));
|
||||||
|
$this->assertSame('abc', (string) ($q['keyword'] ?? ''));
|
||||||
|
|
||||||
|
// 覆盖/清理:status=activated,且不应带 expiry/page
|
||||||
|
$this->assertSame('activated', (string) ($q['status'] ?? ''));
|
||||||
|
$this->assertArrayNotHasKey('expiry', $q);
|
||||||
|
$this->assertArrayNotHasKey('page', $q);
|
||||||
|
|
||||||
|
// “全部”应清空筛选,仅保留 back
|
||||||
|
$allLinks = array_values(array_filter($hrefs, function ($u) {
|
||||||
|
if (!str_starts_with($u, '/admin/site-subscriptions')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$p = parse_url($u);
|
||||||
|
parse_str($p['query'] ?? '', $q2);
|
||||||
|
|
||||||
|
return (($q2['back'] ?? null) === '/admin/platform-orders') && (count($q2) === 1);
|
||||||
|
}));
|
||||||
|
|
||||||
|
$this->assertGreaterThanOrEqual(1, count($allLinks));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user