refactor(http): 重构http模块结构,优化文件组织
- 将alova和vue-query相关文件移动到http目录下 - 统一工具类文件到http/tools目录 - 删除冗余的service/app目录 - 更新相关引用路径 - 添加新的vue-query实现文件
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
/* eslint-disable */
|
||||
// @ts-ignore
|
||||
import * as API from './types';
|
||||
|
||||
export function displayStatusEnum(field: API.IStatusEnum) {
|
||||
return { available: 'available', pending: 'pending', sold: 'sold' }[field];
|
||||
}
|
||||
|
||||
export function displayStatusEnum2(field: API.IStatusEnum2) {
|
||||
return { placed: 'placed', approved: 'approved', delivered: 'delivered' }[
|
||||
field
|
||||
];
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
/* eslint-disable */
|
||||
// @ts-ignore
|
||||
export * from './types';
|
||||
export * from './displayEnumLabel';
|
||||
|
||||
export * from './pet';
|
||||
export * from './pet.vuequery';
|
||||
export * from './store';
|
||||
export * from './store.vuequery';
|
||||
export * from './user';
|
||||
export * from './user.vuequery';
|
||||
@@ -1,193 +0,0 @@
|
||||
/* eslint-disable */
|
||||
// @ts-ignore
|
||||
import request from '@/utils/request';
|
||||
import { CustomRequestOptions } from '@/http/interceptor';
|
||||
|
||||
import * as API from './types';
|
||||
|
||||
/** Update an existing pet PUT /pet */
|
||||
export async function updatePet({
|
||||
body,
|
||||
options,
|
||||
}: {
|
||||
body: API.Pet;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return request<unknown>('/pet', {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: body,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Add a new pet to the store POST /pet */
|
||||
export async function addPet({
|
||||
body,
|
||||
options,
|
||||
}: {
|
||||
body: API.Pet;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return request<unknown>('/pet', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: body,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Find pet by ID Returns a single pet GET /pet/${param0} */
|
||||
export async function getPetById({
|
||||
params,
|
||||
options,
|
||||
}: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.getPetByIdParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
const { petId: param0, ...queryParams } = params;
|
||||
|
||||
return request<API.Pet>(`/pet/${param0}`, {
|
||||
method: 'GET',
|
||||
params: { ...queryParams },
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Updates a pet in the store with form data POST /pet/${param0} */
|
||||
export async function updatePetWithForm({
|
||||
params,
|
||||
body,
|
||||
options,
|
||||
}: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.updatePetWithFormParams;
|
||||
body: {
|
||||
/** Updated name of the pet */
|
||||
name?: string;
|
||||
/** Updated status of the pet */
|
||||
status?: string;
|
||||
};
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
const { petId: param0, ...queryParams } = params;
|
||||
|
||||
return request<unknown>(`/pet/${param0}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
params: { ...queryParams },
|
||||
data: body,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Deletes a pet DELETE /pet/${param0} */
|
||||
export async function deletePet({
|
||||
params,
|
||||
options,
|
||||
}: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.deletePetParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
const { petId: param0, ...queryParams } = params;
|
||||
|
||||
return request<unknown>(`/pet/${param0}`, {
|
||||
method: 'DELETE',
|
||||
params: { ...queryParams },
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** uploads an image POST /pet/${param0}/uploadImage */
|
||||
export async function uploadFile({
|
||||
params,
|
||||
body,
|
||||
file,
|
||||
options,
|
||||
}: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.uploadFileParams;
|
||||
body: {
|
||||
/** Additional data to pass to server */
|
||||
additionalMetadata?: string;
|
||||
};
|
||||
file?: File;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
const { petId: param0, ...queryParams } = params;
|
||||
const formData = new FormData();
|
||||
|
||||
if (file) {
|
||||
formData.append('file', file);
|
||||
}
|
||||
|
||||
Object.keys(body).forEach((ele) => {
|
||||
const item = (body as { [key: string]: any })[ele];
|
||||
|
||||
if (item !== undefined && item !== null) {
|
||||
if (typeof item === 'object' && !(item instanceof File)) {
|
||||
if (item instanceof Array) {
|
||||
item.forEach((f) => formData.append(ele, f || ''));
|
||||
} else {
|
||||
formData.append(ele, JSON.stringify(item));
|
||||
}
|
||||
} else {
|
||||
formData.append(ele, item);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return request<API.ApiResponse>(`/pet/${param0}/uploadImage`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
params: { ...queryParams },
|
||||
data: formData,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Finds Pets by status Multiple status values can be provided with comma separated strings GET /pet/findByStatus */
|
||||
export async function findPetsByStatus({
|
||||
params,
|
||||
options,
|
||||
}: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.findPetsByStatusParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return request<API.Pet[]>('/pet/findByStatus', {
|
||||
method: 'GET',
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Finds Pets by tags Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. GET /pet/findByTags */
|
||||
export async function findPetsByTags({
|
||||
params,
|
||||
options,
|
||||
}: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.findPetsByTagsParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return request<API.Pet[]>('/pet/findByTags', {
|
||||
method: 'GET',
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
/* eslint-disable */
|
||||
// @ts-ignore
|
||||
import { queryOptions, useMutation } from '@tanstack/vue-query';
|
||||
import type { DefaultError } from '@tanstack/vue-query';
|
||||
import request from '@/utils/request';
|
||||
import { CustomRequestOptions } from '@/http/interceptor';
|
||||
|
||||
import * as apis from './pet';
|
||||
import * as API from './types';
|
||||
|
||||
/** Update an existing pet PUT /pet */
|
||||
export function useUpdatePetMutation(options?: {
|
||||
onSuccess?: (value?: unknown) => void;
|
||||
onError?: (error?: DefaultError) => void;
|
||||
}) {
|
||||
const { onSuccess, onError } = options || {};
|
||||
|
||||
const response = useMutation({
|
||||
mutationFn: apis.updatePet,
|
||||
onSuccess(data: unknown) {
|
||||
onSuccess?.(data);
|
||||
},
|
||||
onError(error) {
|
||||
onError?.(error);
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/** Add a new pet to the store POST /pet */
|
||||
export function useAddPetMutation(options?: {
|
||||
onSuccess?: (value?: unknown) => void;
|
||||
onError?: (error?: DefaultError) => void;
|
||||
}) {
|
||||
const { onSuccess, onError } = options || {};
|
||||
|
||||
const response = useMutation({
|
||||
mutationFn: apis.addPet,
|
||||
onSuccess(data: unknown) {
|
||||
onSuccess?.(data);
|
||||
},
|
||||
onError(error) {
|
||||
onError?.(error);
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/** Find pet by ID Returns a single pet GET /pet/${param0} */
|
||||
export function getPetByIdQueryOptions(options: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.getPetByIdParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey }) => {
|
||||
return apis.getPetById(queryKey[1] as typeof options);
|
||||
},
|
||||
queryKey: ['getPetById', options],
|
||||
});
|
||||
}
|
||||
|
||||
/** Updates a pet in the store with form data POST /pet/${param0} */
|
||||
export function useUpdatePetWithFormMutation(options?: {
|
||||
onSuccess?: (value?: unknown) => void;
|
||||
onError?: (error?: DefaultError) => void;
|
||||
}) {
|
||||
const { onSuccess, onError } = options || {};
|
||||
|
||||
const response = useMutation({
|
||||
mutationFn: apis.updatePetWithForm,
|
||||
onSuccess(data: unknown) {
|
||||
onSuccess?.(data);
|
||||
},
|
||||
onError(error) {
|
||||
onError?.(error);
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/** Deletes a pet DELETE /pet/${param0} */
|
||||
export function useDeletePetMutation(options?: {
|
||||
onSuccess?: (value?: unknown) => void;
|
||||
onError?: (error?: DefaultError) => void;
|
||||
}) {
|
||||
const { onSuccess, onError } = options || {};
|
||||
|
||||
const response = useMutation({
|
||||
mutationFn: apis.deletePet,
|
||||
onSuccess(data: unknown) {
|
||||
onSuccess?.(data);
|
||||
},
|
||||
onError(error) {
|
||||
onError?.(error);
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/** uploads an image POST /pet/${param0}/uploadImage */
|
||||
export function useUploadFileMutation(options?: {
|
||||
onSuccess?: (value?: API.ApiResponse) => void;
|
||||
onError?: (error?: DefaultError) => void;
|
||||
}) {
|
||||
const { onSuccess, onError } = options || {};
|
||||
|
||||
const response = useMutation({
|
||||
mutationFn: apis.uploadFile,
|
||||
onSuccess(data: API.ApiResponse) {
|
||||
onSuccess?.(data);
|
||||
},
|
||||
onError(error) {
|
||||
onError?.(error);
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/** Finds Pets by status Multiple status values can be provided with comma separated strings GET /pet/findByStatus */
|
||||
export function findPetsByStatusQueryOptions(options: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.findPetsByStatusParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey }) => {
|
||||
return apis.findPetsByStatus(queryKey[1] as typeof options);
|
||||
},
|
||||
queryKey: ['findPetsByStatus', options],
|
||||
});
|
||||
}
|
||||
|
||||
/** Finds Pets by tags Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. GET /pet/findByTags */
|
||||
export function findPetsByTagsQueryOptions(options: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.findPetsByTagsParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey }) => {
|
||||
return apis.findPetsByTags(queryKey[1] as typeof options);
|
||||
},
|
||||
queryKey: ['findPetsByTags', options],
|
||||
});
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/* eslint-disable */
|
||||
// @ts-ignore
|
||||
import request from '@/utils/request';
|
||||
import { CustomRequestOptions } from '@/http/interceptor';
|
||||
|
||||
import * as API from './types';
|
||||
|
||||
/** Returns pet inventories by status Returns a map of status codes to quantities GET /store/inventory */
|
||||
export async function getInventory({
|
||||
options,
|
||||
}: {
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return request<Record<string, unknown>>('/store/inventory', {
|
||||
method: 'GET',
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Place an order for a pet POST /store/order */
|
||||
export async function placeOrder({
|
||||
body,
|
||||
options,
|
||||
}: {
|
||||
body: API.Order;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return request<API.Order>('/store/order', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: body,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Find purchase order by ID For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions GET /store/order/${param0} */
|
||||
export async function getOrderById({
|
||||
params,
|
||||
options,
|
||||
}: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.getOrderByIdParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
const { orderId: param0, ...queryParams } = params;
|
||||
|
||||
return request<API.Order>(`/store/order/${param0}`, {
|
||||
method: 'GET',
|
||||
params: { ...queryParams },
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Delete purchase order by ID For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors DELETE /store/order/${param0} */
|
||||
export async function deleteOrder({
|
||||
params,
|
||||
options,
|
||||
}: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.deleteOrderParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
const { orderId: param0, ...queryParams } = params;
|
||||
|
||||
return request<unknown>(`/store/order/${param0}`, {
|
||||
method: 'DELETE',
|
||||
params: { ...queryParams },
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/* eslint-disable */
|
||||
// @ts-ignore
|
||||
import { queryOptions, useMutation } from '@tanstack/vue-query';
|
||||
import type { DefaultError } from '@tanstack/vue-query';
|
||||
import request from '@/utils/request';
|
||||
import { CustomRequestOptions } from '@/http/interceptor';
|
||||
|
||||
import * as apis from './store';
|
||||
import * as API from './types';
|
||||
|
||||
/** Returns pet inventories by status Returns a map of status codes to quantities GET /store/inventory */
|
||||
export function getInventoryQueryOptions(options: {
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey }) => {
|
||||
return apis.getInventory(queryKey[1] as typeof options);
|
||||
},
|
||||
queryKey: ['getInventory', options],
|
||||
});
|
||||
}
|
||||
|
||||
/** Place an order for a pet POST /store/order */
|
||||
export function usePlaceOrderMutation(options?: {
|
||||
onSuccess?: (value?: API.Order) => void;
|
||||
onError?: (error?: DefaultError) => void;
|
||||
}) {
|
||||
const { onSuccess, onError } = options || {};
|
||||
|
||||
const response = useMutation({
|
||||
mutationFn: apis.placeOrder,
|
||||
onSuccess(data: API.Order) {
|
||||
onSuccess?.(data);
|
||||
},
|
||||
onError(error) {
|
||||
onError?.(error);
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/** Find purchase order by ID For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions GET /store/order/${param0} */
|
||||
export function getOrderByIdQueryOptions(options: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.getOrderByIdParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey }) => {
|
||||
return apis.getOrderById(queryKey[1] as typeof options);
|
||||
},
|
||||
queryKey: ['getOrderById', options],
|
||||
});
|
||||
}
|
||||
|
||||
/** Delete purchase order by ID For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors DELETE /store/order/${param0} */
|
||||
export function useDeleteOrderMutation(options?: {
|
||||
onSuccess?: (value?: unknown) => void;
|
||||
onError?: (error?: DefaultError) => void;
|
||||
}) {
|
||||
const { onSuccess, onError } = options || {};
|
||||
|
||||
const response = useMutation({
|
||||
mutationFn: apis.deleteOrder,
|
||||
onSuccess(data: unknown) {
|
||||
onSuccess?.(data);
|
||||
},
|
||||
onError(error) {
|
||||
onError?.(error);
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
/* eslint-disable */
|
||||
// @ts-ignore
|
||||
|
||||
export type ApiResponse = {
|
||||
code?: number;
|
||||
type?: string;
|
||||
message?: string;
|
||||
};
|
||||
|
||||
export type Category = {
|
||||
id?: number;
|
||||
name?: string;
|
||||
};
|
||||
|
||||
export type deleteOrderParams = {
|
||||
/** ID of the order that needs to be deleted */
|
||||
orderId: number;
|
||||
};
|
||||
|
||||
export type deletePetParams = {
|
||||
/** Pet id to delete */
|
||||
petId: number;
|
||||
};
|
||||
|
||||
export type deleteUserParams = {
|
||||
/** The name that needs to be deleted */
|
||||
username: string;
|
||||
};
|
||||
|
||||
export type findPetsByStatusParams = {
|
||||
/** Status values that need to be considered for filter */
|
||||
status: ('available' | 'pending' | 'sold')[];
|
||||
};
|
||||
|
||||
export type findPetsByTagsParams = {
|
||||
/** Tags to filter by */
|
||||
tags: string[];
|
||||
};
|
||||
|
||||
export type getOrderByIdParams = {
|
||||
/** ID of pet that needs to be fetched */
|
||||
orderId: number;
|
||||
};
|
||||
|
||||
export type getPetByIdParams = {
|
||||
/** ID of pet to return */
|
||||
petId: number;
|
||||
};
|
||||
|
||||
export type getUserByNameParams = {
|
||||
/** The name that needs to be fetched. Use user1 for testing. */
|
||||
username: string;
|
||||
};
|
||||
|
||||
export type loginUserParams = {
|
||||
/** The user name for login */
|
||||
username: string;
|
||||
/** The password for login in clear text */
|
||||
password: string;
|
||||
};
|
||||
|
||||
export type Order = {
|
||||
id?: number;
|
||||
petId?: number;
|
||||
quantity?: number;
|
||||
shipDate?: string;
|
||||
/** Order Status */
|
||||
status?: 'placed' | 'approved' | 'delivered';
|
||||
complete?: boolean;
|
||||
};
|
||||
|
||||
export type Pet = {
|
||||
id?: number;
|
||||
category?: Category;
|
||||
name: string;
|
||||
photoUrls: string[];
|
||||
tags?: Tag[];
|
||||
/** pet status in the store */
|
||||
status?: 'available' | 'pending' | 'sold';
|
||||
};
|
||||
|
||||
export enum StatusEnum {
|
||||
available = 'available',
|
||||
pending = 'pending',
|
||||
sold = 'sold',
|
||||
}
|
||||
|
||||
export type IStatusEnum = keyof typeof StatusEnum;
|
||||
|
||||
export enum StatusEnum2 {
|
||||
placed = 'placed',
|
||||
approved = 'approved',
|
||||
delivered = 'delivered',
|
||||
}
|
||||
|
||||
export type IStatusEnum2 = keyof typeof StatusEnum2;
|
||||
|
||||
export type Tag = {
|
||||
id?: number;
|
||||
name?: string;
|
||||
};
|
||||
|
||||
export type updatePetWithFormParams = {
|
||||
/** ID of pet that needs to be updated */
|
||||
petId: number;
|
||||
};
|
||||
|
||||
export type updateUserParams = {
|
||||
/** name that need to be updated */
|
||||
username: string;
|
||||
};
|
||||
|
||||
export type uploadFileParams = {
|
||||
/** ID of pet to update */
|
||||
petId: number;
|
||||
};
|
||||
|
||||
export type User = {
|
||||
id?: number;
|
||||
username?: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
email?: string;
|
||||
password?: string;
|
||||
phone?: string;
|
||||
/** User Status */
|
||||
userStatus?: number;
|
||||
};
|
||||
@@ -1,150 +0,0 @@
|
||||
/* eslint-disable */
|
||||
// @ts-ignore
|
||||
import request from '@/utils/request';
|
||||
import { CustomRequestOptions } from '@/http/interceptor';
|
||||
|
||||
import * as API from './types';
|
||||
|
||||
/** Create user This can only be done by the logged in user. 返回值: successful operation POST /user */
|
||||
export async function createUser({
|
||||
body,
|
||||
options,
|
||||
}: {
|
||||
body: API.User;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return request<unknown>('/user', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: body,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Get user by user name GET /user/${param0} */
|
||||
export async function getUserByName({
|
||||
params,
|
||||
options,
|
||||
}: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.getUserByNameParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
const { username: param0, ...queryParams } = params;
|
||||
|
||||
return request<API.User>(`/user/${param0}`, {
|
||||
method: 'GET',
|
||||
params: { ...queryParams },
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Updated user This can only be done by the logged in user. PUT /user/${param0} */
|
||||
export async function updateUser({
|
||||
params,
|
||||
body,
|
||||
options,
|
||||
}: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.updateUserParams;
|
||||
body: API.User;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
const { username: param0, ...queryParams } = params;
|
||||
|
||||
return request<unknown>(`/user/${param0}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
params: { ...queryParams },
|
||||
data: body,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Delete user This can only be done by the logged in user. DELETE /user/${param0} */
|
||||
export async function deleteUser({
|
||||
params,
|
||||
options,
|
||||
}: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.deleteUserParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
const { username: param0, ...queryParams } = params;
|
||||
|
||||
return request<unknown>(`/user/${param0}`, {
|
||||
method: 'DELETE',
|
||||
params: { ...queryParams },
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Creates list of users with given input array 返回值: successful operation POST /user/createWithArray */
|
||||
export async function createUsersWithArrayInput({
|
||||
body,
|
||||
options,
|
||||
}: {
|
||||
body: API.User[];
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return request<unknown>('/user/createWithArray', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: body,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Creates list of users with given input array 返回值: successful operation POST /user/createWithList */
|
||||
export async function createUsersWithListInput({
|
||||
body,
|
||||
options,
|
||||
}: {
|
||||
body: API.User[];
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return request<unknown>('/user/createWithList', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: body,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Logs user into the system GET /user/login */
|
||||
export async function loginUser({
|
||||
params,
|
||||
options,
|
||||
}: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.loginUserParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return request<string>('/user/login', {
|
||||
method: 'GET',
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Logs out current logged in user session 返回值: successful operation GET /user/logout */
|
||||
export async function logoutUser({
|
||||
options,
|
||||
}: {
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return request<unknown>('/user/logout', {
|
||||
method: 'GET',
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
/* eslint-disable */
|
||||
// @ts-ignore
|
||||
import { queryOptions, useMutation } from '@tanstack/vue-query';
|
||||
import type { DefaultError } from '@tanstack/vue-query';
|
||||
import request from '@/utils/request';
|
||||
import { CustomRequestOptions } from '@/http/interceptor';
|
||||
|
||||
import * as apis from './user';
|
||||
import * as API from './types';
|
||||
|
||||
/** Create user This can only be done by the logged in user. 返回值: successful operation POST /user */
|
||||
export function useCreateUserMutation(options?: {
|
||||
onSuccess?: (value?: unknown) => void;
|
||||
onError?: (error?: DefaultError) => void;
|
||||
}) {
|
||||
const { onSuccess, onError } = options || {};
|
||||
|
||||
const response = useMutation({
|
||||
mutationFn: apis.createUser,
|
||||
onSuccess(data: unknown) {
|
||||
onSuccess?.(data);
|
||||
},
|
||||
onError(error) {
|
||||
onError?.(error);
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/** Get user by user name GET /user/${param0} */
|
||||
export function getUserByNameQueryOptions(options: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.getUserByNameParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey }) => {
|
||||
return apis.getUserByName(queryKey[1] as typeof options);
|
||||
},
|
||||
queryKey: ['getUserByName', options],
|
||||
});
|
||||
}
|
||||
|
||||
/** Updated user This can only be done by the logged in user. PUT /user/${param0} */
|
||||
export function useUpdateUserMutation(options?: {
|
||||
onSuccess?: (value?: unknown) => void;
|
||||
onError?: (error?: DefaultError) => void;
|
||||
}) {
|
||||
const { onSuccess, onError } = options || {};
|
||||
|
||||
const response = useMutation({
|
||||
mutationFn: apis.updateUser,
|
||||
onSuccess(data: unknown) {
|
||||
onSuccess?.(data);
|
||||
},
|
||||
onError(error) {
|
||||
onError?.(error);
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/** Delete user This can only be done by the logged in user. DELETE /user/${param0} */
|
||||
export function useDeleteUserMutation(options?: {
|
||||
onSuccess?: (value?: unknown) => void;
|
||||
onError?: (error?: DefaultError) => void;
|
||||
}) {
|
||||
const { onSuccess, onError } = options || {};
|
||||
|
||||
const response = useMutation({
|
||||
mutationFn: apis.deleteUser,
|
||||
onSuccess(data: unknown) {
|
||||
onSuccess?.(data);
|
||||
},
|
||||
onError(error) {
|
||||
onError?.(error);
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/** Creates list of users with given input array 返回值: successful operation POST /user/createWithArray */
|
||||
export function useCreateUsersWithArrayInputMutation(options?: {
|
||||
onSuccess?: (value?: unknown) => void;
|
||||
onError?: (error?: DefaultError) => void;
|
||||
}) {
|
||||
const { onSuccess, onError } = options || {};
|
||||
|
||||
const response = useMutation({
|
||||
mutationFn: apis.createUsersWithArrayInput,
|
||||
onSuccess(data: unknown) {
|
||||
onSuccess?.(data);
|
||||
},
|
||||
onError(error) {
|
||||
onError?.(error);
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/** Creates list of users with given input array 返回值: successful operation POST /user/createWithList */
|
||||
export function useCreateUsersWithListInputMutation(options?: {
|
||||
onSuccess?: (value?: unknown) => void;
|
||||
onError?: (error?: DefaultError) => void;
|
||||
}) {
|
||||
const { onSuccess, onError } = options || {};
|
||||
|
||||
const response = useMutation({
|
||||
mutationFn: apis.createUsersWithListInput,
|
||||
onSuccess(data: unknown) {
|
||||
onSuccess?.(data);
|
||||
},
|
||||
onError(error) {
|
||||
onError?.(error);
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/** Logs user into the system GET /user/login */
|
||||
export function loginUserQueryOptions(options: {
|
||||
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||
params: API.loginUserParams;
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey }) => {
|
||||
return apis.loginUser(queryKey[1] as typeof options);
|
||||
},
|
||||
queryKey: ['loginUser', options],
|
||||
});
|
||||
}
|
||||
|
||||
/** Logs out current logged in user session 返回值: successful operation GET /user/logout */
|
||||
export function logoutUserQueryOptions(options: {
|
||||
options?: CustomRequestOptions;
|
||||
}) {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey }) => {
|
||||
return apis.logoutUser(queryKey[1] as typeof options);
|
||||
},
|
||||
queryKey: ['logoutUser', options],
|
||||
});
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
import { http } from '@/http/http'
|
||||
|
||||
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' })
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
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],
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user