Explorar o código

删除request

zhengnaiwen_citu hai 1 ano
pai
achega
797ad48eb1
Modificáronse 1 ficheiros con 0 adicións e 130 borrados
  1. 0 130
      src/utils/request.js

+ 0 - 130
src/utils/request.js

@@ -1,130 +0,0 @@
-import axios from 'axios'
-import { blobToJson } from '@/utils'
-import { getToken } from '@/utils/auth'
-import qs from 'qs'
-
-// create an axios instance
-const service = axios.create({
-  baseURL: import.meta.env.VITE_BASE_URL,
-  timeout: 120000 // request timeout
-})
-
-// request interceptor
-// 发送请求拦截器
-service.interceptors.request.use(
-  config => {
-    config.headers['tenant-id'] = import.meta.env.VITE_TENANTCODE
-    if (getToken()) {
-      config.headers.token = `Bearer ${getToken()}`
-      config.headers.Authorization = `Bearer ${getToken()}`
-    }
-    config.headers.token = `Bearer ${getToken()}`
-    return config
-  },
-  error => {
-    console.error(error)
-    return Promise.reject(error)
-  }
-)
-
-// 请求返回之后的拦截器
-service.interceptors.response.use(
-  async response => {
-    const res = response.data
-
-    if (response.request.responseType === 'blob') {
-      // 返回的文件流当报错时转化成json
-      if (response.headers['content-type'] === 'application/json') {
-        try {
-          const result = await blobToJson(res)
-          return Promise.reject(result.msg)
-        } catch (error) {
-          return Promise.reject(error)
-        }
-      }
-      const name = response.headers['content-disposition']
-      return {
-        data: res,
-        name: name ? decodeURI(name.replace('attachment;filename=', '')) : '未命名'
-      }
-    }
-
-    // if ([50008, 50012, 50014, 402000, 401].includes(res.code)) {
-    //   // 登录过期
-    //   return Promise.reject(res.msg)
-    // }
-    // // 登录验证码过期
-    // if (res.code === 60902) {
-    //   return Promise.reject(res)
-    // }
-    if (res.code !== 0) {
-      if (res.data) {
-        return Promise.reject(res)
-      }
-      return Promise.reject(res.msg)
-    }
-    return res
-  },
-  error => {
-    console.error(error)
-    return Promise.reject(error)
-  }
-)
-
-// 请求方法
-const http = {
-  post (url, params) {
-    return service.post(url, params, {
-      transformRequest: [(params) => {
-        return JSON.stringify(params)
-      }],
-      headers: {
-        'Content-Type': 'application/json'
-      }
-    })
-  },
-  get (url, params) {
-    return service.get(url, {
-      params: params,
-      paramsSerializer: (params) => {
-        return qs.stringify(params)
-      }
-    })
-  },
-  put(url, params) {
-    return service.put(url, params, {
-      transformRequest: [(params) => {
-        return JSON.stringify(params)
-      }],
-      headers: {
-        'Content-Type': 'application/json'
-      }
-    })
-  },
-  formData (url, params) {
-    return service.post(url, params, {
-      timeout: 600000,
-      headers: {
-        'Content-Type': 'application/x-www-form-urlencoded'
-      }
-    })
-  },
-  upload (url, params) {
-    return service.post(url, params, {
-      timeout: 600000,
-      headers: {
-        'Content-Type': 'multipart/form-data'
-      }
-    })
-  },
-  download (url, params) {
-    return service.post(url, params, {
-      timeout: 10000,
-      headers: {
-        'Content-Type': 'application/json'
-      },
-      responseType: 'blob'
-    })
-  }
-}
-export default http