Commit b41ec423 by 梁建民

格式化

parent c3026ab2
Showing with 43 additions and 40 deletions
...@@ -51,9 +51,9 @@ const getData = (url, type, param, callBack, loading, isheader) => { ...@@ -51,9 +51,9 @@ const getData = (url, type, param, callBack, loading, isheader) => {
wx.hideNavigationBarLoading(); wx.hideNavigationBarLoading();
if (loading) { if (loading) {
wx.hideLoading(); wx.hideLoading();
} }
}, },
fail: (err) => { fail: (err) => {
...@@ -65,53 +65,56 @@ const getData = (url, type, param, callBack, loading, isheader) => { ...@@ -65,53 +65,56 @@ const getData = (url, type, param, callBack, loading, isheader) => {
wx.hideNavigationBarLoading(); wx.hideNavigationBarLoading();
if (loading) { if (loading) {
wx.hideLoading(); wx.hideLoading();
} }
} }
}) })
}; };
//上传文件 //上传文件
const uploadFile = (url,paths,callBack) => { const uploadFile = (url, paths, callBack) => {
wx.showLoading({ wx.showLoading({
title: '上传中', title: '上传中',
mask:true mask: true
}) })
for (var i = 0; i < paths.length; i++) { for (var i = 0; i < paths.length; i++) {
wx.uploadFile({ wx.uploadFile({
url: url, url: url,
filePath: paths[i], filePath: paths[i],
name: 'upload', name: 'upload',
formData: { token: wx.getStorageSync('access_token'), source: 2}, formData: {
header: { token: wx.getStorageSync('access_token'),
"Content-Type": "multipart/form-data" source: 2
}, },
header: {
"Content-Type": "multipart/form-data"
},
success: (res) => { success: (res) => {
var data = JSON.parse(res.data); var data = JSON.parse(res.data);
if (data.errcode == 103200) { if (data.errcode == 103200) {
wx.showToast({ wx.showToast({
title: '上传成功', title: '上传成功',
icon: 'none', icon: 'none',
duration: 2000 duration: 2000
}); });
callBack(data.data[0]) callBack(data.data[0])
} else { } else {
wx.showToast({ wx.showToast({
title: '上传失败', title: '上传失败',
icon: 'none', icon: 'none',
duration: 2000 duration: 2000
}); });
} }
}, },
fail: (e) => { fail: (e) => {
console.log(e) console.log(e)
wx.showToast({ wx.showToast({
title: '上传失败', title: '上传失败',
icon: 'none', icon: 'none',
duration: 2000 duration: 2000
}); });
}, },
complete: () => { complete: () => {
wx.hideLoading(); wx.hideLoading();
...@@ -120,14 +123,14 @@ const uploadFile = (url,paths,callBack) => { ...@@ -120,14 +123,14 @@ const uploadFile = (url,paths,callBack) => {
} }
}; };
const chooseImg = (url,num, callback) => { const chooseImg = (url, num, callback) => {
wx.chooseImage({ wx.chooseImage({
count: num, count: num,
sizeType: ['original', 'compressed'], sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'], sourceType: ['album', 'camera'],
success: (res) => { success: (res) => {
uploadFile(url,res.tempFilePaths, (rtn) => { uploadFile(url, res.tempFilePaths, (rtn) => {
callback(rtn) callback(rtn)
}) })
} }
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment