2018-12-24

详情示例见:https://www.cnblogs.com/cisum/p/9564898.html

2018-12-29

组件下载见:https://www.cnblogs.com/cisum/p/10199507.html

2019-3-14(推荐)

组件demo:https://www.cnblogs.com/cisum/p/10533559.html

index.js

  data: {
list: '',
upload_picture_list: []
},
//选择图片方法
uploadpic: function (e) {
var that = this //获取上下文
var upload_picture_list = that.data.upload_picture_list
//选择图片
wx.chooseImage({
count: 8,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
var tempFiles = res.tempFiles
//把选择的图片 添加到集合里
for (var i in tempFiles) {
tempFiles[i]['upload_percent'] = 0
tempFiles[i]['path_server'] = ''
upload_picture_list.push(tempFiles[i])
}
//显示
that.setData({
upload_picture_list: upload_picture_list,
});
}
})
},
//点击上传事件
uploadimage: function () {
var page = this
var upload_picture_list = page.data.upload_picture_list
//循环把图片上传到服务器 并显示进度
for (var j in upload_picture_list) {
if (upload_picture_list[j]['upload_percent'] == 0) {
      //调用函数
app.util.upload_file_server(app.api.up_pic,page, upload_picture_list, j)
}
}
}, // 删除图片
deleteImg: function(e) {
let upload_picture_list = this.data.upload_picture_list;
let index = e.currentTarget.dataset.index;
upload_picture_list.splice(index, 1);
this.setData({
upload_picture_list: upload_picture_list
});
},
   //上传方法
function upload_file_server(url, that, upload_picture_list, j) {
//上传返回值
const upload_task = wx.uploadFile({
// 模拟https
url: url, //需要用HTTPS,同时在微信公众平台后台添加服务器地址
filePath: upload_picture_list[j]['path'], //上传的文件本地地址
name: 'file',
formData: {
'num': j
},
//附近数据,这里为路径
success: function (res) { var data = JSON.parse(res.data);
// //字符串转化为JSON
if (data.Success == true) { var filename = data.file //存储地址 显示 upload_picture_list[j]['path_server'] = filename
} else {
upload_picture_list[j]['path_server'] = filename
}
that.setData({
upload_picture_list: upload_picture_list
}); wx.setStorageSync('imgs', upload_picture_list);
}
})
//上传 进度方法
upload_task.onProgressUpdate((res) => {
upload_picture_list[j]['upload_percent'] = res.progress
that.setData({
upload_picture_list: upload_picture_list
});
});
}

index.wxml

 <view class="picture_list">

     <view wx:for="{{upload_picture_list}}" class="picture_item" wx:key="{{index}}">
<image wx:if="{{item.upload_percent < 100}}" src="{{item.path}}" mode="aspectFill"></image>
<image wx:if="{{item.upload_percent == 100}}" src="{{item.path_server}}" mode="aspectFill"></image>
<view class="upload_progress" wx:if="{{item.upload_percent < 100}}" data-index="{{index}}" bindtap="previewImg">{{item.upload_percent}}%</view>
<text class='del' bindtap='deleteImg' data-src='{{image}}' style='display:{{isDel}}' data-index="{{index}}">×</text>
</view> <view class='picture_item'>
<view class="add-image" bindtap='uploadpic'>
<text>+</text>
</view>
</view>
</view>
<button bindtap='uploadimage' class='yes-upload'>确定上传</button>

index.wxss

 .add-image, .up-pic image {
margin-top: 2%;
margin-left: 2%;
width: 150rpx;
height: 150rpx;
color: #ddd;
font-size: 144rpx;
line-height: 95%;
text-align: center;
background-color: #fff;
cursor: pointer;
border-radius: 10rpx;
} .picture_list {
padding: 20rpx;
margin-left: 12%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
align-items: flex-start;
align-content: flex-start;
} .picture_item {
margin: 10px;
margin-left:;
position: relative;
width: 160rpx;
height: 160rpx;
} .picture_item .del {
position: absolute;
top: -11rpx;
right: -11rpx;
color: #fff;
border-radius: 50%;
width: 40rpx;
height: 40rpx;
z-index:;
line-height: 35rpx;
text-align: center;
background-color: #f00;
} .upload_progress {
position: absolute;
top:;
left:;
opacity: 0.7;
border-radius: 8rpx;
background-color: #000;
color: #fff;
width: 160rpx;
height: 160rpx;
text-align: center;
line-height: 160rpx;
font-size: 12px;
} .picture_item image {
width: 160rpx;
height: 160rpx;
}

app.api.x :是封装的各类请求url地址

app.util.x :是封装的函数,关于使用

1. 先util添加方法

2. app.js

3. 页面上调用,需要声明

后端php代码

<?php
class Imageadmin
{ public function imageupload()
{
//名字获取
$wxid=$_POST["num"];
//时间获取
$diaryTime=$_POST["datetime"];
//获取日期
$date = $_POST["date"];
$a = substr($_FILES['file']['type'],6);//获取图片后缀
//$a = strstr( $_FILES['file']['type'], '/');
$file_name=$date.'\\'.$diaryTime.'_'.$wxid.'.'.$a;//拼装存储地址path
$file_name1=$date.'/'.$diaryTime.'_'.$wxid.'.'.$a;//拼装图片浏览path
$path = "D:\www\File\\".$file_name;//存储path
$dir = iconv("UTF-8", "GBK","D:\www\File\\".$date);//判断文件夹是否存在
if (!file_exists($dir)){
mkdir ($dir,0777,true);//不存在 创建新文件夹
$panduan = move_uploaded_file($_FILES['file']['tmp_name'], $path);//存入图片
} else {
$panduan = move_uploaded_file($_FILES['file']['tmp_name'], $path);//存入已有文件夹内
}
//保存到指定路径 指定名字
if ($panduan){//存储成功
$res = ['errCode'=>0,'errMsg'=>'图片上传成功','file'=>$file_name1,'Success'=>true];
return json($res);
}else{//失败
$res = ['errCode'=>0,'errMsg'=>'图片上传失败','file'=>'https://127.0.0.1:80/xxxx.png','Success'=>!true];
return json($res);
}
} }
?>

微信小程序-上传多张图片加进度条(支持预览、删除)的更多相关文章

  1. 微信小程序上传多张图片,及php后台处理

    微信小程序上传多张图片,级小程序页面布局直接来代码index.wxml <view class='body' style='width:{{windowWidth}}px;height:{{wi ...

  2. 微信小程序上传Excel文本文件功能

    问题: 在开发过程中会发现微信小程序有很多功能都还不能满足我们的需求,谁叫客户就是上帝呢,前几天小编遇到了这么个问题,就是用微信小程序上传文件,但是还以为微信带有这个模块,可是查了许久还是没有找到,只 ...

  3. 微信小程序之上传多张图片

    之前写过一篇小程序商品发布的博客,里面有上传多张图片的功能,这里单独拿出来实现以下,小程序的upLoadFile一次只能上传一张图片,需要循环调这个接口来实现 for (var i = 0; i &l ...

  4. 微信小程序上传与下载文件

    需要准备的工作: ①.建立微信小程序工程,编写以下代码. ②.通过IDE建立springboot+web工程,编写接收文件以及提供下载文件的方式,并将上传的文件相关信息记录在mysql数据库中.具体请 ...

  5. 微信小程序上传后发布或者体验版测试无数据解决办法

    在做微信小程序开发的过程中,发现小程序在本地调用接口的数据都显示,但是上传之后,发现手机体验没有数据.以下为解决办法: 1.先清除缓存试试. 2.打开微信小程序工具右上角的详情——项目设置,将“不校验 ...

  6. Taro 微信小程序 上传文件到minio

    小程序前端上传文件不建议直接引用minio的js npm包,一来是这个包本身较大,会影响小程序的体积,二来是ak sk需要放到前端存储,不够安全,因此建议通过请求后端拿到签名数据后上传. 由于小程序的 ...

  7. 微信小程序-上传照片-多张显示

    图片就是一个简单的效果 实现 先看wxml和wxss代码 <view class='in-demand'> <view class='dema-title'> <text ...

  8. 微信小程序之wx.request:fail错误,真机预览请求无效问题解决,安卓,ios网络预览异常

    新版开发者工具增加了https检查功能:可使用此功能直接检查排查ssl协议版本问题: 可能原因:0:后台域名没有配置0.1:域名不支持https1:没有重启工具:2:域名没有备案,或是备案后不足24小 ...

  9. 微信小程序上传一或多张图片

    一.要点 1.选取图片 wx.chooseImage({ sizeType: [], // original 原图,compressed 压缩图,默认二者都有 sourceType: [], // a ...

随机推荐

  1. Python机器学习数据挖掘工具sklearn安装和使用

    python借助pip安装第三方库,所以首先确保电脑上已成功安装了pip. 安装sklearn前需要先安装numpy.scipy和pandas等库.安装的方式有两种: 一.前往python的组件库页( ...

  2. preg_replace_callback 正则替换回调方法用法,

    Example #1 preg_replace_callback() 和 匿名函数 <?php /* 一个unix样式的命令行过滤器,用于将段落开始部分的大写字母转换为小写. */ $fp = ...

  3. hdu6136[模拟+优先队列] 2017多校8

    有点麻烦.. /*hdu6136[模拟+优先队列] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long ...

  4. Sentinel系统监控Redis主从节点

    author:JevonWei 版权声明:原创作品 blog:http://119.23.52.191/ --- 构建Sentinel监控Redis的主节点架构 拓扑结构结构 拓扑环境 master ...

  5. HDU 3987 Harry Potter and the Forbidden Forest(边权放大法+最小割)

    Harry Potter and the Forbidden Forest Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65536/ ...

  6. 编程风格——UNIX 高手的 10 个习惯

    引言 当您经常使用某个系统时,往往会陷入某种固定的使用模式.有时,您没有养成以尽可能最好的方式做事的习惯.有时,您的不良习惯甚至会导致出现混乱.纠正此类缺点的最佳方法之一,就是有意识地采用抵制这些坏习 ...

  7. linux之tr

    通过使用 tr,您可以非常容易地实现 sed 的许多最基本功能.您可以将 tr 看作为 sed 的(极其)简化的变体:它可以用一个字符来替换另一个字符,或者可以完全除去一些字符.您也可以用它来除去重复 ...

  8. HDU3538 A sample Hamilton path

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  9. FCKEDITOR配置说明

    原文发布时间为:2009-10-12 -- 来源于本人的百度文章 [由搬家工具导入] fckeditor config.js配置2009-02-13 14:36 FCKConfig.CustomCon ...

  10. manjaro中okular中的pdf文件无法显示中文

    最近发现Manjaro下用Okular打开含有中文的PDF文档时,许多地方显示空白, 开始怀疑是中文字体问题,但是其他的软件中文显示都是正常的. 接着,调整Okular中的中文字体,显示还是不正常. ...