首先选择图片,然后循环,再就是在点击发布的时候循环图片地址赋值,包括删除命令

js代码:

  //选择图片
uploadImgAdd: function(e) {
var imgs = this.data.imgs;
console.log(imgs)
wx.chooseImage({
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
console.log(res)
let tempFilePaths = res.tempFilePaths;
let imgs = this.data.imgs;
console.log('imgs')
console.log(imgs)
//上传的图片
for (var i = 0; i < tempFilePaths.length; i++) {
if (imgs.length >= 9) {
return false;
} else {
imgs.push(tempFilePaths[i])
}
}
//上传的图片放到页面上
this.setData({
imgs: imgs
})
}
})
}, /**
* 获取上传图片地址
*/
//单击发布上传图片和内容
bindFormSubmit: function(e) {
var imgArr = this.data.imgs;
this.addPic(e, imgArr)
},
addPic: function(e, imgArr) {
console.log("imgArr")
console.log(imgArr) let uploadimagsSrc = this.data.uploadimagsSrc;
console.log("uploadimagsSrc")
console.log(uploadimagsSrc)
for (let i in imgArr) {
wx.uploadFile({
url: app.data.urls + 'images/Picture',
filePath: imgArr[i],
header: {
'content-type': 'multipart/form-data'
},
name: 'file',
success: res => {
console.log(res)
let data = res.data;
console.log(data)
console.log([...uploadimagsSrc, data])
uploadimagsSrc = [...uploadimagsSrc, data];
console.log(uploadimagsSrc)
this.setData({
uploadimagsSrc: uploadimagsSrc
})
},
})
} let timer = setInterval(() => {
//间歇调用
if (uploadimagsSrc.length == imgArr.length) {
console.log(uploadimagsSrc)
console.log(imgArr)
debugger
this.sendMessageInfo(e, uploadimagsSrc);
clearInterval(timer); //可取消由 setInterval() 函数设定的定时执行操作
}
}, 500)
},
sendMessageInfo: function(e, imagsSrc) {
var formData = e.detail.value.message
if (formData.length == 0) {
wx.showToast({
title: '意见反馈内容不能为空,说几句话吧~',
icon: 'none',
duration: 1500
})
return false;
}
var replaceLeftRig = formData.replace(/(^\s*)|(\s*$)/g, "").length
if (replaceLeftRig < 15) {
wx.showToast({
title: '意见反馈内容不能少于15个字',
icon: 'none',
duration: 1500
})
return false;
}
imagsSrc = imagsSrc.join(';')
wx.request({
url: app.data.urls + 'feedback/insertCustomerFeedback',
data: {
"customerId": app.data.customerId,
"feedbackMessages": formData,
"imagesAddress": imagsSrc,
},
method: "POST",
header: {
'content-type': 'application/json' // 默认值
},
success: function(res) {
console.log(res)
/**
*
* 异常判断
*
*
*/
if (res.data.status == 200) {
wx.showModal({
content: '谢谢您提交的反馈,后台的小哥哥会第一时间收到哦~',
showCancel: false,
confirmText: "知道了",
success: function(res) {
if (res.confirm) {
wx.navigateBack({
delta: 1
})
}
}
});
} else {
wx.showModal({
content: '系统繁忙',
showCancel: false,
confirmText: "知道了",
success: res => {
console.log(res)
}
});
} }
})
}, //删除图片
uploadImgClose: function(e) {
var imgs = this.data.imgs;
var index = e.currentTarget.dataset.index;
imgs.splice(index, 1);
this.setData({
imgs: imgs
});
// console.log(imgs)
}, feedBack/feedBack

微信小程序 上传图的功能的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

  7. 微信小程序上传文件遇到的坑

    在开发小程序时,使用的花生壳做的内网映射,域名使用花生壳卖的https域名 在做小程序文件上传时,调用接口,老是报错. Caused by: org.apache.commons.fileupload ...

  8. 微信小程序-上传下载

    wx.uploadFile(OBJECT) 上传 将本地资源上传到开发者服务器.如页面通过 wx.chooseImage(图片)/wx.chooseVideo(视频) 等接口获取到一个本地资源的临时文 ...

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

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

随机推荐

  1. CentOS 7 安装配置MySQL

    环境 CentOS Linux release 7.5.1804 (Core) MySQL:mysql80-community-release-el7-1 检查: 在centos7中默认的是maria ...

  2. 基于better-scroll封装一个上拉加载下拉刷新组件

    1.起因 上拉加载和下拉刷新在移动端项目中是很常见的需求,遂自己便基于better-scroll封装了一个下拉刷新上拉加载组件. 2.过程 better-scroll是目前比较好用的开源滚动库,提供很 ...

  3. man帮助命令

    linux系统提供可比较丰富的帮助手册,man是manual(说明书)的缩写,在日常的linux系统管理中经常会用到. 语法: man(选项)(参数) 选项: -a:在所有的man帮助手册中搜索: - ...

  4. c 最简单的链表

    #include <stdio.h> struct node { int data; struct node *next; //指向本身的指针 }; // main() { struct ...

  5. static和extern的作用域--题目

    #include <stdio.h> ; int main(void) { , sum = , count = ; ,count++) // count = 2 { ; count++; ...

  6. elasticsearch的安装和使用

    准备环境: 环境: win7 64位  jdk1.8.0  elasticsearch2.3.3 elasticsearch2.3.3:https://www.elastic.co/thank-you ...

  7. css3特效第二篇--行走的线条&&置顶导航栏

    一.行走的线条. 效果图(加载可能会慢一点儿,请稍等...): html代码: <div class="movingLines"> <img src=" ...

  8. Spring IoC容器实现

    1,Spring的两种IoC容器 BeanFactory 基础类型的IoC容器: 采用延迟初始化策略(容器初始化完成后并不会创建bean的对象,只有当收到初始化请求时才进行初始化): 由于延迟初始化, ...

  9. 洛谷 P3133 [USACO16JAN]无线电联系Radio Contact

    P3133 [USACO16JAN]无线电联系Radio Contact 题目描述 Farmer John has lost his favorite cow bell, and Bessie the ...

  10. EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER

    EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER ...