|
@@ -17,6 +17,7 @@ Page({
|
|
|
tempFilePath: [],
|
|
|
imgId: [],
|
|
|
textValue: '',
|
|
|
+ upload: true
|
|
|
//type: '',
|
|
|
//columnType: ''
|
|
|
},
|
|
@@ -34,61 +35,68 @@ Page({
|
|
|
* 图片上传
|
|
|
*/
|
|
|
uploading: function () {
|
|
|
- var that = this;
|
|
|
- wx.chooseImage({
|
|
|
- count: 2, //最多可以选择的图片总数
|
|
|
- sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
|
- sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
|
|
|
- success: function (res) {
|
|
|
- // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
|
|
|
- var tempFilePaths = res.tempFilePaths;
|
|
|
- //启动上传等待中...
|
|
|
- wx.showToast({
|
|
|
- title: '正在上传...',
|
|
|
- icon: 'loading',
|
|
|
- mask: true,
|
|
|
- duration: 1000
|
|
|
- })
|
|
|
- that.data.tempFilePath.push(tempFilePaths);
|
|
|
- that.setData({
|
|
|
- tempFilePath: that.data.tempFilePath
|
|
|
- })
|
|
|
- var uploadImgCount = 0;
|
|
|
- for (var i = 0, h = tempFilePaths.length; i < h; i++) {
|
|
|
- //上传文件
|
|
|
- wx.uploadFile({
|
|
|
- url: HOST + '/cms/file/upload',
|
|
|
- filePath: tempFilePaths[i],
|
|
|
- name: 'uploadfile_ant',
|
|
|
- header: {
|
|
|
- "Content-Type": "multipart/form-data"
|
|
|
- },
|
|
|
- success: function (res) {
|
|
|
- uploadImgCount++;
|
|
|
- let data = JSON.parse(res.data);
|
|
|
- that.data.imgId.push(data.data.id)
|
|
|
- that.setData({
|
|
|
- imgId: that.data.imgId,
|
|
|
- })
|
|
|
- console.log(data);
|
|
|
- //如果是最后一张,则隐藏等待中
|
|
|
- if (uploadImgCount == tempFilePaths.length) {
|
|
|
+ const that = this;
|
|
|
+ const length = that.data.tempFilePath.length;
|
|
|
+ if(length < 2) {
|
|
|
+ wx.chooseImage({
|
|
|
+ count: 2, //最多可以选择的图片总数
|
|
|
+ sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
|
+ sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
|
|
|
+ success: function (res) {
|
|
|
+ // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
|
|
|
+ var tempFilePaths = res.tempFilePaths;
|
|
|
+ //启动上传等待中...
|
|
|
+ wx.showToast({
|
|
|
+ title: '正在上传...',
|
|
|
+ icon: 'loading',
|
|
|
+ mask: true,
|
|
|
+ duration: 1000
|
|
|
+ })
|
|
|
+ that.data.tempFilePath.push(tempFilePaths);
|
|
|
+ that.setData({
|
|
|
+ tempFilePath: that.data.tempFilePath
|
|
|
+ })
|
|
|
+ var uploadImgCount = 0;
|
|
|
+ for (var i = 0, h = tempFilePaths.length; i < h; i++) {
|
|
|
+ //上传文件
|
|
|
+ wx.uploadFile({
|
|
|
+ url: HOST + '/cms/file/upload',
|
|
|
+ filePath: tempFilePaths[i],
|
|
|
+ name: 'uploadfile_ant',
|
|
|
+ header: {
|
|
|
+ "Content-Type": "multipart/form-data"
|
|
|
+ },
|
|
|
+ success: function (res) {
|
|
|
+ uploadImgCount++;
|
|
|
+ let data = JSON.parse(res.data);
|
|
|
+ that.data.imgId.push(data.data.id)
|
|
|
+ that.setData({
|
|
|
+ imgId: that.data.imgId,
|
|
|
+ })
|
|
|
+ console.log(data)
|
|
|
+ //如果是最后一张,则隐藏等待中
|
|
|
+ if (uploadImgCount == tempFilePaths.length) {
|
|
|
+ wx.hideToast();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
wx.hideToast();
|
|
|
+ wx.showModal({
|
|
|
+ title: '错误提示',
|
|
|
+ content: '上传图片失败',
|
|
|
+ showCancel: false,
|
|
|
+ success: function (res) { }
|
|
|
+ })
|
|
|
}
|
|
|
- },
|
|
|
- fail: function (res) {
|
|
|
- wx.hideToast();
|
|
|
- wx.showModal({
|
|
|
- title: '错误提示',
|
|
|
- content: '上传图片失败',
|
|
|
- showCancel: false,
|
|
|
- success: function (res) { }
|
|
|
- })
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ this.setData({
|
|
|
+ upload: false
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
//点击发送
|
|
|
send: function() {
|