使用 ElementUI image 处理富文本中的图片显示

in 前端 with 0 comment

使用 ElementUI image 处理富文本中的图片显示

效果

QQ20210510-115745-HD.gif
QQ20210510-115811-HD.gif

需求分析

图片解决办法

imageUrl: '',
imageUrls: []

> el-image 占用
<div class="elImage" style="display: none" v-if="imageUrl">
    <el-image ref="imageUrl" style="width: 100px; height: 100px;" :src="imageUrl" :preview-src-list="imageUrls"> </el-image>
</div>

bindImagesLayer() {
        let that = this;
        that.imageUrls = [];
        $('.content img').map(function(item) {
            that.imageUrls.push($(this).attr('src'));
        });
        $('body').on('click', '.content img', function() {
            let url = $(this).attr('src');
            if (!that.imageUrls.includes(url)) {
                that.imageUrls.push(url);
            }
            that.imageUrl = url;
            setTimeout(() => {
                $('.elImage img').click();
            }, 100);
        });
    }
    
async created() {
    await this.bindImagesLayer();
}

.content 为文章内容的 class,获取到其中所有的图片然后再填充到占用的 el-image 中,再手动触发 el-image 的点击事件

视频解决办法

我们首先创建一个弹框组件,用于处理视频的预览

> 下面的这些变量自己data中注册一下

<el-dialog title="" :visible.sync="videoVisible" :append-to-body="true">
        <div class="videodDialog" v-if="videoVisible">
            <video :src="videoUrl" autoplay controls="controls"></video>
        </div>
</el-dialog>

我们来处理视频的预览显示,先展示预览图再显示代码

图片描述...

video 的html结构如下

<div class="video">
            <video controls="controls" width="600" height="150" data-mce-fragment="1">
                <source src="https://trmk-cdn.teachingrecord.com/uploads/20201028/a7c8a18563a1b577537bef7fc25c3de2.mp4" type="video/mp4">
            </video>
            <div class="video-mask">
                <span class="video-icon"></span>
            </div>
        </div>
        

已知html结构,我们来创建一下css

>video.scss
video {
max-width: 100%;
margin: 0px auto;
cursor: pointer;

}

.video {
    position: relative;
    width: 320px;

    .video-mask {
        position: absolute;
        top: 0;
        width: 100%;
        height: 100%;
        cursor: pointer;

        .video-icon {
            content: '';
            position: absolute;
            left: 50%;
            top: 50%;
            display: block;
            transform: translate(-50%, -50%) scale(1.5);
            opacity: 1;
            transition: all 0.2s;
            padding: 14px;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-size: 20px;
            background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAcHklEQVR4Xu1dabB1RXVdS2KcQHHCIaVYRsEpokISVASZBAQ1EgGNIyjiEMshyqCocQA0RpOUQxBBKMtQJYMGQSWKMkmc0AgWKmpZaoxokJSgKPLDlVqf/fDyePec7j7DPUPvqlf3fd/rcXWv2927d+9NFCkIFASWIsCCTUGgILAcgUKQMjsKAhUIFIKU6VEQKAQpc6AgkIdAWUHycCu5ZoJAIchMBrp0Mw+BQpA83EqumSBQCNLDQEvaHMCDAdwdwB3DzxYLvy/+n8fkOgC/3OBz8f+uIHl1D82fdRWFIC0Ov6S7BiI8JHyaFP79Pi1Ws1iUCXIFgG8ufhbitId2IUgDLCU9GsDu4cdE2KpBcW1mXSPOZwF8luQX2ix8TmUVgiSMdiDEjgB2AbAHgDskZF9l0usBnAfgQgBfLISJH4pCkAqsJHlr9BQAOwN4LIB7x0M76JQ/AXAJgIsAnEPyB4Nu7QobVwiyDnxJtwfw5EAMf/rfU5YbAZxtoviT5DVT7mxq3wpBAmKS9lwgRleH6tTx6Tu9ybFIFpNn1jJrgkjaGsDBgRiPnPVMuGXnve3yqvJhkl+aKzazJIikhwF4XiDHXXoe/BsA/BbAsk835zYAblvx2XOTcSqAk0n6oD8rmRVBJFkD5RXDP7fucKR/BuBKAN8Jn5t+J+nPxiJpWwDbAPDn4u/3aFx4dQHefpkoH+u4nsEUPwuChPOFSfGMjpD/NIDPBK3QlSSv7aieymIl3SkQxlo3n6me0FE7zgdwCskPdVT+YIqdNEHCvcURQSPVJuiXB0J4olxA0vcMgxNJvqd5PIBdA2Ee3nIjLwXwdpJntFzuYIqbJEEk2c7JxDgSwGYtoe39tw+tJsRlLZXZazGStguE2S9cdLZV/4kAjpnifcrkCCLp6YEYngxNxUQ4yz8kv9a0sCHll/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ipotAIch0x7b0rAUE/h9sZWFfbA+bUgAAAABJRU5ErkJggg==);
            /* 你的图片*/
            background-size: 40px;
            z-index: 999;
            background-repeat: no-repeat;
            background-position: center center;
            cursor: pointer;
        }
    }

    .video-mask:hover {
        .video-icon {
            opacity: 1;
            transform: translate(-50%, -50%) scale(2.2);
        }
    }
}
.layui-layer-content {
    video {
        width: 100%;
        height: 95%;
    }
}

上述代码中,我们的icon是base64转码的

再之需要使用动态js来控制,video的展示

export default function videoContro(video, callback) {
    let videoContainer = video.parentNode;
    console.log(video);

    // 设置poster属性:(非本地视频资源会有跨域截图问题)
    video.addEventListener('loadeddata', function(e) {
        video.removeAttribute('controls');
    });

    let videoMask = document.createElement('div');
    videoMask.setAttribute('class', 'video-mask');

    let videoIcon = document.createElement('span');
    videoIcon.setAttribute('class', 'video-icon');
    videoMask.appendChild(videoIcon);

    videoContainer.appendChild(videoMask);

    /**
     * 设置播放状态
     */
    function vidplaySate(e) {
        let src = $(video)
            .children('source')
            .attr('src');

        callback(src);
    }
    videoMask.addEventListener('click', vidplaySate, false);
}

vue 调用控制方式

async created() {
    await this.bindImagesLayer();
    setTimeout(() => {
        this.initVideo();
    }, 1000);
}

method() {
    ...
    /**
    * 初始化播放器的一些配置
    */
    initVideo() {
        let videos = document.querySelectorAll('.docHtml video');
        let callback = this.videoCallback;
        videos.forEach(video => {
            videoContro(video, callback);
        });
    },

    videoCallback(src) {
        this.videoUrl = src;
        this.videoVisible = true;
    }
}

Comments are closed.