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 } from '@/utils/datetime'
/** 分组管理页 · 像素复刻旧版 admin.html panel-group-manage(自绘:顶部数据权限分组摘要 chips + 分组列表表格 + 新建分组;全量无分页同旧版)。
* script 逻辑沿用现有 Vue 实现;编辑器保留现有组件。 */
@@ -51,16 +55,22 @@ function canEditOf(group: ShopGroupItem): boolean {
return currentUserId.value != null && group.leaderUserId != null && currentUserId.value === group.leaderUserId
}
const batchListGate = createLatestRequestGate()
async function loadGroups() {
const token = batchListGate.begin()
loading.value = true
loadFailure.value = ''
try {
rows.value = await fetchShopGroups(companyTab.requestCompanyId, platformTab.active)
const items = await fetchShopGroups(companyTab.requestCompanyId, platformTab.active)
if (!batchListGate.isCurrent(token)) return
rows.value = items
} 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
}
}
@@ -84,11 +94,24 @@ function openEdit(group: ShopGroupItem) {
editorVisible.value = true
}
const batch = useRowSelection({
pageRows: () => pagedGroups.value,
rowId: (row) => row.id,
rowLabel: (row) => row.name,
deleteOne: (id) => deleteShopGroup(id),
refresh: loadGroups,
blocked: () => loading.value || !!loadFailure.value,
scope: () => [companyTab.activeId, platformTab.active, currentUserId.value],
precheck: (row) => canEditOf(row) ? undefined : '无权删除此分组',
})
async function removeGroup(group: ShopGroupItem) {
if (batch.busy) return
const ok = await openAdminConfirm({ message: `确定删除分组“${group.name}”吗?`, danger: true })
if (!ok) return
try {
await deleteShopGroup(group.id)
batch.removeFromSelection(group.id)
ElMessage.success('删除成功')
await loadGroups()
} catch (error) {
@@ -119,10 +142,15 @@ onMounted(loadGroups)
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="loadGroups" />
<BatchDeleteActions :batch="batch" />
<div class="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 style="width: 58px">序号</th>
<th style="width: 16%">分组名称</th>
<th style="width: 12%">组长</th>
@@ -135,7 +163,11 @@ onMounted(loadGroups)
</thead>
<tbody>
<template v-if="filteredRows.length">
<tr v-for="(group, index) in pagedGroups" :key="group.id">
<tr v-for="(group, index) in pagedGroups" :key="group.id" :class="{ 'batch-selected': batch.isSelected(group) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(group) || `选择 ${batch.label(group)}`" :checked="batch.isSelected(group)"
:disabled="batch.disabled || !!batch.reason(group)" @change="batch.toggle(group)" />
</td>
<td>{{ index + 1 }}</td>
<td>{{ group.name }}</td>
<td>{{ group.leaderUsername || '-' }}</td>
@@ -151,17 +183,17 @@ onMounted(loadGroups)
<td class="ops-cell">
<template v-if="canEditOf(group)">
<button class="btn btn-sm" type="button" @click="openEdit(group)">编辑</button>
<button class="btn btn-sm btn-danger" type="button" @click="removeGroup(group)">删除</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="removeGroup(group)">删除</button>
</template>
<span v-else class="member-none">-</span>
</td>
</tr>
</template>
<tr v-else-if="loading">
<td colspan="8" class="empty-tip">加载中...</td>
<td colspan="9" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="8" class="empty-tip">{{ filterKeyword || filterLeader ? '暂无匹配分组' : '暂无分组' }}</td>
<td colspan="9" class="empty-tip">{{ filterKeyword || filterLeader ? '暂无匹配分组' : '暂无分组' }}</td>
</tr>
</tbody>
</table>