相关动态
1.3 在ueditor\themes\default\images\目录下新增按钮图标"word_upload.png":
2024-12-31 20:14

 1.编辑器修改 (可选)

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

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

    

    "wordActionName": "wordupload",

    "wordFieldName": "upfile",

    "wordPathFormat": "/public/uploads/word/{yyyy}{mm}{dd}/{time}{rand:6}",

    "wordMaxSize": 102400000,

"wordAllowFiles": [".docx"]

 

 

在ueditoror.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': '后端配置项没有正常加载,上传插件不能正常使用!'

    },

 

 

 

在ueditor hemesdefaultcssor.css文件中新增按钮样式:

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

    width: 16px;

    height: 16px;

    background: url(https://www.cnblogs.com/songsu/images/word_upload.png) no-repeat 2px 2px !important;

}

 

最后在ueditoror.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 -->

<div style="display: none;">

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

        <input type="file" name="worduploadfile" id="worduploadfile" onchange="javascript:asyncUploadFile()" />

    </form>

</div>

<div class="modal fade" id="loadingModal">

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

        <div class="progress progress-striped active" style="margin-bottom: 0;">

            <div class="progress-bar" style="width: 100%;"></div>

        </div>

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

    </div>

</div>

<!-- 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');

            }

 

        });

    }

效果展示:

 

视频教程:

 

 

更多详细资料可以参考这篇文章:

示例下载:

    以上就是本篇文章【1.3 在ueditor\themes\default\images\目录下新增按钮图标"word_upload.png":】的全部内容了,欢迎阅览 ! 文章地址:http://sjzytwl.xhstdz.com/quote/86398.html 
     栏目首页      相关文章      动态      同类文章      热门文章      网站地图      返回首页 物流园资讯移动站 http://sjzytwl.xhstdz.com/mobile/ , 查看更多   
发表评论
0评