Feat:自定义处理剪贴板函数支持返回Promise实例
This commit is contained in:
parent
726ebc5e88
commit
2a8b71497f
@ -150,5 +150,6 @@ export const defaultOpt = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
// 如果你的处理逻辑存在异步逻辑,也可以返回一个promise
|
||||||
customHandleClipboardText: null
|
customHandleClipboardText: null
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,8 @@ import {
|
|||||||
simpleDeepClone,
|
simpleDeepClone,
|
||||||
walk,
|
walk,
|
||||||
bfsWalk,
|
bfsWalk,
|
||||||
loadImage
|
loadImage,
|
||||||
|
isUndef
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
import { shapeList } from './node/Shape'
|
import { shapeList } from './node/Shape'
|
||||||
import { lineStyleProps } from '../../themes/default'
|
import { lineStyleProps } from '../../themes/default'
|
||||||
@ -668,14 +669,23 @@ class Render {
|
|||||||
if (text) {
|
if (text) {
|
||||||
// 判断粘贴的是否是simple-mind-map的数据
|
// 判断粘贴的是否是simple-mind-map的数据
|
||||||
let smmData = null
|
let smmData = null
|
||||||
|
let useDefault = true
|
||||||
|
// 用户自定义处理
|
||||||
if (this.mindMap.opt.customHandleClipboardText) {
|
if (this.mindMap.opt.customHandleClipboardText) {
|
||||||
const res = this.mindMap.opt.customHandleClipboardText(text)
|
try {
|
||||||
if (typeof res === 'object' && res.simpleMindMap) {
|
const res = await this.mindMap.opt.customHandleClipboardText(text)
|
||||||
smmData = res.data
|
if (!isUndef(res)) {
|
||||||
} else {
|
useDefault = false
|
||||||
text = String(res)
|
if (typeof res === 'object' && res.simpleMindMap) {
|
||||||
}
|
smmData = res.data
|
||||||
} else {
|
} else {
|
||||||
|
text = String(res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {}
|
||||||
|
}
|
||||||
|
// 默认处理
|
||||||
|
if (useDefault) {
|
||||||
try {
|
try {
|
||||||
const parsedData = JSON.parse(text)
|
const parsedData = JSON.parse(text)
|
||||||
if (parsedData && parsedData.simpleMindMap) {
|
if (parsedData && parsedData.simpleMindMap) {
|
||||||
|
|||||||
@ -64,13 +64,13 @@ const transformXmind = async (content, files) => {
|
|||||||
}
|
}
|
||||||
// 图片
|
// 图片
|
||||||
if (node.image && /\.(jpg|jpeg|png|gif|webp)$/.test(node.image.src)) {
|
if (node.image && /\.(jpg|jpeg|png|gif|webp)$/.test(node.image.src)) {
|
||||||
|
// 处理异步逻辑
|
||||||
|
let resolve = null
|
||||||
|
let promise = new Promise(_resolve => {
|
||||||
|
resolve = _resolve
|
||||||
|
})
|
||||||
|
waitLoadImageList.push(promise)
|
||||||
try {
|
try {
|
||||||
// 处理异步逻辑
|
|
||||||
let resolve = null
|
|
||||||
let promise = new Promise(_resolve => {
|
|
||||||
resolve = _resolve
|
|
||||||
})
|
|
||||||
waitLoadImageList.push(promise)
|
|
||||||
// 读取图片
|
// 读取图片
|
||||||
let imageType = /\.([^.]+)$/.exec(node.image.src)[1]
|
let imageType = /\.([^.]+)$/.exec(node.image.src)[1]
|
||||||
let imageBase64 =
|
let imageBase64 =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user