当前位置:网站首页>Editor MAVON editor for offline use
Editor MAVON editor for offline use
2022-07-28 17:29:00 【Code code of a house】
cnd part , It can be configured together with the operation and maintenance personnel
vue2 Use
1.1 stay public Under the folder , All files put into the editor
1.2 introduce
1.2.1script Let's introduce
import Vue from 'vue'
import mavonEditor from 'mavon-editor'
Vue.use(mavonEditor)
import '../../../../public/mavon-editor/dist/css/index.css'
1.2.2style Let's introduce
@import url(../../../../public/mavon-editor/dist/markdown/github-markdown.min.css);
@import url(../../../../public/mavon-editor/dist/katex/katex.min.css);
1.3 establish / edit page
<mavon-editor
@imgAdd="$imgAdd"
ref="md"
:subfield = "true"
:toolbars="toolbars"
:codeStyle="codeStyle"
:boxShadow="false"
:imageFilter = "uploadBefore"
:ishljs="true"
:external-link="externalLink"
v-model="content"/>
data in
// Because there are cdn file , Offline needs to be in data Add this field to the editor
externalLink: {
markdown_css: false,
hljs_js: () => '/public/mavon-editor/dist/highlightjs/highlight.min.js',
hljs_css: (css) => '/public/mavon-editor/dist/highlightjs/styles/' + css + '.min.css',
hljs_lang: (lang) => '/public/mavon-editor/dist/highlightjs/languages/' + lang + '.min.js',
katex_css: () => '/public/mavon-editor/dist/katex/katex.min.css',
katex_js: () => '/public/mavon-editor/dist/katex/katex.min.js',
},
// Editor menu bar
toolbars: {
bold: true, // bold
italic: true, // Italics
header: true, // title
underline: true, // Underline
strikethrough: true, // Center line
mark: false, // Mark
superscript: false, // Upper corner mark
subscript: false, // Bottom corner
quote: false, // quote
ol: true, // Ordered list
ul: true, // Unordered list
link: true, // link
imagelink: true, // Picture links
code: true, // code
table: true, // form
fullscreen: false, // Full screen editing
readmodel: false, // Immersive reading
htmlcode: false, // Exhibition html Source code
help: false, // help
/* 1.3.5 */
undo: true, // The previous step
redo: true, // next step
trash: true, // Empty
save: false, // preservation ( Trigger events Medium save event )
/* 1.4.2 */
navigation: false, // Navigation directory
/* 2.1.8 */
alignleft: true, // Align left
aligncenter: true, // In the middle
alignright: true, // Right alignment
/* 2.2.1 */
subfield: true, // Single and double column mode
preview: true, // preview
},
// Image address storage array
mdImgMap: {
},
1.3.1 Upload image processing
// Picture size limit
uploadBefore(f){
if(f.size>2016324){
this.$message.error('error', ' Pictures are limited to 2M')
return false
}else {
return true
}
},
$imgAdd(pos, $file){
// First step . Upload the picture to the server .
let requestConfig = {
headers: {
"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundary8uUfBPZgr1wjjfGu",
},
};
var formdata = new FormData();
formdata.append('file', $file);
uploadImgSec(formdata,requestConfig).then(res => {
// Call interface
if(res.httpCode == 200) {
let fullImgPath = this.gb.imgAddress(res.fileName);// Modify address public function
this.mdImgMap[pos] = fullImgPath
}else {
this.$refs.md.$refs.toolbar_left.$imgDel(pos)
this.$message.error(' File upload failed ')
}
this.loading = false;
})
},
stay global In file , Encapsulates the image address processing function
You can configure different addresses according to different environments , At present, it is the same
local.imgAddress = function (path) {
if(process.env.VUE_APP_MODE == 'production'){
return 'files/' + path
// return 'http://10.134.52.22/files/' + path
} else if(process.env.VUE_APP_MODE == 'test'|| process.env.VUE_APP_MODE == 'development'){
return 'files/' + path
// return 'http://10.11.1.22/files/' + path
}
}
1.3.2 Submit and process all picture addresses
let mdVal = this.gb.mdImgmap2Url(self.content, this.mdImgMap)
global In file , Encapsulated will markdown Replace multiple pictures in the document with picture links ( Key value pair )
local.mdImgmap2Url = function (mdValue, imgMap) {
if (imgMap instanceof Object) {
for (let key in imgMap) {
mdValue = local.mdImg2Url(mdValue, key, imgMap[key])
}
}
return mdValue
}
Because the back end is put xss Handle , therefore <'/ When translated , Front end with v-html Display processing
1.3 Preview page
<mavon-editor
id="articleContentPanel"
class="md"
:value="gb.escape2Html(detail.content)"
:subfield="false"
:defaultOpen="'preview'"
:toolbarsFlag="false"
:editable="false"
:scrollStyle="true"
:ishljs="true"
:boxShadow="false"
:externalLink="false"
:previewBackground="'#ffffff'"
></mavon-editor>
The two processing contents here have translation problems , One is the function of encapsulation , One is v-html( It may not be completely resolved )
1.3.1 v-html Method
// Put the following code in the page
<div style="display: none" id="eidtHtml" v-html="detail.content"></div>
// Process the interface request after it succeeds
setTimeout(function () {
let getHtmlVal = $('#eidtHtml').html();
self.content = getHtmlVal;
},200)
1.3.2 Self encapsulation function
global In file
local.escape2Html = function(str) {
var arrEntities={
'lt':'<','gt':'>','nbsp':' ','amp':'&','#92':'\\\\','#x2f':'/','quot':'\\"','#x27':'\'','#35':'#'};
return str.replace(/&(lt|gt|nbsp|amp|quot|#92|#x2f|#x27|#35);/ig,function(all,t){
return arrEntities[t];
});
}
ts Use
The introduction method is the same
setup-return Configuration menu in
The address of processing pictures is different
const handleEditorDetailImgAdd = async (pos: any, file: any) => {
let name = file.name// file name
let formData = new FormData()
formData.append("file", file)
const result = await store.dispatch("bugsModule/uploadImage", formData)
if (result.ok) {
let oStr = `(${
pos})`// Serial number
let nStrShow = `(${
store.state.globalModule.prefixPath}/${
result.filePath})`// Address
let index = formState.detail.indexOf(oStr)
let str = formState.detail.replace(oStr, "")
let insertStr = (source: any, start: any, newStr: any) => {
return source.slice(0, start) + newStr + source.slice(start)
}
formState.detail = insertStr(str, index, nStrShow)
}
}
stay store Next modules in global Under the document idnex.ts in , Encapsulate the image path
import {
Module } from 'vuex';
import RootStateTypes from '@/store/interface';
import {
GlobalModuleTypes,
} from '@/store/modules/global/interface';
const globalModule: Module<GlobalModuleTypes, RootStateTypes> = {
namespaced: true,
state: {
prefixPath: [],
},
mutations: {
getPrefixPath(state, data) {
state.prefixPath = data
}
},
actions: {
async getImagePrefix({
commit }) {
try {
let path = '';
if (process.env.VUE_APP_MODE === 'production') {
path = 'files';
} else {
path = 'files';
}
commit("getPrefixPath", path)
} catch (error) {
console.log("globalModule action getImagePrefix error: ", error);
}
},
},
modules: {
}
}
export default globalModule;
interface.ts In file
export interface GlobalModuleTypes {
prefixPath: string[];
}
边栏推荐
- Cf/atc/lc topic score website
- Atcoder beginer contest 240 g.reporting Takahashi (classical problems of Combinatorial Mathematics)
- 异步FIFO基本原理(基于Verilog的简单实现)
- Reasoning Over Semantic-Level Graph for Fact Checking
- Soft exam review summary
- 《Kubernetes》你需要掌握的 Service 和 Ingress
- 【impala】【报错解决】 Impala cannot read or execute the parent directory of dfs.domain.socket.path的解决方法
- MySQL数据库增删改查(基础操作命令详解)
- Selection and application of inductors in high speed circuits
- [kibana] problem sorting kibana 7.x no indices match pattern "APM-*“
猜你喜欢

微服务架构-服务注册中心和服务网关(6.8) (转载)

net框架

Verilog daily question (vl24 multi bit MUX synchronizer cross time domain output)

Goweb开发之Beego框架实战:第四节 数据库配置及连接

Wechat applet cash red packet returns the error "the IP address is not the available IP address you set on the merchant platform". The ultimate solution

Goweb开发之Beego框架实战:第四节 数据库配置及连接

微信小程序现金红包返回“IP地址非你在商户平台设置的可用IP地址”错误终极解决方法

Jupyter notebook win installation record

The practice of the beego framework of goweb development: Section II project initialization configuration

How do we do full link grayscale on the database?
随机推荐
连接设计与测试平台——SystemVerilog 接口知识点总结
Verilog 每日一题(VL8 使用generate…for语句简化代码)
Selection of resistance in high speed circuit
Linear algebra and matrix theory (10)
Encountered.Sqlite file processing during Android Development
Batch download files
全链路灰度在数据库上我们是怎么做的?
Verilog 每日一题 (VL5 信号发生器)
解决SQL Server数据库独占的问题
C# 导入Excel文件数据的几种方法
Selection and application of inductors in high speed circuits
Verilog daily question (vl29 single port RAM)
Gray code and binary conversion and typical examples (4bits gray code counter)
Steps to configure V530 switch
【kibana】问题整理 kibana 7.x No indices match pattern “apm-*“
SNAT、DNAT 防火墙规则的备份和还原
Role of Fortress machine
MySQL数据库增删改查(基础操作命令详解)
Code implementation additive attention
Self study examination in April 2021