跳到主要内容
Xeditor
用于在网页上编辑和格式化文本内容,支持多种字体、颜色、对齐方式、列表、表格等功能,可以插入图片、视频、链接等媒体资源。

说明

富文本组件不支持在search form搜索表单中使用。

示例

默认的xeditor

PCPhonePad
<page>
<actions>
<button
text="清除"
target="myEditor.clear"
/>
<button
text="确定"
status="primary"
target="myEditor.confirm"
/>
</actions>
<form x="myEditor"
label-size="0"
confirm-button="{{false}}"
clear-button="{{false}}"
@confirm="confimHandler"
>
<item
node="xeditor"
name="xeditor"
toolbarConfig="{{toolbarConfig}}"
editorConfig="{{editorConfig}}"
value="{{value}}"
colspan="{{6}}"
uploadImage_customInsert="{{customInsert}}"
uploadVideo_customInsert="{{customInsert}}"
/>
</form>
</page>


export default XPage({
data: {
toolbarConfig: {},
editorConfig: {
placeholder: '请输入',
MENU_CONF: {
uploadImage: {
fieldName: 'file',
server: '//testapi-nodedmallos.dmall.com/cabinx/file/upload',
withCredentials: true,
},
uploadVideo: {
fieldName: 'file',
server: '//testapi-nodedmallos.dmall.com/cabinx/file/upload',
withCredentials: true,
},
},
},
value: '',
},
show() {
},
confimHandler(data) {
console.info(data)
},
customInsert(res, insertFn) {
insertFn(res.url);
},
});



simple的xeditor

PCPhonePad
<page>
<actions>
<button
text="清除"
target="myEditor.clear"
/>
<button
text="确定"
status="primary"
target="myEditor.confirm"
/>
</actions>
<form x="myEditor"
label-size="0"
confirm-button="{{false}}"
clear-button="{{false}}"
@confirm="confimHandler">
<item
node="xeditor"
name="xeditor"
mode="simple"
toolbarConfig="{{toolbarConfig}}"
editorConfig="{{editorConfig}}"
value="{{value}}"
colspan="{{6}}"
uploadImage_customInsert="{{customInsert}}"
uploadVideo_customInsert="{{customInsert}}"
/>
</form>
</page>


export default XPage({
data: {
toolbarConfig: {},
editorConfig: {
placeholder: '请输入',
MENU_CONF: {
uploadImage: {
fieldName: 'file',
server: '//testapi-nodedmallos.dmall.com/cabinx/file/upload',
withCredentials: true,
},
uploadVideo: {
fieldName: 'file',
server: '//testapi-nodedmallos.dmall.com/cabinx/file/upload',
withCredentials: true,
},
},
},
value: '',
},
show() {
},
confimHandler(data) {
console.info(data)
},
customInsert(res, insertFn) {
insertFn(res.url);
},
});


Attributes

属性说明类型可选值默认值版本
name名称String----PC--
valuehtml值String----PC--
mode编辑器内置了两种模式,default:默认模式 - 集成了富文本所有功能,simple:简洁模式 - 仅有部分常见功能,但更加简洁易用Stringsimple/default'default'PC--
toolbarConfig工具栏配置,详细请参考三方组件wangEditor v5Object----PC--
editorConfig编辑器配置,详细请参考三方组件wangEditor v5Object----PC--
height高度,使用px等绝对值String----PC--
disabled禁用Boolean----PC--

TIPS:editorConfig在三方文档中配置为函数function类型的请全部使用组件xeditor的属性配置(属性名称为:父级key_函数key),在editorConfig中配置无效。图片和视频的customUpload在双线程不支持,其他非函数配置不变。 如上传图片和视频服务器返回结构不符合要求时可以使用customInsert自定义插入图片函数:


三方配置为:

editorConfig={
MENU_CONF:{
uploadImage:{
customInsert(res,insertFn){
insertFn(res.url);
}
},
uploadVideo:{
customInsert(res,insertFn){
insertFn(res.url);
}
},
}
}

需改为如下方式使用:

<item node="xeditor" uploadImage_customInsert="{{customInsert}}" uploadVideo_customInsert="{{customInsert}}"/>

Events

名称说明回调参数版本
changed值改变后触发(value)PC--
focus聚焦触发(editor)PC--
blur失焦触发(editor)PC--
maxLength达到 maxlength 限制时触发(editor)PC--
customAlert自定义编辑器 alert(info, type)PC--
customPaste自定义粘贴,粘贴时触发(editor,event,callback)PC--

Methods

名称说明入参返回版本
getEditor获取editor实例--{ instance:Object }PC--