123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import request from '../utils/request.js'
- class uploadImg extends request {
- static async uploadCommentImgs(tempFilePaths) {
- wx.showLoading({
- title: '上传图片中...',
- mask: true
- });
- var uploads = [];
- tempFilePaths.forEach((item, i) => {
- uploads[i] = request.upload(`${this.BASE_URL}Common/upload`, 'image', item)
- }
- );
- var imgUrls = [];
- Promise.all(uploads).then(res => {
- //图片上传完成
- // resolve(res)
- console.log(res)
- wx.hideLoading()
- res.forEach(function (item) {
- imgUrls.push(item.data.url)
- })
- return imgUrls;
- }).catch(err => {
- // reject(err)
- console.log(err)
- wx.hideLoading()
- wx.showToast({
- title: '上传失败请重试',
- icon: 'none'
- })
- })
- }
- static async uploadAvatar(tempFilePaths) {
- wx.showLoading({
- title: '上传图片中...',
- mask: true
- });
- const res = await request.upload(`${this.BASE_URL}Common/upload`, 'image', tempFilePaths)
- wx.hideLoading()
- return res.data.url
- }
- }
- export default uploadImg
|