// 默认url 地址携带 参数
const default_query={
pinUuid: store.getters.pinUuid,
ebiId: store.getters.ebiId
}
query=Object.assign(query, default_query)
url=urlQueryFormat(url, query)
data.pinUuid=store.getters.pinUuid
data=Object.assign(data, default_query)
// 过滤重复的请求 事件
// eslint-disable-next-line no-unused-vars
const repeat=messagelist.findRepeat(url, data, method)
// if (repeat.length > 0) {
// eslint-disable-next-line no-constant-condition
if (false) {
Message.warning(‘数据正在获取中, 请稍后…’)
return Promise.reject({ message: ‘数据正在获取中, 请稍后…’ })
} else {
// 获取 分配的 rid 即 index
const rid=messagelist.add(url, data, method)
return new Promise((resolve, reject)=> {
// eslint-disable-next-line prefer-const
let reqState={ url, method }
if (method.toLowerCase()===’get’) reqState[‘params’]=data
else if (method.toLowerCase()===’post’) {
reqState[‘data’]=data
if (type===’x_www_form_urlencoded’) {
request.defaults.headers.post[‘Content-Type’]=HttpConstant.FORM_DATA_REQ
let ret=”
for (const it in reqState) {
ret +=encodeURIComponent(it) + ‘=’ + encodeURIComponent(reqState[it]) + ‘&’
}
reqState[‘data’]=ret
} else if (type===’form_data’) {
request.defaults.headers.post[‘Content-Type’]=HttpConstant.MUL_FORM_REQ
} else if (type===’blob’) {
request.defaults.headers.post[‘Content-Type’]=HttpConstant.APPLICATION_BLOB_REQ
reqState.responseType=type
} else {
request.defaults.headers.post[‘Content-Type’]=HttpConstant.FORM_DATA_REQ
}
}
request(reqState).then(res=> {
// setTimeout(()=> { // 测试用 fortest
messagelist.del(rid)
resolve(res)
// }, 1000 * 2)
}).catch(err=> {
// 当请求错误 是否需要重新发包 网络错误等 处理
messagelist.del(rid)
reject(err)
})
})
}
}