diff --git a/simple-mind-map/src/plugins/Search.js b/simple-mind-map/src/plugins/Search.js index 58c2a29e..b83f7272 100644 --- a/simple-mind-map/src/plugins/Search.js +++ b/simple-mind-map/src/plugins/Search.js @@ -1,4 +1,4 @@ -import { bfsWalk, getTextFromHtml } from '../utils/index' +import { bfsWalk, getTextFromHtml, isUndef } from '../utils/index' // 搜索插件 class Search { @@ -30,8 +30,8 @@ class Search { // 搜索 search(text, callback) { - text = String(text).trim() - if (!text) return this.endSearch() + if (isUndef(text)) return this.endSearch() + text = String(text) this.isSearching = true if (this.searchText === text) { // 和上一次搜索文本一样,那么搜索下一个 @@ -89,9 +89,13 @@ class Search { // 替换当前节点 replace(replaceText) { - replaceText = String(replaceText).trim() - if (!replaceText || !this.isSearching || this.matchNodeList.length <= 0) + if ( + isUndef(replaceText) || + !this.isSearching || + this.matchNodeList.length <= 0 + ) return + replaceText = String(replaceText) let currentNode = this.matchNodeList[this.currentIndex] if (!currentNode) return let text = this.getReplacedText(currentNode, this.searchText, replaceText) @@ -110,9 +114,13 @@ class Search { // 替换所有 replaceAll(replaceText) { - replaceText = String(replaceText).trim() - if (!replaceText || !this.isSearching || this.matchNodeList.length <= 0) + if ( + isUndef(replaceText) || + !this.isSearching || + this.matchNodeList.length <= 0 + ) return + replaceText = String(replaceText) this.matchNodeList.forEach(node => { let text = this.getReplacedText(node, this.searchText, replaceText) this.mindMap.renderer.setNodeDataRender( diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index 886e5385..453f2259 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -465,4 +465,9 @@ export const removeHTMLEntities = (str) => { // 获取一个数据的类型 export const getType = (data) => { return Object.prototype.toString.call(data).slice(7, -1) +} + +// 判断一个数据是否是null和undefined和空字符串 +export const isUndef = (data) => { + return data === null || data === undefined || data === '' } \ No newline at end of file diff --git a/web/src/pages/Edit/components/Search.vue b/web/src/pages/Edit/components/Search.vue index 396ac1fe..70f8870a 100644 --- a/web/src/pages/Edit/components/Search.vue +++ b/web/src/pages/Edit/components/Search.vue @@ -15,7 +15,7 @@ {{ $t('search.replace') }} @@ -49,6 +49,7 @@