quill编辑器自定义音频、视频、行内style样式(字符边框、首行缩进)

news/2024/7/1 9:34:50

文章目录

  • 一、音频
    • 1、自定义内容
    • 2、引入使用
  • 二、视频
    • 1、自定义内容
    • 2、引入使用
  • 三、文本添加行内style样式(文本边框)
    • 1、不带有下拉框
      • (1)自定义内容
      • (2)引入使用
    • 2、带有下拉框
      • (1)自定义内容
      • (2)引入使用
  • 四、段落添加行内style样式(首行缩进)
    • 1、不带有下拉框
      • (1)自定义内容
      • (2)引入使用(见文本添加,类同)
    • 2、带有下拉框
      • (1)自定义内容
      • (2)引入使用


一、音频

1、自定义内容

import { Quill } from 'vue-quill-editor';
const BlockEmbed = Quill.import('blots/block/embed');


// 音频
class AudioBlot extends BlockEmbed {
  static create(value) {
    console.log(value)
    const node = super.create(value);
    node.setAttribute('src', value.url);
    node.setAttribute('controls', true);
    node.setAttribute('name', value.name);
    node.setAttribute('controlsList', 'nodownload');
    return node;
  }
  // 添加value获取当前的audio元素。拿到audio元素的属性。
  static value(domNode) {
    const value = {
      url: '',
      name: '',
    };
    // 这里要加判断。不然会显示undefined
    if (domNode.getAttribute('src')) {
      value.url = domNode.getAttribute('src');
      value.name = domNode.getAttribute('name');
    }
    console.log(value)
    return value;
  }
}
AudioBlot.blotName = 'audio';
AudioBlot.tagName = 'audio';
export default { AudioBlot};

2、引入使用

引入

import blotsInfo from '../utils/audio-blot'
Quill.register(blotsInfo.AudioBlot);

将选择好的文件地址插入到编辑器中

const quill = this.$refs.myQuillEditor.quill;
// insertEmbed(index: Number(插入的位置), type: String(标签类型), value: any(参数,将传入到create的方法中去), source: String = 'api')
quill.insertEmbed(this.curCursor, 'audio', { url: this.currentMaterial });

二、视频

1、自定义内容

import { Quill } from 'vue-quill-editor';
const BlockEmbed = Quill.import('blots/block/embed');


// 视频
class VideoBlot extends BlockEmbed {
  static create(value) {
    let node = super.create(value);
    node.setAttribute('src', value.url || value);   //设置audio的src属性
    node.setAttribute('controls', true);   //设置audio的controls,否则他将不会显示
    node.setAttribute('controlsList', 'nodownload');   //设置audio的下载功能为不能下载
    node.setAttribute('id', 'videoAuto');     //设置一个id
    node.setAttribute('style', 'width:100%');     //设置一个id
    //外层套入div (不套入会产生无法删除乱起八糟的问题😀)
    let divNode = document.createElement("span");
    divNode.appendChild(node)
    if (!value.url) {
      divNode.innerHTML = divNode.innerHTML.replace('<video', '<iframe class="ql-video" frameborder="0" allowfullscreen="true"').replace('<video', '</iframe')
      divNode.getElementsByTagName('iframe')[0].style = 'width:auto'
    }
    return divNode;
  }
  // 添加value获取当前的audio元素。拿到audio元素的属性。
  static value(domNode) {
    const value = {
      url: '',
      name: '',
    };
    // 这里要加判断。不然会显示undefined
    if (domNode.getAttribute('src')) {
      value.url = domNode.getAttribute('src');
      value.name = domNode.getAttribute('name');
    }
    return value;
  }
}
VideoBlot.blotName = 'video';
VideoBlot.tagName = 'video';
export default { VideoBlot};

2、引入使用

引入

import blotsInfo from '../utils/audio-blot'
Quill.register(blotsInfo.VideoBlot);

将选择好的文件地址插入到编辑器中

const quill = this.$refs.myQuillEditor.quill;
// insertEmbed(index: Number(插入的位置), type: String(标签类型), value: any(参数,将传入到create的方法中去), source: String = 'api')
quill.insertEmbed(this.curCursor, 'video', { url: this.currentMaterial });

三、文本添加行内style样式(文本边框)

1、不带有下拉框

  • 优点:点击一下添加样式,点击一下取消样式
  • 缺点:样式比较单一,没有更多可选项

(1)自定义内容

// 自定义字符边框
const inline = Quill.import('blots/inline')

class WordBox extends inline {
  static create(value) {
    const node = super.create(value);
    //设置需要的样式
    node.setAttribute('style', 'border:1px solid #000000');
    return node;
  }
}

WordBox.blotName = 'wordBox'; //工具栏中的名字与此名字需保持一致
WordBox.tagName = 'wordBox';  //需要添加的标签名

export default { WordBox };

(2)引入使用

引入

import blotsInfo from '../utils/audio-blot'
Quill.register(blotsInfo.WordBox, true);

往工具栏中添加操作按钮(点击操作按钮即可取消或添加样式)

//工具栏
const container = [
   ['wordBox',]
]

js修改操作按钮样式

// 工具栏附件按钮
const wordBox = document.querySelector(".ql-wordBox");
wordBox.className = "ql-wordBox";
wordBox.innerHTML = "框";

2、带有下拉框

  • 优点:可设置多种样式,可选项多
  • 缺点:白名单中还需设置‘none’用于清除样式,否则无法清除

(1)自定义内容

// 自定义字符边框
var Parchment = Quill.import('parchment');

let config = {
  scope: Parchment.Scope.INLINE,
  // 会有下拉框列表
  whitelist: ['none','1px solid #000000','1px solid #f53309']
  //可设置成没有下拉框的,但会导致无法清除样式
  // whitelist: ['1px solid #000000']  
};

let WordBox = new Parchment.Attributor.Style('wordBox', 'border', config);

export default { WordBox };

(2)引入使用

引入

import blotsInfo from '../utils/audio-blot'
Quill.register(blotsInfo.WordBox, true);

往工具栏中添加操作按钮

//工具栏
const container = [
   [{wordBox: [false,'1px solid #000000','1px solid #f53309']},]
]

js修改操作按钮样式

// 工具栏附件按钮
let a = document.querySelectorAll(".ql-wordBox")[0]
let b = document.querySelectorAll(".ql-wordBox")[1]
//添加默认显示内容
let stit = document.createElement('span')
stit.innerHTML = '文本框';
stit.setAttribute('style', 'margin-right:20px;line-height: 24px;')
a.children[0].insertBefore(stit, a.children[0].children[0])

// 遍历下拉框列表添加值
let i = a.children[1].children.length
while (i) {
  i--;
  let item = a.children[1].children[i]
  item.innerHTML = item.dataset.value ? item.dataset.value.slice(item.dataset.value.indexOf('#')) : '无'
}

显示效果

在这里插入图片描述
在这里插入图片描述

四、段落添加行内style样式(首行缩进)

注意由于与文本添加的几乎相同,所以只写部分代码

1、不带有下拉框

(1)自定义内容

// 自定义首行缩进
const Block = Quill.import('blots/block')

class WordBox extends Block{
  static create(value) {
    const node = super.create(value);
    //设置需要的样式
    node.setAttribute('style', 'text-indent: 2em;');
    return node;
  }
}

WordBox.blotName = 'wordBox'; //工具栏中的名字与此名字需保持一致
WordBox.tagName = 'div';  //需要添加的标签名,p标签的话无法取消样式

export default { WordBox };

(2)引入使用(见文本添加,类同)

2、带有下拉框

  • 优点:可设置多种样式,可选项多
  • 缺点:白名单中还需设置‘none’用于清除样式,否则无法清除

(1)自定义内容

// 自定义字符边框
var Parchment = Quill.import('parchment');

let config = {
  scope: Parchment.Scope.BLOCK,
  // 会有下拉框列表
  whitelist: ['none','2em','3em']
};

let WordBox = new Parchment.Attributor.Style('wordBox', 'text-indent', config);

export default { WordBox };

(2)引入使用

往工具栏中添加操作按钮

//工具栏
const container = [
   [{wordBox: [false,'2em','3em']},]
]

js修改操作按钮样式

// 工具栏附件按钮
let a = document.querySelectorAll(".ql-wordBox")[0]
let b = document.querySelectorAll(".ql-wordBox")[1]
//添加默认显示内容
let stit = document.createElement('span')
stit.innerHTML = '首行缩进';
stit.setAttribute('style', 'margin-right:20px;line-height: 24px;')
a.children[0].insertBefore(stit, a.children[0].children[0])

// 遍历下拉框列表添加值
let i = a.children[1].children.length
while (i) {
  i--;
  let item = a.children[1].children[i]
  item.innerHTML = item.dataset.value ? item.dataset.value : '无'
}

http://lihuaxi.xjx100.cn/news/1117216.html

相关文章

单例模式的饿汉和懒汉写法(基于C++)

目录 单例模式例程饿汉懒汉 对比函数调用线程安全总结 单例模式 单例模式确保一个类只有一个实例&#xff0c;并提供全局访问点。这样可以避免在系统中出现多个相同的对象&#xff0c;从而提高系统的性能和可维护性。 单例模式的实现包括饿汉和懒汉&#xff0c;下面介绍C中这两…

汽车轮胎充电宝打气泵方案

我们知道新能源车是没有配置充气泵的&#xff0c;所以在平时日常使用中我们还需要配置一个充气泵。充气泵方案便是在这个用户需求上面开发出来的。它体积小、外观精美、带有多模式充气并车胎检测等功能&#xff0c;是现在有车一族的出行必备物品。 充气泵方案其功能设计集成于一…

k8s巡检脚本

#!/bin/bash #检查kubectl是否已经安装 if ! command -v kubectl &> /dev/null then echo -n "kubectl 未安装&#xff0c;请先安装kubectl"exitfi echo -e “开始集群状态信息收集/” #检查集群状态: echo -n “检查集群正常状态:” kubectl cluster…

SSD系列2——PriorBox

SSD系列&#xff1a; SSD系列1——网络结构 SSD系列2——PriorBox SSD系列3——损失计算 PriorBox SSD采用PriorBox来进行区域生成&#xff0c;其思想与Faster RCNN的Anchor类似。PriorBox的本质是在原图上的一系列矩形框&#xff0c;即特征图上的一个点根据下采样率可以得到在…

【深入理解redis】数据结构

文章目录 动态字符串SDS字符串编码类型 intsetDictZipListZipList的连锁更新问题 QuickListSkipListRedisObjectStringListSet结构ZSETHash Redis 共有 5 种基本数据结构&#xff1a;String&#xff08;字符串&#xff09;、List&#xff08;列表&#xff09;、Set&#xff08;…

树结构 数据可视化

这边有个 树结构数据&#xff0c;想做一个可视化展示的需求&#xff1b;首先想到的是 python pyecharts, 一直传说 python 做数据可视化 一把梭&#xff1b; pyecharts 在线实例展示 pyecharts 官网 当看到上面的 示例 后&#xff0c;这不就我想找的嘛&#xff01;哈哈 随后 找…

KingbaseES V8R6 最老事务阻止vacuum freeze

前言 最近生产环境发生几次由于长事务导致表、库年龄没法回收的情况。我们要规避这种情况的发生&#xff0c;不要等发生了再去强制中断会话连接。 当数据库中存在最老事务版本xmin&#xff0c;那么早于他的快照可以被标记为frozen&#xff0c;如果在最老事务之后产生的快照版本…

纽扣电池/含纽扣电池商品亚马逊美国澳洲站点合规认证要求!

纽扣电池/含纽扣电池商品亚马逊美澳站点合规认证 亚马逊美国站纽扣电池&#xff08;含纽扣电池产品&#xff09;合规要求标准&#xff1a; 16CFR1700.15部分(防毒包装标准) 16CFR1700.20部分(特殊包装的检测程序) ANSI C18.3M(便携式锂原电池的安全标准) 警示标签声明要求(…