Quill富文本基于视频的改造

一、视频上传弹窗

<!-- 视频上传 -->
    <el-dialog
      width="50%"
      title="视频上传"
      :visible.sync="videoUploadTag"
      append-to-body
    >
      <el-input
        v-model="videoLink"
        placeholder="请输入视频链接,仅支持MP4、Ogg、WebM格式。例https://xxxx/xx.mp4"
        clearable
      ></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="videoUploadTag = false">取 消</el-button>
        <el-button type="primary" @click="addVideoLink">添 加</el-button>
      </span>
    </el-dialog>

二、初始化配置

import Quill from "quill";
// 视频video
const BlockEmbed = Quill.import("blots/block/embed");
class VideoBlot extends BlockEmbed {// 自定义视频:大小等属性
  static create(value) {
    let node = super.create()
    node.setAttribute('src', value.url)
    node.setAttribute('controls', value.controls)
    node.setAttribute('width', value.width)
    node.setAttribute('height', value.height)
    node.setAttribute('webkit-playsinline', true)
    node.setAttribute('playsinline', true)
    node.setAttribute('x5-playsinline', true)
    return node
  }

  static value(node) {
    return {
      url: node.getAttribute('src'),
      controls: node.getAttribute('controls'),
      width: node.getAttribute('width'),
      height: node.getAttribute('height')
    }
  }
}
VideoBlot.blotName = 'video'
VideoBlot.tagName = 'video'
Quill.register(VideoBlot)

三、确认上传视频方法:

// 确认上传视频
    addVideoLink() {
      if (this.videoLink.length == 0) {
        this.$message.error("请输入视频链接");
      }
      //当编辑器中没有输入文本时,这里获取到的 range 为 null
      var range = this.Quill.selection.savedRange;
      //视频插入在富文本中的位置
      var index = 0;
      if (range == null) {
        index = 0;
      } else {
        index = range.index;
      }
      //隐藏弹框
      this.videoUploadTag = false;
      //将视频链接插入到当前的富文本当中
      this.Quill.insertEmbed(index, "video", {
        url: this.videoLink,
        controls: "controls",
        width: '100%'
      });
    },

四、toolbar配置,劫持原来的视频点击事件

handlers: {
              image: function (value) {
                // 劫持原来的图片点击按钮事件
                QuillWatch.emit(this.quill.id);
              },
              video: function (val) {
                self.videoUploadTag = true;
                self.videoLink = '';
              },
            },
//显示插入视频链接弹框的标识
      videoUploadTag: false,
      //弹框插入的视频链接记录
      videoLink: "",

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值