From dc628e34942702cce9df3809338386930c3d0c2d Mon Sep 17 00:00:00 2001 From: wangqiao Date: Wed, 27 Aug 2025 16:24:22 +0800 Subject: [PATCH] Update API request formatting and error handling --- api/home/index.ts | 10 +++++----- pages/home/components/PopularDrawings.vue | 24 ++++++++++++++--------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/api/home/index.ts b/api/home/index.ts index d6d26f9..da854a4 100644 --- a/api/home/index.ts +++ b/api/home/index.ts @@ -15,7 +15,7 @@ import type { * @returns */ export const hotTop = (params: ThotTopReq) => { - return useFetchRequest.get>('/prod-api/app-api/business/app/project-draw/hot-top', { query:params }) + return useDollarFetchRequest.get>('/prod-api/app-api/business/app/project-draw/hot-top', { query: params }) } /** @@ -24,21 +24,21 @@ export const hotTop = (params: ThotTopReq) => { * @returns */ export const recommendTop = (params: ThotTopReq) => { - return useFetchRequest.get>('/prod-api/app-api/business/app/project-draw/recommend-top', { query:params }) + return useFetchRequest.get>('/prod-api/app-api/business/app/project-draw/recommend-top', { query: params }) } /** * 获取最新图纸信息 */ export const newDraw = (params: { type: number; limit: number }) => { - return useFetchRequest.get>('/prod-api/app-api/business/project/index/draw-new', { query:params }) + return useFetchRequest.get>('/prod-api/app-api/business/project/index/draw-new', { query: params }) } /** * 首页-热点标签 */ export const hotTag = (params: { type: number; limit: number; size: number }) => { - return useFetchRequest.get>('/prod-api/app-api/business/project/index/index-hot-tab', { query:params }) + return useFetchRequest.get>('/prod-api/app-api/business/project/index/index-hot-tab', { query: params }) } /** @@ -59,7 +59,7 @@ export const top = (params: { type: number; limit: number }) => { * 获取用户top数据 */ export const userTop = (params: { type?: number }) => { - return useFetchRequest.get>('/prod-api/app-api/business/project/index/user-top', { query:params }) + return useFetchRequest.get>('/prod-api/app-api/business/project/index/user-top', { query: params }) } /** diff --git a/pages/home/components/PopularDrawings.vue b/pages/home/components/PopularDrawings.vue index 79b1436..5d54bb3 100644 --- a/pages/home/components/PopularDrawings.vue +++ b/pages/home/components/PopularDrawings.vue @@ -146,7 +146,7 @@ // }) // } - const { data: projectTypeList, refresh: getParent } = useAsyncData('projectTypeListChildren-PopularDrawings-popularDrawings', async () => { + const { data: projectTypeList, refresh: getParent } = await useAsyncData('projectTypeListChildren-PopularDrawings-popularDrawings', async () => { const res = await hotTag({ type: query.type, limit: 6, @@ -154,7 +154,7 @@ }) const all = [{ id: '0', name: '全部分类', children: [] }] if (Array.isArray(res.data) && res.data?.length > 0) { - const total = [...res.data,...all] + const total = [...res.data, ...all] // query.projectTypeDay = total[0]?.id || '' // query.projectType = total[0]!.children?.[0]?.id || '' return total @@ -162,13 +162,21 @@ return [] }) - const {data: hotTopList, refresh: getHotTop} = useAsyncData('hotTop-PopularDrawings-popularDrawings', async () => { + if (!projectTypeList.value?.length) { + throw createError({ + statusCode: 404, + statusMessage: 'Page Not Found', + fatal: true, + }) + } + + const { data: hotTopList, refresh: getHotTop } = useAsyncData('hotTop-PopularDrawings-popularDrawings', async () => { const res = await hotTop({ type: query.type, // @ts-ignore - projectType: query.projectTypeDay, + projectType: query.projectTypeDay || projectTypeList.value[0].id, isDomestic: query.isDomestic || 1, - projectTypeTop: query.projectTypeDay, + projectTypeTop: query.projectTypeDay || projectTypeList.value?.[0].id, }) return res.data || [] }) @@ -197,8 +205,6 @@ // }) // } - - const handleHover = (item: ProjectDictNodeVO) => { query.projectTypeDay = item.id || '' if (item.name === '全部分类') return @@ -217,8 +223,8 @@ watch( () => query.type, async () => { - await getParent(); - await getHotTop(); + await getParent() + await getHotTop() }, { // immediate: true,