mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-21 10:27:44 +08:00
Fix:修复切换主题时,换行的文本样式没有改变的问题
This commit is contained in:
parent
e6ede72169
commit
138cc4b3e8
@ -7,7 +7,8 @@ import {
|
||||
isWhite,
|
||||
getVisibleColorFromTheme,
|
||||
isUndef,
|
||||
checkSmmFormatData
|
||||
checkSmmFormatData,
|
||||
removeHtmlNodeByClass
|
||||
} from '../utils'
|
||||
import { CONSTANTS } from '../constants/constant'
|
||||
|
||||
@ -309,6 +310,8 @@ class RichText {
|
||||
// 获取当前正在编辑的内容
|
||||
getEditText() {
|
||||
let html = this.quill.container.firstChild.innerHTML
|
||||
// 去除ql-cursor节点
|
||||
html = removeHtmlNodeByClass(html, '.ql-cursor')
|
||||
// 去除最后的空行
|
||||
return html.replace(/<p><br><\/p>$/, '')
|
||||
}
|
||||
@ -488,7 +491,7 @@ class RichText {
|
||||
// 格式化当前选中的文本
|
||||
formatText(config = {}, clear = false, pure = false) {
|
||||
if (!this.range && !this.lastRange) return
|
||||
if(!pure) this.syncFormatToNodeConfig(config, clear)
|
||||
if (!pure) this.syncFormatToNodeConfig(config, clear)
|
||||
let rangeLost = !this.range
|
||||
let range = rangeLost ? this.lastRange : this.range
|
||||
clear
|
||||
@ -636,36 +639,6 @@ class RichText {
|
||||
}
|
||||
}
|
||||
|
||||
// 处理导出为图片
|
||||
async handleExportPng(node) {
|
||||
let el = document.createElement('div')
|
||||
el.style.position = 'absolute'
|
||||
el.style.left = '-9999999px'
|
||||
el.appendChild(node)
|
||||
this.mindMap.el.appendChild(el)
|
||||
// 遍历所有节点,将它们的margin和padding设为0
|
||||
let walk = root => {
|
||||
root.style.margin = 0
|
||||
root.style.padding = 0
|
||||
if (root.hasChildNodes()) {
|
||||
Array.from(root.children).forEach(item => {
|
||||
walk(item)
|
||||
})
|
||||
}
|
||||
}
|
||||
walk(node)
|
||||
|
||||
// 如果使用html2canvas
|
||||
// let canvas = await html2canvas(el, {
|
||||
// backgroundColor: null
|
||||
// })
|
||||
// return canvas.toDataURL()
|
||||
|
||||
const res = await domtoimage.toPng(el)
|
||||
this.mindMap.el.removeChild(el)
|
||||
return res
|
||||
}
|
||||
|
||||
// 将所有节点转换成非富文本节点
|
||||
transformAllNodesToNormalNode() {
|
||||
walk(
|
||||
|
||||
@ -535,6 +535,20 @@ export const replaceHtmlText = (html, searchText, replaceText) => {
|
||||
return replaceHtmlTextEl.innerHTML
|
||||
}
|
||||
|
||||
// 去除html字符串中指定选择器的节点,然后返回html字符串
|
||||
let removeHtmlNodeByClassEl = null
|
||||
export const removeHtmlNodeByClass = (html, selector) => {
|
||||
if (!removeHtmlNodeByClassEl) {
|
||||
removeHtmlNodeByClassEl = document.createElement('div')
|
||||
}
|
||||
removeHtmlNodeByClassEl.innerHTML = html
|
||||
const node = removeHtmlNodeByClassEl.querySelector(selector)
|
||||
if (node) {
|
||||
node.parentNode.removeChild(node)
|
||||
}
|
||||
return removeHtmlNodeByClassEl.innerHTML
|
||||
}
|
||||
|
||||
// 判断一个颜色是否是白色
|
||||
export const isWhite = color => {
|
||||
color = String(color).replaceAll(/\s+/g, '')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user