mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-26 12:57:42 +08:00
1 line
18 KiB
JavaScript
1 line
18 KiB
JavaScript
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d0c191e"],{4738:function(v,e,t){"use strict";t.r(e);var s=function(){var v=this;v._self._c;return v._m(0)},_=[function(){var v=this,e=v._self._c;return e("div",[e("h1",[v._v("内置工具方法")]),e("h2",[v._v("基础工具方法")]),e("p",[v._v("引用:")]),e("pre",{staticClass:"hljs"},[e("code",[e("span",{staticClass:"hljs-keyword"},[v._v("import")]),v._v(" {walk, ...} "),e("span",{staticClass:"hljs-keyword"},[v._v("from")]),v._v(" "),e("span",{staticClass:"hljs-string"},[v._v("'simple-mind-map/src/utils'")]),v._v("\n")])]),e("h3",[v._v("方法")]),e("h4",[v._v("resizeImgSizeByOriginRatio(width, height, newWidth, newHeight)")]),e("blockquote",[e("p",[v._v("v0.6.5+")])]),e("p",[e("code",[v._v("width")]),v._v(": 图片原始的宽度")]),e("p",[e("code",[v._v("height")]),v._v(":图片原始的高度")]),e("p",[e("code",[v._v("newWidth")]),v._v(":要缩放到的宽度")]),e("p",[e("code",[v._v("newHeight")]),v._v(":要缩放到的高度")]),e("p",[v._v("按比例缩放图片。在保持图片原始宽高比的情况下缩放到指定的"),e("code",[v._v("newWidth")]),v._v("、"),e("code",[v._v("newHeight")]),v._v("大小。")]),e("h4",[v._v("walk(root, parent, beforeCallback, afterCallback, isRoot, layerIndex = 0, index = 0)")]),e("p",[v._v("深度优先遍历树")]),e("p",[e("code",[v._v("root")]),v._v(":要遍历的树的根节点")]),e("p",[e("code",[v._v("parent")]),v._v(":父节点")]),e("p",[e("code",[v._v("beforeCallback")]),v._v(":前序遍历回调函数,回调参数为:root, parent, isRoot, layerIndex, index")]),e("p",[e("code",[v._v("afterCallback")]),v._v(":后序遍历回调函数,回调参数为:root, parent, isRoot, layerIndex, index")]),e("p",[e("code",[v._v("isRoot")]),v._v(":是否是根节点")]),e("p",[e("code",[v._v("layerIndex")]),v._v(":节点层级")]),e("p",[e("code",[v._v("index")]),v._v(":节点在同级节点里的索引")]),e("p",[v._v("示例:")]),e("pre",{staticClass:"hljs"},[e("code",[v._v("walk(tree, "),e("span",{staticClass:"hljs-literal"},[v._v("null")]),v._v(", "),e("span",{staticClass:"hljs-function"},[v._v("() =>")]),v._v(" {}, "),e("span",{staticClass:"hljs-function"},[v._v("() =>")]),v._v(" {}, "),e("span",{staticClass:"hljs-literal"},[v._v("false")]),v._v(", "),e("span",{staticClass:"hljs-number"},[v._v("0")]),v._v(", "),e("span",{staticClass:"hljs-number"},[v._v("0")]),v._v(")\n")])]),e("h4",[v._v("bfsWalk(root, callback)")]),e("p",[v._v("广度优先遍历树")]),e("h4",[v._v("resizeImgSize(width, height, maxWidth, maxHeight)")]),e("p",[v._v("缩放图片的尺寸")]),e("p",[e("code",[v._v("width")]),v._v(":图片原本的宽")]),e("p",[e("code",[v._v("height")]),v._v(":图片原本的高")]),e("p",[e("code",[v._v("maxWidth")]),v._v(":要缩放到的宽")]),e("p",[e("code",[v._v("maxHeight")]),v._v(":要缩放到的高")]),e("p",[e("code",[v._v("maxWidth")]),v._v("和"),e("code",[v._v("maxHeight")]),v._v("可以同时都传,也可以只传一个")]),e("h4",[v._v("resizeImg(imgUrl, maxWidth, maxHeight)")]),e("p",[v._v("缩放图片,内部先加载图片,然后调用"),e("code",[v._v("resizeImgSize")]),v._v("方法,返回一个"),e("code",[v._v("promise")])]),e("h4",[v._v("simpleDeepClone(data)")]),e("p",[v._v("极简的深拷贝方法,只能针对全是基本数据的对象,否则会报错")]),e("h4",[v._v("copyRenderTree(tree, root)")]),e("p",[v._v("复制渲染树数据,示例:")]),e("pre",{staticClass:"hljs"},[e("code",[v._v("copyRenderTree({}, "),e("span",{staticClass:"hljs-built_in"},[v._v("this")]),v._v(".mindMap.renderer.renderTree)\n")])]),e("h4",[v._v("copyNodeTree(tree, root, removeActiveState, removeId)")]),e("ul",[e("li",[e("p",[e("code",[v._v("removeActiveState")]),v._v(":"),e("code",[v._v("Boolean")]),v._v(",默认为"),e("code",[v._v("false")]),v._v(",是否移除节点的激活状态")])]),e("li",[e("p",[e("code",[v._v("removeId")]),v._v(":v0.7.3-fix.1+,是否移除节点数据中的uid,默认为"),e("code",[v._v("true")])])])]),e("blockquote",[e("ul",[e("li",[e("code",[v._v("keepId")]),v._v(": (原第四个参数)"),e("code",[v._v("Boolean")]),v._v(",默认为"),e("code",[v._v("false")]),v._v(",是否保留被复制节点的"),e("code",[v._v("id")]),v._v(",默认会删除"),e("code",[v._v("id")]),v._v("防止节点"),e("code",[v._v("id")]),v._v("重复,但是对于移动节点的场景,节点原"),e("code",[v._v("id")]),v._v("需要保留。")])])]),e("p",[v._v("复制节点树数据,主要是剔除其中的引用"),e("code",[v._v("node")]),v._v("实例的"),e("code",[v._v("_node")]),v._v(",然后复制"),e("code",[v._v("data")]),v._v("对象的数据,示例:")]),e("pre",{staticClass:"hljs"},[e("code",[v._v("copyNodeTree({}, node)\n")])]),e("h4",[v._v("imgToDataUrl(src)")]),e("p",[v._v("图片转成dataURL")]),e("h4",[v._v("downloadFile(file, fileName)")]),e("p",[v._v("下载文件")]),e("h4",[v._v("throttle(fn, time = 300, ctx)")]),e("p",[v._v("节流函数")]),e("h4",[v._v("asyncRun(taskList, callback = () => {})")]),e("p",[v._v("异步执行任务队列,多个任务是同步执行的,没有先后顺序")]),e("h4",[v._v("degToRad(deg)")]),e("blockquote",[e("p",[v._v("v0.2.24+")])]),e("p",[v._v("角度转弧度")]),e("h4",[v._v("camelCaseToHyphen(str)")]),e("blockquote",[e("p",[v._v("v0.2.24+")])]),e("p",[v._v("驼峰转连字符")]),e("h4",[v._v("joinFontStr({ italic, bold, fontSize, fontFamily })")]),e("blockquote",[e("p",[v._v("v0.3.4+")])]),e("p",[v._v("拼接"),e("code",[v._v("css")]),v._v("字体的"),e("code",[v._v("font")]),v._v("属性值")]),e("h4",[v._v("measureText(text, { italic, bold, fontSize, fontFamily })")]),e("blockquote",[e("p",[v._v("v0.3.4+")])]),e("p",[v._v("测量文本的宽高,返回值:")]),e("pre",{staticClass:"hljs"},[e("code",[v._v("{ width, height }\n")])]),e("h4",[v._v("getTextFromHtml(html)")]),e("p",[v._v("提取html字符串里的纯文本内容。")]),e("h4",[v._v("readBlob(blob)")]),e("blockquote",[e("p",[v._v("v0.5.9+")])]),e("p",[v._v("将"),e("code",[v._v("blob")]),v._v("数据转成"),e("code",[v._v("data:url")]),v._v("数据。")]),e("h4",[v._v("parseDataUrl(data)")]),e("blockquote",[e("p",[v._v("v0.6.6+")])]),e("p",[v._v("解析"),e("code",[v._v("data:url")]),v._v("数据,返回:")]),e("pre",{staticClass:"hljs"},[e("code",[v._v("{\n type,"),e("span",{staticClass:"hljs-comment"},[v._v("// 数据的文件类型")]),v._v("\n base64"),e("span",{staticClass:"hljs-comment"},[v._v("// base64数据")]),v._v("\n}\n")])]),e("h4",[v._v("getImageSize(src)")]),e("blockquote",[e("p",[v._v("v0.6.6+")])]),e("ul",[e("li",[e("code",[v._v("src")]),v._v(":图片的url")])]),e("p",[v._v("获取图片的大小。返回:")]),e("pre",{staticClass:"hljs"},[e("code",[v._v("{\n width,\n height\n}\n")])]),e("h4",[v._v("loadImage(imgFile)")]),e("blockquote",[e("p",[v._v("v0.6.8+")])]),e("ul",[e("li",[e("code",[v._v("imgFile")]),v._v(":图片类型的File对象")])]),e("p",[v._v("加载图片,返回:")]),e("pre",{staticClass:"hljs"},[e("code",[v._v("{\n url,"),e("span",{staticClass:"hljs-comment"},[v._v("// DataUrl")]),v._v("\n size"),e("span",{staticClass:"hljs-comment"},[v._v("// { width, height } 图片宽高")]),v._v("\n}\n")])]),e("h4",[v._v("getType(data)")]),e("blockquote",[e("p",[v._v("v0.6.9+")])]),e("p",[v._v("获取一个数据的类型,比如"),e("code",[v._v("Boolean")]),v._v("、"),e("code",[v._v("Array")]),v._v("等。")]),e("h4",[v._v("removeHtmlStyle(html)")]),e("blockquote",[e("p",[v._v("v0.6.10+")])]),e("p",[v._v("移除html字符串中节点的内联样式。")]),e("h4",[v._v("addHtmlStyle(html, tag, style)")]),e("blockquote",[e("p",[v._v("v0.6.10+")])]),e("p",[v._v("给html标签中指定的标签添加内联样式。")]),e("h4",[v._v("checkIsRichText(str)")]),e("blockquote",[e("p",[v._v("v0.6.10+")])]),e("p",[v._v("检查一个字符串是否是富文本字符。")]),e("h4",[v._v("isWhite(color)")]),e("blockquote",[e("p",[v._v("v0.6.11+")])]),e("p",[v._v("判断一个颜色是否是白色。")]),e("h4",[v._v("isTransparent(color)")]),e("blockquote",[e("p",[v._v("v0.6.11+")])]),e("p",[v._v("判断一个颜色是否是透明。")]),e("h4",[v._v("nodeRichTextToTextWithWrap(html)")]),e("blockquote",[e("p",[v._v("v0.6.12+")])]),e("p",[v._v("将"),e("code",[v._v("<p><span></span><p>")]),v._v("形式的节点富文本内容转换成"),e("code",[v._v("\\n")]),v._v("换行的文本。")]),e("h4",[v._v("textToNodeRichTextWithWrap(html)")]),e("blockquote",[e("p",[v._v("v0.6.12+")])]),e("p",[v._v("将"),e("code",[v._v("<br>")]),v._v("换行的文本转换成"),e("code",[v._v("<p><span></span><p>")]),v._v("形式的节点富文本内容。")]),e("h4",[v._v("isMobile()")]),e("blockquote",[e("p",[v._v("v0.6.13+")])]),e("p",[v._v("判断是否是移动端环境。")]),e("h4",[v._v("getTopAncestorsFomNodeList(list)")]),e("blockquote",[e("p",[v._v("v0.7.2+")])]),e("ul",[e("li",[e("code",[v._v("list")]),v._v(":Arrray,节点实例列表。")])]),e("p",[v._v("从节点实例列表里找出最顶层的节点列表。")]),e("h4",[v._v("checkTwoRectIsOverlap(minx1, maxx1, miny1, maxy1, minx2, maxx2, miny2, maxy2)")]),e("blockquote",[e("p",[v._v("v0.7.2+")])]),e("p",[v._v("参数为两个矩形的位置。")]),e("p",[v._v("判断两个矩形是否重叠。")]),e("h4",[v._v("focusInput(el)")]),e("blockquote",[e("p",[v._v("v0.7.2+")])]),e("ul",[e("li",[e("code",[v._v("el")]),v._v(":DOM节点,可聚焦的元素,一般为输入框元素。")])]),e("p",[v._v("聚焦指定输入框。")]),e("h4",[v._v("selectAllInput(el)")]),e("blockquote",[e("p",[v._v("v0.7.2+")])]),e("ul",[e("li",[e("code",[v._v("el")]),v._v(":DOM节点,可聚焦的元素,一般为输入框元素。")])]),e("p",[v._v("聚焦并全选指定输入框。")]),e("h4",[v._v("addDataToAppointNodes(appointNodes, data = {})")]),e("blockquote",[e("p",[v._v("v0.7.2+")])]),e("ul",[e("li",[e("p",[e("code",[v._v("appointNodes")]),v._v(":节点实例列表,数组类型。")])]),e("li",[e("p",[e("code",[v._v("data")]),v._v(":要附加到指定节点实例列表树中所有节点的数据中的数据。")])])]),e("p",[v._v("给指定的节点列表树数据添加附加数据,会修改原数据。")]),e("h4",[v._v("createUidForAppointNodes(appointNodes, createNewId)")]),e("blockquote",[e("p",[v._v("v0.7.2+")])]),e("ul",[e("li",[e("p",[e("code",[v._v("appointNodes")]),v._v(":节点实例列表,数组类型。")])]),e("li",[e("p",[e("code",[v._v("createNewId")]),v._v(":v0.7.3-fix.1+,"),e("code",[v._v("Boolean")]),v._v(",默认为"),e("code",[v._v("false")]),v._v(",即如果节点不存在"),e("code",[v._v("uid")]),v._v("的话,会创建新的"),e("code",[v._v("uid")]),v._v("。如果传"),e("code",[v._v("true")]),v._v(",那么无论节点数据原来是否存在"),e("code",[v._v("uid")]),v._v(",都会创建新的"),e("code",[v._v("uid")])])])]),e("p",[v._v("给指定的节点列表树数据添加uid(如果uid不存在的话),会修改原数据。")]),e("h4",[v._v("getNodeIndex(node)")]),e("blockquote",[e("p",[v._v("v0.7.2+")])]),e("ul",[e("li",[e("code",[v._v("node")]),v._v(":节点实例。")])]),e("p",[v._v("获取节点在同级里的位置索引。")]),e("h4",[v._v("mergerIconList(list)")]),e("blockquote",[e("p",[v._v("v0.7.2+")])]),e("ul",[e("li",[e("code",[v._v("list")]),v._v(":要合并到库内部的节点图标数组。")])]),e("pre",{staticClass:"hljs"},[e("code",[e("span",{staticClass:"hljs-comment"},[v._v("// const data = [")]),v._v("\n"),e("span",{staticClass:"hljs-comment"},[v._v("// { type: 'priority', name: '优先级图标', list: [{ name: '1', icon: 'a' }, { name: 2, icon: 'b' }] },")]),v._v("\n"),e("span",{staticClass:"hljs-comment"},[v._v("// { type: 'priority', name: '优先级图标', list: [{ name: '2', icon: 'c' }, { name: 3, icon: 'd' }] },")]),v._v("\n"),e("span",{staticClass:"hljs-comment"},[v._v("// ];")]),v._v("\n\n"),e("span",{staticClass:"hljs-comment"},[v._v("// mergerIconList(data) 结果")]),v._v("\n\n"),e("span",{staticClass:"hljs-comment"},[v._v("// [")]),v._v("\n"),e("span",{staticClass:"hljs-comment"},[v._v("// { type: 'priority', name: '优先级图标', list: [{ name: '1', icon: 'a' }, { name: 2, icon: 'c' }, { name: 3, icon: 'd' }] },")]),v._v("\n"),e("span",{staticClass:"hljs-comment"},[v._v("// ]")]),v._v("\n")])]),e("p",[v._v("合并图标数组。")]),e("h4",[v._v("generateColorByContent(str)")]),e("blockquote",[e("p",[v._v("v0.7.2+")])]),e("ul",[e("li",[e("code",[v._v("str")]),v._v(":字符串。")])]),e("p",[v._v("根据传入的内容生成颜色,同样的内容会生成同样的颜色。")]),e("h4",[v._v("htmlEscape(str)")]),e("blockquote",[e("p",[v._v("v0.7.2+")])]),e("ul",[e("li",[e("code",[v._v("str")]),v._v(":字符串。")])]),e("p",[v._v("转义传入的字符串,目前会转义如下三个字符:")]),e("pre",{staticClass:"hljs"},[e("code",[v._v("& -> &\n< -> <\n> -> >\n")])]),e("h4",[v._v("isSameObject(a, b)")]),e("blockquote",[e("p",[v._v("v0.7.3+")])]),e("ul",[e("li",[e("code",[v._v("a")]),v._v("、"),e("code",[v._v("b")]),v._v(":Object | Array, 要进行对比的两个对象")])]),e("p",[v._v("判断两个对象是否相同,只处理对象或数组。")]),e("h4",[v._v("getNodeDataIndex(node)")]),e("blockquote",[e("p",[v._v("v0.8.0+")])]),e("p",[v._v("获取节点在兄弟节点中的位置索引。")]),e("h4",[v._v("getNodeIndexInNodeList(node, nodeList)")]),e("blockquote",[e("p",[v._v("v0.8.0+")])]),e("p",[v._v("从一个节点列表里找出某个节点的索引。")]),e("h4",[v._v("setDataToClipboard(data)")]),e("blockquote",[e("p",[v._v("v0.8.0+")])]),e("ul",[e("li",[e("code",[v._v("data")]),v._v(":Object | Array")])]),e("p",[v._v("将数据设置到用户剪切板中。")]),e("h4",[v._v("getDataFromClipboard()")]),e("blockquote",[e("p",[v._v("v0.8.0+")])]),e("p",[v._v("从用户剪贴板中读取文字和图片,返回:")]),e("pre",{staticClass:"hljs"},[e("code",[v._v("{\n text,\n img\n}\n")])]),e("h4",[v._v("removeFromParentNodeData(node)")]),e("blockquote",[e("p",[v._v("v0.8.0+")])]),e("p",[v._v("从节点的父节点的"),e("code",[v._v("nodeData.children")]),v._v("列表中移除该节点的数据。")]),e("h4",[v._v("checkHasSupSubRelation()")]),e("blockquote",[e("p",[v._v("v0.8.1+")])]),e("p",[v._v("从给定的节点实例列表里判断是否存在上下级关系。")]),e("h4",[v._v("handleSelfCloseTags(str)")]),e("blockquote",[e("p",[v._v("v0.9.1+")])]),e("ul",[e("li",[e("code",[v._v("str")]),v._v(":html字符串")])]),e("p",[v._v("给html自闭合标签添加闭合状态,"),e("code",[v._v('<div><img src="xxx"></div>')]),v._v(" -> "),e("code",[v._v('<div><img src="xxx" /></div>')]),v._v("。")]),e("h4",[v._v("checkNodeListIsEqual(list1, list2)")]),e("blockquote",[e("p",[v._v("v0.9.1+")])]),e("ul",[e("li",[e("code",[v._v("list1/list2")]),v._v(":节点实例列表")])]),e("p",[v._v("检查两个节点实例列表包含的节点是否是一样的。")]),e("h2",[v._v("在canvas中模拟css的背景属性")]),e("p",[v._v("引入:")]),e("pre",{staticClass:"hljs"},[e("code",[e("span",{staticClass:"hljs-keyword"},[v._v("import")]),v._v(" drawBackgroundImageToCanvas "),e("span",{staticClass:"hljs-keyword"},[v._v("from")]),v._v(" "),e("span",{staticClass:"hljs-string"},[v._v("'simple-mind-map/src/utils/simulateCSSBackgroundInCanvas'")]),v._v("\n")])]),e("p",[v._v("使用:")]),e("pre",{staticClass:"hljs"},[e("code",[e("span",{staticClass:"hljs-keyword"},[v._v("let")]),v._v(" width = "),e("span",{staticClass:"hljs-number"},[v._v("500")]),v._v("\n"),e("span",{staticClass:"hljs-keyword"},[v._v("let")]),v._v(" height = "),e("span",{staticClass:"hljs-number"},[v._v("500")]),v._v("\n"),e("span",{staticClass:"hljs-keyword"},[v._v("let")]),v._v(" img = "),e("span",{staticClass:"hljs-string"},[v._v("'/1.jpg'")]),v._v("\n"),e("span",{staticClass:"hljs-keyword"},[v._v("let")]),v._v(" canvas = "),e("span",{staticClass:"hljs-built_in"},[v._v("document")]),v._v(".createElement("),e("span",{staticClass:"hljs-string"},[v._v("'canvas'")]),v._v(")\ncanvas.width = width\ncanvas.height = height\ndrawBackgroundImageToCanvas(ctx, width, height, img, {\n "),e("span",{staticClass:"hljs-attr"},[v._v("backgroundRepeat")]),v._v(": "),e("span",{staticClass:"hljs-string"},[v._v("'repeat-y'")]),v._v(",\n "),e("span",{staticClass:"hljs-attr"},[v._v("backgroundSize")]),v._v(": "),e("span",{staticClass:"hljs-string"},[v._v("'60%'")]),v._v(",\n "),e("span",{staticClass:"hljs-attr"},[v._v("backgroundPosition")]),v._v(": "),e("span",{staticClass:"hljs-string"},[v._v("'center center'")]),v._v("\n}, "),e("span",{staticClass:"hljs-function"},[v._v("("),e("span",{staticClass:"hljs-params"},[v._v("err")]),v._v(") =>")]),v._v(" {\n "),e("span",{staticClass:"hljs-keyword"},[v._v("if")]),v._v(" (err) {\n "),e("span",{staticClass:"hljs-comment"},[v._v("// 失败")]),v._v("\n } "),e("span",{staticClass:"hljs-keyword"},[v._v("else")]),v._v(" {\n "),e("span",{staticClass:"hljs-comment"},[v._v("// 成功")]),v._v("\n }\n})\n")])]),e("h2",[v._v("LRU缓存类")]),e("blockquote",[e("p",[v._v("v0.5.10+")])]),e("p",[v._v("引入:")]),e("pre",{staticClass:"hljs"},[e("code",[e("span",{staticClass:"hljs-keyword"},[v._v("import")]),v._v(" Lru "),e("span",{staticClass:"hljs-keyword"},[v._v("from")]),v._v(" "),e("span",{staticClass:"hljs-string"},[v._v("'simple-mind-map/src/utils/Lru.js'")]),v._v("\n")])]),e("h3",[v._v("构造函数")]),e("pre",{staticClass:"hljs"},[e("code",[e("span",{staticClass:"hljs-keyword"},[v._v("let")]),v._v(" lru = "),e("span",{staticClass:"hljs-keyword"},[v._v("new")]),v._v(" Lru(max)\n")])]),e("p",[e("code",[v._v("max")]),v._v(":指定最大缓存数量。")]),e("h3",[v._v("实例属性")]),e("h4",[v._v("size")]),e("p",[v._v("当前缓存的数量。")]),e("h4",[v._v("pool")]),e("p",[v._v("获取缓存池。")]),e("h3",[v._v("实例方法")]),e("h4",[v._v("add(key, value)")]),e("p",[v._v("添加缓存。")]),e("h4",[v._v("delete(key)")]),e("p",[v._v("删除指定缓存。")]),e("h4",[v._v("has(key)")]),e("p",[v._v("检查某个缓存是否存在。")]),e("h4",[v._v("get(key)")]),e("p",[v._v("获取某个缓存的值。")]),e("h4",[v._v("clear()")]),e("blockquote",[e("p",[v._v("v0.9.2+")])]),e("p",[v._v("清空缓存池。")])])}],a={},o=a,l=t("2877"),c=Object(l["a"])(o,s,_,!1,null,null,null);e["default"]=c.exports}}]); |