chore(admin-ui): migrate products list to list card and admin pagination

This commit is contained in:
萝卜
2026-03-16 03:42:43 +08:00
parent 08c6912d14
commit 053fc71dc8
2 changed files with 53 additions and 6 deletions

View File

@@ -54,7 +54,7 @@
<div class="stat-box"><div class="muted">累计失败商品</div><strong class="num-sm">{{ $importHistoryStats['total_failed'] ?? 0 }}</strong></div>
<div class="stat-box"><div class="muted">含失败批次</div><strong class="num-sm">{{ $importHistoryStats['warning_imports'] ?? 0 }}</strong></div>
</div>
<table>
<table class="list-card-table">
<thead><tr><th>ID</th><th>导入时间</th><th>商家</th><th>上传文件</th><th>结果</th><th>失败明细</th></tr></thead>
<tbody>
@forelse($importHistories->take(5) as $history)
@@ -171,8 +171,13 @@
</form>
</div>
<div class="card">
<h3>商品列表</h3>
<div class="card list-card">
<div class="list-card-header">
<div>
<h3 class="list-card-title">商品列表</h3>
</div>
</div>
<div class="list-card-body">
<form id="platform-batch-form" method="post" action="/admin/products/batch" onsubmit="return confirm('确认执行本次批量操作?');">
@csrf
@php
@@ -195,7 +200,7 @@
</div>
</form>
<p class="muted muted-tight">平台侧批量改分类会校验所选分类是否属于被勾选商品对应商家;若混选了不同商家的商品,请选择各自可用的分类或先分批处理。</p>
<table>
<table class="list-card-table">
<thead><tr><th><input type="checkbox" data-check-all="platform-products"></th><th>ID</th><th>商家</th><th>标题</th><th>分类</th><th>SKU</th><th>售价/原价</th><th>库存</th><th>创建时间</th><th>更新时间</th><th>状态</th><th>操作</th></tr></thead>
<tbody>
@foreach($products as $product)
@@ -216,7 +221,7 @@
@endforeach
</tbody>
</table>
</div>
</form>
<script>
document.addEventListener('DOMContentLoaded', function () {
const master = document.querySelector('[data-check-all="platform-products"]');
@@ -232,5 +237,7 @@
});
</script>
<div class="pagination-wrap">{{ $products->links() }}</div>
{{ $products->links('pagination.admin') }}
</div>
</div>
@endsection

View File

@@ -0,0 +1,40 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminProductsIndexShouldUseListCardAndAdminPaginationTest 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_admin_products_index_should_use_list_card_and_admin_pagination(): void
{
$this->loginAsPlatformAdmin();
$res = $this->get('/admin/products');
$res->assertOk();
// 护栏:商品列表区域应走统一 List Card 骨架。
$res->assertSee('list-card', false);
$res->assertSee('list-card-header', false);
$res->assertSee('list-card-body', false);
$res->assertSee('list-card-table', false);
// 分页统一:数据量可能不足导致 hasPages=false因此用扫描型护栏断言。
$blade = file_get_contents(resource_path('views/admin/products/index.blade.php'));
$this->assertIsString($blade);
$this->assertStringContainsString("links('pagination.admin')", $blade);
}
}