chore: 优化代码结构,将 CustomRequestOptions 定义到 http/types.ts 下
This commit is contained in:
@@ -4,7 +4,7 @@ export default [
|
||||
{
|
||||
schemaPath: 'http://petstore.swagger.io/v2/swagger.json',
|
||||
serversPath: './src/service',
|
||||
requestLibPath: `import request from '@/http/vue-query';\n import { CustomRequestOptions } from '@/http/interceptor';`,
|
||||
requestLibPath: `import request from '@/http/vue-query';\n import { CustomRequestOptions } from '@/http/types';`,
|
||||
requestOptionsType: 'CustomRequestOptions',
|
||||
isGenReactQuery: true,
|
||||
reactQueryMode: 'vue',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { uniappRequestAdapter } from '@alova/adapter-uniapp'
|
||||
import type { IResponse } from './tools/types'
|
||||
import type { IResponse } from './types'
|
||||
import AdapterUniapp from '@alova/adapter-uniapp'
|
||||
import { createAlova } from 'alova'
|
||||
import { createServerTokenAuthentication } from 'alova/client'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { CustomRequestOptions } from '@/http/interceptor'
|
||||
import type { CustomRequestOptions } from '@/http/types'
|
||||
|
||||
export function http<T>(options: CustomRequestOptions) {
|
||||
// 1. 返回 Promise 对象
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import type { CustomRequestOptions } from '@/http/types'
|
||||
import { useUserStore } from '@/store'
|
||||
import { getEnvBaseUrl } from '@/utils'
|
||||
import { platform } from '@/utils/platform'
|
||||
import { stringifyQuery } from './tools/queryString'
|
||||
|
||||
export type CustomRequestOptions = UniApp.RequestOptions & {
|
||||
query?: Record<string, any>
|
||||
/** 出错时是否隐藏错误提示 */
|
||||
hideErrorToast?: boolean
|
||||
} & IUniUploadFileOptions // 添加uni.uploadFile参数类型
|
||||
|
||||
// 请求基准地址
|
||||
const baseUrl = getEnvBaseUrl()
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/**
|
||||
* 在 uniapp 的 RequestOptions 和 IUniUploadFileOptions 基础上,添加自定义参数
|
||||
*/
|
||||
export type CustomRequestOptions = UniApp.RequestOptions & {
|
||||
query?: Record<string, any>
|
||||
/** 出错时是否隐藏错误提示 */
|
||||
hideErrorToast?: boolean
|
||||
} & IUniUploadFileOptions // 添加uni.uploadFile参数类型
|
||||
|
||||
// 通用响应格式
|
||||
export interface IResponse<T = any> {
|
||||
code: number | string
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { CustomRequestOptions } from '@/http/interceptor'
|
||||
import type { CustomRequestOptions } from '@/http/types'
|
||||
import { http } from './http'
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable */
|
||||
// @ts-ignore
|
||||
import request from '@/http/vue-query';
|
||||
import { CustomRequestOptions } from '@/http/interceptor';
|
||||
import type { CustomRequestOptions } from '@/http/types';
|
||||
|
||||
import * as API from './types';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { queryOptions, useMutation } from '@tanstack/vue-query';
|
||||
import type { DefaultError } from '@tanstack/vue-query';
|
||||
import request from '@/http/vue-query';
|
||||
import { CustomRequestOptions } from '@/http/interceptor';
|
||||
import type { CustomRequestOptions } from '@/http/types';
|
||||
|
||||
import * as apis from './pet';
|
||||
import * as API from './types';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable */
|
||||
// @ts-ignore
|
||||
import request from '@/http/vue-query';
|
||||
import { CustomRequestOptions } from '@/http/interceptor';
|
||||
import type { CustomRequestOptions } from '@/http/types';
|
||||
|
||||
import * as API from './types';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { queryOptions, useMutation } from '@tanstack/vue-query';
|
||||
import type { DefaultError } from '@tanstack/vue-query';
|
||||
import request from '@/http/vue-query';
|
||||
import { CustomRequestOptions } from '@/http/interceptor';
|
||||
import type { CustomRequestOptions } from '@/http/types';
|
||||
|
||||
import * as apis from './store';
|
||||
import * as API from './types';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable */
|
||||
// @ts-ignore
|
||||
import request from '@/http/vue-query';
|
||||
import { CustomRequestOptions } from '@/http/interceptor';
|
||||
import type { CustomRequestOptions } from '@/http/types';
|
||||
|
||||
import * as API from './types';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { queryOptions, useMutation } from '@tanstack/vue-query';
|
||||
import type { DefaultError } from '@tanstack/vue-query';
|
||||
import request from '@/http/vue-query';
|
||||
import { CustomRequestOptions } from '@/http/interceptor';
|
||||
import type { CustomRequestOptions } from '@/http/types';
|
||||
|
||||
import * as apis from './user';
|
||||
import * as API from './types';
|
||||
|
||||
Reference in New Issue
Block a user