瀏覽代碼

学生和课程管理删除功能调整

zhangjie 1 年之前
父節點
當前提交
566d0e476c
共有 2 個文件被更改,包括 65 次插入36 次删除
  1. 32 18
      src/modules/base/views/CourseManage.vue
  2. 33 18
      src/modules/base/views/StudentManage.vue

+ 32 - 18
src/modules/base/views/CourseManage.vue

@@ -51,7 +51,6 @@
           <el-button
             v-if="checkPrivilege('button', 'Delete')"
             type="danger"
-            :disabled="!filterHasQuery"
             @click="toBatchDelete"
             >批量删除</el-button
           >
@@ -83,7 +82,16 @@
       </div>
     </div>
     <div class="part-box part-box-pad">
-      <el-table ref="TableList" :data="courses">
+      <el-table
+        ref="TableList"
+        :data="courses"
+        @selection-change="handleSelectionChange"
+      >
+        <el-table-column
+          type="selection"
+          width="55"
+          align="center"
+        ></el-table-column>
         <el-table-column
           type="index"
           label="序号"
@@ -180,12 +188,7 @@
 </template>
 
 <script>
-import {
-  courseListPage,
-  deleteCourse,
-  batchDeleteCourse,
-  exportCourse,
-} from "../api";
+import { courseListPage, deleteCourse, exportCourse } from "../api";
 import pickerOptions from "@/constants/datePickerOptions";
 import ModifyCourse from "../components/ModifyCourse";
 import ImportFile from "../../../components/ImportFile.vue";
@@ -212,6 +215,7 @@ export default {
       size: this.GLOBAL.pageSize,
       total: 0,
       courses: [],
+      multipleSelection: [],
       curCourse: {},
       loading: false,
       // import
@@ -263,6 +267,9 @@ export default {
       this.current = page;
       this.getList();
     },
+    handleSelectionChange(val) {
+      this.multipleSelection = val.map((item) => item.id);
+    },
     toAdd() {
       this.curCourse = {};
       this.$refs.ModifyCourse.open();
@@ -282,16 +289,23 @@ export default {
         })
         .catch(() => {});
     },
-    toBatchDelete() {
-      this.$confirm(`确定要删除当前查询的所有课程吗?`, "提示", {
-        type: "warning",
-      })
-        .then(async () => {
-          await batchDeleteCourse({ ...this.filter });
-          this.$message.success("操作成功!");
-          this.toPage(1);
-        })
-        .catch(() => {});
+    async toBatchDelete() {
+      if (!this.multipleSelection.length) {
+        this.$message.error("请选择要删除的课程");
+        return;
+      }
+      const confirm = await this.$confirm(
+        `确定要删除当前选择的所有课程吗?`,
+        "提示",
+        {
+          type: "warning",
+        }
+      ).catch(() => {});
+      if (confirm !== "confirm") return;
+
+      await deleteCourse(this.multipleSelection);
+      this.$message.success("操作成功!");
+      this.deletePageLastItem();
     },
     async toExportCourse() {
       if (this.loading) return;

+ 33 - 18
src/modules/base/views/StudentManage.vue

@@ -47,7 +47,6 @@
             v-if="checkPrivilege('button', 'delete')"
             type="danger"
             icon="el-icon-delete"
-            :disabled="!filterHasQuery"
             @click="toBatchDelete"
             >批量删除</el-button
           >
@@ -86,7 +85,16 @@
       </div>
     </div>
     <div class="part-box part-box-pad">
-      <el-table ref="TableList" :data="dataList">
+      <el-table
+        ref="TableList"
+        :data="dataList"
+        @selection-change="handleSelectionChange"
+      >
+        <el-table-column
+          type="selection"
+          width="55"
+          align="center"
+        ></el-table-column>
         <el-table-column
           type="index"
           label="序号"
@@ -174,12 +182,7 @@
 </template>
 
 <script>
-import {
-  studentListQuery,
-  deleteStudent,
-  deleteFilterStudent,
-  exportStudent,
-} from "../api";
+import { studentListQuery, deleteStudent, exportStudent } from "../api";
 import ModifyStudent from "../components/ModifyStudent";
 import ImportFile from "../../../components/ImportFile.vue";
 import { downloadByApi } from "@/plugins/download";
@@ -202,6 +205,7 @@ export default {
       size: this.GLOBAL.pageSize,
       total: 0,
       dataList: [],
+      multipleSelection: [],
       curRow: {},
       loading: false,
       // import
@@ -237,6 +241,9 @@ export default {
       this.current = page;
       this.getList();
     },
+    handleSelectionChange(val) {
+      this.multipleSelection = val.map((item) => item.id);
+    },
     toAdd() {
       this.curRow = {};
       this.$refs.ModifyStudent.open();
@@ -245,16 +252,24 @@ export default {
       this.curRow = row;
       this.$refs.ModifyStudent.open();
     },
-    toBatchDelete() {
-      this.$confirm(`确定要根据设置的筛选条件删除所有数据吗?`, "提示", {
-        type: "warning",
-      })
-        .then(async () => {
-          await deleteFilterStudent(this.filter);
-          this.$message.success("删除成功!");
-          this.toPage(1);
-        })
-        .catch(() => {});
+    async toBatchDelete() {
+      if (!this.multipleSelection.length) {
+        this.$message.error("请选择要删除的学生");
+        return;
+      }
+      const confirm = await this.$confirm(
+        `确定要删除当前选择的所有学生吗?`,
+        "提示",
+        {
+          type: "warning",
+        }
+      ).catch(() => {});
+
+      if (confirm !== "confirm") return;
+
+      await deleteStudent(this.multipleSelection);
+      this.$message.success("删除成功!");
+      this.deletePageLastItem();
     },
     toDelete(row) {
       this.$confirm(`确定要删除学生【${row.studentName}】吗?`, "提示", {