From 278b4e0afad8e00d1fa27b0b620d967634f6da33 Mon Sep 17 00:00:00 2001 From: Shu Guang <61069967+shuguangnet@users.noreply.github.com> Date: Sat, 17 May 2025 22:13:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E6=88=91=E7=9A=84?= =?UTF-8?q?=E5=B8=96=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/index.js | 19 +++-------- src/views/account/center/index.vue | 53 ++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/api/index.js b/src/api/index.js index 79d6ea3b..bbbe319b 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -221,21 +221,10 @@ export function ArticleById(data) { }); } // 通过id删除文章√ -export function DeteleArticleById(data) { - const formData = new FormData(); - - // 将data对象的属性添加到FormData对象中 - for (let key in data) { - formData.append(key, data[key]); - } - - return request({ - url: '/article/deleteArticleById', - method: 'post', - data: formData, - - }); -} +export const DeteleArticleById = id => request({ + url: `/article/deleteArticleById?id=${id}`, // 将id作为查询参数放入URL + method: 'post' +}); // 更新文章√ export function UpArtile(data) { const formData = new FormData(); diff --git a/src/views/account/center/index.vue b/src/views/account/center/index.vue index 28ceffe9..48ff99bb 100644 --- a/src/views/account/center/index.vue +++ b/src/views/account/center/index.vue @@ -135,13 +135,14 @@ class="article-item" v-for="(article, index) in articles" :key="index" - @click="viewArticle(article)" > -
+
-
{{ article.articleTitle }}
+
+ {{ article.articleTitle }} +
{{ formatDate(article.publishTime) }}
-
+ 修改 + 删除
@@ -205,6 +198,8 @@ import PageView from "../../../layouts/PageView.vue"; import RouteView from "../../../layouts/RouteView.vue"; import { AppPage, ArticlePage, ProjectPage } from "./page"; import { mapGetters } from "vuex"; +import { DeteleArticleById } from "@/api/index"; +import { Modal } from "ant-design-vue"; export default { components: { @@ -268,6 +263,30 @@ export default { this.fetchStats(); }, methods: { + editArticle(id) { + this.$router.push(`/article/edit/${id}`); + }, + deleteItemArticle(article) { + // 参数重命名为article + Modal.confirm({ + title: "提示", + content: "确定要删除这篇文章吗?", + onOk: () => { + // 直接传递articleId作为参数 + DeteleArticleById(article.articleId) + .then((res) => { + this.$message.success("删除成功"); + this.fetchArticles(); + }) + .catch((err) => { + console.error("删除失败详情:", err); + this.$message.error( + `删除失败: ${err.response?.data?.message || "服务器异常"}` + ); + }); + }, + }); + }, // 获取比赛信息 // 修改 fetchCompetitions 方法 fetchCompetitions() {