记录文章浏览量功能

This commit is contained in:
宇阳
2024-10-12 18:18:44 +08:00
parent 50b209dae2
commit 11e07ebabc
3 changed files with 11 additions and 3 deletions

View File

@@ -19,4 +19,9 @@ export const getRandomArticleListAPI = async () => {
// 获取推荐文章列表
export const getRecommendedArticleListAPI = async () => {
return await Request<Article[]>("GET", "/article/hot");
}
// 递增浏览量
export const recordViewAPI = async (id: number) => {
return await Request<void>("GET", `/article/view/${id}`);
}

View File

@@ -1,4 +1,4 @@
import { getArticleDataAPI } from '@/api/article'
import { getArticleDataAPI, recordViewAPI } from '@/api/article'
import Starry from "@/components/Starry"
import Swiper from "@/components/Swiper"
@@ -25,6 +25,9 @@ export default async ({ params }: Props) => {
const id = params.id
const { data } = await getArticleDataAPI(id)
// 记录文章访问量
await recordViewAPI(id)
// 图标样式
const iconSty = "flex justify-center items-center w-5 h-5 rounded-full text-xs mr-1"

View File

@@ -1,5 +1,5 @@
// const url = "http://localhost:9999/api"
const url = "http://api.liuyuyang.net/api"
const url = "http://localhost:9003/api"
// const url = "http://api.liuyuyang.net/api"
export default async <T>(method: string, api: string, data?: any, caching = true) => {
const res = await fetch(`${url}${api}`, {