兴国资源网 Design By www.nnzcdc.com
本文实例为大家分享了微信小程序选择图片控件的具体代码,供大家参考,具体内容如下
xml:
<loading hidden="{{loadingHidden}}"> 加载中... </loading> <view class="add_carimg"> <block> <view class="load_iamge"> <text class="load_head_text">上传施工车辆照片</text> <text class="load_foot_text">{{imgbox.length}}/2</text> </view> <view class='pages'> <view class="images_box"> <block wx:key="imgbox" wx:for="{{imgbox}}"> <view class='img-box'> <image class='img' src='{{item}}' data-message="{{item}}" bindtap="imgYu"></image> <view class='img-delect' data-deindex='{{index}}' bindtap='imgDelete1'> <image class='img' src='/pages/images/delete_btn.png'></image> </view> </view> </block> <view class='img-box' bindtap='addPic1' wx:if="{{imgbox.length<2}}"> <image class='img' src='/pages/images/load_image.png'></image> </view> </view> </view> </block> </view> <view> <button class="work_btn" bindtap="shanggang">上岗</button> </view>
css:
.work_btn { width: 60%; height: 35px; line-height: 35px; margin-top: 15px; border-radius: 5px; font-size: 30rpx; color: white; background-color: rgb(2, 218, 247); } .work_btn:active { width: 60%; height: 35px; line-height: 35px; margin-top: 15px; border-radius: 5px; font-size: 30rpx; color: white; background-color: rgb(151, 222, 231); } /*********/ .load_iamge { width: 100%; height: 30px; margin-top: 10px; display: flex; flex-direction: row; } .load_head_text { width: 95%; height: 20px; margin-bottom: 5px; margin-top: 5px; } .load_foot_text { width: 5%; height: 20px; margin-right: 15px; margin-top: 5px; margin-bottom: 5px; float: right; } .pages { width: 98%; margin: auto; overflow: hidden; } /* 图片 */ .images_box { width: 100%; display: flex; flex-direction: row; flex-wrap: wrap; justify-content: flex-start; background-color: white; } .img-box { border: 2rpx; border-style: solid; border-color: rgba(170, 167, 167, 0.452); width: 200rpx; height: 200rpx; margin-left: 35rpx; margin-top: 20rpx; margin-bottom: 20rpx; position: relative; } /* 删除图片 */ .img-delect { width: 50rpx; height: 50rpx; border-radius: 50%; position: absolute; right: -20rpx; top: -20rpx; } .img { width: 100%; height: 100%; }
js:
Page({ /** * 页面的初始数据 */ data: { tempFilePaths: '', imgbox: [], //选择图片 fileIDs: [], //上传云存储后的返回值 src: 0, }, onLoad: function (options) { }, //图片点击事件 imgYu: function (event) { var that = this; console.log(event.target.dataset.message + "这是啥"); var src = event.target.dataset.message; //图片预览 wx.previewImage({ current: src, // 当前显示图片的http链接 urls: [src] // 需要预览的图片http链接列表 }) }, // 删除照片 && imgDelete1: function (e) { let that = this; let index = e.currentTarget.dataset.deindex; let imgbox = this.data.imgbox; imgbox.splice(index, 1) that.setData({ imgbox: imgbox }); }, // 删除照片 && imgDelete1: function (e) { let that = this; let index = e.currentTarget.dataset.deindex; let imgbox = this.data.imgbox; imgbox.splice(index, 1) that.setData({ imgbox: imgbox }); }, // 选择图片 &&& addPic1: function (e) { var imgbox = this.data.imgbox; console.log(imgbox) var that = this; var n = 2; if (2 > imgbox.length > 0) { n = 2 - imgbox.length; } else if (imgbox.length == 2) { n = 1; } wx.chooseImage({ count: n, // 默认9,设置图片张数 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: function (res) { // console.log(res.tempFilePaths) // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 var tempFilePaths = res.tempFilePaths console.log('路径' + tempFilePaths); if (imgbox.length == 0) { imgbox = tempFilePaths } else if (2 > imgbox.length) { imgbox = imgbox.concat(tempFilePaths); } that.setData({ imgbox: imgbox, imgnum: imgbox.length }); } }) }, //图片 imgbox: function (e) { this.setData({ imgbox: e.detail.value }) }, })
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
兴国资源网 Design By www.nnzcdc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
兴国资源网 Design By www.nnzcdc.com
暂无评论...
更新日志
2024年05月20日
2024年05月20日
- 张琍敏1978-雪中莲[台湾复刻版][WAV+CUE]
- 叶蕴仪1993-睡美人[日本版][WAV+CUE]
- 夜晚助兴音乐-群星《新时代床头音乐-性能量》2CD[WAV]
- 24K德国HD金碟《历届奥斯卡获奖金曲》3CD[WAV整轨]
- 邰正宵《重燃爱恋 贰 Walk On》[FLAC/分轨][431.72MB]
- 苏文劭《雨停出来走走》[320K/MP3][81.11MB]
- 苏文劭《雨停出来走走》[FLAC/分轨][210.76MB]
- 群星《2024好听新歌04》十倍音质WAV分轨
- 陈宁《弹指之间HQ》头版限量[低速原抓WAV+CUE]
- 陈宁《故人还》HQCDII限量签名版[低速原抓WAV+CUE]
- 苏文劭《春曲(Lessons)》[320K/MP3][39.8MB]
- 苏文劭《春曲(Lessons)》[FLAC/分轨][97.78MB]
- 群星《2006香港高级视听展原音精选 SACD》[ISO][2G]
- 张琍敏1977-枫林小雨[台湾复刻版][WAV+CUE]
- 林一峰2014-COOKINGMUSIC[香港首版][WAV+CUE]