refactor(http): 重构http模块结构,优化文件组织

- 将alova和vue-query相关文件移动到http目录下
- 统一工具类文件到http/tools目录
- 删除冗余的service/app目录
- 更新相关引用路径
- 添加新的vue-query实现文件
This commit is contained in:
feige996
2025-08-05 17:49:33 +08:00
parent fc92d23c4a
commit 17e5030dfe
22 changed files with 64 additions and 1055 deletions

View File

@@ -1,4 +1,4 @@
import { API_DOMAINS, http } from '@/http/request/alova'
import { API_DOMAINS, http } from '@/http/alova'
export interface IFoo {
id: number

11
src/api/foo-vue-query.ts Normal file
View File

@@ -0,0 +1,11 @@
import { queryOptions } from '@tanstack/vue-query'
import { getFooAPI } from './foo'
export function getFooQueryOptions(name: string) {
return queryOptions({
queryFn: async ({ queryKey }) => {
return getFooAPI(queryKey[1])
},
queryKey: ['getFoo', name],
})
}

View File

@@ -14,3 +14,30 @@ export function foo() {
},
})
}
export interface IFooItem {
id: string
name: string
}
/** GET 请求 */
export function getFooAPI(name: string) {
return http.get<IFooItem>('/foo', { name })
}
/** GET 请求;支持 传递 header 的范例 */
export function getFooAPI2(name: string) {
return http.get<IFooItem>('/foo', { name }, { 'Content-Type-100': '100' })
}
/** POST 请求 */
export function postFooAPI(name: string) {
return http.post<IFooItem>('/foo', { name })
}
/** POST 请求;需要传递 query 参数的范例微信小程序经常有同时需要query参数和body参数的场景 */
export function postFooAPI2(name: string) {
return http.post<IFooItem>('/foo', { name })
}
/** POST 请求;支持 传递 header 的范例 */
export function postFooAPI3(name: string) {
return http.post<IFooItem>('/foo', { name }, { name }, { 'Content-Type-100': '100' })
}