From 2fe36051f8ab2e2f70796beacae0f1b095f2dc1c Mon Sep 17 00:00:00 2001 From: wangqiao Date: Wed, 20 Aug 2025 22:58:08 +0800 Subject: [PATCH] Refactor API requests and update component structure --- .vscode/settings.json | 5 ++ api/home/index.ts | 7 +- composables/useFetchRequest.ts | 46 +++-------- layout/kl-menus-v2/index.vue | 1 - .../components/LearningRecommendations.vue | 20 +++-- pages/home/components/MainContent.vue | 81 ++++++++++++------- pages/home/components/RecommendedColumns.vue | 35 ++++---- pages/home/components/SideMenu.vue | 37 +++++---- 8 files changed, 123 insertions(+), 109 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9de90c6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "editor.formatOnSave": true, + "editor.defaultFormatter": "esbenp.prettier-vscode", + "prettier.configPath": "./.prettierrc" +} \ No newline at end of file diff --git a/api/home/index.ts b/api/home/index.ts index c7b2236..2d557e5 100644 --- a/api/home/index.ts +++ b/api/home/index.ts @@ -24,7 +24,7 @@ export const hotTop = (params: ThotTopReq) => { * @returns */ export const recommendTop = (params: ThotTopReq) => { - return useDollarFetchRequest.get>('/prod-api/app-api/business/app/project-draw/recommend-top', { params }) + return useFetchRequest.get>('/prod-api/app-api/business/app/project-draw/recommend-top', { params }) } /** @@ -72,14 +72,13 @@ export const settinngPage = (params: { pageNo?: number; pageSize: number; type: * 获得首页设置信息分页 */ export const getSettingPage = (params: { type: number }) => { - return useDollarFetchRequest.get>('/prod-api/app-api/system/index-setting/list', { params }) + return useFetchRequest.get>('/prod-api/app-api/system/index-setting/list', { params }) } /** * 首页-标签2 */ export const tab2 = () => { - return useDollarFetchRequest.get>('/prod-api/app-api/business/project/index/index-tab2', { - server: true + return useFetchRequest.get>('/prod-api/app-api/business/project/index/index-tab2', { }) } diff --git a/composables/useFetchRequest.ts b/composables/useFetchRequest.ts index f9b58ac..5b4ef53 100644 --- a/composables/useFetchRequest.ts +++ b/composables/useFetchRequest.ts @@ -35,22 +35,15 @@ const useServerRequest = async ( // return useFetch(url, { ...defaultOptions, ...opts } as any); // 明确转换返回类型 const response = await useFetch(url, { ...defaultOptions, ...opts, key: 'unique-key-' + Date.now(), } as any); - return response as unknown as T; + return response.data.value as unknown as T; }; // GET请求 export const get = ( endpoint: string, config?: Omit - ): Promise<{ - data: T; - pending: boolean; - error: any; - refresh: () => Promise; - execute: () => Promise; - status: number; - }> => { - return useServerRequest(endpoint, { ...config, method: 'GET' }) + ): Promise => { + return useServerRequest(endpoint, { ...config, method: 'GET' }) } // POST请求 @@ -58,15 +51,8 @@ const useServerRequest = async ( endpoint: string, body?: any, config?: Omit - ): Promise<{ - data: T; - pending: boolean; - error: any; - refresh: () => Promise; - execute: () => Promise; - status: number; - }> => { - return useServerRequest(endpoint, { ...config, method: 'POST', body }) + ): Promise => { + return useServerRequest(endpoint, { ...config, method: 'POST', body }) } @@ -74,15 +60,8 @@ const useServerRequest = async ( export const del = ( endpoint: string, config?: Omit - ): Promise<{ - data: T; - pending: boolean; - error: any; - refresh: () => Promise; - execute: () => Promise; - status: number; - }> => { - return useServerRequest(endpoint, { ...config, method: 'DELETE' }) + ): Promise => { + return useServerRequest(endpoint, { ...config, method: 'DELETE' }) } // PUT请求 @@ -90,13 +69,6 @@ const useServerRequest = async ( endpoint: string, body?: any, config?: Omit - ): Promise<{ - data: T; - pending: boolean; - error: any; - refresh: () => Promise; - execute: () => Promise; - status: number; - }> => { - return useServerRequest(endpoint, { ...config, method: 'PUT', body }) + ): Promise => { + return useServerRequest(endpoint, { ...config, method: 'PUT', body }) } diff --git a/layout/kl-menus-v2/index.vue b/layout/kl-menus-v2/index.vue index a0f14fb..89ddb81 100644 --- a/layout/kl-menus-v2/index.vue +++ b/layout/kl-menus-v2/index.vue @@ -10,7 +10,6 @@ diff --git a/pages/home/components/LearningRecommendations.vue b/pages/home/components/LearningRecommendations.vue index fe6ec00..0e53ea1 100644 --- a/pages/home/components/LearningRecommendations.vue +++ b/pages/home/components/LearningRecommendations.vue @@ -31,14 +31,20 @@ status: 0, }) - const bannerList = ref([]) - const getBanner = async () => { + const { data: bannerList } = useAsyncData('get-setting-Page', async () => { const res = await getSettingPage(pageReq) - if (res.code === 0) { - bannerList.value = res.data - } - } - getBanner() + return res.data + }) + + + // const bannerList = ref([]) + // const getBanner = async () => { + // const res = await getSettingPage(pageReq) + // if (res.code === 0) { + // bannerList.value = res.data + // } + // } + // getBanner() const handleClick = (url: string) => { navigateTo(url) diff --git a/pages/home/components/MainContent.vue b/pages/home/components/MainContent.vue index ea004ee..b43ee57 100644 --- a/pages/home/components/MainContent.vue +++ b/pages/home/components/MainContent.vue @@ -1,53 +1,74 @@ -`