富文本编辑器使用开源项目:wangEditor
具体使用请参考下方官网,以下仅做示例,上传接口请改为实际后端接口
目前上传接口返回数据是写死在json里面的
wangEditor

欢迎使用 wangEditor 富文本编辑器

        var E = window.wangEditor;
        var editor = new E('#editor');
        editor.customConfig.uploadImgServer = "../api/upload.json";
        editor.customConfig.uploadFileName = 'image';
        editor.customConfig.pasteFilterStyle = false;
        editor.customConfig.uploadImgMaxLength = 5;
        editor.customConfig.uploadImgHooks = {
            // 上传超时
            timeout: function (xhr, editor) {
                layer.msg('上传超时!')
            },
            // 如果服务器端返回的不是 {errno:0, data: [...]} 这种格式,可使用该配置
            customInsert: function (insertImg, result, editor) {
                console.log(result);
                if (result.code == 1) {
                    var url = result.data.url;
                    url.forEach(function (e) {
                        insertImg(e);
                    })
                } else {
                    layer.msg(result.msg);
                }
            }
        };
        editor.customConfig.customAlert = function (info) {
            layer.msg(info);
        };
        editor.create();