Przeglądaj źródła

增加删除功能

罗永浩 5 miesięcy temu
rodzic
commit
f3c2cadfe5

+ 53 - 19
addons/admin/src/views/system/article/components/list.vue

@@ -39,10 +39,15 @@
                 创建
               </el-button>
               <!-- 导入按钮,仅在 defaultType 为 9 时可见 -->
-              <el-button v-if="defaultType == 9 && permission.includes(permissionMap['add'])" type="success"
+              <el-button v-if="isSmartReplyType && permission.includes(permissionMap['add'])" type="success"
                 icon="el-icon-upload2" size="small" @click="openImportDialog">
                 导入
               </el-button>
+              <!-- 批量删除按钮,仅在智能问答类型时可见 -->
+              <el-button v-if="isSmartReplyType && permission.includes(permissionMap['delete'])" type="danger"
+                icon="el-icon-delete" size="small" @click="batchRemove">
+                批量删除
+              </el-button>
             </div>
           </el-col>
         </el-row>
@@ -68,10 +73,15 @@
               <el-switch v-model="row.status" @change="handleStatusChange(row)" :active-value="1" :inactive-value="2" />
             </template>
           </el-table-column>
-          <el-table-column label="操作" width="130px" align="center" :resizable="false" fixed="right">
+          <el-table-column label="操作" width="180px" align="center" :resizable="false" fixed="right">
             <template slot-scope="{row}">
               <el-link @click="edit(row)" icon="el-icon-edit" type="primary" :underline="false"
                 v-if="permission.includes(permissionMap['edit'])">修改</el-link>
+              <el-popconfirm v-if="isSmartReplyType && permission.includes(permissionMap['delete'])"
+                title="确定要删除此智能问答吗?" confirm-button-text="确定删除" cancel-button-text="取消" @confirm="remove(row)"
+                class="ele-action">
+                <el-link slot="reference" icon="el-icon-delete" type="danger" :underline="false">删除</el-link>
+              </el-popconfirm>
             </template>
           </el-table-column>
         </template>
@@ -178,6 +188,19 @@ export default {
   },
   computed: {
     ...mapGetters(["permission"]),
+    // 判断是否为智能问答类型
+    isSmartReplyType() {
+      if (!this.defaultType) return false;
+
+      // 处理 defaultType 可能是 Number、String 或 Array 的情况
+      if (Array.isArray(this.defaultType)) {
+        // 如果是数组,检查是否包含9
+        return this.defaultType.includes(9) || this.defaultType.includes('9');
+      } else {
+        // 单个值,判断是否等于9
+        return Number(this.defaultType) === 9 && this.permission.includes(this.permissionMap['delete']);
+      }
+    },
     editContent() {
       return {
         menubar: false,
@@ -242,23 +265,7 @@ export default {
     /* 删除 */
     remove(row) {
       if (!row) {  // 批量删除
-        if (this.choose.length === 0) return this.$message.error('请至少选择一条数据');
-        let ids = this.choose.map(d => d.id);
-        this.$confirm('确定要删除选中的记录吗?', '提示', { type: 'warning' }).then(() => {
-          const loading = this.$loading({ lock: true });
-          this.$http.post('/article/delete', { id: ids }).then(res => {
-            loading.close();
-            if (res.data.code === 0) {
-              this.$message({ type: 'success', message: res.data.msg });
-              this.$refs.table.reload();
-            } else {
-              this.$message.error(res.data.msg);
-            }
-          }).catch(e => {
-            loading.close();
-            this.$message.error(e.message);
-          });
-        }).catch(() => 0);
+        this.batchRemove();
       } else {  // 单个删除
         const loading = this.$loading({ lock: true });
         this.$http.post('/article/delete', { id: row.id }).then(res => {
@@ -275,6 +282,33 @@ export default {
         });
       }
     },
+    /* 批量删除 */
+    batchRemove() {
+      if (this.choose.length === 0) return this.$message.error('请至少选择一条数据');
+      let ids = this.choose.map(d => d.id);
+      const deleteText = this.isSmartReplyType ? '智能问答' : '记录';
+      this.$confirm(`确定要删除选中的${ids.length}条${deleteText}吗?`, '提示', {
+        type: 'warning',
+        confirmButtonText: "确定删除",
+        cancelButtonText: "取消"
+      }).then(() => {
+        const loading = this.$loading({ lock: true });
+        this.$http.post('/article/delete', { id: ids }).then(res => {
+          loading.close();
+          if (res.data.code === 0) {
+            this.$message({ type: 'success', message: res.data.msg });
+            this.$refs.table.reload();
+          } else {
+            this.$message.error(res.data.msg);
+          }
+        }).catch(e => {
+          loading.close();
+          this.$message.error(e.message);
+        });
+      }).catch(() => {
+        // 用户取消删除
+      });
+    },
     /* 处理状态切换 */
     handleStatusChange(row) {
       this.editStatus(row);