上传组件upLoadImgComponent.wxml
<view class='upload_warp_img'>
<view class='img-preview-con' wx:for='{{imgList}}' wx:key="*this">
<image src='{{item}}' class='img-preview-url' mode='widthFix' data-id='{{index}}' catchtap="previewImage"></image>
<image src="/images/delImg.png" class='img-preview-del' data-id='{{index}}' catchtap="delImage"></image>
</view>
<view class='add-content' wx:if='{{imgList.length<maxNum}}'>
<view class='add-img' catchtap="chooseImage">
<image src="/images/addImg.png"></image>
<text>{{addText}}</text>
</view>
</view>
</view>
<view class='img-preview' wx:if='{{previewImg}}' catchtap='closePreview'>
<image src='{{previewImg}}' mode='widthFix'></image>
</view>
上传组件upLoadImgComponent.js
Component({
properties: {
addText:{
type:String,
value:'上传图片'
},
maxNum:{
type:Number,
value:1,
},
imgList:{
type:Array,
value:[],
}
},
data: {
imgList:[],
previewImg: '',
cvsList:[],
},
methods: {
chooseImage: function (e) {
let that = this;
let imgNum = that.properties.maxNum - that.data.imgList.length;
wx.chooseImage({
count: imgNum,
sizeType: 'compressed',
sourceType: ['album', 'camera'],
success(res) {
let imgUrl = res.tempFilePaths;
let imgList = that.data.imgList;
for (var i = 0; i < imgUrl.length; i++) {
imgList.push(imgUrl[i]);
}
that.setData({
imgList: imgList
})
that.triggerEvent("getImgList", imgList)
}
})
},
delImage: function (e) {
let that = this
let index = e.currentTarget.dataset.id;
wx.showModal({
title: '提示',
content: '确定要删除该图片吗?',
showCancel: true,
success: function (res) {
if (res.confirm) {
console.log(index);
let imgList = that.data.imgList;
imgList.splice(index, 1);
that.setData({
imgList: imgList,
});
that.triggerEvent("delImg", that.data.imgList)
}
}
})
},
previewImage: function (e) {
let that = this
let index = e.currentTarget.dataset.id;
that.setData({
showTxtarea: false,
previewImg: that.data.imgList[index],
});
},
closePreview: function () {
this.setData({
showTxtarea: true,
previewImg: '',
});
},
}
})
上传组件upLoadImgComponent.wxss
.upload_warp_img {
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
margin-top: 30rpx;
}
.upload_warp_img view {
margin-bottom: 30rpx;
}
.img-preview-con {
margin: 10rpx;
width: 40vw;
height: 210rpx;
position: relative;
overflow: hidden;
}
.img-preview-con .img-preview-url {
width: 100%;
}
.img-preview-del {
position: absolute;
right: 0;
top: 0;
width: 50rpx;
height: 50rpx;
z-index: 90;
}
.add-content {
width: 40vw;
height: 210rpx;
}
.add-content image {
width: 100%;
height: 100%;
}
.add-content .add-img {
width: 100%;
background: #efefef;
height: 100%;
padding: 20rpx;
box-sizing: border-box;
text-align: center;
border-radius: 16rpx;
margin: 10rpx;
}
.add-content .add-img text{
display: block;
font-size: 30rpx;
color: #C9C9C9;
}
.add-content .add-img image {
width: 34%;
height: 34%;
margin-top: 10%;
}
.img-preview-cvs-con{
display: flex;
position: absolute;
bottom: 0;
left: 100%;
}
.img-preview-cvs {
margin-right: 40rpx;
width: 190rpx;
height: 190rpx;
}
.img-preview-cvs canvas {
width: 100%;
height: 100%;
}
.img-preview{
width: 100%;
height: 100%;
position: fixed;
left: 0;
top: 0;
background: #000;
z-index: 100;
padding: 5%;
box-sizing: border-box;
display: flex;
align-items: center;
}
.img-preview image{
width: 100%;
display: block;
margin-top: -25%;
}
.result-con{
display: flex;
flex-direction: column;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)