var app = getApp();
Component({
properties: {
html: {
value: "",
type: String,
},
placeholder: {
value: "介绍一下你的活动详情吧,支持文字和图片...",
type: String,
}
},
data: {
formats: {},
bottom: 0,
readOnly: false,
_focus: false,
html: null,
act_location:'',
act_title:'',
act_member:'',
title:'',
imgSrc:''
},
getHtml: function(e) {
console.log("hqhtml", e.detail.html)
},
methods: {
readOnlyChange() {
this.setData({
readOnly: !this.data.readOnly
})
},
onLoad() {
this.setData({
html:app.globalData.html
})
},
onLoad: function (options) {
const db = wx.cloud.database({
env: 'huodongxingqiu-6g8n0q7s0e028ff9'
})
db.collection('ACT_INFO').get({
success: res => {
console.log(res.data)
this.setData({
array: res.data
})
}
})
},
act_title(event) {
console.log(event.detail);
this.setData({
act_title:event.detail.value,
})
},
act_location(loca) {
console.log(loca.detail);
this.setData({
act_location:loca.detail.value,
})
},
onEditorReady: function() {
const that = this;
that.createSelectorQuery().select('#editor').context(function(res) {
that.editorCtx = res.context;
}).exec();
},
undo() {
this.editorCtx.undo();
},
redo() {
this.editorCtx.redo();
},
format(e) {
let {
name,
value
} = e.target.dataset;
if (!name) return;
this.editorCtx.format(name, value);
},
onStatusChange(e) {
const formats = e.detail;
this.setData({
formats
});
},
insertDivider() {
this.editorCtx.insertDivider({
success: function() {
console.log('insert divider success')
}
});
},
clear() {
this.editorCtx.clear({
success: function(res) {
console.log("clear success")
}
});
},
removeFormat() {
this.editorCtx.removeFormat();
},
insertDate() {
const date = new Date()
const formatDate = `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`
this.editorCtx.insertText({
text: formatDate
});
},
insertActImage() {
wx.chooseImage({
count: 1,
success: chooseResult => {
wx.cloud.uploadFile({
cloudPath:'images/Act_info/'+this.data.act_title+'.png',
filePath: chooseResult.tempFilePaths[0],
config: {
env: this.data.envId
}
}).then(res => {
console.log('上传成功', res);
this.setData({
imgSrc: res.fileID
});
app.globalData.imagesSrc = res.fileID
wx.hideLoading();
}).catch((e) => {
console.log(e);
wx.hideLoading();
});
},
});
},
onimgEditorReady: function() {
const that = this;
that.createSelectorQuery().select('#imgeditor').context(function(res) {
that.ditorCtx = res.context;
}).exec();
},
chooseImage(e) {
console.log("图片-----", e)
wx.chooseImage({
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: res => {
const images = this.data.Actimages.concat(res.tempFilePaths);
this.data.images = images.length <= 3 ? images : images.slice(0, 3);
console.log(this.data.images)
}
})
},
insertImage() {
wx.chooseImage({
count: 6,
success: (res) => {
var base64 = "data:image/png;base64," + wx.getFileSystemManager().readFileSync(res.tempFilePaths[0], "base64")
this.editorCtx.insertImage({
src: base64,
width: '100%',
data: {
id: 'abcde',
role: 'gods'
},
success: () => {
console.log('insert image success')
}
})
}
});
},
onimgEditorReady: function() {
const that = this;
that.createSelectorQuery().select('#editor').context(function(res) {
that.ditorCtx = res.context;
}).exec();
},
chooseImage(e) {
console.log("图片-----", e)
wx.chooseImage({
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: res => {
const images = this.data.images.concat(res.tempFilePaths);
this.data.images = images.length <= 3 ? images : images.slice(0, 3);
console.log(this.data.images)
}
})
},
toDeatil() {
this.editorCtx.getContents({
success: (res) => {
this.triggerEvent('getHtml', {
html: res.html
})
app.globalData.html = res.html
},
fail: (res) => {
console.log("fail:", res);
}
});
},
toImgDeatil() {
this.editorCtx.getContents({
success: (res) => {
this.triggerEvent('getImg', {
act_title: res.Img
})
app.globalData.act_img = res.Img
},
fail: (res) => {
console.log("fail:", res);
}
});
},
clickLogText() {
this.editorCtx.getContents({
success: (res) => {
app.globalData.act_title = this.data.act_title
app.globalData.act_location = this.data.act_location
app.globalData.act_img = this.data.images
console.log(app.globalData.html)
wx.navigateTo({
url: '/pages/me/release_act/preview/preview'
})
},
fail: (res) => {
console.log("fail:" , res);
}
});
const db = wx.cloud.database({
env: 'huodongxingqiu-6g8n0q7s0e028ff9'
})
db.collection('ACT_INFO').add({
data:{
Act_ID: app.globalData.act_title,
Act_subject: '公益活动',
Act_comment:app.globalData.html,
Act_data_start:'',
Act_data_end:'',
Act_location:app.globalData.act_location,
Act_menber:'',
Act_picture_url:app.globalData.imagesSrc,
},
success:function(res){
成功回调
}
})
},
},
})
那就做拆分去上传
超过单条记录的容量限制的吧,图片可以存云存储,数据库记录fileID