From 1ef219878c5397c38be612d49685a2ce73850cd4 Mon Sep 17 00:00:00 2001 From: wangqiao Date: Tue, 19 Aug 2025 22:19:08 +0800 Subject: [PATCH] Refactor API requests and update component structure --- api/home/index.ts | 22 +- composables/useDollarFetchRequest.ts | 3 +- composables/useFetchRequest.ts | 46 ++- layout/default.vue | 2 +- layout/kl-menus-v2/index.vue | 2 +- layout/kl-search/index.vue | 4 +- nuxt.config.ts | 2 +- pages/home/components/Leaderboard.vue | 5 +- pages/home/components/SideMenu.vue | 385 ++++++++++++++------------ pages/home/index.vue | 49 ---- pages/index.vue | 49 ++++ utils/RefreshToken.ts | 30 +- 12 files changed, 329 insertions(+), 270 deletions(-) delete mode 100644 pages/home/index.vue create mode 100644 pages/index.vue diff --git a/api/home/index.ts b/api/home/index.ts index e7656e3..c7b2236 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', { params }) + return useDollarFetchRequest.get>('/prod-api/app-api/business/app/project-draw/hot-top', { params }) } /** @@ -24,60 +24,62 @@ export const hotTop = (params: ThotTopReq) => { * @returns */ export const recommendTop = (params: ThotTopReq) => { - return useFetchRequest.get>('/prod-api/app-api/business/app/project-draw/recommend-top', { params }) + return useDollarFetchRequest.get>('/prod-api/app-api/business/app/project-draw/recommend-top', { params }) } /** * 获取最新图纸信息 */ export const newDraw = (params: { type: number; limit: number }) => { - return useFetchRequest.get>('/prod-api/app-api/business/project/index/draw-new', { params }) + return useDollarFetchRequest.get>('/prod-api/app-api/business/project/index/draw-new', { params }) } /** * 首页-热点标签 */ export const hotTag = (params: { type: number; limit: number; size: number }) => { - return useFetchRequest.get>('/prod-api/app-api/business/project/index/index-hot-tab', { params }) + return useDollarFetchRequest.get>('/prod-api/app-api/business/project/index/index-hot-tab', { params }) } /** * 首页-标签 */ export const tag = () => { - return useFetchRequest.get>('/prod-api/app-api/business/project/index/index-tab', {}) + return useDollarFetchRequest.get>('/prod-api/app-api/business/project/index/index-tab', {}) } /** * 获取top数据 */ export const top = (params: { type: number; limit: number }) => { - return useFetchRequest.get>('/prod-api/app-api/business/project/index/top', { params }) + return useDollarFetchRequest.get>('/prod-api/app-api/business/project/index/top', { params }) } /** * 获取用户top数据 */ export const userTop = (params: { type?: number }) => { - return useFetchRequest.get>('/prod-api/app-api/business/project/index/user-top', { params }) + return useDollarFetchRequest.get>('/prod-api/app-api/business/project/index/user-top', { params }) } /** * 设置首页设置信息分页 */ export const settinngPage = (params: { pageNo?: number; pageSize: number; type: number; status: number; innerType?: number }) => { - return useFetchRequest.get>('/prod-api/admin-api/system/index-setting/page', { params }) + return useDollarFetchRequest.get>('/prod-api/admin-api/system/index-setting/page', { params }) } /** * 获得首页设置信息分页 */ export const getSettingPage = (params: { type: number }) => { - return useFetchRequest.get>('/prod-api/app-api/system/index-setting/list', { params }) + return useDollarFetchRequest.get>('/prod-api/app-api/system/index-setting/list', { params }) } /** * 首页-标签2 */ export const tab2 = () => { - return useFetchRequest.get>('/prod-api/app-api/business/project/index/index-tab2', {}) + return useDollarFetchRequest.get>('/prod-api/app-api/business/project/index/index-tab2', { + server: true + }) } diff --git a/composables/useDollarFetchRequest.ts b/composables/useDollarFetchRequest.ts index 119d784..63e50ea 100644 --- a/composables/useDollarFetchRequest.ts +++ b/composables/useDollarFetchRequest.ts @@ -44,6 +44,7 @@ const useClientRequest = async ( config?: Omit ): Promise => { return useClientRequest(endpoint, { ...config, method: 'GET' }) + } // POST请求 @@ -71,4 +72,4 @@ const useClientRequest = async ( config?: Omit ): Promise => { return useClientRequest(endpoint, { ...config, method: 'PUT', body }) - } \ No newline at end of file + } diff --git a/composables/useFetchRequest.ts b/composables/useFetchRequest.ts index b8d5e61..f9b58ac 100644 --- a/composables/useFetchRequest.ts +++ b/composables/useFetchRequest.ts @@ -34,7 +34,7 @@ const useServerRequest = async ( }; // return useFetch(url, { ...defaultOptions, ...opts } as any); // 明确转换返回类型 - const response = await 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; }; @@ -42,8 +42,15 @@ const useServerRequest = async ( export const get = ( endpoint: string, config?: Omit - ): Promise => { - return useServerRequest(endpoint, { ...config, method: 'GET' }) + ): Promise<{ + data: T; + pending: boolean; + error: any; + refresh: () => Promise; + execute: () => Promise; + status: number; + }> => { + return useServerRequest(endpoint, { ...config, method: 'GET' }) } // POST请求 @@ -51,8 +58,15 @@ const useServerRequest = async ( endpoint: string, body?: any, config?: Omit - ): Promise => { - return useServerRequest(endpoint, { ...config, method: 'POST', body }) + ): Promise<{ + data: T; + pending: boolean; + error: any; + refresh: () => Promise; + execute: () => Promise; + status: number; + }> => { + return useServerRequest(endpoint, { ...config, method: 'POST', body }) } @@ -60,8 +74,15 @@ const useServerRequest = async ( export const del = ( endpoint: string, config?: Omit - ): Promise => { - return useServerRequest(endpoint, { ...config, method: 'DELETE' }) + ): Promise<{ + data: T; + pending: boolean; + error: any; + refresh: () => Promise; + execute: () => Promise; + status: number; + }> => { + return useServerRequest(endpoint, { ...config, method: 'DELETE' }) } // PUT请求 @@ -69,6 +90,13 @@ const useServerRequest = async ( endpoint: string, body?: any, config?: Omit - ): Promise => { - return useServerRequest(endpoint, { ...config, method: 'PUT', body }) + ): Promise<{ + data: T; + pending: boolean; + error: any; + refresh: () => Promise; + execute: () => Promise; + status: number; + }> => { + return useServerRequest(endpoint, { ...config, method: 'PUT', body }) } diff --git a/layout/default.vue b/layout/default.vue index 318c426..85f2ab2 100644 --- a/layout/default.vue +++ b/layout/default.vue @@ -10,7 +10,7 @@ diff --git a/layout/kl-menus-v2/index.vue b/layout/kl-menus-v2/index.vue index f92ad64..a0f14fb 100644 --- a/layout/kl-menus-v2/index.vue +++ b/layout/kl-menus-v2/index.vue @@ -2,7 +2,7 @@
-
+
全部资源分类
diff --git a/layout/kl-search/index.vue b/layout/kl-search/index.vue index 2cbb5ff..e47ef24 100644 --- a/layout/kl-search/index.vue +++ b/layout/kl-search/index.vue @@ -3,7 +3,7 @@
-
+
图夕夕
@@ -14,7 +14,7 @@ type="text" placeholder="搜一搜" :prefix-icon="Search" - class="no-right-border box-border h40 w-100% rounded-bl-4px rounded-br-0px rounded-tl-4px rounded-tr-0px bg-[#F8F8F8] text-14px outline-#999" + class="no-right-border box-border h-40px w-100% rounded-bl-4px rounded-br-0px rounded-tl-4px rounded-tr-0px bg-[#F8F8F8] text-14px outline-#999" @focus="handleHot(), (showHotList = true)" @input="handleInput" /> diff --git a/nuxt.config.ts b/nuxt.config.ts index b13d720..72c19d9 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -115,6 +115,6 @@ export default defineNuxtConfig({ }, build: { - transpile: ["vueuc", "@css-render/vue3-ssr"], + transpile: ["vueuc", "@css-render/vue3-ssr","@unocss"], }, }); diff --git a/pages/home/components/Leaderboard.vue b/pages/home/components/Leaderboard.vue index 7270c19..4387d41 100644 --- a/pages/home/components/Leaderboard.vue +++ b/pages/home/components/Leaderboard.vue @@ -1,7 +1,7 @@