Selaa lähdekoodia

fix: 去掉无用文件

liangan 2 viikkoa sitten
vanhempi
sitoutus
7168e7375b
3 muutettua tiedostoa jossa 1 lisäystä ja 75 poistoa
  1. 0 1
      openapi-ts-request.config.ts
  2. 1 0
      src/utils/http.ts
  3. 0 74
      src/utils/request.ts

+ 0 - 1
openapi-ts-request.config.ts

@@ -4,7 +4,6 @@ export default [
   {
     schemaPath: 'http://petstore.swagger.io/v2/swagger.json',
     serversPath: './src/service/app',
-    requestLibPath: `import request from '@/utils/request';\n import { CustomRequestOptions } from '@/interceptors/request';`,
     requestOptionsType: 'CustomRequestOptions',
     isGenReactQuery: true,
     reactQueryMode: 'vue',

+ 1 - 0
src/utils/http.ts

@@ -24,6 +24,7 @@ export function http<T>(options: CustomRequestOptions) {
             resolve(res.data as IResData<T>)
           }
           else if (res.data.code === '598') {
+            console.log('598', res.data)
             userStore.removeUserInfo()
             toast.error((res.data as IResData<T>).msg || (res.data as IResData<T>).message)
             const redirect = getLastPageUrl()

+ 0 - 74
src/utils/request.ts

@@ -1,74 +0,0 @@
-import type { CustomRequestOptions } from '@/interceptors/request'
-import { t } from '@/locale'
-import { toast } from './toast'
-
-/**
- * 请求方法: 主要是对 uni.request 的封装,去适配 openapi-ts-request 的 request 方法
- * @param options 请求参数
- * @returns 返回 Promise 对象
- */
-function 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.removeUserInfo()
-          // uni.navigateTo({ url: '/pages/login/login' })
-          reject(res)
-        }
-        else {
-          // 其他错误 -> 根据后端错误信息轻提示
-          !options.hideErrorToast
-          && toast.info((res.data as IResData<T>).msg || (res.data as IResData<T>).message || t('common.error.request'))
-          reject(res)
-        }
-      },
-      // 响应失败
-      fail(err) {
-        toast.error(t('common.error.network'))
-        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)
-}