1、教学楼添加批量删除功能;

2、教学楼导入代号从excel获取,不要自己生成
This commit is contained in:
2026-09-16 09:07:47 +08:00
parent d9b10a3f05
commit b30e39f91a
7 changed files with 336 additions and 35 deletions
+15 -1
View File
@@ -17,7 +17,7 @@ export function addBuild(data) {
}
/**
* 删除教学楼(后端仅提供单条删除,参数为 id)
* 删除教学楼(参数为 id,已绑定教学场地时后端会拒绝)
* POST /build/delete
*/
export function deleteBuild(id) {
@@ -28,6 +28,20 @@ export function deleteBuild(id) {
})
}
/**
* 批量删除教学楼
* POST /build/batchDelete
* 已绑定教学场地的教学楼会跳过不删,返回 { deleteCount, skipCount, skipList, message }
* @param ids 教学楼ID数组
*/
export function batchDeleteBuild(ids) {
return request({
url: '/build/batchDelete',
method: 'post',
data: ids
})
}
/**
* 更新教学楼
* POST /build/update
@@ -95,7 +95,7 @@
<el-button icon="el-icon-download" :loading="importDialog.downloading" @click="handleDownloadTemplate">
下载导入模板
</el-button>
<span class="tip-text">模板 sheet 为「教学楼表」,只需填写教学楼名称/地点/备注</span>
<span class="tip-text">模板 sheet 为「教学楼表」,教学楼标识号留空则自动生成,代号已存在的行将跳过</span>
</el-form-item>
<el-form-item label="数据文件">
<div class="file-input">
@@ -110,7 +110,12 @@
</el-form-item>
<el-form-item label="导入结果" v-if="importDialog.result">
<div class="import-result">
共导入 <span class="num">{{ importDialog.result }}</span> 条教学楼数据。
共导入 <span class="num">{{ importDialog.result.insertCount }}</span> 条教学楼数据<template
v-if="importDialog.result.skipCount > 0">,跳过 <span
class="num warn">{{ importDialog.result.skipCount }}</span> 条(教学楼代号已存在)</template>。
<div v-if="importDialog.result.skipList && importDialog.result.skipList.length" class="skip-detail">
<div v-for="(item, idx) in importDialog.result.skipList" :key="idx">{{ item }}</div>
</div>
</div>
</el-form-item>
</el-form>
@@ -127,7 +132,7 @@
import { saveAs } from 'file-saver'
import {
addBuild,
deleteBuild,
batchDeleteBuild,
updateBuild,
listBuild,
importBuild,
@@ -318,7 +323,7 @@ export default {
})
},
/* ---------- 删除(后端仅提供单条删除,多选时逐条调用) ---------- */
/* ---------- 删除(批量删除,已绑定教学场地的由后端跳过) ---------- */
handleBatchDelete() {
const rows = this.selectedRows || []
if (rows.length === 0) {
@@ -326,7 +331,7 @@ export default {
return
}
const names = rows.map(row => row.jxlmc || row.jxldh).join('、')
this.$confirm('确定删除选中的 ' + rows.length + ' 条教学楼数据吗?' + '(' + names + ')', '提示', {
this.$confirm('确定删除选中的 ' + rows.length + ' 条教学楼数据吗?' + '(' + names + ')已绑定教学场地的教学楼不会被删除。', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
@@ -335,13 +340,23 @@ export default {
doBatchDelete(rows) {
this.loading = true
const tasks = rows.map(row => deleteBuild(row.id))
Promise.all(tasks).then(() => {
this.$message.success('已删除 ' + rows.length + ' 条教学楼数据')
batchDeleteBuild(rows.map(row => row.id)).then(response => {
const data = (response && response.data) || {}
const deleteCount = data.deleteCount || 0
const skipList = data.skipList || []
this.loading = false
if (skipList.length > 0) {
const detailHtml = skipList.map(item => '<div>' + item + '</div>').join('')
this.$alert(
'已删除 ' + deleteCount + ' 条,' + skipList.length + ' 条因已绑定教学场地未删除。<br/>' + detailHtml,
'删除结果',
{ dangerouslyUseHTMLString: true, confirmButtonText: '确定' }
)
} else {
this.$message.success('已删除 ' + deleteCount + ' 条教学楼数据')
}
this.fetchList()
}).catch(() => {
this.$message.error('部分数据删除失败,请刷新后重试')
this.loading = false
this.fetchList()
})
@@ -406,11 +421,16 @@ export default {
}
this.importDialog.importing = true
importBuild(this.importDialog.file).then(response => {
const count = (response && response.data) || 0
const data = (response && response.data) || {}
this.clearImportFile()
this.importDialog.importing = false
this.importDialog.result = count
this.$message.success('导入成功,共导入 ' + count + ' 条')
this.importDialog.result = {
insertCount: data.insertCount || 0,
skipCount: data.skipCount || 0,
skipList: data.skipList || []
}
const skipTip = data.skipCount > 0 ? ',跳过 ' + data.skipCount + ' 条已存在代号' : ''
this.$message.success('导入成功,共导入 ' + (data.insertCount || 0) + ' 条' + skipTip)
this.fetchList()
}).catch(() => {
this.importDialog.importing = false
@@ -492,6 +512,18 @@ export default {
font-weight: 600;
color: #67c23a;
padding: 0 4px;
&.warn {
color: #e6a23c;
}
}
.skip-detail {
margin-top: 8px;
font-size: 13px;
color: #909399;
max-height: 120px;
overflow-y: auto;
}
}
}