|
@@ -20,7 +20,6 @@ module.exports = {
|
|
|
})
|
|
|
},
|
|
|
async afterRead(event) {
|
|
|
- const { form } = this.data
|
|
|
const { file } = event.detail
|
|
|
const { formkey, maxsize = '2' } = event.currentTarget.dataset
|
|
|
const maxSize = maxsize * 1024 * 1024
|
|
@@ -33,14 +32,13 @@ module.exports = {
|
|
|
wx.showToast({
|
|
|
title: '上传中',
|
|
|
icon: 'loading',
|
|
|
- duration: 600 * 1000
|
|
|
+ duration: 200000
|
|
|
})
|
|
|
|
|
|
const result = _file.map(async item => {
|
|
|
// 压缩图片时传入的路径
|
|
|
item.filePath = item.url
|
|
|
item.formkey = formkey
|
|
|
- // item.url = ''
|
|
|
|
|
|
const compressResult = item.size > maxSize ? await this.compressJs(item) : item
|
|
|
|
|
@@ -50,15 +48,17 @@ module.exports = {
|
|
|
try {
|
|
|
const res = await Promise.all(result)
|
|
|
|
|
|
- this.setData({
|
|
|
- ['form.' + formkey]: form[formkey].concat(...res)
|
|
|
- })
|
|
|
+ if (this.uploadCallBack) {
|
|
|
+ this.uploadCallBack(res)
|
|
|
+ }
|
|
|
+
|
|
|
wx.showToast({
|
|
|
title: '上传成功',
|
|
|
icon: 'success',
|
|
|
duration: 2000
|
|
|
})
|
|
|
} catch (err) {
|
|
|
+ console.log(err)
|
|
|
wx.showToast({
|
|
|
title: '上传出错',
|
|
|
icon: 'none',
|
|
@@ -74,5 +74,53 @@ module.exports = {
|
|
|
this.setData({
|
|
|
['form.' + formkey]: this.data.form[formkey]
|
|
|
})
|
|
|
+ },
|
|
|
+ async uploadImg(event) {
|
|
|
+ const { formkey, maxsize = '2' } = event.currentTarget.dataset
|
|
|
+ const maxSize = maxsize * 1024 * 1024
|
|
|
+
|
|
|
+ try {
|
|
|
+ const { errMsg, tempFiles } = await wx.chooseImage({
|
|
|
+ count: 1,
|
|
|
+ sizeType: ['original', 'compressed']
|
|
|
+ })
|
|
|
+
|
|
|
+ if (errMsg === 'chooseImage:ok') {
|
|
|
+ wx.showToast({
|
|
|
+ title: '上传中',
|
|
|
+ icon: 'loading',
|
|
|
+ duration: 200000
|
|
|
+ })
|
|
|
+ const result = tempFiles.map(async item => {
|
|
|
+ item.filePath = item.path
|
|
|
+ item.formkey = formkey
|
|
|
+
|
|
|
+ const compressResult = item.size > maxSize ? await this.compressJs(item) : item
|
|
|
+ return handleUpload(compressResult)
|
|
|
+ })
|
|
|
+
|
|
|
+ try {
|
|
|
+ const res = await Promise.all(result)
|
|
|
+
|
|
|
+ if (this.uploadCallBack) {
|
|
|
+ this.uploadCallBack(res)
|
|
|
+ }
|
|
|
+
|
|
|
+ wx.showToast({
|
|
|
+ title: '图片上传成功',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ } catch (err) {
|
|
|
+ console.log(err)
|
|
|
+ wx.showToast({
|
|
|
+ title: '图片上传出错',
|
|
|
+ icon: 'error',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ }
|
|
|
}
|
|
|
}
|