feat: 地图列表批量删除 — checkbox多选+POST batch-delete API
This commit is contained in:
@@ -43,6 +43,7 @@ export const mapApi = {
|
||||
create: (data: any) => api.post('/maps', data),
|
||||
update: (id: number, data: any) => api.put(`/maps/${id}`, data),
|
||||
delete: (id: number) => api.delete(`/maps/${id}`),
|
||||
batchDelete: (ids: number[]) => api.post('/maps/batch-delete', { ids }),
|
||||
createWithTemplate: (data: any) => api.post('/maps/create-with-template', data),
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,13 @@
|
||||
<div>
|
||||
<div style="display:flex;justify-content:space-between;margin-bottom:16px;">
|
||||
<h3>战略地图</h3>
|
||||
<el-button type="primary" @click="showForm=true;form={}">新建地图</el-button>
|
||||
<div>
|
||||
<el-button type="danger" size="small" :disabled="selectedIds.length === 0" @click="batchDelete">批量删除({{ selectedIds.length }})</el-button>
|
||||
<el-button type="primary" @click="showForm=true;form={}">新建地图</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-table :data="maps" style="width:100%">
|
||||
<el-table :data="maps" style="width:100%" @selection-change="onSelectionChange">
|
||||
<el-table-column type="selection" width="40" />
|
||||
<el-table-column prop="title" label="地图名称" min-width="200" />
|
||||
<el-table-column prop="version" label="版本" width="80" />
|
||||
<el-table-column prop="status" label="状态" width="80">
|
||||
@@ -66,6 +70,24 @@ const showForm = ref(false)
|
||||
const editingMap = ref<any>(null)
|
||||
const form = ref<any>({})
|
||||
const createMode = ref("blank")
|
||||
const selectedIds = ref<number[]>([])
|
||||
|
||||
function onSelectionChange(rows: any[]) {
|
||||
selectedIds.value = rows.map(r => r.id)
|
||||
}
|
||||
|
||||
async function batchDelete() {
|
||||
if (selectedIds.value.length === 0) return
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定删除选中的 ${selectedIds.value.length} 个地图?`, "批量删除")
|
||||
await mapApi.batchDelete(selectedIds.value)
|
||||
ElMessage.success(`已删除 ${selectedIds.value.length} 个地图`)
|
||||
selectedIds.value = []
|
||||
load()
|
||||
} catch (e: any) {
|
||||
if (e !== "cancel") ElMessage.error("批量删除失败")
|
||||
}
|
||||
}
|
||||
|
||||
async function load() {
|
||||
try { const r: any = await mapApi.list(); maps.value = r.data || [] } catch (e) {}
|
||||
|
||||
Reference in New Issue
Block a user