From e4e31893db5fea91097380b86029d94ce25e7845 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Thu, 2 Apr 2020 10:07:42 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A9=BA=E6=A0=BC=E4=B8=8D=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/single/text.js | 21 ++++++++++++++------- src/core/alias.js | 5 ++--- src/css/base/tree/ztree.css | 2 +- src/less/base/tree/ztree.less | 2 +- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/base/single/text.js b/src/base/single/text.js index b5d819e5b4..c3457e85a3 100644 --- a/src/base/single/text.js +++ b/src/base/single/text.js @@ -55,7 +55,7 @@ BI.Text = BI.inherit(BI.Single, { } this.element.css({ textAlign: o.textAlign, - whiteSpace: o.whiteSpace, + whiteSpace: this._getTextWrap(), textOverflow: o.whiteSpace === "nowrap" ? "ellipsis" : "", overflow: o.whiteSpace === "nowrap" ? "" : (BI.isWidthOrHeight(o.height) ? "auto" : "") }); @@ -90,6 +90,17 @@ BI.Text = BI.inherit(BI.Single, { } }, + _getTextWrap: function () { + var o = this.options; + switch (o.whiteSpace) { + case "nowrap": + return "pre"; + case "normal": + default: + return "pre-wrap"; + } + }, + _getShowText: function () { var o = this.options; return BI.isFunction(o.text) ? o.text() : o.text; @@ -136,12 +147,8 @@ BI.Text = BI.inherit(BI.Single, { this.text.element.html(BI.htmlEncode(this._getShowText())); return; } - if (/\s/.test(text)) { - this.text.element[0].innerHTML = BI.htmlEncode(this._getShowText()); - } else { - // textContent性能更好,并且原生防xss - this.text.element[0].textContent = this._getShowText(); - } + // textContent性能更好,并且原生防xss + this.text.element[0].textContent = this._getShowText(); BI.isKey(this.options.keyword) && this.doRedMark(this.options.keyword); } }); diff --git a/src/core/alias.js b/src/core/alias.js index bcb82eef02..a41d967a4b 100644 --- a/src/core/alias.js +++ b/src/core/alias.js @@ -416,11 +416,10 @@ "&": "&", "\"": """, "<": "<", - ">": ">", - " ": " " + ">": ">" }; BI.htmlEncode = function (text) { - return BI.isNull(text) ? "" : BI.replaceAll(text + "", "&|\"|<|>|\\s", function (v) { + return BI.isNull(text) ? "" : BI.replaceAll(text + "", "&|\"|<|>", function (v) { return SPECIAL_TAGS[v] ? SPECIAL_TAGS[v] : " "; }); }; diff --git a/src/css/base/tree/ztree.css b/src/css/base/tree/ztree.css index f6f6668ca6..5f2d9413ad 100644 --- a/src/css/base/tree/ztree.css +++ b/src/css/base/tree/ztree.css @@ -12,7 +12,7 @@ list-style: none; line-height: 14px; text-align: left; - white-space: nowrap; + white-space: pre; outline: 0; } .ztree li ul { diff --git a/src/less/base/tree/ztree.less b/src/less/base/tree/ztree.less index 0b9cde391e..77e5fed2a3 100644 --- a/src/less/base/tree/ztree.less +++ b/src/less/base/tree/ztree.less @@ -16,7 +16,7 @@ list-style: none; line-height: 14px; text-align: left; - white-space: nowrap; + white-space: pre; outline: 0 }