feat: 链接批量操作(删除/移动分类)
- 后端 batch-delete + batch-move 接口 - 前端多选checkbox + 批量操作栏 - 支持批量删除(确认弹窗) - 支持批量移动分类 - 选中后自动显示操作栏,取消选择收起
This commit is contained in:
@@ -23,7 +23,17 @@
|
||||
<el-skeleton :rows="5" animated />
|
||||
</div>
|
||||
<div v-else class="table-wrap">
|
||||
<el-table :data="links">
|
||||
<div v-if="selectedIds.length > 0" class="batch-bar">
|
||||
<span>已选 {{ selectedIds.length }} 条</span>
|
||||
<el-button size="small" type="danger" @click="batchDelete">批量删除</el-button>
|
||||
<el-select v-model="batchMoveCat" placeholder="移动至..." size="small" style="width:140px;margin-left:8px">
|
||||
<el-option v-for="c in categories" :key="c.id" :label="c.name" :value="c.id" />
|
||||
</el-select>
|
||||
<el-button size="small" @click="batchMove" :disabled="!batchMoveCat">移动</el-button>
|
||||
<el-button size="small" text @click="selectedIds = []">取消选择</el-button>
|
||||
</div>
|
||||
<el-table :data="links" @selection-change="(rows:any) => selectedIds = rows.map((r:any) => r.id)">
|
||||
<el-table-column type="selection" width="45" />
|
||||
<el-table-column label="图标" width="60" align="center">
|
||||
<template #default="scope">
|
||||
<span class="link-icon-preview">{{ scope.row.iconUrl ? '🖼' : scope.row.title[0] }}</span>
|
||||
@@ -110,6 +120,8 @@ const total = ref(0)
|
||||
const dialogVisible = ref(false)
|
||||
const editId = ref(null)
|
||||
const form = ref({ title: '', url: '', categoryId: '', description: '', iconUrl: '', sort: 0, isShow: true })
|
||||
const selectedIds = ref<number[]>([])
|
||||
const batchMoveCat = ref<number>()
|
||||
const dialogWidth = computed(() => window.innerWidth < 500 ? '92%' : '500px')
|
||||
|
||||
async function loadLinks() {
|
||||
@@ -127,6 +139,25 @@ async function loadCats() {
|
||||
categories.value = (await adminApi.getCategories()).result.data
|
||||
}
|
||||
|
||||
async function batchDelete() {
|
||||
if (!selectedIds.value.length) return
|
||||
await ElMessageBox.confirm(`确定删除选中的 ${selectedIds.value.length} 条链接?`)
|
||||
await adminApi.batchDelete(selectedIds.value)
|
||||
ElMessage.success(`已删除 ${selectedIds.value.length} 条`)
|
||||
selectedIds.value = []
|
||||
batchMoveCat.value = undefined
|
||||
await loadLinks()
|
||||
}
|
||||
|
||||
async function batchMove() {
|
||||
if (!selectedIds.value.length || !batchMoveCat.value) return
|
||||
await adminApi.batchMove(selectedIds.value, batchMoveCat.value)
|
||||
ElMessage.success(`已移动 ${selectedIds.value.length} 条链接`)
|
||||
selectedIds.value = []
|
||||
batchMoveCat.value = undefined
|
||||
await loadLinks()
|
||||
}
|
||||
|
||||
function openDialog(row?: any) {
|
||||
editId.value = row?.id || null
|
||||
form.value = row || { title: '', url: '', categoryId: '', description: '', iconUrl: '', sort: 0, isShow: true }
|
||||
@@ -161,6 +192,17 @@ onMounted(async () => { await loadLinks(); await loadCats() })
|
||||
.table-wrap { overflow-x: auto; }
|
||||
.loading-wrap { padding: 20px; }
|
||||
.pagination-wrap { display: flex; justify-content: center; margin-top: 20px; }
|
||||
.batch-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 16px;
|
||||
background: #f0f4ff;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
html.dark .batch-bar { background: #1e293b; }
|
||||
.link-icon-preview {
|
||||
display: inline-flex;
|
||||
width: 32px;
|
||||
|
||||
Reference in New Issue
Block a user