kindeditor配置(kindeditor配置及功能实现详解[通俗易懂])

发布时间:2025-12-10 19:11:50 浏览次数:13

kindeditor配置及功能实现详解[通俗易懂]-kindeditor vue

kindeditor配置及功能实现详解[通俗易懂]”wordPathFormat”:”/public/uploads/word/{yyyy}{mm}{dd}/{time}{rand:6}”,/*上传保存路径,可以自定义保存路径和文件名格式*/”wordActionName”:”wordupload”,/*执行上传视频的action名称*/”wordAllowFiles”:[“.docx”]/*仅支持docx格式的word*/”wordFieldName”:”upfile”,/*提交的视频表单名称*/

1.编辑器修改 (可选)

1.1在ueditor/config.json中添加代码块

/*上传word配置*/

“wordActionName”: “wordupload”, /*执行上传视频的action名称*/

“wordFieldName”: “upfile”, /*提交的视频表单名称*/

“wordPathFormat”: “/public/uploads/word/{yyyy}{mm}{dd}/{time}{rand:6}”, /*上传保存路径,可以自定义保存路径和文件名格式*/

“wordMaxSize”: 102400000, /*上传大小限制,单位B,默认100MB */

“wordAllowFiles”: [“.docx”] /*仅支持docx格式的word */

1.2 修改编辑器配置文件

在ueditor\ueditor.config.js文件中,新增按钮名称”wordupload”,并添加鼠标悬浮提示

,labelMap:{

‘wordupload’: ‘上传word文件’,

}

1.2.1 对应 /ueditor/lang/**

en.js

‘wordupload’:{

‘exceedSizeError’: ‘File Size Exceed’,

‘exceedTypeError’: ‘File Type Not Allow’,

‘jsonEncodeError’: ‘Server Return Format Error’,

‘loading’:”loading…”,

‘loadError’:”load error”,

‘errorLoadConfig’: ‘Server config not loaded, upload can not work.’,

},

zh-cn.js

‘wordupload’:{

‘exceedSizeError’: ‘文件大小超出限制’,

‘exceedTypeError’: ‘文件格式不允许’,

‘jsonEncodeError’: ‘服务器返回格式错误’,

‘loading’:”正在上传…”,

‘loadError’:”上传错误”,

‘errorLoadConfig’: ‘后端配置项没有正常加载,上传插件不能正常使用!’

},

1.3 在ueditor\themes\default\images\目录下新增按钮图标”word_upload.png”:

在ueditor\themes\default\css\ueditor.css文件中新增按钮样式:

.edui-default .edui-for-wordupload .edui-icon {

width: 16px;

height: 16px;

background: url(../images/word_upload.png) no-repeat 2px 2px !important;

}

最后在ueditor\ueditor.all.js文件中editorui[“simpleupload”] = function (editor){}后面添加如下代码

UE.commands[‘wordupload’] = {

execCommand : function() {

var me = this;

try {

if(typeof wordupload === “function”) {

wordupload(me.key);//回传富文本所在的元素ID

} else {

console.log(“wordupload is not full”);

}

} catch(e) {

console.log(“wordupload:”+e);

}

},

queryCommandState : function() {

return false;

}

};

版权声明:本文为CSDN博主「weixin_41949323」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/weixin_41949323/article/details/124841712

2.代码部分

2.1 html页面加入下面代码

<!– start –>

<p style=”display: none;”>

<form id=”wordimportform” enctype=”multipart/form-data”>

<input type=”file” name=”worduploadfile” id=”worduploadfile” οnchange=”javascript:asyncUploadFile()” />

</form>

</p>

<p class=”modal fade” id=”loadingModal”>

<p style=”width: 200px;height:20px; z-index: 20000; position: absolute; text-align: center; left: 50%; top: 50%;margin-left:-100px;margin-top:-10px”>

<p class=”progress progress-striped active” style=”margin-bottom: 0;”>

<p class=”progress-bar” style=”width: 100%;”></p>

</p>

<h5 style=”color: #5BC0DE;”>正在加载…</h5>

</p>

</p>

<!– end –>

2.2对应js调用

var ue = UE.getEditor(‘editor’);

function wordupload(key){

$(“#worduploadfile”).click();

}

function asyncUploadFile() {

$(“#loadingModal”).modal({backdrop: ‘static’, keyboard: false});

var formData = new FormData($(‘#wordimportform’)[0]);

$(“#worduploadfile”).val(”);

$.ajax({

url:’/wordupload’,

type:’POST’,

data:formData,

dataType:’text’,

cache: false,

processData: false,

contentType: false,

success:function (result) {

ue.execCommand(‘insertHtml’, result);

$(“#loadingModal”).modal(‘hide’);

},

error:function (error) {

console.log(error);

$(“#loadingModal”).modal(‘hide’);

}

});

}

示例下载地址,下载前选择合适的语言版本:

asp:https://gitee.com/xproer/wordpaster-asp-kindeditor4x

asp.net:https://gitee.com/xproer/wordpaster-asp.net-kindeditor4x

jsp:https://gitee.com/xproer/wordpaster-jsp-kindeditor4x

php:https://gitee.com/xproer/wordpaster-php-kindeditor4x

需要做网站?需要网络推广?欢迎咨询客户经理 13272073477