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) + }) + + +