Auto merge base into tabbar

This commit is contained in:
GitHub Actions
2025-01-14 13:59:27 +00:00
15 changed files with 672 additions and 300 deletions

View File

@@ -24,7 +24,7 @@
<!-- http://localhost:9000/#/pages/index/request -->
<wd-button @click="run" class="my-6">发送请求</wd-button>
<view class="h-12">
<view class="h-16">
<view v-if="loading">loading...</view>
<block v-else>
<view class="text-xl">请求数据如下</view>
@@ -37,7 +37,7 @@
<script lang="ts" setup>
import { getFooAPI, postFooAPI, IFooItem } from '@/service/index/foo'
import { findPetsByStatus } from '@/service/app'
import { findPetsByStatusQueryOptions } from '@/service/app'
import { useQuery } from '@tanstack/vue-query'
const recommendUrl = ref('http://laf.run/signup?code=ohaOgIX')
@@ -59,12 +59,7 @@ const {
error: error2,
isLoading: isLoading2,
refetch,
} = useQuery({
queryKey: ['findPetsByStatus'],
queryFn: () => {
return findPetsByStatus({ params: { status: ['available'] } })
},
})
} = useQuery(findPetsByStatusQueryOptions({ params: { status: ['available'] } }))
const reset = () => {
data.value = initialData

View File

@@ -1,11 +1,13 @@
/* eslint-disable */
// @ts-ignore
import * as API from './types'
import * as API from './types';
export function displayStatusEnum(field: API.IStatusEnum) {
return { available: 'available', pending: 'pending', sold: 'sold' }[field]
return { available: 'available', pending: 'pending', sold: 'sold' }[field];
}
export function displayStatusEnum2(field: API.IStatusEnum2) {
return { placed: 'placed', approved: 'approved', delivered: 'delivered' }[field]
return { placed: 'placed', approved: 'approved', delivered: 'delivered' }[
field
];
}

View File

@@ -1,8 +1,11 @@
/* eslint-disable */
// @ts-ignore
export * from './types'
export * from './displayEnumLabel'
export * from './types';
export * from './displayEnumLabel';
export * from './pet'
export * from './store'
export * from './user'
export * from './pet';
export * from './pet.vuequery';
export * from './store';
export * from './store.vuequery';
export * from './user';
export * from './user.vuequery';

View File

@@ -1,17 +1,17 @@
/* eslint-disable */
// @ts-ignore
import { request } from '@/utils/http'
import { CustomRequestOptions } from '@/interceptors/request'
import request from '@/utils/request';
import { CustomRequestOptions } from '@/interceptors/request';
import * as API from './types'
import * as API from './types';
/** Update an existing pet PUT /pet */
export async function updatePet({
body,
options,
}: {
body: API.Pet
options?: CustomRequestOptions
body: API.Pet;
options?: CustomRequestOptions;
}) {
return request<unknown>('/pet', {
method: 'PUT',
@@ -20,11 +20,17 @@ export async function updatePet({
},
data: body,
...(options || {}),
})
});
}
/** Add a new pet to the store POST /pet */
export async function addPet({ body, options }: { body: API.Pet; options?: CustomRequestOptions }) {
export async function addPet({
body,
options,
}: {
body: API.Pet;
options?: CustomRequestOptions;
}) {
return request<unknown>('/pet', {
method: 'POST',
headers: {
@@ -32,7 +38,7 @@ export async function addPet({ body, options }: { body: API.Pet; options?: Custo
},
data: body,
...(options || {}),
})
});
}
/** Find pet by ID Returns a single pet GET /pet/${param0} */
@@ -41,16 +47,16 @@ export async function getPetById({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.getPetByIdParams
options?: CustomRequestOptions
params: API.getPetByIdParams;
options?: CustomRequestOptions;
}) {
const { petId: param0, ...queryParams } = params
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} */
@@ -60,16 +66,16 @@ export async function updatePetWithForm({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.updatePetWithFormParams
params: API.updatePetWithFormParams;
body: {
/** Updated name of the pet */
name?: string
name?: string;
/** Updated status of the pet */
status?: string
}
options?: CustomRequestOptions
status?: string;
};
options?: CustomRequestOptions;
}) {
const { petId: param0, ...queryParams } = params
const { petId: param0, ...queryParams } = params;
return request<unknown>(`/pet/${param0}`, {
method: 'POST',
@@ -79,7 +85,7 @@ export async function updatePetWithForm({
params: { ...queryParams },
data: body,
...(options || {}),
})
});
}
/** Deletes a pet DELETE /pet/${param0} */
@@ -88,16 +94,16 @@ export async function deletePet({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.deletePetParams
options?: CustomRequestOptions
params: API.deletePetParams;
options?: CustomRequestOptions;
}) {
const { petId: param0, ...queryParams } = params
const { petId: param0, ...queryParams } = params;
return request<unknown>(`/pet/${param0}`, {
method: 'DELETE',
params: { ...queryParams },
...(options || {}),
})
});
}
/** uploads an image POST /pet/${param0}/uploadImage */
@@ -108,36 +114,36 @@ export async function uploadFile({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.uploadFileParams
params: API.uploadFileParams;
body: {
/** Additional data to pass to server */
additionalMetadata?: string
}
file?: File
options?: CustomRequestOptions
additionalMetadata?: string;
};
file?: File;
options?: CustomRequestOptions;
}) {
const { petId: param0, ...queryParams } = params
const formData = new FormData()
const { petId: param0, ...queryParams } = params;
const formData = new FormData();
if (file) {
formData.append('file', file)
formData.append('file', file);
}
Object.keys(body).forEach((ele) => {
const item = (body as { [key: string]: any })[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 || ''))
item.forEach((f) => formData.append(ele, f || ''));
} else {
formData.append(ele, JSON.stringify(item))
formData.append(ele, JSON.stringify(item));
}
} else {
formData.append(ele, item)
formData.append(ele, item);
}
}
})
});
return request<API.ApiResponse>(`/pet/${param0}/uploadImage`, {
method: 'POST',
@@ -147,7 +153,7 @@ export async function uploadFile({
params: { ...queryParams },
data: formData,
...(options || {}),
})
});
}
/** Finds Pets by status Multiple status values can be provided with comma separated strings GET /pet/findByStatus */
@@ -156,8 +162,8 @@ export async function findPetsByStatus({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.findPetsByStatusParams
options?: CustomRequestOptions
params: API.findPetsByStatusParams;
options?: CustomRequestOptions;
}) {
return request<API.Pet[]>('/pet/findByStatus', {
method: 'GET',
@@ -165,7 +171,7 @@ export async function findPetsByStatus({
...params,
},
...(options || {}),
})
});
}
/** Finds Pets by tags Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. GET /pet/findByTags */
@@ -174,8 +180,8 @@ export async function findPetsByTags({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.findPetsByTagsParams
options?: CustomRequestOptions
params: API.findPetsByTagsParams;
options?: CustomRequestOptions;
}) {
return request<API.Pet[]>('/pet/findByTags', {
method: 'GET',
@@ -183,5 +189,5 @@ export async function findPetsByTags({
...params,
},
...(options || {}),
})
});
}

View File

@@ -0,0 +1,151 @@
/* 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 '@/interceptors/request';
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],
});
}

View File

@@ -1,16 +1,20 @@
/* eslint-disable */
// @ts-ignore
import { request } from '@/utils/http'
import { CustomRequestOptions } from '@/interceptors/request'
import request from '@/utils/request';
import { CustomRequestOptions } from '@/interceptors/request';
import * as API from './types'
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 }) {
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 */
@@ -18,8 +22,8 @@ export async function placeOrder({
body,
options,
}: {
body: API.Order
options?: CustomRequestOptions
body: API.Order;
options?: CustomRequestOptions;
}) {
return request<API.Order>('/store/order', {
method: 'POST',
@@ -28,7 +32,7 @@ export async function placeOrder({
},
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} */
@@ -37,16 +41,16 @@ export async function getOrderById({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.getOrderByIdParams
options?: CustomRequestOptions
params: API.getOrderByIdParams;
options?: CustomRequestOptions;
}) {
const { orderId: param0, ...queryParams } = params
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} */
@@ -55,14 +59,14 @@ export async function deleteOrder({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.deleteOrderParams
options?: CustomRequestOptions
params: API.deleteOrderParams;
options?: CustomRequestOptions;
}) {
const { orderId: param0, ...queryParams } = params
const { orderId: param0, ...queryParams } = params;
return request<unknown>(`/store/order/${param0}`, {
method: 'DELETE',
params: { ...queryParams },
...(options || {}),
})
});
}

View File

@@ -0,0 +1,75 @@
/* 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 '@/interceptors/request';
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;
}

View File

@@ -2,82 +2,82 @@
// @ts-ignore
export type ApiResponse = {
code?: number
type?: string
message?: string
}
code?: number;
type?: string;
message?: string;
};
export type Category = {
id?: number
name?: string
}
id?: number;
name?: string;
};
export type deleteOrderParams = {
/** ID of the order that needs to be deleted */
orderId: number
}
orderId: number;
};
export type deletePetParams = {
/** Pet id to delete */
petId: number
}
petId: number;
};
export type deleteUserParams = {
/** The name that needs to be deleted */
username: string
}
username: string;
};
export type findPetsByStatusParams = {
/** Status values that need to be considered for filter */
status: ('available' | 'pending' | 'sold')[]
}
status: ('available' | 'pending' | 'sold')[];
};
export type findPetsByTagsParams = {
/** Tags to filter by */
tags: string[]
}
tags: string[];
};
export type getOrderByIdParams = {
/** ID of pet that needs to be fetched */
orderId: number
}
orderId: number;
};
export type getPetByIdParams = {
/** ID of pet to return */
petId: number
}
petId: number;
};
export type getUserByNameParams = {
/** The name that needs to be fetched. Use user1 for testing. */
username: string
}
username: string;
};
export type loginUserParams = {
/** The user name for login */
username: string
username: string;
/** The password for login in clear text */
password: string
}
password: string;
};
export type Order = {
id?: number
petId?: number
quantity?: number
shipDate?: string
id?: number;
petId?: number;
quantity?: number;
shipDate?: string;
/** Order Status */
status?: 'placed' | 'approved' | 'delivered'
complete?: boolean
}
status?: 'placed' | 'approved' | 'delivered';
complete?: boolean;
};
export type Pet = {
id?: number
category?: Category
name: string
photoUrls: string[]
tags?: Tag[]
id?: number;
category?: Category;
name: string;
photoUrls: string[];
tags?: Tag[];
/** pet status in the store */
status?: 'available' | 'pending' | 'sold'
}
status?: 'available' | 'pending' | 'sold';
};
export enum StatusEnum {
available = 'available',
@@ -85,7 +85,7 @@ export enum StatusEnum {
sold = 'sold',
}
export type IStatusEnum = keyof typeof StatusEnum
export type IStatusEnum = keyof typeof StatusEnum;
export enum StatusEnum2 {
placed = 'placed',
@@ -93,36 +93,36 @@ export enum StatusEnum2 {
delivered = 'delivered',
}
export type IStatusEnum2 = keyof typeof StatusEnum2
export type IStatusEnum2 = keyof typeof StatusEnum2;
export type Tag = {
id?: number
name?: string
}
id?: number;
name?: string;
};
export type updatePetWithFormParams = {
/** ID of pet that needs to be updated */
petId: number
}
petId: number;
};
export type updateUserParams = {
/** name that need to be updated */
username: string
}
username: string;
};
export type uploadFileParams = {
/** ID of pet to update */
petId: number
}
petId: number;
};
export type User = {
id?: number
username?: string
firstName?: string
lastName?: string
email?: string
password?: string
phone?: string
id?: number;
username?: string;
firstName?: string;
lastName?: string;
email?: string;
password?: string;
phone?: string;
/** User Status */
userStatus?: number
}
userStatus?: number;
};

View File

@@ -1,17 +1,17 @@
/* eslint-disable */
// @ts-ignore
import { request } from '@/utils/http'
import { CustomRequestOptions } from '@/interceptors/request'
import request from '@/utils/request';
import { CustomRequestOptions } from '@/interceptors/request';
import * as API from './types'
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
body: API.User;
options?: CustomRequestOptions;
}) {
return request<unknown>('/user', {
method: 'POST',
@@ -20,7 +20,7 @@ export async function createUser({
},
data: body,
...(options || {}),
})
});
}
/** Get user by user name GET /user/${param0} */
@@ -29,16 +29,16 @@ export async function getUserByName({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.getUserByNameParams
options?: CustomRequestOptions
params: API.getUserByNameParams;
options?: CustomRequestOptions;
}) {
const { username: param0, ...queryParams } = params
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} */
@@ -48,11 +48,11 @@ export async function updateUser({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.updateUserParams
body: API.User
options?: CustomRequestOptions
params: API.updateUserParams;
body: API.User;
options?: CustomRequestOptions;
}) {
const { username: param0, ...queryParams } = params
const { username: param0, ...queryParams } = params;
return request<unknown>(`/user/${param0}`, {
method: 'PUT',
@@ -62,7 +62,7 @@ export async function updateUser({
params: { ...queryParams },
data: body,
...(options || {}),
})
});
}
/** Delete user This can only be done by the logged in user. DELETE /user/${param0} */
@@ -71,16 +71,16 @@ export async function deleteUser({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.deleteUserParams
options?: CustomRequestOptions
params: API.deleteUserParams;
options?: CustomRequestOptions;
}) {
const { username: param0, ...queryParams } = params
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 */
@@ -88,8 +88,8 @@ export async function createUsersWithArrayInput({
body,
options,
}: {
body: API.User[]
options?: CustomRequestOptions
body: API.User[];
options?: CustomRequestOptions;
}) {
return request<unknown>('/user/createWithArray', {
method: 'POST',
@@ -98,7 +98,7 @@ export async function createUsersWithArrayInput({
},
data: body,
...(options || {}),
})
});
}
/** Creates list of users with given input array 返回值: successful operation POST /user/createWithList */
@@ -106,8 +106,8 @@ export async function createUsersWithListInput({
body,
options,
}: {
body: API.User[]
options?: CustomRequestOptions
body: API.User[];
options?: CustomRequestOptions;
}) {
return request<unknown>('/user/createWithList', {
method: 'POST',
@@ -116,7 +116,7 @@ export async function createUsersWithListInput({
},
data: body,
...(options || {}),
})
});
}
/** Logs user into the system GET /user/login */
@@ -125,8 +125,8 @@ export async function loginUser({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.loginUserParams
options?: CustomRequestOptions
params: API.loginUserParams;
options?: CustomRequestOptions;
}) {
return request<string>('/user/login', {
method: 'GET',
@@ -134,13 +134,17 @@ export async function loginUser({
...params,
},
...(options || {}),
})
});
}
/** Logs out current logged in user session 返回值: successful operation GET /user/logout */
export async function logoutUser({ options }: { options?: CustomRequestOptions }) {
export async function logoutUser({
options,
}: {
options?: CustomRequestOptions;
}) {
return request<unknown>('/user/logout', {
method: 'GET',
...(options || {}),
})
});
}

View File

@@ -0,0 +1,149 @@
/* 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 '@/interceptors/request';
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],
});
}

View File

@@ -78,31 +78,3 @@ export const httpPost = <T>(
http.get = httpGet
http.post = httpPost
/*
* openapi-ts-request 工具的 request 跨客户端适配方法
*/
export const request = <T = unknown>(
url: string,
options: Omit<CustomRequestOptions, 'url'> & {
params?: Record<string, unknown>
headers?: Record<string, unknown>
},
) => {
const requestOptions = {
url,
...options,
}
if (options.params) {
requestOptions.query = requestOptions.params
delete requestOptions.params
}
if (options.headers) {
requestOptions.header = options.headers
delete requestOptions.headers
}
return http<T>(requestOptions)
}

76
src/utils/request.ts Normal file
View File

@@ -0,0 +1,76 @@
import { CustomRequestOptions } from '@/interceptors/request'
/**
* 请求方法: 主要是对 uni.request 的封装,去适配 openapi-ts-request 的 request 方法
* @param options 请求参数
* @returns 返回 Promise 对象
*/
const http = <T>(options: CustomRequestOptions) => {
// 1. 返回 Promise 对象
return new Promise<T>((resolve, reject) => {
uni.request({
...options,
dataType: 'json',
// #ifndef MP-WEIXIN
responseType: 'json',
// #endif
// 响应成功
success(res) {
// 状态码 2xx参考 axios 的设计
if (res.statusCode >= 200 && res.statusCode < 300) {
// 2.1 提取核心数据 res.data
resolve(res.data as T)
} else if (res.statusCode === 401) {
// 401错误 -> 清理用户信息,跳转到登录页
// userStore.clearUserInfo()
// uni.navigateTo({ url: '/pages/login/login' })
reject(res)
} else {
// 其他错误 -> 根据后端错误信息轻提示
!options.hideErrorToast &&
uni.showToast({
icon: 'none',
title: (res.data as T & { msg?: string })?.msg || '请求错误',
})
reject(res)
}
},
// 响应失败
fail(err) {
uni.showToast({
icon: 'none',
title: '网络错误,换个网络试试',
})
reject(err)
},
})
})
}
/*
* openapi-ts-request 工具的 request 跨客户端适配方法
*/
export default function request<T = unknown>(
url: string,
options: Omit<CustomRequestOptions, 'url'> & {
params?: Record<string, unknown>
headers?: Record<string, unknown>
},
) {
const requestOptions = {
url,
...options,
}
if (options.params) {
requestOptions.query = requestOptions.params
delete requestOptions.params
}
if (options.headers) {
requestOptions.header = options.headers
delete requestOptions.headers
}
return http<T>(requestOptions)
}