微信小程序怎样制作上传图片功能,并可多选、查看和删除
Admin 2022-11-19 群英技术资讯 944 次浏览
这篇文章主要介绍了“微信小程序怎样制作上传图片功能,并可多选、查看和删除”相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇微信小程序怎样制作上传图片功能,并可多选、查看和删除文章都会有所收获,下面我们一起来看看吧。具体内容如下
用到的api
wx.chooseMedia(); 用于拍摄或从手机相册中选择图片或视频
功能:点击上传图片,可多选,或者拍照上传;点击图片放大查看;长按图片删除
效果图

json里面引用weui的组件uploader
{
"navigationBarTitleText": "评价工单",
"usingComponents": {
"mp-uploader": "weui-miniprogram/uploader/uploader",
"mp-cells": "weui-miniprogram/cells/cells",
"mp-cell": "weui-miniprogram/cell/cell"
}
}
wxml
<view class="weui-uploader">
<view class="img-v weui-uploader__bd">
<view class='pic' wx:for="{{technicianAssessPicture}}" wx:for-item="item" wx:key="*this">
<image class='weui-uploader__img ' src="{{item}}" data-index="{{index}}" mode="aspectFill" bindlongpress="deleteTechnician" bindtap="previewTechnician">
</image>
</view>
<view class="weui-uploader__input-box pic" bindtap="technicianImg"> </view>
</view>
</view>
js
data:(){
technicianAssessPicture: [], // 技师图片
}
// 上传技师图片
technicianImg: function (e) {
var that = this;
var technicianAssessPicture = this.data.technicianAssessPicture;
if (technicianAssessPicture.length >= 9) {
this.setData({
lenMore: 1
});
setTimeout(function () {
that.setData({
lenMore: 0
});
}, 2500);
return false;
}
wx.chooseMedia({
count: 9, // 默认9
mediaType: ['image','video'], // 文件类型
// image 只能拍摄图片或从相册选择图片
// video 只能拍摄视频或从相册选择视频
// sizeType: ['original', 'compressed'], //所选的图片的尺寸 original原图,compressed压缩图
// 仅对 mediaType 为 image 时有效,是否压缩所选文件
sourceType: ['album', 'camera'], //图片和视频选择的来源
maxDuration: 30, // 拍摄视频最长拍摄时间,单位秒。时间范围为 3s 至 60s 之间。不限制相册。
camera: 'back', // 仅在 sourceType 为 camera 时生效,使用前置或后置摄像头
// back 使用后置摄像头;front 使用前置摄像头
success: function (res) {
var tempFilePaths = res.tempFiles;
var technicianAssessPicture = that.data.technicianAssessPicture;
for (var i = 0; i < tempFilePaths.length; i++) {
if (technicianAssessPicture.length >= 9) {
that.setData({
technicianAssessPicture: technicianAssessPicture
});
return false;
} else {
const tempFilePaths1 = tempFilePaths.map(v=>v.tempFilePath)
// tempFilePaths数据是json数组,我们需要的是普通数组需要处理一下
technicianAssessPicture.push(tempFilePaths1[i]);
}
}
that.setData({
technicianAssessPicture: technicianAssessPicture
});
console.log(that.data.technicianAssessPicture, 'hhhhhhhhhhhhhhhhhhhhh');
}
});
},
处理后打印出来的数据

预览,删除
// 预览图片
previewTechnician: function (e) {
//获取当前图片的下标
var index = e.currentTarget.dataset.index;
//所有图片
var technicianAssessPicture = this.data.technicianAssessPicture;
wx.previewImage({
//当前显示图片
current: technicianAssessPicture[index],
//所有图片
urls: technicianAssessPicture
})
},
// 长按删除
deleteTechnician: function (e) {
var that = this;
var technicianAssessPicture = that.data.technicianAssessPicture;
var index = e.currentTarget.dataset.index; // 获取当前长按图片下标
wx.showModal({
// cancelColor: 'cancelColor',
title: '提示',
content: '确定要删除此图片吗?',
success: function (res) {
if (res.confirm) {
console.log('确定');
technicianAssessPicture.splice(index, 1);
} else if (res.cancel) {
console.log('取消');
return false;
}
that.setData({
technicianAssessPicture
})
}
})
},到此,关于“微信小程序怎样制作上传图片功能,并可多选、查看和删除”的学习就结束了,希望能够解决大家的疑惑,另外大家动手实践也很重要,对大家加深理解和学习很有帮助。如果想要学习更多的相关知识,欢迎关注群英网络,小编每天都会给大家分享实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
微信小程序中的下拉框怎样做?在实际的项目中,我们常会遇到实现下拉框效果的需求,今天我们就来了解一下怎样做一个简单的小程序中的select下拉框,这里使用到的是transform过渡,实现效果及代码如下。
目录累加/累积求最大/最小值格式化搜索参数反序列化搜索参数拉平嵌套数组实现 flat数组去重数组计数获取对象多个属性反转字符串不知道大家平常用 Reduce 多不多,反正本瓜用
这篇文章主要介绍了Nest.js 授权验证的方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
我们都知道监听器的作用是在每次响应式状态发生变化时触发,在组合式 API 中,我们可以使用 watch()函数和watchEffect()函数,下面我们来看下vue3如何进行数据监听watch/watchEffect,感兴趣的朋友一起看看吧
目录前言何为Promise.all?原生 Promise.all 测试手动实现Promise.all测试案例Promise.race原生 Promise.race 测试手写Promise.race测试案例Promise.any原生 Promise.any 测试手写Promise.any测试案例Promise.allSe
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008