Bläddra i källkod

feat(公告管理): 添加公告删除功能

yz 2 veckor sedan
förälder
incheckning
0f0cc6b3d6
2 ändrade filer med 50 tillägg och 1 borttagningar
  1. 6 0
      src/views/announcement/index.vue
  2. 44 1
      src/views/announcement/mixins/announcementIndex.js

+ 6 - 0
src/views/announcement/index.vue

@@ -36,6 +36,12 @@
                     icon="el-icon-view"
                     @click="handleDetail(row)"
                 >预览</el-button>
+                <el-button
+                    type="text"
+                    size="small"
+                    icon="el-icon-delete"
+                    @click="handleRowDelete(row)"
+                >删除</el-button>
             </template>
 
             <!-- 客户黑名单字段自定义插槽 -->

+ 44 - 1
src/views/announcement/mixins/announcementIndex.js

@@ -8,7 +8,7 @@
  * @typedef {import("@/api/announcement").NoticeRecord} NoticeRecord
  */
 
-import { getList, update, add, getAnnouncement, getCategoryList } from "@/api/announcement";
+import { getList, update, add, getAnnouncement, getCategoryList, deleteNotice } from "@/api/announcement";
 import { getCustomerList } from "@/api/common/index";
 import { mapGetters } from "vuex";
 import {
@@ -499,6 +499,49 @@ export default {
             }
         },
 
+        // 新增:单行删除(操作列按钮)
+        /**
+         * 行删除(操作列按钮)
+         * @this {import('@/views/announcement/types').AnnouncementComponent & import('vue').default}
+         * @param {Partial<NoticeItem>} row - 当前行数据
+         * @returns {Promise<void>}
+         */
+        async handleRowDelete(row) {
+            const id = row && row.id;
+            if (!id) {
+                this.$message.warning("缺少公告ID,无法删除");
+                return;
+            }
+            try {
+                await this.$confirm("确定将选择数据删除?", {
+                    confirmButtonText: "确定",
+                    cancelButtonText: "取消",
+                    type: "warning"
+                });
+
+                await deleteNotice(id);
+
+                this.$message({
+                    type: "success",
+                    message: "操作成功!"
+                });
+                // 刷新列表
+                this.onLoad(this.page, this.query);
+            } catch (error) {
+                if (error !== 'cancel') {
+                    console.error('删除公告失败:', error);
+                    this.$message({
+                        type: "error",
+                        message: "删除失败,请稍后重试"
+                    });
+                } else {
+                    this.$message({
+                        type: "info",
+                        message: "已取消删除"
+                    });
+                }
+            }
+        },
         /**
          * 保存行数据
          * @async