diff --git a/simple-mind-map/index.js b/simple-mind-map/index.js index 27c182e2..91f3b9cd 100644 --- a/simple-mind-map/index.js +++ b/simple-mind-map/index.js @@ -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 diff --git a/simple-mind-map/src/constants/constant.js b/simple-mind-map/src/constants/constant.js index f0046027..a4e8abf5 100644 --- a/simple-mind-map/src/constants/constant.js +++ b/simple-mind-map/src/constants/constant.js @@ -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纸的宽高 diff --git a/simple-mind-map/src/plugins/Export.js b/simple-mind-map/src/plugins/Export.js index 32a89fdf..31d2d3bc 100644 --- a/simple-mind-map/src/plugins/Export.js +++ b/simple-mind-map/src/plugins/Export.js @@ -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(``) - ) + foreignObjectList[0].add(SVG(``)) isAddResetCss = true } }