微信小程序多图片上传

html

<view class="list1">
    <view class="fonts">上传事件相关资料或文件(jpg/pdf/word)<text class="xuan">(选填)</text> </view>
    <view class="cell">
        <view class='jinList' wx:for="{{uploaderList}}" wx:key="index">
            <image class="close1" bindtap="close" data-index="{{index}}" src="../../images/close1.png"></image>
        <image class="jinListImg" wx:if="{{type != 'file'}}" bindtap='showImg' data-index="{{index}}" src='{{item}}'></image>
            <image class="jinListImg" src="../../images/img.png" wx:if="{{type == 'file'}}" mode="aspectFill"></image>
    </view>
    <view class="jia jia1" bindtap="upImg">
            <image src="../../images/jia.png"  wx:if="{{isHidden}}"></image>
        </view>
    </view>
</view>

js

data: {
    isHidden: true,//原始添加
    url: [],//上传文件路径
    type: '',//上传文件类型
    uploaderList: [],//上传文件数组
    showModal: false,
  },
// // 上传图片
  upImg() {
    var that = this
 
    wx.chooseMessageFile({
      count: 1,
      type: 'all',
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        //  console.log('vvvvvvvv',res.tempFiles)
 
        const tempFilePaths = res.tempFiles[0].path
        const type = res.tempFiles[0].type
        wx.uploadFile({
          url: app.globalData.urlSrc + '/api/chuan/index',
          filePath: tempFilePaths,
          name: 'file',
          success(res) {
            const datas = JSON.parse(res.data)
            console.log('上传文件', datas)
            var status = datas.status
            that.data.list
            if (status == 1) {
              var upFiles = datas.data
              if (upFiles != '') {
                let tempFile = tempFilePaths;
                let uploaderList = that.data.uploaderList.concat(tempFile);//返回页面的图片数据
                that.data.url = that.data.url.concat(upFiles);//传给后台的图片数据
                that.setData({
                  type: type,
                  uploaderList: uploaderList
                })
              }
            }
          }
        })
 
      }
    })
 
  },
 
  // 删除上传
  close(e) {
    var that = this
    var nowList = [];//新数据
    var uploaderList = that.data.uploaderList;//原数据
 
    for (let i = 0; i < uploaderList.length; i++) {
      if (i == e.currentTarget.dataset.index) {
        continue;
      } else {
        nowList.push(uploaderList[i])
      }
    }
    that.setData({
      uploaderList: nowList,
      isHidden: true
    })
  },

css

.list1 {
  width: 670rpx;
  margin: 0 auto;
}

.tops {
  display: flex;
  margin-bottom: 22rpx;
}

.left1 {
  margin-left: 12rpx;
  line-height: 44rpx;
  text-align: left;
}

.listImg1 {
  width: 44rpx;
  height: 44rpx;
  margin-left: 24rpx;
}

.textarea1 {
  width: 670rpx;
  height: 250rpx;
  line-height: 40rpx;
  border-radius: 44rpx;
  background-color: rgba(255, 255, 255, 1);
  color: rgba(16, 16, 16, 1);
  font-size: 14px;
  text-align: left;
  border: 1px solid rgba(240, 240, 240, 1);
  margin:0 auto;
  padding: 20rpx 40rpx;
  box-sizing: border-box;
  margin-bottom: 40rpx;
}
.jia{
  width: 140rpx;
  height: 140rpx;
  margin-top: 40rpx;
}
.jia image{
  width: 140rpx;
  height: 140rpx;
}
.cell {
  width: 100%;
  overflow: hidden;
}
.jinListImg {
  width: 140rpx;
  height: 140rpx;
  border-radius: 24rpx;
}

.close1 {
  width: 40rpx;
  height: 40rpx;
  position: absolute;
  margin-left: 100rpx;
}

.jia1 {
  float: left;
  position: relative;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序007

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值