@@ -61,10 +61,6 @@ export default {
6161 type: Array ,
6262 default : () => []
6363 },
64- clearRecovery: { // 清空搜索关键词时, 是否复原排序顺序
65- type: Boolean ,
66- default: false
67- },
6864 props: { // 配置项
6965 type: Object ,
7066 default : () => {
@@ -104,14 +100,17 @@ export default {
104100 _search (val ) {
105101 clearTimeout (this .timer )
106102 this .timer = setTimeout (_ => {
107- if (val || ! this .clearRecovery ) return this .deepData = this ._getLdqTree (this .deepData )
103+ if (val) return this .deepData = this ._getLdqTree (this .deepData )
104+ const keys = this .showCheckbox ? this .getCheckedKeys () : []
108105 /**
109- * 如果清空搜索关键词时, 开启了复原初始结构 clearRecovery = true 时
110- * 经测试 4k+ 的单一树节点卡顿在15秒左右, 建议分散处理可以降到2秒左右
106+ * 这里必须先清空数据, 再进行赋值, 不然会产生严重的性能问题
107+ * 很有可能是vue内部对多次赋值操作进行合并所产生的
111108 */
112- const keys = this .showCheckbox ? this .getCheckedKeys () : []
113- this .deepData = deepCopy (this .sourceData )
114- this .setCheckedByKeys (keys, true )
109+ this .deepData = []
110+ this .$nextTick (_ => {
111+ this .deepData = deepCopy (this .sourceData )
112+ this .setCheckedByKeys (keys, true )
113+ })
115114 }, this .searchDebounce )
116115 }
117116 },
@@ -199,12 +198,12 @@ export default {
199198 },
200199 _initData () { // 初始化数据
201200 const { children } = this .defaultProps
202- const _deep = (arr , parent ) => {
201+ const dfs = (arr , parent ) => {
203202 let checkedNum = 0 , anyOne = false
204203 arr .forEach (item => {
205204 this ._initNode (item, parent)
206205 checkedNum += + item .checked
207- item[children].length && _deep (item[children], item)
206+ item[children].length && dfs (item[children], item)
208207 item .expand && parent && (parent .expand = true )
209208 if (item .indeterminate ) anyOne = true
210209 })
@@ -215,7 +214,7 @@ export default {
215214 parent .indeterminate = anyOne || (!! checkedNum && checkedNum != arr .length ) || (! parent .checked && !! this ._preorder (arr, item => item .checked ))
216215 }
217216 }
218- _deep (this .sourceData )
217+ dfs (this .sourceData )
219218 const data = deepCopy (this .sourceData )
220219 this .deepData = this ._getLdqTree (data)
221220 },
0 commit comments