Update API request formatting and error handling

This commit is contained in:
wangqiao
2025-08-27 16:24:22 +08:00
parent 600c3e9f18
commit dc628e3494
2 changed files with 20 additions and 14 deletions

View File

@ -15,7 +15,7 @@ import type {
* @returns * @returns
*/ */
export const hotTop = (params: ThotTopReq) => { export const hotTop = (params: ThotTopReq) => {
return useFetchRequest.get<IResponse<ProjectDrawPageRespVO[]>>('/prod-api/app-api/business/app/project-draw/hot-top', { query:params }) return useDollarFetchRequest.get<IResponse<ProjectDrawPageRespVO[]>>('/prod-api/app-api/business/app/project-draw/hot-top', { query: params })
} }
/** /**
@ -24,21 +24,21 @@ export const hotTop = (params: ThotTopReq) => {
* @returns * @returns
*/ */
export const recommendTop = (params: ThotTopReq) => { export const recommendTop = (params: ThotTopReq) => {
return useFetchRequest.get<IResponse<ProjectDrawPageRespVO[]>>('/prod-api/app-api/business/app/project-draw/recommend-top', { query:params }) return useFetchRequest.get<IResponse<ProjectDrawPageRespVO[]>>('/prod-api/app-api/business/app/project-draw/recommend-top', { query: params })
} }
/** /**
* 获取最新图纸信息 * 获取最新图纸信息
*/ */
export const newDraw = (params: { type: number; limit: number }) => { export const newDraw = (params: { type: number; limit: number }) => {
return useFetchRequest.get<IResponse<ProjectDrawPageRespVO[]>>('/prod-api/app-api/business/project/index/draw-new', { query:params }) return useFetchRequest.get<IResponse<ProjectDrawPageRespVO[]>>('/prod-api/app-api/business/project/index/draw-new', { query: params })
} }
/** /**
* 首页-热点标签 * 首页-热点标签
*/ */
export const hotTag = (params: { type: number; limit: number; size: number }) => { export const hotTag = (params: { type: number; limit: number; size: number }) => {
return useFetchRequest.get<IResponse<ProjectDictNodeVO[]>>('/prod-api/app-api/business/project/index/index-hot-tab', { query:params }) return useFetchRequest.get<IResponse<ProjectDictNodeVO[]>>('/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数据 * 获取用户top数据
*/ */
export const userTop = (params: { type?: number }) => { export const userTop = (params: { type?: number }) => {
return useFetchRequest.get<IResponse<ProjectTrendingScoreUserInfoVO[]>>('/prod-api/app-api/business/project/index/user-top', { query:params }) return useFetchRequest.get<IResponse<ProjectTrendingScoreUserInfoVO[]>>('/prod-api/app-api/business/project/index/user-top', { query: params })
} }
/** /**

View File

@ -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({ const res = await hotTag({
type: query.type, type: query.type,
limit: 6, limit: 6,
@ -154,7 +154,7 @@
}) })
const all = [{ id: '0', name: '全部分类', children: [] }] const all = [{ id: '0', name: '全部分类', children: [] }]
if (Array.isArray(res.data) && res.data?.length > 0) { 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.projectTypeDay = total[0]?.id || ''
// query.projectType = total[0]!.children?.[0]?.id || '' // query.projectType = total[0]!.children?.[0]?.id || ''
return total return total
@ -162,13 +162,21 @@
return [] 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({ const res = await hotTop({
type: query.type, type: query.type,
// @ts-ignore // @ts-ignore
projectType: query.projectTypeDay, projectType: query.projectTypeDay || projectTypeList.value[0].id,
isDomestic: query.isDomestic || 1, isDomestic: query.isDomestic || 1,
projectTypeTop: query.projectTypeDay, projectTypeTop: query.projectTypeDay || projectTypeList.value?.[0].id,
}) })
return res.data || [] return res.data || []
}) })
@ -197,8 +205,6 @@
// }) // })
// } // }
const handleHover = (item: ProjectDictNodeVO) => { const handleHover = (item: ProjectDictNodeVO) => {
query.projectTypeDay = item.id || '' query.projectTypeDay = item.id || ''
if (item.name === '全部分类') return if (item.name === '全部分类') return
@ -217,8 +223,8 @@
watch( watch(
() => query.type, () => query.type,
async () => { async () => {
await getParent(); await getParent()
await getHotTop(); await getHotTop()
}, },
{ {
// immediate: true, // immediate: true,