getCloudPath(path) {
let result = 0
wx.cloud.uploadFile({
cloudPath: 'image/' + new Date().getTime() + "_" + Math.floor(Math.random() * 1000) + ".jpg",
filePath: path,
success: res => {
console.log("upload success", res.fileID)
result = res.fileID
}, fail: res => {
result = 0
}
})
return result
},
that.editorCtx.getContents({
success(res) {
wx.showLoading({ title: '发布中...', })
var html = res.html
if (res.text.trim()=="") {
wx.hideLoading()
that.setData({
showOneButtonDialog: true,
test_content1: '请添加文章内容'
})
} else {
for (var i = 0; i < that.data.imagelist_local.length; i++) {
if (html.indexOf(that.data.imagelist_local[i]) >= 0) {
let cloudpath = that.getCloudPath(that.data.imagelist_local[i])
html.replace(that.data.imagelist_local[i], cloudpath)
}
}
if(that.data.programid==''){
db.collection('Program').add({
data: {
title: e.detail.value.title,
html: html,
content: res.text,
datetime: util.formatTime(new Date()),
creater: app.globalData.csridinfo.StaffName,
id: that.data.index,
},
success: (res) => {
wx.showToast({
title: '发布成功',
})
}, fail: (res) => {
wx.showToast({
title: '发布失败',
icon: 'error'
})
}
})
}else{
db.collection('Program').doc(that.data.programid)
.update({
data:{
title: e.detail.value.title,
html: html,
content: res.text,
datetime: util.formatTime(new Date()),
id: that.data.index,
},success:(res)=>{
wx.showToast({
title: '发布成功',
})
},fail:(res)=>{
wx.showToast({
title: '发布失败',
icon: 'error'
})
}
})
}
}
}
})
学学async await promise吧 代码执行顺序不是你想的样子 必学 社区高频问题