feat(admin): 为支持单删的管理列表补齐批量删除

This commit is contained in:
2026-11-20 12:08:28 +08:00
parent 132c19d51f
commit 51c41b238a
43 changed files with 2806 additions and 1948 deletions
@@ -1,4 +1,7 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
/**
* 品牌Gating库管理页(独立菜单 admin_brand_gating,V174 恢复)。
* 数据源 /api/admin/brand-gating(biz_brand_gating,全平台共享,不随公司 Tab 收窄)。
@@ -191,7 +194,18 @@ async function toggleStatus(row: BrandGatingRow): Promise<void> {
}
}
const batch = useRowSelection({
pageRows: () => rows.value,
rowId: (row) => row.id,
rowLabel: (row) => row.brand || `ID ${row.id}`,
deleteOne: (id) => deleteBrandGating(id),
refresh: () => Promise.all([loadPage(), loadStats()]),
blocked: () => pageLoading.value || busyRowId.value !== 0 || !!loadError.value,
consequence: '删除后可能影响已有数据,此操作不可恢复。',
})
async function removeRow(row: BrandGatingRow): Promise<void> {
if (batch.busy) return
const confirmed = await openAdminConfirm({ danger: true,
targetName: row.brand,
message: `确认删除 ID=${row.id} 的「${row.brand}」Gating记录?此操作可能影响已有数据。`,
@@ -200,6 +214,7 @@ async function removeRow(row: BrandGatingRow): Promise<void> {
busyRowId.value = row.id
try {
await deleteBrandGating(row.id)
batch.removeFromSelection(row.id)
feedback('已删除', 'success')
const nextPage = rows.value.length === 1 && page.value > 1 ? page.value - 1 : page.value
await Promise.all([loadPage(nextPage), loadStats()])
@@ -328,10 +343,15 @@ onMounted(() => {
<LoadFailureBar v-if="loadError" :message="loadError" @retry="loadPage()" />
<BatchDeleteActions :batch="batch" />
<div class="g-table-wrap" v-loading="pageLoading">
<table v-if="rows.length" class="g-table">
<thead>
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th style="width: 64px">ID</th>
<th>品牌</th>
<th>ASIN</th>
@@ -346,7 +366,11 @@ onMounted(() => {
</tr>
</thead>
<tbody>
<tr v-for="row in rows" :key="row.id">
<tr v-for="row in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
</td>
<td class="g-dim">{{ row.id }}</td>
<td class="g-strong">{{ row.brand }}</td>
<td class="g-mono">{{ row.asin || '—' }}</td>
@@ -375,7 +399,7 @@ onMounted(() => {
<button
class="g-btn g-btn-sm g-btn-danger"
type="button"
:disabled="busyRowId === row.id"
:disabled="batch.busy || busyRowId === row.id"
@click="removeRow(row)"
>
删除