wk
2024-06-13 9acf4430b2a93bd6db86908663fc843fce040429
api/index.js
@@ -1,4 +1,4 @@
import { fetch } from '@/api/request.js'
import { fetch,fetchId } from '@/api/request.js'
const typeObj = {
   headerGET: { 'Content-type': 'application/x-www-from-urlencoded' },
@@ -33,6 +33,20 @@
   opt.data = params
   return fetch(url, opt)
}
export const reqGetId = (url, params, opt = {}) => {
   opt.header = typeObj['headerGET']
   opt.method = 'GET'
   opt.data = params
   return fetchId(url, opt)
}
// urlParam是拼接路径的参数
export const reqGet2 = (url, params, opt = {}) => {
   // opt.header = typeObj['headerGET']
   // opt.method = 'GET'
   // let newUrl = `${url}/${params}`
   // return fetch(newUrl, opt)
}
// post请求
// urlType是指定拼接路径还是传json格式参数
@@ -59,3 +73,27 @@
   }
   return fetch(url, opt, urlType)
}
export const reqPut = (url, params, urlType, opt = {}) => {
   opt.method = 'Put'
   if (urlType == 'params') {
      Object.keys(params).map(item => {
         // 这里面不能用params.item,点运算符加标识符的形式取值,因为item是Object.keys生成的每一项键都是字符串,不是标识符,可以用[]的形式访问
         if (params[item] == null) {
            params[item] = ''
         }
      })
      opt.params = params
      opt.header = typeObj['headerPut']
   } else if (urlType == 'json') {
      opt.header = typeObj['jsonPut']
      opt.data = params
   } else if (urlType == 'utf8') {
      opt.header = typeObj['utfPOSt']
      opt.data = params
   } else {
      opt.data = params
      opt.header = typeObj['headerPut']
   }
   return fetch(url, opt, urlType)
}