|
|
|
|
@ -5,6 +5,8 @@ Page({
|
|
|
|
|
* 页面的初始数据
|
|
|
|
|
*/
|
|
|
|
|
data: {
|
|
|
|
|
files: [],
|
|
|
|
|
newAddImg: [],
|
|
|
|
|
textVal: "",
|
|
|
|
|
loading: false,
|
|
|
|
|
subLoad: false,
|
|
|
|
|
@ -14,7 +16,125 @@ Page({
|
|
|
|
|
],
|
|
|
|
|
actived:0
|
|
|
|
|
},
|
|
|
|
|
chooseMedia () {
|
|
|
|
|
var that = this;
|
|
|
|
|
wx.chooseMedia({
|
|
|
|
|
count: 4,
|
|
|
|
|
mediaType: ['image'],
|
|
|
|
|
sizeType: ['original', 'compressed'],
|
|
|
|
|
sourceType: ['album', 'camera'],
|
|
|
|
|
success (res) {
|
|
|
|
|
// tempFilePath可以作为 img 标签的 src 属性显示图片
|
|
|
|
|
wx.showLoading({
|
|
|
|
|
title: '上传中...',
|
|
|
|
|
})
|
|
|
|
|
console.log(res);
|
|
|
|
|
var currData = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tempFilePaths = res.tempFiles;
|
|
|
|
|
tempFilePaths.forEach((item, index) => {
|
|
|
|
|
|
|
|
|
|
wx.uploadFile({
|
|
|
|
|
url: app.globalData.ip + "/imgs/uploadImage",
|
|
|
|
|
method: "post",
|
|
|
|
|
// data:currData,
|
|
|
|
|
// name: "uploadFile",
|
|
|
|
|
filePath: tempFilePaths[index].tempFilePath,
|
|
|
|
|
name: "uploadFile",
|
|
|
|
|
header: app.globalData.headers,
|
|
|
|
|
success: function (res) {
|
|
|
|
|
console.log(that.data.files);
|
|
|
|
|
console.log(JSON.parse(res.data).data);
|
|
|
|
|
|
|
|
|
|
that.data.files.push({ url: JSON.parse(res.data).data, id: -999 })
|
|
|
|
|
that.data.newAddImg.push(JSON.parse(res.data).data)
|
|
|
|
|
that.setData({
|
|
|
|
|
files: that.data.files,
|
|
|
|
|
newAddImg: that.data.newAddImg
|
|
|
|
|
})
|
|
|
|
|
// currData.data = JSON.parse(res.data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
that.pushImg();
|
|
|
|
|
// console.log(that.data.files);
|
|
|
|
|
|
|
|
|
|
// that.updateImgs(currData.type,currData.fkId,currData.data.data);
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
fail: function (res) {
|
|
|
|
|
console.log(res);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
delImgs (e) {
|
|
|
|
|
var that = this;
|
|
|
|
|
var url = e.currentTarget.dataset.url;
|
|
|
|
|
var id = e.currentTarget.dataset.id;
|
|
|
|
|
console.log(that.data.files)
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '提示',
|
|
|
|
|
content: '确定要删除该图片?',
|
|
|
|
|
confirmColor: '#00BEBE',
|
|
|
|
|
success (res) {
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
that.data.files.forEach((item, index) => {
|
|
|
|
|
if (item.url == url) {
|
|
|
|
|
that.data.files.splice(index, 1);
|
|
|
|
|
that.data.newAddImg.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
that.pushImg();
|
|
|
|
|
that.setData({
|
|
|
|
|
files: that.data.files,
|
|
|
|
|
newAddImg: that.data.newAddImg
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
} else if (res.cancel) {
|
|
|
|
|
console.log('用户点击取消')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
pushImg () {
|
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
|
|
console.log(that.data.files);
|
|
|
|
|
|
|
|
|
|
that.data.urls = [];
|
|
|
|
|
// that.data.files.forEach(item=>{
|
|
|
|
|
// that.data.urls.push(item.url)
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
let curr = [];
|
|
|
|
|
that.data.files.forEach(item => {
|
|
|
|
|
curr.push({ url: item.url, id: item.id })
|
|
|
|
|
})
|
|
|
|
|
that.setData({
|
|
|
|
|
urls: curr
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
showImgs (e) {
|
|
|
|
|
var that = this;
|
|
|
|
|
console.log(that.data.urls);
|
|
|
|
|
let curr = [];
|
|
|
|
|
that.data.urls.forEach(item => {
|
|
|
|
|
curr.push(item.url)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
wx.previewImage({
|
|
|
|
|
current: e.mark.url, // 当前显示图片的 http 链接
|
|
|
|
|
urls: curr // 需要预览的图片 http 链接列表
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
|
*/
|
|
|
|
|
@ -62,8 +182,8 @@ Page({
|
|
|
|
|
const that = this;
|
|
|
|
|
if (that.data.subLoad) return
|
|
|
|
|
that.data.subLoad = true
|
|
|
|
|
console.log(that.data.textVal)
|
|
|
|
|
|
|
|
|
|
console.log(that.data.newAddImg)
|
|
|
|
|
// return
|
|
|
|
|
// that.setData({
|
|
|
|
|
// success: true,
|
|
|
|
|
// loading: false,
|
|
|
|
|
@ -80,7 +200,9 @@ console.log(that.data.textVal)
|
|
|
|
|
method: 'post',
|
|
|
|
|
header: app.globalData.headers,
|
|
|
|
|
data: {
|
|
|
|
|
content: that.data.textVal
|
|
|
|
|
content: that.data.textVal,
|
|
|
|
|
actived: Number(that.data.actived + 1),
|
|
|
|
|
imgs:that.data.newAddImg.toString()
|
|
|
|
|
},
|
|
|
|
|
success: function (res) {
|
|
|
|
|
console.log(res);
|
|
|
|
|
|