Fix:修复节点图片加载失败时导出图片也会失败的问题

This commit is contained in:
街角小林 2023-12-12 09:17:22 +08:00
parent 52600f6fdf
commit 2863c0404a
3 changed files with 12 additions and 8 deletions

View File

@ -495,7 +495,7 @@ class MindMap {
}
// 移除插件
;[...MindMap.pluginList].forEach(plugin => {
if (this[plugin.instanceName].beforePluginDestroy) {
if (this[plugin.instanceName] && this[plugin.instanceName].beforePluginDestroy) {
this[plugin.instanceName].beforePluginDestroy()
}
this[plugin.instanceName] = null

View File

@ -328,7 +328,8 @@ export const ERROR_TYPES = {
CUSTOM_HANDLE_CLIPBOARD_TEXT_ERROR: 'custom_handle_clipboard_text_error',
LOAD_CLIPBOARD_IMAGE_ERROR: 'load_clipboard_image_error',
BEFORE_TEXT_EDIT_ERROR: 'before_text_edit_error',
EXPORT_ERROR: 'export_error'
EXPORT_ERROR: 'export_error',
EXPORT_LOAD_IMAGE_ERROR: 'export_load_image_error'
}
// a4纸的宽高

View File

@ -9,7 +9,7 @@ import {
import { SVG } from '@svgdotjs/svg.js'
import drawBackgroundImageToCanvas from '../utils/simulateCSSBackgroundInCanvas'
import { transformToMarkdown } from '../parse/toMarkdown'
import { a4Size } from '../constants/constant'
import { a4Size, ERROR_TYPES } from '../constants/constant'
// 导出插件
class Export {
@ -47,7 +47,8 @@ class Export {
// 获取svg数据
async getSvgData() {
let { exportPaddingX, exportPaddingY } = this.mindMap.opt
let { exportPaddingX, exportPaddingY, errorHandler, resetCss } =
this.mindMap.opt
let { svg, svgHTML } = this.mindMap.getSvgData({
paddingX: exportPaddingX,
paddingY: exportPaddingY
@ -66,15 +67,17 @@ class Export {
return item.attr('src')
})
const taskList = [...task1, ...task2]
await Promise.all(taskList)
try {
await Promise.all(taskList)
} catch (error) {
errorHandler(ERROR_TYPES.EXPORT_LOAD_IMAGE_ERROR, error)
}
// 开启了节点富文本编辑,需要增加一些样式
let isAddResetCss
if (this.mindMap.richText) {
const foreignObjectList = svg.find('foreignObject')
if (foreignObjectList.length > 0) {
foreignObjectList[0].add(
SVG(`<style>${this.mindMap.opt.resetCss}</style>`)
)
foreignObjectList[0].add(SVG(`<style>${resetCss}</style>`))
isAddResetCss = true
}
}