Files
xk-doctor-wx/common/js/common.js
2025-02-13 10:31:01 +08:00

54 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export async function requestConfig(ins, options, successHandler = null, failHandler = null, completeHandler = null){
// base
ins.header = options.header || ins.header
//原来是ins.baseUrl = options.baseUrl || ins.baseUrl
let baseUrl = options.baseUrl || ins.baseUrl;
// config base
let config = {
url:`${baseUrl}${options.url?options.url:''}`,
header:ins.header
}
if(ins.requestInterceptor){
let _cg = null
// 合并请求拦截器配置
try {
_cg = await ins.requestInterceptor(Object.assign({}, options, config))
} catch (e){
return false
}
// config为false或null return
if(!_cg || typeof _cg !== 'object'){
return false
}
// 更新options
Object.assign(options, _cg)
config.url = options.url
config.header = options.header
}
const type = options.type || "request"
// config 详情 如果options没有直接使用删除props
if(type === "request"){
config["data"] = options.data || options.params || {}
config["method"] = options.method || "GET"
config["dataType"] = options.dataType || "json"
config["responseType"] = options.responseType || "text"
config['sslVerify'] = false
}else if(type === "upload"){
config["filePath"] = options.filePath
config["name"] = options.name
config["method"] = options.method || "POST"
config["formData"] = options.formData
// fileType for alipay
config["fileType"] = options.fileType || "image"
config['sslVerify'] = false
// 强制删除 Content-Type
delete config.header["Content-Type"]
}
return config
}
function _isPromise(obj) {
return obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'
}