浏览代码

feat: 添加多选和批量删除功能,优化培训记录管理

xieyong 1 周之前
父节点
当前提交
5d2a15c470
共有 1 个文件被更改,包括 44 次插入 和 0 次删除
  1. 44 0
      src/views/safetyTraining/offlineTrainingRecords/index.vue

+ 44 - 0
src/views/safetyTraining/offlineTrainingRecords/index.vue

@@ -21,6 +21,7 @@
             :cache-key="cacheKeyUrl"
             height="calc(100vh - 350px)"
             @columns-change="handleColumnChange"
+            @selection-change="handleSelectionChange"
           >
             <template v-slot:toolbar>
               <div class="toolbar-left">
@@ -32,6 +33,15 @@
                   @click="handleAdd"
                   >添加记录</el-button
                 >
+                <el-button
+                  type="danger"
+                  size="small"
+                  icon="el-icon-delete"
+                  :disabled="!selectedRows.length"
+                  v-if="$hasPermission('ehs:offlineTraining:delete')"
+                  @click="handleBatchDelete"
+                  >批量删除</el-button
+                >
               </div>
             </template>
             <template v-slot:action="{ row }">
@@ -92,8 +102,17 @@
     mixins: [tabMixins],
     data() {
       return {
+        selectedRows: [],
         // 表格列配置
         columns: [
+          {
+            columnKey: 'selection',
+            type: 'selection',
+            width: 50,
+            align: 'center',
+            reserveSelection: true,
+            fixed: 'left'
+          },
           {
             columnKey: 'index',
             label: '序号',
@@ -243,6 +262,31 @@
           })
           .catch(() => {});
       },
+      // 多选
+      handleSelectionChange(rows) {
+        this.selectedRows = rows || [];
+      },
+      // 批量删除
+      handleBatchDelete() {
+        const ids = this.selectedRows.map((row) => row.id);
+        if (!ids.length) {
+          this.$message.warning('请至少选择一条数据');
+          return;
+        }
+        this.$confirm(`确认删除选中的 ${ids.length} 条培训记录吗?`, '提示', {
+          confirmButtonText: '确定',
+          cancelButtonText: '取消',
+          type: 'warning'
+        })
+          .then(() => remove(ids))
+          .then((message) => {
+            this.$message.success(message || '删除成功');
+            this.selectedRows = [];
+            this.$refs.table.clearSelection();
+            this.$refs.table.reload({ page: 1 });
+          })
+          .catch(() => {});
+      },
       // 搜索
       handleSearch(where) {
         this.$refs.table.reload({ page: 1, where });