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,8 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
import { createLatestRequestGate } from '@/utils/latest-request'
import { formatDateTime, orderedPair } from '@/utils/datetime'
/** 数据去重总数据(registry) · 像素复刻旧版 admin.html panel-dedupe-total-data(自绘:分组摘要 + 双行筛选 + 旧式表格/分页 + 编辑/导入弹窗 + 导出等待遮罩)。
* script 逻辑沿用现有 Vue 实现(查询/编辑/删除/导入轮询/导出秒表)。 */
@@ -107,13 +111,17 @@ function stopExportWait(): void {
exportWaitVisible.value = false
}
const batchListGate = createLatestRequestGate()
async function load(): Promise<void> {
const token = batchListGate.begin()
loading.value = true
loadFailure.value = ''
try {
const result = await fetchDedupeTotalList(
toDedupeListParams(filter, page.value, pageSize.value, pendingCursor, companyTab.requestCompanyId),
)
if (!batchListGate.isCurrent(token)) return
rows.value = result.items
total.value = result.total
if (result.page >= 1) page.value = result.page
@@ -121,10 +129,11 @@ async function load(): Promise<void> {
pageCursor.value = result.nextLastId ?? null
pendingCursor = null
} catch (error) {
if (!batchListGate.isCurrent(token)) return
loadFailure.value = loadFailureMessage(error, '去重数据加载失败')
showAdminFeedback(loadFailure.value, 'error')
} finally {
loading.value = false
if (batchListGate.isCurrent(token)) loading.value = false
}
}
@@ -192,11 +201,23 @@ async function saveEdit(): Promise<void> {
}
}
const batch = useRowSelection({
pageRows: () => rows.value,
rowId: (row) => row.id,
rowLabel: (row) => row.dataValue,
deleteOne: (id) => deleteDedupeTotal(id),
refresh: load,
blocked: () => loading.value || !!loadFailure.value,
scope: () => companyTab.activeId,
})
async function removeRow(row: DedupeTotalItem): Promise<void> {
if (batch.busy) return
// 对齐旧版:浏览器原生 confirm 确认后删除。
if (!(await openAdminConfirm({ message: `确定删除总数据“${row.dataValue}”吗?`, danger: true }))) return
try {
await deleteDedupeTotal(row.id)
batch.removeFromSelection(row.id)
ElMessage.success('删除成功')
await load()
} catch (error) {
@@ -408,10 +429,15 @@ onUnmounted(() => {
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll dedupe-table-scroll">
<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>ID</th>
<th>ASIN</th>
<th>国家</th>
@@ -424,7 +450,11 @@ onUnmounted(() => {
</thead>
<tbody>
<template v-if="rows.length">
<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>{{ row.id }}</td>
<td class="mono-cell">{{ row.dataValue }}</td>
<td>{{ asinCountryLabel(row.country || '') }}</td>
@@ -434,15 +464,15 @@ onUnmounted(() => {
<td>{{ formatDateTime(row.updatedAt) }}</td>
<td class="ops-cell">
<button class="btn btn-sm" type="button" @click="openEdit(row)">编辑</button>
<button class="btn btn-sm btn-danger" type="button" @click="removeRow(row)">删除</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="removeRow(row)">删除</button>
</td>
</tr>
</template>
<tr v-else-if="loading">
<td :colspan="isSuperAdmin ? 8 : 7" class="empty-tip">加载中...</td>
<td :colspan="isSuperAdmin ? 9 : 8" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td :colspan="isSuperAdmin ? 8 : 7" class="empty-tip">暂无总数据</td>
<td :colspan="isSuperAdmin ? 9 : 8" class="empty-tip">暂无总数据</td>
</tr>
</tbody>
</table>
@@ -541,353 +571,4 @@ onUnmounted(() => {
</div>
</template>
<style scoped>
/* 像素复刻旧版 admin.html panel-dedupe-total-data(蓝白末层样式)。 */
.dedupe-view {
font-family: inherit;
color: var(--c-text, #24384d);
display: flex;
flex-direction: column;
gap: 18px;
}
.form-box,
.panel-box {
width: 100%;
min-width: 0;
padding: 20px 22px 24px;
border: 1px solid #d8e3ee;
border-radius: 14px;
background: linear-gradient(145deg, #ffffff, #f9fbfd);
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
}
h3 {
margin: 0 0 16px;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.dedupe-panel-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.dedupe-panel-head h3 {
margin: 0;
}
.dedupe-head-actions {
display: flex;
gap: 10px;
}
.dedupe-filter-row {
display: grid;
grid-template-columns: repeat(4, minmax(160px, 1fr)) auto;
gap: 12px;
align-items: end;
margin-bottom: 16px;
}
.dedupe-filter-row .form-group {
min-width: 0;
}
.dedupe-filter-actions {
display: flex;
gap: 10px;
align-items: center;
white-space: nowrap;
}
.dedupe-filter-date-row {
display: flex;
gap: 12px;
align-items: flex-end;
flex-wrap: wrap;
margin-bottom: 16px;
}
.dedupe-filter-date-row .form-group {
flex: 0 0 200px;
min-width: 0;
}
.dedupe-filter-date-row .dedupe-filter-actions {
margin-left: auto;
}
.form-group {
display: flex;
flex-direction: column;
gap: 7px;
margin-bottom: 0;
}
.form-group label {
color: #5b6f83;
font-size: 12.5px;
font-weight: 600;
}
/* 下拉壳由全局 .el-select.admin-filter(main.css:42px/9px 圆角/#f8fbfd 浅底/focus ring)出,
与亚马逊面同一套;这里只留 input 的原生壳规则(2026-11-17 原生 select 全换 el-select)。 */
.form-group input {
min-width: 0;
min-height: 42px;
padding: 8px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
color-scheme: light;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.form-group input:hover {
border-color: #9fb7cd;
}
.form-group input:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.form-group input[type="file"] {
background: #ffffff;
padding: 6px 10px;
}
.form-group input[type="date"] {
color-scheme: light;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 42px;
padding: 9px 18px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13.5px;
cursor: pointer;
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}
.btn:hover:not(:disabled) {
background: linear-gradient(135deg, #7094ba, #5d83ac);
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.6;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border-color: #c7d7e5;
}
.btn-secondary:hover:not(:disabled) {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.btn-sm {
min-height: 36px;
padding: 7px 12px;
}
.table-scroll {
width: 100%;
min-width: 0;
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 10px;
background: #ffffff;
}
.table-scroll table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.dedupe-table-scroll > table {
min-width: 900px;
}
.table-scroll th,
.table-scroll td {
padding: 10px 12px;
text-align: left;
font-size: 13.5px;
line-height: 1.5;
border-bottom: 1px solid #e0e8ef;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.table-scroll th {
background: #edf4fa;
color: #4e6479;
border-bottom-color: #d5e1eb;
font-size: 12.5px;
font-weight: 600;
letter-spacing: 0.4px;
}
.table-scroll tbody tr:hover td {
background: #f1f7fb;
}
.table-scroll tbody tr:last-child td {
border-bottom: 0;
}
.mono-cell {
font-family: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
font-size: 12.5px;
}
.ops-cell {
display: flex;
align-items: center;
gap: 8px;
white-space: nowrap;
text-align: right;
flex-wrap: wrap;
}
.empty-tip {
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
}
.pagination {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-top: 18px;
color: #5b6f83;
font-size: 13px;
}
.pagination button {
min-height: 30px;
padding: 4px 12px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #5b6f83;
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.pagination button:hover:not(:disabled) {
background: #edf5fb;
border-color: #95b1cb;
color: #2f5d8b;
}
.pagination button:disabled {
background: #eef3f7;
color: #9baaba;
cursor: not-allowed;
}
.page-total {
margin-right: 4px;
}
.page-jump {
display: inline-flex;
align-items: center;
gap: 6px;
}
.page-jump input {
width: 56px;
min-height: 30px;
padding: 4px 8px;
border: 1px solid #cbd9e6;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 13px;
font-family: inherit;
}
.modal-mask {
position: fixed;
inset: 0;
z-index: 3000;
display: flex;
align-items: center;
justify-content: center;
padding: 40px 20px;
background: rgba(45, 66, 86, 0.36);
backdrop-filter: blur(6px);
}
.modal {
display: flex;
flex-direction: column;
width: min(560px, 100%);
max-height: 84vh;
padding: 22px 24px;
border: 1px solid #c7d7e5;
border-radius: 14px;
background: #ffffff;
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
overflow-y: auto;
}
.modal .form-group {
margin-bottom: 14px;
}
.modal-actions {
display: flex;
gap: 10px;
margin-top: 16px;
}
.progress-wrap {
margin-top: 12px;
}
.progress-text {
font-size: 12.5px;
color: #5b6f83;
line-height: 1.6;
}
.dedupe-export-wait-mask {
position: fixed;
inset: 0;
z-index: 3100;
display: flex;
align-items: center;
justify-content: center;
background: rgba(45, 66, 86, 0.36);
backdrop-filter: blur(6px);
}
.dedupe-export-wait {
display: flex;
align-items: center;
gap: 14px;
padding: 22px 28px;
border: 1px solid #c7d7e5;
border-radius: 14px;
background: #ffffff;
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
}
.request-spinner {
width: 26px;
height: 26px;
flex: none;
border: 3px solid #d5e3ef;
border-top-color: #5f85ad;
border-radius: 50%;
animation: dedupe-spin 0.9s linear infinite;
}
@keyframes dedupe-spin {
to { transform: rotate(360deg); }
}
.dedupe-export-wait-title {
font-size: 15px;
font-weight: 600;
color: #24384d;
}
.dedupe-export-wait-detail {
margin-top: 4px;
font-size: 12.5px;
color: #5b6f83;
}
</style>
<style scoped src="./DedupeRegistryPage.css"></style>