You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.3 KiB
55 lines
1.3 KiB
export default class{
|
|
cookies = ""
|
|
constructor(){
|
|
|
|
}
|
|
processCookies(cookies){
|
|
if(cookies.constructor==String)
|
|
cookies = cookies.split(/,(?!\s)/g);
|
|
cookies = this.cookies = cookies.map(item => item.split(";")[0]).join(";");
|
|
return cookies;
|
|
}
|
|
request({url, data, header, method, dataType, responseType, success, fail, complete}) {
|
|
console.debug("wx.requests arguments", arguments[0], new Date().getTime());
|
|
return wx.request({
|
|
url,
|
|
data,
|
|
header: {...header, "Cookie": this.cookies},
|
|
method,
|
|
dataType,
|
|
responseType,
|
|
success: (res) => {
|
|
if (res.cookies && res.cookies.length)
|
|
this.processCookies(res.cookies);
|
|
if (res.header["Set-Cookie"])
|
|
this.processCookies(res.header["Set-Cookie"]);
|
|
success(res);
|
|
},
|
|
fail: fail,
|
|
complete: complete
|
|
});
|
|
}
|
|
uploadFile({url, filePath, name, header, formData, success, fail, complete}){
|
|
return wx.uploadFile({
|
|
url,
|
|
filePath,
|
|
name,
|
|
header: {"Cookie": this.cookies, ...header},
|
|
formData,
|
|
success,
|
|
fail,
|
|
complete
|
|
})
|
|
}
|
|
downloadFile({url, header, filePath, success, fail, complete}){
|
|
return wx.downloadFile({
|
|
url,
|
|
header: {...header, "Cookie": this.cookies},
|
|
filePath,
|
|
success,
|
|
fail,
|
|
complete
|
|
})
|
|
}
|
|
}
|