1.编辑器优化

2024.1.14 sws
master
sws 2024-01-15 10:48:41 +08:00
parent a1f860f0e7
commit e66c993bd7
2 changed files with 13 additions and 24 deletions

View File

@ -46,7 +46,8 @@
<view class="form-gorup">
<view class="form-gorup-title padding-right-main">内容<text class="form-group-tips-must">*</text></view>
<view class="margin-top-main sp-editor">
<sp-editor :templates="(data || null) !== null ? data.content : ''" @input="rich_text_event" @upinImage="up_in_image_event"></sp-editor>
<!-- <sp-editor :templates="(data || null) !== null ? data.content : ''" @input="rich_text_event" @upinImage="up_in_image_event"></sp-editor> -->
<sp-editor @init="initEditor" @input="rich_text_event" @upinImage="up_in_image_event"></sp-editor>
</view>
</view>
</view>
@ -304,13 +305,19 @@
//
rich_text_event(e) {
console.log('==== input :', e);
// console.log('==== input :', e);
var new_data = this.data;
new_data.content = e.html;
this.setData({
data: new_data,
});
},
initEditor(editor) {
//
editor.setContents({
html: (this.data || null) !== null ? this.data.content : '',
});
},
//
up_in_image_event(tempFiles, editorCtx) {

View File

@ -85,13 +85,6 @@
});
// #endif
},
watch: {
templates: function (new_val, old_val) {
if (new_val !== old_val) {
this.onEditorReady();
}
},
},
methods: {
onEditorReady() {
// #ifdef MP-BAIDU
@ -167,21 +160,8 @@
// count: 1, // 9
success: (res) => {
const { tempFiles } = res;
/**
* 使用uniCloud.uploadFile进行云存储时需要开启$emit('upinImage')事件
* 再注释掉insertImage否则在富文本中插入的图片都是本地路径
* 一般可能需要在传给父组件的upinImage事件中先遍历tempFiles
* 再用uploadFile拿到云存储的图片路径
* 最后将该路径insertImage到src属性中
* 这一过程等于是将下方注释掉的this.editorCtx.insertImage方法移到父组件中
* 由使用者在父组件中使用子传父的upinImage方法中的editorCtx参数手动调用editorCtx.insertImage操作
*/
//
this.$emit('upinImage', tempFiles, this.editorCtx);
/* this.editorCtx.insertImage({
src: tempFiles[0].path,
width: '80%',
success: function () {}
}) */
},
fail() {
uni.showToast({
@ -225,7 +205,9 @@
content: `超过${maxlength}字数啦~`,
confirmText: '确定',
showCancel: false,
success: ({ confirm, cancel }) => {},
success: () => {
this.$emit('overMax', { html, text });
},
});
} else {
this.$emit('input', { html, text });