Compare commits
No commits in common. '9463a158aa065ab3a5f38ac0000090797f5a5326' and 'a2c031743c1acabe4cf83b430f14f29cff17ad69' have entirely different histories.
9463a158aa
...
a2c031743c
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
@ -1,126 +0,0 @@ |
||||
var app = getApp(); //引入全局app.js,我们可以在globalData中定义一些公用的数据,比如baseUrl、token
|
||||
|
||||
const request = function(url, options) { |
||||
let header = { |
||||
'content-type': 'application/json;charset=utf-8' |
||||
}; |
||||
|
||||
if (app.globalData.token) { |
||||
header.Authorization = app.globalData.token; |
||||
} |
||||
// 检查外部传递的请求头是否存在
|
||||
if (options.header && typeof options.header === 'object') { |
||||
// 合并外部传递的请求头
|
||||
header = Object.assign({}, header, options.header); |
||||
} |
||||
return new Promise((resolve, reject) => { |
||||
wx.request({ |
||||
url: app.globalData.baseUrl + url, |
||||
method: options.method, |
||||
data: options.data, |
||||
header: header, |
||||
success: (res) => { |
||||
if (res.data.code == 500) { |
||||
wx.showModal({ |
||||
showCancel: false, |
||||
title: '提示', |
||||
content: res.data.message |
||||
}); |
||||
reject(res.data.message); |
||||
} else { |
||||
resolve(res); |
||||
} |
||||
}, |
||||
fail: (err) => { |
||||
reject(err); |
||||
} |
||||
}); |
||||
}); |
||||
}; |
||||
|
||||
const get = function(url, data, header) { |
||||
return request(url, { |
||||
method: "GET", |
||||
data, |
||||
header |
||||
}); |
||||
} |
||||
|
||||
const post = function(url, data, header) { |
||||
return request(url, { |
||||
method: "POST", |
||||
data, |
||||
header |
||||
}); |
||||
} |
||||
|
||||
|
||||
//上传图片文件
|
||||
const upImgFile = function(url, imgSrc) { |
||||
let header = { |
||||
// 'content-type': 'multipart/form-data'
|
||||
'content-type': 'application/json;charset=utf-8' |
||||
}; |
||||
|
||||
if (app.globalData.token) { |
||||
header.Authorization = app.globalData.token; |
||||
} |
||||
// 检查外部传递的请求头是否存在
|
||||
// if (options.header && typeof options.header === 'object') {
|
||||
// // 合并外部传递的请求头
|
||||
// header = Object.assign({}, header, options.header);
|
||||
// }
|
||||
return new Promise((resolve, reject) => { |
||||
|
||||
wx.uploadFile({ |
||||
url: app.globalData.baseUrl + url, |
||||
name: "file", |
||||
filePath: imgSrc, |
||||
header: header, |
||||
formData: { |
||||
"file": "upimagefile", |
||||
}, |
||||
success: function (res) { |
||||
if (res.data.code == 500) { |
||||
wx.showModal({ |
||||
showCancel: false, |
||||
title: '提示', |
||||
content: res.data.message |
||||
}); |
||||
reject(res.data.message); |
||||
} else { |
||||
resolve(res); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
// wx.request({
|
||||
// url: app.globalData.baseUrl + url,
|
||||
// method: options.method,
|
||||
// data: options.data,
|
||||
// header: header,
|
||||
// success: (res) => {
|
||||
// if (res.data.code == 500) {
|
||||
// wx.showModal({
|
||||
// showCancel: false,
|
||||
// title: '提示',
|
||||
// content: res.data.message
|
||||
// });
|
||||
// reject(res.data.message);
|
||||
// } else {
|
||||
// resolve(res);
|
||||
// }
|
||||
// },
|
||||
// fail: (err) => {
|
||||
// reject(err);
|
||||
// }
|
||||
// });
|
||||
}); |
||||
}; |
||||
|
||||
//暴露出去
|
||||
module.exports = { |
||||
get, |
||||
post, |
||||
upImgFile |
||||
}; |