var pages = getCurrentPages();
var content = this.data.content;
var attachments = this.data.attachments;
if (content.length == 0 && attachments.length == 1) {
wx.showModal({
content: '请输入发布文本或添加附件',
showCancel: false,
confirmText: "确定",
})
return;
}
if (pages.length >= 2) {
var prevPage = pages[pages.length - 2]; //上一个页面
var publishData = {};
if (content.length > 0) {
publishData.content = content;
}
if (attachments.length > 0) {
attachments.splice(attachments.length - 1, 1);
}
publishData.attachments = attachments;
//直接调用上一个页面的setData()方法,把数据存到上一个页面中去
prevPage.setData({
publishData: publishData
})
wx.navigateBack();
}