博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
微信小程序杂技之---九宫格图片排版与操作
阅读量:2065 次
发布时间:2019-04-29

本文共 2875 字,大约阅读时间需要 9 分钟。

效果图

在这里插入图片描述

功能: 上传,删除,预览,九宫格,多张上传,单张上传
wxml
JS
Page({  data: {    imgList:[]  },   upload(e){  //上传图片    let that=this;    let imgList = that.data.imgList;    let count = 9-imgList.length;    wx.chooseImage({      count: count, // 默认9      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有      success: function (res) {        wx.showLoading({          title: '图片上传中',        })        // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片        var tempFilePaths = res.tempFilePaths        console.log(tempFilePaths)        let newDatas = {};        for (let keyName in datas) {          newDatas[keyName] = datas[keyName];        }        // 此处循环一个一个上传        for (let i = 0; i < tempFilePaths.length; i++) {        wx.uploadFile({          url: XXX, //仅为示例,非真实的接口地址          filePath: tempFilePaths[i],          name: '文件名字',          formData: newDatas,          success: function (res) {            console.log("res",res)            let datas = JSON.parse(JSON.parse(res.data).data);            console.log(datas)            // 图片展示所用            let imgList = that.data.imgList;            if (datas.code==200){              imgList.push(datas.response.file_path)              that.setData({                imgList              })                       wx.hideLoading();            }else{              wx.hideLoading();              wx.showModal({                title: '提示',                content: ‘失败’,                showCancel: false              })             }            //do something          }        })      }      },      fail:function(err){        console.log(err);      }    })      },    preview(e){  //预览图片    let img = e.currentTarget.dataset.src;    let imgList = this.data.imgList;    imgList.push(img);    wx.previewImage({      current: img, // 当前显示图片的http链接      urls: imgList// 需要预览的图片http链接列表    })  },    delImg(e){  //删除图片    let that = this;    console.log('点击删除图片===>',e);    let index = e.currentTarget.dataset.index;    let imgList = that.data.imgList;    wx.showModal({      title: '提示',      content: '删除该图片?',      confirmColor:'red',      success (res) {        if (res.confirm) {          console.log('用户点击确定')          imgList.splice(index,1);          that.setData({            imgList          })        } else if (res.cancel) {          console.log('用户点击取消')        }      }    })  }  )}
wxss
.img_box{  display: flex;  flex-wrap: wrap;  margin: 20rpx;  width: 100%;}.img_item_i{  display: block;  width: 100%;  height: 100%;}.add_icon{  display: block;  width: 50%;  height: 50%;}.img_item {  width: 30%;  height: 210rpx;  position: relative;  margin-right: 2%;  margin-bottom: 2%;  border: 1px solid #c0ccda;} .closeImv {  position: absolute;  right: 0rpx;  top: 0rpx;  width: 50rpx;  height: 50rpx;}

转载地址:http://ikzmf.baihongyu.com/

你可能感兴趣的文章
配置 containerd 镜像仓库完全攻略
查看>>
Kubernetes Pod 突然就无法挂载 Ceph RBD 存储卷了。。
查看>>
什么?WireGuard 可以让躲在 NAT 后面的客户端之间直连了??
查看>>
k8s集群内的节点,可能没你想象的那么健壮!(磁盘管理篇)
查看>>
利用 ebpf sockmap/redirection 提升 socket 性能(2020)
查看>>
春节前最后一波福利,Alibaba Java 训练营]5天突破面向对象编程限时免费报名!...
查看>>
我就要在容器里写文件!?
查看>>
支付宝集五福最全攻略,五分钟集齐五福!
查看>>
Runc 容器初始化和容器逃逸
查看>>
使用 GDB + Qemu 调试 Linux 内核
查看>>
介绍一个小工具:SSL-exporter
查看>>
深入理解 tc ebpf 的 direct-action (da) 模式(2020)
查看>>
为容器时代设计的高级 eBPF 内核特性(FOSDEM, 2021)
查看>>
Loki系列文章
查看>>
字节跳动面试官问:微服务下如何保证分布式事务的最终一致性?
查看>>
使用 Prometheus 监控 WireGuard
查看>>
BPF 可移植性和 CO-RE(一次编译,到处运行)
查看>>
万字长文:彻底搞懂容器镜像构建
查看>>
GitHub 又又又多了一个新主题 —— Dimmed Dark 主题!
查看>>
cgroup 挂载失败是什么鬼???
查看>>