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'
/** 店铺数据记录页 · 像素复刻旧版 admin.html panel-shop-data-crawl-tasks(自绘:form-box 筛选[h4 筛选条件] + panel-box toolbar[全选/批量下载/权限配置/汇总] + 每店卡片网格 + 旧式分页(店铺级+卡片级 9/页))。
* script 逻辑沿用现有 Vue 实现(批量打包/删除结果文件[保留]/权限授权)。 */
@@ -129,19 +133,24 @@ function toFilter(): ShopDataFilter {
}
}
const batchListGate = createLatestRequestGate()
async function load() {
const token = batchListGate.begin()
loading.value = true
loadFailure.value = ''
try {
const result = await fetchShopDataTaskList(toFilter(), page.value, pageSize.value, companyTab.requestCompanyId)
if (!batchListGate.isCurrent(token)) return
groups.value = result.items
totalShops.value = result.total
page.value = result.page
} catch (error) {
if (!batchListGate.isCurrent(token)) return
loadFailure.value = error instanceof Error ? error.message : '店铺数据记录加载失败'
showAdminFeedback(loadFailure.value, 'error')
} finally {
loading.value = false
if (batchListGate.isCurrent(token)) loading.value = false
}
}
@@ -256,12 +265,26 @@ async function downloadBatch() {
}
}
const batch = useRowSelection({
pageRows: () => pagedResultRows.value,
rowId: (row) => row.resultId,
rowLabel: (row) => `${row.shopName || '店铺'}(${row.filename || row.taskNo || row.resultId})`,
deleteOne: (id) => deleteShopDataResultHistory(id),
refresh: load,
blocked: () => loading.value || !!loadFailure.value || !!deletingKey.value,
scope: () => companyTab.activeId,
precheck: (row) => isTerminalStatus(row.status) && row.resultId ? undefined : '仅终态数据记录可删除',
consequence: '店铺数据文件及对应记录将一起删除,此操作不可恢复。',
})
async function removeRowByRow(row: ShopDataResultRow) {
if (batch.busy) return
// 管理端真删:删除该店这条店铺数据记录(累计档 + 文件 + 明细),前台任务记录仍保留但文件不可再下载
if (!(await openAdminConfirm({ message: `确认删除店铺“${row.shopName}”这条店铺数据记录及其数据文件?此操作不可恢复。`, danger: true }))) return
deletingKey.value = row.resultId
try {
await deleteShopDataResultHistory(row.resultId)
batch.removeFromSelection(row.resultId)
ElMessage.success('删除成功')
await load()
} catch (error) {
@@ -371,14 +394,25 @@ onMounted(load)
</div>
</div>
<div class="sd-toolbar">
<label class="sd-select-all">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
全选本页可删除记录
</label>
<BatchDeleteActions :batch="batch" />
</div>
<div v-loading="loading" class="shop-card-grid">
<template v-if="allResultRows.length">
<article
v-for="row in pagedResultRows"
:key="row.resultId || `${row.taskNo}-${row.filename}`"
class="sd-card"
:class="{ 'batch-selected': batch.isSelected(row) }"
>
<header class="sd-card-head">
<BatchDeleteCheckbox v-if="!batch.reason(row)" :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
<span class="sd-shop-name" :title="row.shopName || '-'">{{ row.shopName || '-' }}</span>
</header>
<div class="sd-card-select-row">
@@ -418,7 +452,7 @@ onMounted(load)
v-if="isTerminalStatus(row.status) && !!row.resultId"
class="btn btn-sm btn-danger"
type="button"
:disabled="deletingKey === row.resultId"
:disabled="batch.busy || deletingKey === row.resultId"
@click="removeRowByRow(row)"
>
{{ deletingKey === row.resultId ? '删除中...' : '删除' }}
@@ -462,354 +496,4 @@ onMounted(load)
</div>
</template>
<style scoped>
/* 像素复刻旧版 admin.html panel-shop-data-crawl-tasks(蓝白末层)。 */
.sd-view {
font-family: inherit;
color: #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 14px;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.sd-filter-title {
margin: 0 0 14px;
font-size: 13.5px;
font-weight: 600;
color: #40586e;
}
.form-row {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 14px 18px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 7px;
margin-bottom: 0;
}
.form-group label {
color: #5b6f83;
font-size: 12.5px;
font-weight: 600;
}
.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);
}
.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.55;
}
.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;
}
.sd-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
flex-wrap: wrap;
margin-bottom: 14px;
}
.sd-toolbar-main {
display: inline-flex;
align-items: center;
gap: 14px;
flex-wrap: wrap;
}
.sd-toolbar-side {
display: inline-flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
justify-content: flex-end;
}
.sd-select-all {
display: inline-flex;
align-items: center;
gap: 7px;
font-size: 13px;
color: #5b6f83;
cursor: pointer;
}
.sd-summary {
color: #5b6f83;
font-size: 13px;
white-space: nowrap;
}
.sd-shop-pager {
display: inline-flex;
align-items: center;
gap: 8px;
font-size: 13px;
color: #5b6f83;
}
.sd-shop-pager button,
.pagination button,
.jump-btn {
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;
}
.sd-shop-pager button:hover:not(:disabled),
.pagination button:hover:not(:disabled) {
background: #edf5fb;
border-color: #95b1cb;
color: #2f5d8b;
}
.sd-shop-pager button:disabled,
.pagination button:disabled {
background: #eef3f7;
color: #9baaba;
cursor: not-allowed;
}
.sd-shop-pager input,
.page-jump input {
width: 52px;
min-height: 30px;
padding: 4px 8px;
border: 1px solid #cbd9e6;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 13px;
font-family: inherit;
}
.shop-card-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 14px;
}
.sd-card {
border: 1px solid #d8e3ee;
border-radius: 12px;
background: #ffffff;
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
overflow: hidden;
}
.sd-card-head {
display: flex;
align-items: center;
gap: 10px;
padding: 12px 16px;
border-bottom: 1px solid #e6edf4;
}
.sd-shop-name {
font-weight: 600;
color: #24384d;
}
.sd-card-select-row {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 16px 0;
}
.shop-card-task-no {
flex: 1 1 auto;
min-width: 0;
font-weight: 600;
font-size: 12px;
color: #24384d;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.sd-card-row {
display: flex;
align-items: flex-start;
gap: 10px;
padding: 6px 16px;
font-size: 13px;
}
.sd-card-label {
flex: none;
width: 52px;
color: #8293a5;
}
.sd-card-value {
color: #40586e;
min-width: 0;
}
.sd-card-file {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.sd-card-actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
padding: 6px 16px 14px;
}
.st-pill {
display: inline-flex;
align-items: center;
padding: 2px 10px;
border-radius: 999px;
font-size: 12px;
line-height: 1.7;
border: 1px solid transparent;
white-space: nowrap;
flex: none;
}
.st-pill.is-success {
color: #3d7158;
background: #e8f2eb;
border-color: #bdd7c5;
}
.st-pill.is-failed {
color: #91474f;
background: #f8ebeb;
border-color: #e4c2c5;
}
.st-pill.is-cancelled {
color: #5b6f83;
background: #f1f6fa;
border-color: #d6e2ec;
}
.st-pill.is-pending,
.st-pill.is-running {
color: #8a6d3b;
background: #fbf4ea;
border-color: #e7d3ae;
}
.country-chip {
padding: 1px 8px;
margin-right: 4px;
border-radius: 999px;
background: #eef4fa;
color: #40586e;
font-size: 12px;
}
.dim {
color: #8293a5;
font-size: 12px;
}
.sd-progress-hint {
margin: 10px 0 0;
text-align: center;
color: #5b6f83;
font-size: 13px;
}
.empty-tip {
grid-column: 1 / -1;
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;
}
.page-total {
margin-right: 4px;
}
.page-jump {
display: inline-flex;
align-items: center;
gap: 6px;
}
@media (max-width: 1400px) {
.shop-card-grid {
grid-template-columns: repeat(3, 1fr);
}
}
@media (max-width: 1100px) {
.shop-card-grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 760px) {
.shop-card-grid {
grid-template-columns: 1fr;
}
}
</style>
<style scoped src="./ShopDataTasksPage.css"></style>