From cd4f1b1bd8470423f5607ede7cb717c878bcb1f6 Mon Sep 17 00:00:00 2001
From: wanglin2 <1013335014@qq.com>
Date: Fri, 28 Jul 2023 17:34:55 +0800
Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E6=90=9C=E7=B4=A2=E6=94=AF?=
=?UTF-8?q?=E6=8C=81=E6=90=9C=E7=B4=A2=E7=A9=BA=E7=99=BD=E5=AD=97=E7=AC=A6?=
=?UTF-8?q?=E5=92=8C=E6=9B=BF=E6=8D=A2=E4=B8=BA=E7=A9=BA=E7=99=BD=E5=AD=97?=
=?UTF-8?q?=E7=AC=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
simple-mind-map/src/plugins/Search.js | 22 +++++++++++++++-------
simple-mind-map/src/utils/index.js | 5 +++++
web/src/pages/Edit/components/Search.vue | 7 +++++--
3 files changed, 25 insertions(+), 9 deletions(-)
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 @@