vue-quill-editor使用模版

devtools/2024/10/15 21:30:03/

上传图片
上传视频

<template><div><quill-editorstyle="padding-left: 0; padding-top: 0px; margin-top: 0px"ref="editorRef"v-model="content"class="ql-editor":options="editorOption"@blur="onEditorBlur($event)"@focus="onEditorFocus($event)"@change="onEditorChange($event)"/><el-dialogtitle="视频上传":visible.sync="dialogVisible"width="30%"append-to-body:before-close="closeDig"><el-uploadv-loading="loading"class="upload-demo"dragaction=""list-type="video/mp4":before-upload="beforeUpload":on-remove="removefile":limit="1":on-success="handleSuccess":http-request="uploadVoide":file-list="backfile":on-exceed="handleExceed":multiple="multiple"multiple><i class="el-icon-upload"></i><div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div><div class="el-upload__tip" slot="tip">只能上传mp4且不超过500MB</div></el-upload><!-- <span slot="footer" class="dialog-footer"><el-button @click="closeDig">取 消</el-button><el-button type="primary" @click="dialogVisible = false">确 定</el-button></span> --></el-dialog></div></template><script>import { Notification, Loading } from "element-ui";import { quillEditor } from "vue-quill-editor";import { uploadOss } from "@/api/uploadOss";import "quill/dist/quill.core.css";import "quill/dist/quill.snow.css";import "quill/dist/quill.bubble.css";//优化图片自定义大小 新建的css文件的保存位置,如不同,需要修改import "@/assets/styles/quillEditor.css";import imageResize from "quill-image-resize-module";Quill.register("modules/imageResize", imageResize);import { ImageDrop } from "quill-image-drop-module";Quill.register("modules/imageDrop", ImageDrop);//优化文字大小选项及样式var sizes = [false, "16px", "18px", "20px", "22px", "26px", "28px", "30px"];var Size = Quill.import("formats/size");Size.whitelist = sizes;Quill.register(Size, true);// Quill.register(Video, true)export default {components: {quillEditor,},props: {videoPrefix: {type: String,default: "hos/quillEditor/video"},imagePrefix: {type: String,default: "hos/quillEditor/image"},notUpdate: {type: Boolean,default: false}},data() {return {content: undefined,dialogVisible: false,multiple: false,loading: false,typelist:["mp4"],editorOption: {modules: {toolbar: {container: [],handlers: {image: this.imageUploadOss,'video': this.videoUploadOss,},},imageDrop: true, // 拖动加载图片组件。imageResize: {//调整大小组件。displayStyles: {backgroundColor: "black",border: "none",color: "white",},modules: ["Resize", "DisplaySize", "Toolbar"],},},placeholder: "请输入正文",},backfile:[]};},created() {if(!this.notUpdate){this.editorOption.modules.toolbar.container = [["bold", "italic", "underline", "strike"], // 加粗 斜体 下划线 删除线["blockquote", "code-block"], // 引用  代码块[{ header: 1 }, { header: 2 }], // 1、2 级标题[{ list: "ordered" }, { list: "bullet" }], // 有序、无序列表[{ script: "sub" }, { script: "super" }], // 上标/下标[{ indent: "-1" }, { indent: "+1" }], // 缩进[{ direction: "rtl" }], // 文本方向[{ size: sizes }], // 字体大小[{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题[{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色// [{ font: ['songti'] }], // 字体种类[{ align: [] }], // 对齐方式["clean"], // 清除文本格式["image", "video"], // 链接、图片、视频]}else {this.editorOption.modules.toolbar.container = []}},methods: {tabClick() {// 清空内容this.content = "";},initContent(info){this.content = info},// 失去焦点事件onEditorBlur(quill) {this.$emit('onEditorBlur', quill)},// 获得焦点事件onEditorFocus(quill) {this.$emit('onEditorFocus', quill)},// 准备富文本编辑器onEditorReady(quill) {this.$emit('onEditorReady', quill)},// 内容改变事件onEditorChange({ quill, html, text }) {this.$emit('onEditorChange', { quill, html, text })},imageUploadOss() {const { quill } = this.$refs.editorRef;let fileInput = quill.container.querySelector("input.ql-image[type=file]");if (fileInput === null) {fileInput = document.createElement("input");fileInput.setAttribute("type", "file");// 设置图片参数名fileInput.setAttribute("name", "file");// 可设置上传图片的格式fileInput.setAttribute("accept","image/png, image/gif, image/jpeg, image/bmp, image/x-icon");fileInput.classList.add("ql-image");// 监听选择文件fileInput.addEventListener("change", () => {const formData = new FormData();formData.append("file", fileInput.files[0]);formData.append("imageUrl", this.imagePrefix + "/");uploadOss(formData).then((res) => {if (res.status === "200") {const length = quill.getSelection(true).index;quill.insertEmbed(length,"image",process.env.VUE_APP_DOMAIN_STATIC + res.result);quill.setSelection(length + 1);}}).catch((err) => {console.log(err);Notification.error("图片上传失败");});});}fileInput.click();},videoUploadOss(){// document.querySelector('#upvideoshow').click()this.dialogVisible = true},handleExceed(files, fileList) {this.$message.warning(`当前限制选择 1 个文件`);},handleSuccess(res, file, fileList) {// this.imageUrl = URL.createObjectURL(file.raw);console.log('fileList',fileList)console.log(file.raw)},beforeUpload(file) {const typelist = ["video/mp4"];var bool = typelist.some((item) => {console.log(file.type)return item == file.type;});const isLt2M = file.size / 1024 / 1024 < 500;if (!bool) {this.$message.error("只能是mp4格式的视频!");}if (!isLt2M) {this.$message.error("上传视频大小不能超过 500MB!");}return bool && isLt2M;},removefile(file, fileList) {console.log('remove',file)},uploadVoide(params){this.loading = trueconst { quill } = this.$refs.editorRef;console.log('uploadVoide params',params)const form = new FormData(); // 使用FormData传参数和文件form.append("file", params.file); // 文件form.append("imageUrl", this.videoPrefix + "/");uploadOss(form).then((res) => {if (res.status === "200") {this.closeDig()const length = quill.getSelection(true).index;quill.insertEmbed(length,"video",process.env.VUE_APP_DOMAIN_STATIC + res.result);quill.setSelection(length + 1);}}).catch((err) => {console.log(err);Notification.error("视频上传失败");}).finally(()=> (this.loading = false));},closeDig(){this.backfile = []this.dialogVisible = false}},};</script><style scoped lang="scss">::v-deep(.ql-tooltip){left: 0px!important;}</style>

http://www.ppmy.cn/devtools/126355.html

相关文章

ffmpeg面向对象——rtsp拉流探索(1)

目录 0.avformat_open_input的rtsp流程程纯净版1.rtsp拉流流程图2.rtsp拉流对象图 标准rtsp协议的基石是tcp&#xff0c;本节探索下ffmpeg的rtsp拉流协议tcp的创建及rtsp协商过程。 0.avformat_open_input的rtsp流程程纯净版 ffmpeg拉流&#xff0c;从avformat_open_input接口…

ubuntu 安装docker, docker-compose

1. 安装curl apt-get update apt upgradeapt install curl 2.安装&#xff1a; curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun 3. 验证&#xff1a; docker -v 4. 安装docker-compose : # 下载 curl -L "https://github.com/docker/compose/rel…

【uniapp】使用uniapp实现一个输入英文单词翻译组件

目录 1、组件代码 2、组件代码 3、调用页面 4、展示 前言&#xff1a;使用uniapp调用一个在线单词翻译功能 1、组件代码 2、组件代码 YouDaoWordTranslator <template><view class"translator"><input class"ipttext" type"te…

2024.10.14 软考学习笔记

刷题网站&#xff1a; 软考中级软件设计师在线试题、软考解析及答案-51CTO题库-软考在线做题备考工具

汇总10个AI免费一键生成PPT的网站

一、前言 PPT幻灯片是现代办公和学习中的重要组成部分。它在工作、研究或培训中扮演着重要角色&#xff0c;并能够让观众更好地理解信息。随着当今人工智能技术的快速发展&#xff0c;现在有很多免费的AI PPT生成器可供选择&#xff0c;帮助用户更加便捷地制作出高效且具有较强…

uniapp 编程体验

全局变量 方法一 改App.vue // App.vue export default {globalData: {userInfo: null,token: },onLaunch: function () {// 初始化全局变量this.globalData.userInfo { name: 张三, age: 30 };} }// 在其他页面或组件中访问 const app getApp(); console.log(app.globalDa…

2024 年 04 月编程语言排行榜,PHP 排名创新低?

编程语言的流行度总是变化莫测&#xff0c;每个月的排行榜都揭示着新的趋势。2024年4月的编程语言排行榜揭示了一个引人关注的现象&#xff1a;PHP的排名再次下滑&#xff0c;创下了历史新低。这种变化对于PHP开发者和整个技术社区来说&#xff0c;意味着什么呢&#xff1f; P…

目标检测——Cascade R-CNN算法解读

论文&#xff1a; Cascade R-CNN: Delving into High Quality Object Detection (2017.12.3) 链接&#xff1a;https://arxiv.org/abs/1712.00726 Cascade R-CNN: High Quality Object Detection and Instance Segmentation (2019.6.24) 链接&#xff1a;https://arxiv.org/abs…