wangeditor4转发时将原信息作为引用放在新内容之后,并不可编辑

下载   
npm install @wangeditor/editor-for-vue --save

官网地址

快速开始 | wangEditor

父组件代码
    <wangeditor
	  @change="grtUrl"
	  :editcontent="editcontent"
	  :actionstate="actions"
	  ref="wangeditor"
    ></wangeditor>
wangeditor 组件代码 
<template>
	<div class="website">
		<div
			id="websiteEditorElem"
			class="websiteEd"
			style="background: #ffffff; border-bottom: none"
		></div>
	</div>
</template>

<script>
import E from "wangeditor";
import { decode } from "@/utils/localencryption";
import { getfileserverpost } from "@/api/rollcall";
import axios from "axios";
export default {
	name: "wangEditor2",
	props: {
		editcontent: {
			type: String,
		},
		actionstate: {
			type: String,
		},
	},

	data() {
		return {
			editor: "",
			name: "",
			formCaseEnd: {},
			contents: "",
			action: "",
		};
	},
	watch: {},
	computed: {},
	mounted() {
		this.init();
		this.onChange();
	},
	methods: {
		handClear() {
			this.editor.txt.clear();
		},
		handDisable() {
			this.editor.disable();
		},
		handeditcontent(n, v) {
			this.contents = n;
			if (v != 1) {
				this.editor.txt.html(n);
			}
		},
		handfileListOn(row) {
			if (typeof row == "string") {
				console.log(row, "you1");
				let editorDom =
					document.getElementsByClassName("w-e-text-container");
				editorDom[0].setAttribute(
					"style",
					"height:410px;border-bottom:1px solid #ccc"
				);
			} else if (typeof row == "number") {
				console.log(row, "无u");
				let editorDom =
					document.getElementsByClassName("w-e-text-container");
				editorDom[0].setAttribute(
					"style",
					"height:485px;border-bottom:1px solid #ccc"
				);
			}
		},
		onChange() {
			getfileserverpost().then((res) => {
				if (res.status == 200) {
					this.action = res.data;
				}
			});
		},
		init() {
			this.editor = new E("#websiteEditorElem");
			this.$nextTick(() => {
				// console.log(editorDom[0], "dom----");
				if (this.actionstate == "edit") {
					let editorDom =
						document.getElementsByClassName("w-e-text-container");
					editorDom[0].setAttribute("style", "height:350px;border-bottom:1px solid #ccc");
					const dom2 = document.getElementById("websiteEditorElem");
					var div = document.createElement("p");
					div.innerHTML = this.contents;
					dom2.children[1].children[0].appendChild(div);
					dom2.children[1].children[0].removeAttribute(
						"contenteditable"
					);
					dom2.children[1].children[0].children[0].setAttribute(
						"contenteditable",
						"true"
					);
					dom2.children[1].children[0].children[0].setAttribute(
						"style",
						"outline:0px solid transparent;"
					);
				}
				if (this.actionstate == "details") {
					this.handfileListOn();
				}
				if (this.actionstate == "create") {
					let editorDom =
						document.getElementsByClassName("w-e-text-container");
					editorDom[0].setAttribute(
						"style",
						"height:350px;border-bottom:1px solid #ccc"
					);
				}
			});
			if (this.actionstate == "details") {
				this.editor.config.menus = [];
			} else {
				this.editor.config.excludeMenus = [
					"emoticon",
					"link",
					"code",
					"video",
				];
			}
			// if (this.actionstate == "create" || this.actionstate == "edit") {
			// }
			this.editor.config.lang = "en";
			this.editor.i18next = window.i18next;
			this.editor.config.placeholder = "";
			this.editor.config.showFullScreen = false;
			this.editor.config.uploadImgShowBase64 = true;
			this.editor.config.showLinkImg = false;
			this.editor.config.debug = true;
			this.editor.config.uploadFileName = "image";
			this.editor.config.customUploadImg = (resultFiles, insertImgFn) => {
				let imageUrl = [];
				const token = decode("token");
				resultFiles.forEach((item) => {
					if (item) {
						return new Promise((innerResolve) => {
							let form = new FormData();
							var newName = this.$md5(
								String(new Date().getTime())
							);
							console.log(this.action, "this.action--");
							form.append("file", item, newName);
							form.append("auth_token", decode("token"));
							form.append("output", "json");
							axios({
								//url: "https://testfs.mijicall.com:8080/group1/upload",
								url: this.action,
								method: "POST",
								data: form,
							})
								//成功回调
								.then((res) => {
									console.log(res, "===res");
									if (res.data) {
										const urlItem =
											res.data.domain + "" + res.data.src;
										let obj = {};
										obj.name = urlItem.substring(
											urlItem.lastIndexOf("/") + 1,
											urlItem.indexOf("?")
										);
										obj.url =
											urlItem.indexOf("auth_token") == -1
												? urlItem +
												  `?auth_token=${token}`
												: urlItem;
										console.log(obj, "obi--");
										insertImgFn(obj.url);
									}
								});
						});
					}
				});
			};
			this.editor.config.focus = true;
			this.editor.create();
			this.editor.txt.html(this.contents);
			this.editor.config.onchange = (html) => {
				this.info_ = html; // 绑定当前逐渐地值
				this.$emit("change", this.info_);
			};
		},
	},
};
</script>
<style lang="scss" scoped>
.website {
	width: 100% !important;
	//height: 350px;
	min-height: 300px;
}
.websiteEd {
	//height: 340px;
}
.formDate {
	width: 350px;
	height: 170px;
	padding-top: 20px;
	background: #f0f0f0;
}
</style>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将 WangEditor4 和 MathJax 集成并打印,你可以按照以下步骤操作: 1. 首先,确保你已经正确引入了 WangEditor4 和 MathJax 的相关文件,包括 CSS 和 JavaScript 文件。 2. 在你的 HTML 文件中,创建一个用于显示编辑内容的容器元素,例如一个 `<div>` 元素。 3. 在 JavaScript 中,初始化 WangEditor4 编辑器,并设置相关配置项。你可以参考 WangEditor4 的文档来了解可用的配置项。确保你在配置项中启用了 MathJax 的支持。 ```javascript const editor = new wangEditor('#editorContainer'); editor.config.math.enabled = true; // 启用 MathJax 支持 editor.create(); ``` 4. 当用户点击打印按钮或执行打印操作,获取编辑器中的内容,并将其中的 MathJax 表达式转换为可打印的格式。 ```javascript function printContent() { const content = editor.txt.html(); // 获取编辑内容 const printedContent = convertMathJaxForPrint(content); // 将 MathJax 表达式转换为可打印格式 console.log(printedContent); // 在控制台输出打印内容,可以根据需要进行打印操作 } function convertMathJaxForPrint(content) { // 使用正则表达式或其他方法将 MathJax 表达式转换为可打印格式 // 例如,将 <span class="math-tex">...</span> 转换为相应的数学表达式 // 参考 MathJax 的文档来了解如何解析和处理 MathJax 表达式 } ``` 注意,上述代码中的 `convertMathJaxForPrint` 函数是一个示例,你需要根据实际情况来编写将 MathJax 表达式转换为可打印格式的逻辑。 5. 根据你的需求,将打印内容传递给打印操作或打印预览功能,以完成打印操作。 请注意,上述代码仅为示例,具体实现可能会因你使用的版本和具体需求而有所不同。你需要根据 WangEditor4 和 MathJax 的文档来进行相关配置和操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值