From 30d46a37fcd383cf69b2f1faa1b2ebe270bfc095 Mon Sep 17 00:00:00 2001 From: linjinyuan <2841541624@qq.com> Date: Thu, 8 Sep 2022 18:20:32 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=B0=8F=E7=A8=8B=E5=BA=8F=E3=80=91--?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=E6=88=91=E7=9A=84=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/api/news.ts | 35 ++++++++ app/src/components/news-card/news-card.vue | 8 +- app/src/pages.json | 6 ++ app/src/pages/collection/collection.vue | 50 +++++++++++ app/src/pages/news/component/news-list.vue | 2 +- app/src/pages/news_detail/news_detail.vue | 99 ++++++++++++++++++++-- 6 files changed, 190 insertions(+), 10 deletions(-) create mode 100644 app/src/pages/collection/collection.vue diff --git a/app/src/api/news.ts b/app/src/api/news.ts index e9be6baf..c26c5a86 100644 --- a/app/src/api/news.ts +++ b/app/src/api/news.ts @@ -15,3 +15,38 @@ export function getArticleCate() { export function getArticleList(data: Record) { return request.get({ url: '/article/list', data: data }) } + +/** + * @description 获取文章详情 + * @param { number } id + * @return { Promise } + */ +export function getArticleDetail(data: { id: number }) { + return request.get({ url: '/article/detail', data: data }) +} + +/** + * @description 加入收藏 + * @param { number } articleId + * @return { Promise } + */ +export function addCollect(data: { articleId: number }) { + return request.post({ url: '/article/addCollect', data: data }) +} + +/** + * @description 取消收藏 + * @param { number } id + * @return { Promise } + */ +export function cancelCollect(data: { articleId: number }) { + return request.post({ url: '/article/cancelCollect', data: data }) +} + +/** + * @description 获取收藏列表 + * @return { Promise } + */ +export function getCollect() { + return request.get({ url: '/article/collect' }) +} diff --git a/app/src/components/news-card/news-card.vue b/app/src/components/news-card/news-card.vue index 57189362..66347442 100644 --- a/app/src/components/news-card/news-card.vue +++ b/app/src/components/news-card/news-card.vue @@ -1,5 +1,5 @@ diff --git a/app/src/pages/news_detail/news_detail.vue b/app/src/pages/news_detail/news_detail.vue index 02409e35..417415ab 100644 --- a/app/src/pages/news_detail/news_detail.vue +++ b/app/src/pages/news_detail/news_detail.vue @@ -1,8 +1,95 @@ + + + + {{ newsData.title }} + + 作者: {{ newsData.author }} + {{ newsData.createTime }} + + + {{ newsData.visit }} + + + + + + + + + 摘要: {{ newsData.summary }} + + + + + + + + + + + + + + 收藏 + + + + + - - \ No newline at end of file + + const newsData = ref< any >({}) + let newsId = '' + + + const getData = async (id) => { + newsData.value = await getArticleDetail({ id }) + } + + const handleAddCollect = async (articleId: number) => { + try{ + if( newsData.value.collect ) { + await cancelCollect({ articleId }) + } else await addCollect({ articleId }) + getData(newsId) + }catch(e){ + //TODO handle the exception + } + } + + onLoad((options: any) => { + newsId = options.id + getData(newsId) + }) + + +